diff --git a/app/src/main/java/com/gh/common/util/CommentUtils.java b/app/src/main/java/com/gh/common/util/CommentUtils.java index 20d7c83fe2..83eb65c0f8 100644 --- a/app/src/main/java/com/gh/common/util/CommentUtils.java +++ b/app/src/main/java/com/gh/common/util/CommentUtils.java @@ -19,6 +19,7 @@ import com.gh.gamecenter.adapter.viewholder.CommentViewHolder; import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.UserDataEntity; import com.gh.gamecenter.entity.UserInfoEntity; +import com.gh.gamecenter.manager.UserManager; import com.lightgame.utils.Utils; import org.json.JSONException; @@ -283,7 +284,7 @@ public class CommentUtils { } //检查是否是自身评论 - UserInfoEntity userInfo = LoginUtils.getUserInfo(mContext); + UserInfoEntity userInfo = UserManager.getInstance().getUserInfoEntity(); if (userDataEntity != null && userDataEntity.isCommentOwn() && userInfo != null) { holder.commentUserNameTv.setText(userInfo.getName()); ImageUtils.Companion.display(holder.commentUserIconDv, userInfo.getIcon()); diff --git a/app/src/main/java/com/gh/common/util/LoginUtils.java b/app/src/main/java/com/gh/common/util/LoginUtils.java index d45acc3ec3..6930bbfcd7 100644 --- a/app/src/main/java/com/gh/common/util/LoginUtils.java +++ b/app/src/main/java/com/gh/common/util/LoginUtils.java @@ -1,38 +1,25 @@ package com.gh.common.util; -import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import android.text.TextUtils; -import com.gh.gamecenter.R; -import com.gh.gamecenter.entity.LoginResponseEntity; import com.gh.gamecenter.entity.UserInfoEntity; import com.gh.gamecenter.eventbus.EBReuse; -import com.gh.gamecenter.manager.RefreshTokenManager; -import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.personal.PersonalFragment; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.lightgame.utils.Utils; import org.greenrobot.eventbus.EventBus; import org.json.JSONException; import org.json.JSONObject; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - import okhttp3.MediaType; import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.HttpException; -import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -47,49 +34,49 @@ public class LoginUtils { qq, wechat, weibo, phone, refresh, oldUserPhone } - public static void checkPhoneNum(final Context context, final String phoneName, final onCaptchaCallBackListener listener) { // 老用户登录检查手机是否登录过 - RetrofitManager.getInstance(context).getApi() - .checkPhoneNum(phoneName) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(ResponseBody response) { - super.onResponse(response); - try { - JSONObject content = new JSONObject(response.string()); - String status = content.getString("status"); - if ("ok".equals(status)) { - getPhoneCaptcha(context, phoneName, listener); - } else { - DialogUtils.showWarningDialog(context, null, "手机号已存在,请使用未登录过的手机号,以保证数据正常同步到新账号上" - , null, "我知道了", null, null); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(HttpException e) { - super.onFailure(e); - if (e == null) { - Utils.toast(context, "请检查网络是否可用"); - return; - } - try { - ResponseBody responseBody = e.response().errorBody(); - String string = responseBody.string(); - JSONObject content = new JSONObject(string); - int code = content.getInt("code"); - outputErrorHint(context, code); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - }); - - } +// public static void checkPhoneNum(final Context context, final String phoneName, final onCaptchaCallBackListener listener) { // 老用户登录检查手机是否登录过 +// RetrofitManager.getInstance(context).getApi() +// .checkPhoneNum(phoneName) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Response() { +// @Override +// public void onResponse(ResponseBody response) { +// super.onResponse(response); +// try { +// JSONObject content = new JSONObject(response.string()); +// String status = content.getString("status"); +// if ("ok".equals(status)) { +// getPhoneCaptcha(context, phoneName, listener); +// } else { +// DialogUtils.showWarningDialog(context, null, "手机号已存在,请使用未登录过的手机号,以保证数据正常同步到新账号上" +// , null, "我知道了", null, null); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// @Override +// public void onFailure(HttpException e) { +// super.onFailure(e); +// if (e == null) { +// Utils.toast(context, "请检查网络是否可用"); +// return; +// } +// try { +// ResponseBody responseBody = e.response().errorBody(); +// String string = responseBody.string(); +// JSONObject content = new JSONObject(string); +// int code = content.getInt("code"); +// outputErrorHint(context, code); +// } catch (Exception e1) { +// e1.printStackTrace(); +// } +// } +// }); +// +// } // 获取验证码 public static void getPhoneCaptcha(final Context context, String phoneNum, final onCaptchaCallBackListener listener) { @@ -140,117 +127,6 @@ public class LoginUtils { } - // 登录前,做好body判断 - public static void login(final Context context, final JSONObject content, final LoginTag loginTag, - final onLoginCallBackListener listener) { - -// Observable observable = null; -// String userToken = null; -// -// try { -// JSONObject device = DeviceUtils.getLoginDevice(context.getApplicationContext()); -// content.put("device", device); -// RequestBody body = RequestBody.create(MediaType.parse("application/json"), content.toString()); -// -// if (loginTag == LoginTag.weibo) { -// userToken = content.getString("uid"); -// observable = RetrofitManager.getInstance(context).getUsersea().loginByWeibo(body); -// } else if (loginTag == LoginTag.qq) { -// userToken = content.getString("openid"); -// observable = RetrofitManager.getInstance(context).getUsersea().loginByQQ(body); -// } else if (loginTag == LoginTag.wechat) { -// userToken = content.getString("openid"); -// observable = RetrofitManager.getInstance(context).getUsersea().loginByWechat(body); -// } else if (loginTag == LoginTag.phone || loginTag == LoginTag.oldUserPhone) { -// userToken = content.getString("mobile"); -// observable = RetrofitManager.getInstance(context).getUsersea().loginByMobile(body); -// } else { -// return; -// } -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// -// if (observable == null) return; -// -// final String finalUserToken = userToken; -// observable -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(new Response() { -// @Override -// public void onResponse(LoginResponseEntity response) { -// super.onResponse(response); -// if (loginTag.equals(LoginTag.phone) || loginTag.equals(LoginTag.oldUserPhone)) { -// try { -// response.setLoginType(content.getString("mobile")); -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// } else { -// response.setLoginType(loginTag.name()); -// } -// response.setUserToken(finalUserToken); -// saveLoginToken(context, response); -// -// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); -// String syncDeviceID = sp.getString("syncDeviceID", null); -// if (!TextUtils.isEmpty(syncDeviceID)) { -// syncUserData(context, syncDeviceID, listener, loginTag); -// sp.edit().putString("syncDeviceID", null).apply(); // 清空 -// } else { -// getUserData(context, false, listener, loginTag); -// } -// } -// -// @Override -// public void onFailure(HttpException e) { -// super.onFailure(e); -// if (listener != null) { -// listener.onLoginFailure(); -// } -// try { -// ResponseBody responseBody = e.response().errorBody(); -// String string = responseBody.string(); -// JSONObject content = new JSONObject(string); -// int code = content.getInt("code"); -// -// if (loginTag.equals(LoginTag.phone)) { -// outputErrorHint(context, code); -// } else { -// if (loginTag.equals(LoginTag.qq)) { -// GetLoginDataUtils.getInstance(context).QQLogout(); -// } -// Utils.toast(context, context.getString(R.string.login_failure_hint)); -// } -// } catch (Exception e1) { -// Utils.toast(context, context.getString(R.string.login_failure_hint)); -// e1.printStackTrace(); -// } -// } -// }); - } - - private static void syncUserData(final Context context, String syncDeviceID, - final onLoginCallBackListener listener, - final LoginTag loginTag) { - - String loginType; - if (LoginTag.phone.equals(loginTag)) { - loginType = "mobile"; - } else { - loginType = loginTag.toString(); - } - - HashMap map = new HashMap<>(); - map.put("device_id", syncDeviceID); - map.put("login_type", loginType); - RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString()); - RetrofitManager.getInstance(context).getApi().syncUserData(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(userInfoResponse(context, loginTag, listener)); - } // 注销登录 public static void logout(final Context context, final OnLogoutListener listener) { @@ -289,235 +165,6 @@ public class LoginUtils { EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGOUT_TAG)); } - // 检查本地是否有缓存token,有则马上登录 - public static void checkLogin(Context context, onLoginCallBackListener listener) { - LoginResponseEntity loginToken = getLoginToken(context); - - if (loginToken != null && loginToken.getAccessToken() != null) { - LoginResponseEntity.AccessToken accessToken = loginToken.getAccessToken(); - Long accessExpire = accessToken.getExpire(); - if (accessExpire != null && accessExpire > Utils.getTime(context)) { - getUserData(context, false, listener, null); - } else { - LoginResponseEntity.RefreshToken refreshToken = loginToken.getRefreshToken(); - Long refreshExpire = refreshToken.getExpire(); - if (refreshExpire != null && refreshExpire > Utils.getTime(context)) { - Map params = new HashMap<>(); - params.put("refresh_token", refreshToken.getValue()); - RefreshTokenManager.getInstance().refreshToken(context, false, new JSONObject(params), listener); - } else { - // 重新登录 - cleanUserData(context); - } - } - } - } - - private static Response userInfoResponse(final Context context, - final LoginTag loginTag, - final onLoginCallBackListener listener) { - return new Response() { - @Override - public void onResponse(UserInfoEntity response) { - super.onResponse(response); - - saveUserInfo(context, response); - if (listener != null) { - listener.onLogin(response, loginTag); - } - - if (loginTag != null && !LoginTag.refresh.equals(loginTag)) { - Utils.toast(context, context.getString(R.string.login_success)); - } - } - - @Override - public void onFailure(HttpException e) { - super.onFailure(e); - if (listener != null) { - listener.onLoginFailure(); - } - if (loginTag != null) { - Utils.toast(context, context.getString(R.string.login_failure_hint)); - } - if (loginTag != null && loginTag.equals(LoginTag.qq)) { - GetLoginDataUtils.getInstance(context).QQLogout(); - } - } - }; - } - - // 获取用户信息 - public static void getUserData(final Context context, boolean isRunMainThread, final onLoginCallBackListener listener, final LoginTag loginTag) { - - Observable observable; - if (isRunMainThread) { - observable = RetrofitManager.getInstance(context) - .getApi() - .getUserInfo(); - } else { - observable = RetrofitManager.getInstance(context) - .getApi() - .getUserInfo() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); - } - observable.subscribe(userInfoResponse(context, loginTag, listener)); - } - - // 获取本地缓存用户信息 - public static UserInfoEntity getUserInfo(Context context) { -// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); -// String loginData = sp.getString("user_info", null); -// if (!TextUtils.isEmpty(loginData)) { -// Type listType = new TypeToken() { -// }.getType(); -// return new Gson().fromJson(loginData, listType); -// } - return UserManager.getInstance().getUserInfoEntity(); - } - - - // 在本地缓存用户信息 - public static void saveUserInfo(Context context, UserInfoEntity entity) { - if (entity != null) { - String region = entity.getRegion(); - if (region != null && region.contains("中国")) { // 转换地区格式 - String replace = region.replace("中国 ", ""); - entity.setRegion(replace); - } - - String s = new Gson().toJson(entity); - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor edit = sp.edit(); - edit.putString("user_info", s); - edit.apply(); - } - } - - //获取本地缓存用户token - public static LoginResponseEntity getLoginToken(Context context) { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - String loginData = sp.getString("login_token", null); - if (!TextUtils.isEmpty(loginData)) { - Type listType = new TypeToken() { - }.getType(); - return new Gson().fromJson(loginData, listType); - } - return null; - } - - //获取本地缓存用户token - public static String getToken(Context context) { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - String loginData = sp.getString("login_token", null); - if (!TextUtils.isEmpty(loginData)) { - Type listType = new TypeToken() { - }.getType(); - LoginResponseEntity entity = new Gson().fromJson(loginData, listType); - if (entity != null && entity.getAccessToken() != null) { - return entity.getAccessToken().getValue(); - } - } - return null; - } - - // 在本地缓存用户token - public static void saveLoginToken(Context context, LoginResponseEntity entity) { - if (entity != null) { - if (TextUtils.isEmpty(entity.getLoginType())) { - LoginResponseEntity loginToken = getLoginToken(context); - if (loginToken != null) { - entity.setLoginType(loginToken.getLoginType()); - } - } - - String s = new Gson().toJson(entity); - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor edit = sp.edit(); - edit.putString("login_token", s); - edit.apply(); - } - } - - //更改用户信息 - public static void changeUserInfo(final onChangeUserInfoListener listener, final Context context, - final String content, final String editType) { - final UserInfoEntity entity = getUserInfo(context); - if (entity == null) { - return; - } - Map map = new HashMap<>(); - map.put(editType, content); - - final Dialog loadingDialog = DialogUtils.showWaitDialog(context, "正在修改信息..."); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(map).toString()); - RetrofitManager.getInstance(context) - .getUsersea() - .changeUserInfo(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(ResponseBody response) { - super.onResponse(response); - if (loadingDialog != null) { - loadingDialog.dismiss(); - } - switch (editType) { - case "name": - entity.setName(content); - break; - case "contact": - entity.setContact(content); - break; - case "gender": - entity.setGender(content); - break; - case "region": - entity.setRegion(content); - break; - case "icon": - entity.setIcon(content); - break; - default: - return; - } - - saveUserInfo(context, entity); - - - listener.onChange(); - - } - - @Override - public void onFailure(HttpException e) { - super.onFailure(e); - if (loadingDialog != null) { - loadingDialog.dismiss(); - } - Utils.toast(context, "修改失败"); - - if (e == null) { - Utils.toast(context, "请检查网络是否可用"); - return; - } - try { - ResponseBody responseBody = e.response().errorBody(); - String string = responseBody.string(); - JSONObject content = new JSONObject(string); - int code = content.getInt("code"); - outputErrorHint(context, code); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - }); - } - public static void outputErrorHint(Context context, int code) { switch (code) { @@ -659,11 +306,6 @@ public class LoginUtils { void onCompleted(); } - // 更改用户信息回调 - public interface onChangeUserInfoListener { - void onChange(); - } - // 获取验证码回调 public interface onCaptchaCallBackListener { void onCaptcha(String serviceId); diff --git a/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java b/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java index 9802b7263e..bb677c71f9 100644 --- a/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java @@ -19,12 +19,12 @@ import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.ImageUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.PostCommentUtils; import com.gh.gamecenter.adapter.CommentDetailAdapter; import com.gh.gamecenter.adapter.OnCommentCallBackListener; import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.UserInfoEntity; +import com.gh.gamecenter.manager.UserManager; import com.lightgame.utils.Utils; import org.json.JSONException; @@ -105,7 +105,7 @@ public class CommentDetailActivity extends BaseActivity implements OnCommentCall } }); - mUserInfo = LoginUtils.getUserInfo(this); + mUserInfo = UserManager.getInstance().getUserInfoEntity(); if (mUserInfo != null) { ImageUtils.Companion.display(mCommentUserIcon, mUserInfo.getIcon()); mCommentUserName.setText(mUserInfo.getName()); diff --git a/app/src/main/java/com/gh/gamecenter/CropImageActivity.java b/app/src/main/java/com/gh/gamecenter/CropImageActivity.java index 4e55621891..2002f49a1a 100644 --- a/app/src/main/java/com/gh/gamecenter/CropImageActivity.java +++ b/app/src/main/java/com/gh/gamecenter/CropImageActivity.java @@ -25,8 +25,8 @@ import com.gh.common.util.BitmapUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.EntranceUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.view.CropImageCustom; +import com.gh.gamecenter.manager.UserManager; import com.lightgame.download.FileUtils; import org.json.JSONException; @@ -54,6 +54,8 @@ public class CropImageActivity extends BaseActivity { private SharedPreferences sp; + private UserManager mUserManager; + private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { @@ -92,6 +94,8 @@ public class CropImageActivity extends BaseActivity { sp = PreferenceManager.getDefaultSharedPreferences(this); + mUserManager = UserManager.getInstance(); + RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); TextView confirm = new TextView(this); @@ -119,7 +123,7 @@ public class CropImageActivity extends BaseActivity { handler.sendEmptyMessage(1); return null; } - return Observable.just(LoginUtils.getToken(CropImageActivity.this)); + return Observable.just(mUserManager.getToken()); } }).flatMap(new Func1>() { @Override @@ -137,7 +141,7 @@ public class CropImageActivity extends BaseActivity { if (result != null) { try { if (result.getInt("statusCode") == 401) { - return Observable.just(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=icon", path, LoginUtils.getToken(CropImageActivity.this))); + return Observable.just(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=icon", path,mUserManager.getToken())); } } catch (JSONException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 704b9212ca..477c126809 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -36,14 +36,13 @@ import com.gh.common.util.DeviceUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.GameUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.TrafficUtils; import com.gh.download.DownloadManager; -import com.gh.gamecenter.db.info.InstallInfo; import com.gh.gamecenter.db.info.GameInfo; +import com.gh.gamecenter.db.info.InstallInfo; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameDigestEntity; import com.gh.gamecenter.entity.GameEntity; @@ -54,12 +53,13 @@ import com.gh.gamecenter.eventbus.EBPackage; import com.gh.gamecenter.eventbus.EBShowDialog; import com.gh.gamecenter.eventbus.EBSkip; import com.gh.gamecenter.fragment.MainFragment; -import com.gh.gamecenter.manager.InstallManager; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.FilterManager; import com.gh.gamecenter.manager.GameManager; +import com.gh.gamecenter.manager.InstallManager; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.manager.UpdateManager; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.ObservableUtil; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -666,7 +666,7 @@ public class MainActivity extends BaseActivity { getSuggestionType(); final String message = Config.getExceptionMsg(this); - if (LoginUtils.getUserInfo(this) != null && !TextUtils.isEmpty(message)) { + if (!TextUtils.isEmpty(UserManager.getInstance().getToken()) && !TextUtils.isEmpty(message)) { Config.setExceptionMsg(this, null); AppUncaughtHandler.reportException(this, new Throwable(message)); DialogUtils.showWarningDialog(this, "发生闪退", "光环助手刚刚发生了闪退,马上反馈以帮助我们更好地修复问题?(只需简单描述你刚才的操作)" diff --git a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java index 03af8b2f86..1cefddb18d 100644 --- a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java @@ -25,7 +25,6 @@ import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.ImageUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.PostCommentUtils; import com.gh.common.util.TimestampUtils; import com.gh.common.util.TokenUtils; @@ -38,6 +37,7 @@ import com.gh.gamecenter.entity.UserInfoEntity; import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.CommentManager; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.OkHttpCache; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -212,7 +212,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall } }); - mUserInfo = LoginUtils.getUserInfo(this); + mUserInfo = UserManager.getInstance().getUserInfoEntity(); if (mUserInfo != null) { ImageUtils.Companion.display(mMessageDetailIconDv, mUserInfo.getIcon()); mMessageDetailUserNameTv.setText(mUserInfo.getName()); @@ -527,7 +527,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(EBReuse reuse) { if (reuse.getType().equals(LOGIN_TAG)) { // 登入 - mUserInfo = LoginUtils.getUserInfo(this); + mUserInfo = UserManager.getInstance().getUserInfoEntity(); if (mUserInfo != null) { ImageUtils.Companion.display(mMessageDetailIconDv, mUserInfo.getIcon()); mMessageDetailUserNameTv.setText(mUserInfo.getName()); diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index 53f4e46837..7f8999a752 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -34,13 +34,13 @@ import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.EntranceUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PatternUtils; import com.gh.gamecenter.entity.InstallGameEntity; import com.gh.gamecenter.entity.SuggestionTypeEntity; import com.gh.gamecenter.entity.UserInfoEntity; import com.gh.gamecenter.fragment.WaitingDialogFragment; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.RetrofitManager; import com.gh.gamecenter.suggest.SuggestPicAdapter; @@ -262,7 +262,7 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt } } - UserInfoEntity userInfo = LoginUtils.getUserInfo(this); + UserInfoEntity userInfo = UserManager.getInstance().getUserInfoEntity(); if (userInfo != null && !TextUtils.isEmpty(userInfo.getContact())) { mSuggestEmailEt.setText(userInfo.getContact()); } @@ -462,10 +462,10 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt for (String s : mAdapter.getFileList()) { path = getCacheDir() + File.separator + System.currentTimeMillis() + index + ".jpg"; if (BitmapUtils.savePicture(path, s)) { - subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", path, LoginUtils.getToken(SuggestionActivity.this))); + subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", path, UserManager.getInstance().getToken())); index++; } else { - subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", s, LoginUtils.getToken(SuggestionActivity.this))); + subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", s, UserManager.getInstance().getToken())); } } subscriber.onCompleted(); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java index e5dcf4b286..ddc449ce9e 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java @@ -10,13 +10,13 @@ import com.gh.common.util.ConcernUtils; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.StringUtils; import com.gh.gamecenter.ConcernActivity; import com.gh.gamecenter.GameDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; @@ -52,7 +52,7 @@ public class ConcernAdapter extends BaseRecyclerAdapter { } public void initConcernGame() { - if (TextUtils.isEmpty(LoginUtils.getToken(mContext))) { + if (TextUtils.isEmpty(UserManager.getInstance().getToken())) { mListener.loadDone(null); return; } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ToolBoxRvAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/ToolBoxRvAdapter.java index 6fe3e8d49f..f83bddc991 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/ToolBoxRvAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/ToolBoxRvAdapter.java @@ -13,7 +13,6 @@ import android.widget.TextView; import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.ImageUtils; -import com.gh.common.util.LoginUtils; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SuggestionActivity; @@ -22,6 +21,7 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.adapter.viewholder.LibaoSearchViewHolder; import com.gh.gamecenter.adapter.viewholder.ToolBoxViewHolder; import com.gh.gamecenter.entity.ToolBoxEntity; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; @@ -65,7 +65,7 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter { this.mIsSearch = isSearch; this.mSerchKey = key; - mToken = LoginUtils.getToken(mContext); + mToken = UserManager.getInstance().getToken(); mSearchListener = searchListener; mCallBackListener = listener; mEntityList = new ArrayList<>(); diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java index df0e7cdad3..605881ef96 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao2FragmentAdapter.java @@ -14,13 +14,13 @@ import com.gh.common.constant.ItemViewType; import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.LibaoUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.PlatformUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.adapter.viewholder.LibaoNormalViewHolder; import com.gh.gamecenter.entity.LibaoEntity; import com.gh.gamecenter.entity.LibaoStatusEntity; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.newsdetail.NewsDetailCommentViewHolder; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -75,7 +75,7 @@ class Libao2FragmentAdapter extends BaseRecyclerAdapter { // 加载数据 public void addList(final int offset) { - if (TextUtils.isEmpty(LoginUtils.getToken(mContext))) { + if (TextUtils.isEmpty(UserManager.getInstance().getToken())) { mCallBackListener.loadDone(null); return; } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java index 041d7855c2..c145b491e3 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java @@ -12,7 +12,6 @@ import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.DialogUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.LibaoUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.PlatformUtils; import com.gh.gamecenter.LibaoDetailActivity; import com.gh.gamecenter.R; @@ -22,6 +21,7 @@ import com.gh.gamecenter.entity.LibaoEntity; import com.gh.gamecenter.entity.LibaoStatusEntity; import com.gh.gamecenter.entity.UserDataEntity; import com.gh.gamecenter.entity.UserDataLibaoEntity; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; @@ -57,7 +57,7 @@ class Libao3FragmentAdapter extends BaseRecyclerAdapter } void loadData(int offset) { - if (TextUtils.isEmpty(LoginUtils.getToken(mContext))) { + if (TextUtils.isEmpty(UserManager.getInstance().getToken())) { mCallBackListener.loadDone(null); return; } diff --git a/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java index 94eb7450ba..b10db7e631 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java @@ -15,7 +15,6 @@ import com.gh.common.util.ConcernContentUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.LibaoUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.NewsUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.StringUtils; @@ -29,6 +28,7 @@ import com.gh.gamecenter.entity.UserDataEntity; import com.gh.gamecenter.entity.UserDataLibaoEntity; import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.manager.CommentManager; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.ObservableUtil; @@ -94,7 +94,7 @@ public class News2FragmentAdapter extends BaseRecyclerAdapter { return; } - if (TextUtils.isEmpty(LoginUtils.getToken(mContext))) { + if (TextUtils.isEmpty(UserManager.getInstance().getToken())) { isLoading = true; listener.loadEmpty(); return; diff --git a/app/src/main/java/com/gh/gamecenter/news/News3Fragment.java b/app/src/main/java/com/gh/gamecenter/news/News3Fragment.java index b272bed772..27b7b70d84 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News3Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/News3Fragment.java @@ -17,7 +17,6 @@ import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.fragment.BaseFragment; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; -import com.gh.common.util.LoginUtils; import com.gh.common.util.NewsUtils; import com.gh.common.util.StringUtils; import com.gh.gamecenter.ConcernActivity; @@ -29,6 +28,7 @@ import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.eventbus.EBUISwitch; import com.gh.gamecenter.manager.DataCollectionManager; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.jakewharton.rxbinding.view.RxView; @@ -249,7 +249,7 @@ public class News3Fragment extends BaseFragment implements SwipeRefreshLayout.On if (NewsWrapperFragment.EB_NEWSFRAGMENT_TAG.equals(busNine.getFrom())) { if (busNine.getPosition() == 2 && mLoading.getVisibility() == View.VISIBLE) { mStrategyAdapter.addList(0); - if (!TextUtils.isEmpty(LoginUtils.getToken(getContext()))) { + if (!TextUtils.isEmpty(UserManager.getInstance().getToken())) { getConcernGame(); } } diff --git a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java index 5ad35147a9..ef643fd48d 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java @@ -35,7 +35,7 @@ import com.gh.gamecenter.SuggestSelectActivity; import com.gh.gamecenter.SuggestionActivity; import com.gh.gamecenter.UserInfoActivity; import com.gh.gamecenter.entity.AppEntity; -import com.gh.gamecenter.entity.LoginResponseEntity; +import com.gh.gamecenter.entity.LoginTokenEntity; import com.gh.gamecenter.entity.MessageUnreadEntity; import com.gh.gamecenter.entity.UserInfoEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; @@ -44,6 +44,7 @@ import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.login.ApiResponse; import com.gh.gamecenter.login.LoginTag; import com.gh.gamecenter.login.UserViewModel; +import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.message.MessageFragment; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -111,9 +112,6 @@ public class PersonalFragment extends BaseFragment implements Observer(); - mCurRegin = LoginUtils.getUserInfo(mContext).getRegion(); + mCurRegin = UserManager.getInstance().getUserInfoEntity().getRegion(); initData(); } diff --git a/app/src/main/java/com/gh/gamecenter/region/RegionProvAdapter.java b/app/src/main/java/com/gh/gamecenter/region/RegionProvAdapter.java index e109bbbc30..14caaaa4df 100644 --- a/app/src/main/java/com/gh/gamecenter/region/RegionProvAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/region/RegionProvAdapter.java @@ -6,9 +6,9 @@ import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; -import com.gh.common.util.LoginUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.AreaViewHolder; +import com.gh.gamecenter.manager.UserManager; import com.lightgame.adapter.BaseRecyclerAdapter; import java.util.List; @@ -29,7 +29,7 @@ public class RegionProvAdapter extends BaseRecyclerAdapter { super(context); mListener = listener; mProvList = provList; - mCurRegin = LoginUtils.getUserInfo(mContext).getRegion(); + mCurRegin = UserManager.getInstance().getUserInfoEntity().getRegion(); } @Override diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt index 7a2d7780b4..b4ffbd01f8 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt +++ b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt @@ -6,6 +6,7 @@ import com.gh.common.util.LoginUtils import com.gh.gamecenter.entity.UserInfoEntity import com.gh.gamecenter.eventbus.EBReuse import com.gh.gamecenter.manager.RefreshTokenManager +import com.gh.gamecenter.manager.UserManager import com.gh.gamecenter.personal.PersonalFragment import com.lightgame.config.CommonDebug import com.lightgame.utils.Utils @@ -58,7 +59,7 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto break } - val loginToken = LoginUtils.getLoginToken(mContext) + val loginToken = UserManager.getInstance().loginTokenEntity if (response != null && token != null && loginToken != null) { // TOKEN 过期处理 val refreshToken = loginToken.refreshToken val refreshExpire = refreshToken?.expire @@ -70,7 +71,7 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto RefreshTokenManager.getInstance().refreshToken(mContext, true, JSONObject(params), object : LoginUtils.onLoginCallBackListener { override fun onLogin(entity: UserInfoEntity, loginTag: LoginUtils.LoginTag) { - val userLoginToken = LoginUtils.getLoginToken(mContext) + val userLoginToken = UserManager.getInstance().loginTokenEntity val newBuilder = request.newBuilder() newBuilder.header("TOKEN", userLoginToken?.accessToken?.value) request = newBuilder.build()