优化掉线问题
This commit is contained in:
@ -9,6 +9,8 @@ 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.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -16,6 +18,7 @@ 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;
|
||||
|
||||
@ -269,8 +272,18 @@ public class LoginUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void cleanRefreshToken(Context context) {
|
||||
LoginResponseEntity loginToken = getLoginToken(context);
|
||||
if (loginToken != null && loginToken.getRefreshToken() != null) {
|
||||
loginToken.getRefreshToken().setValue(null);
|
||||
saveLoginToken(context, loginToken);
|
||||
}
|
||||
}
|
||||
|
||||
// 清除本地用户相关信息
|
||||
public static void cleanUserData(Context context) {
|
||||
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGOUT_TAG));
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("user_info", null);
|
||||
@ -295,6 +308,7 @@ public class LoginUtils {
|
||||
if (refreshExpire != null && refreshExpire > Utils.getTime(context)) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("refresh_token", refreshToken.getValue());
|
||||
LoginUtils.cleanRefreshToken(context);
|
||||
login(context, new JSONObject(params), LoginTag.refresh, listener); // 刷新accessToken
|
||||
} else {
|
||||
// 重新登录
|
||||
|
||||
@ -15,11 +15,13 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.tencent.bugly.beta.tinker.TinkerManager;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/28.
|
||||
@ -32,6 +34,8 @@ public class AboutActivity extends BaseActivity {
|
||||
RelativeLayout mAboutUpdateRl;
|
||||
@BindView(R.id.about_version_pb)
|
||||
ProgressBar mAboutPb;
|
||||
@BindView(R.id.about_tv_version)
|
||||
TextView mVersionName;
|
||||
|
||||
private Handler handler = new MyHandler(this);
|
||||
|
||||
@ -52,7 +56,7 @@ public class AboutActivity extends BaseActivity {
|
||||
initTitle(getString(R.string.title_about));
|
||||
|
||||
// ((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this));
|
||||
((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getPatchVersionName()); // TODO 版本号暂时与gradle versionName不一致
|
||||
mVersionName.setText("V" + PackageUtils.getPatchVersionName()); // TODO 版本号暂时与gradle versionName不一致
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,6 +75,15 @@ public class AboutActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@OnLongClick(R.id.about_tv_version)
|
||||
public boolean OnLongClick(View view) {
|
||||
if (view.getId() == R.id.about_tv_version) {
|
||||
String tinkerId = TinkerManager.getTinkerId();
|
||||
mVersionName.setText("V" + PackageUtils.getPatchVersionName() + "." + tinkerId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class MyHandler extends Handler {
|
||||
|
||||
private WeakReference<AboutActivity> mWeakReference;
|
||||
|
||||
@ -714,7 +714,6 @@ public class MainActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
|
||||
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -278,7 +277,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGOUT_TAG));
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
@ -469,6 +469,7 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
viewHolder.loading.setVisibility(View.VISIBLE);
|
||||
viewHolder.hint.setText(R.string.loading);
|
||||
addHotComment(0);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -61,15 +61,16 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto
|
||||
break
|
||||
}
|
||||
|
||||
if (response != null && token != null) { // TOKEN 过期处理
|
||||
val loginToken = LoginUtils.getLoginToken(mContext)
|
||||
|
||||
val loginToken = LoginUtils.getLoginToken(mContext)
|
||||
if (response != null && token != null && loginToken != null) { // TOKEN 过期处理
|
||||
val refreshToken = loginToken.refreshToken
|
||||
val refreshExpire = refreshToken?.expire
|
||||
if (refreshExpire != null && refreshExpire > Utils.getTime(mContext)) {
|
||||
val params = HashMap<String, String>()
|
||||
val value = refreshToken.value
|
||||
if (value == null) break
|
||||
LoginUtils.cleanRefreshToken(mContext)
|
||||
|
||||
params.put("refresh_token", value)
|
||||
val jsonObject = JSONObject(params)
|
||||
try {
|
||||
@ -106,7 +107,6 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
LoginUtils.cleanUserData(mContext)
|
||||
EventBus.getDefault().post(EBReuse(PersonalFragment.LOGOUT_TAG))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -128,7 +128,6 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto
|
||||
val code = content.getInt("code")
|
||||
LoginUtils.cleanUserData(mContext)
|
||||
Utils.toast(mContext, mContext.getString(R.string.login_refresh_error))
|
||||
EventBus.getDefault().post(EBReuse(PersonalFragment.LOGOUT_TAG))
|
||||
tryCount = 4 // 只要token刷新异常直接主动退出登录
|
||||
if (code == 40802) { // 其他设备登录了该账号
|
||||
EventBus.getDefault().post(EBShowDialog("loginException", string)) // 打开提示框
|
||||
@ -142,7 +141,6 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto
|
||||
} else {
|
||||
// 重新登录
|
||||
LoginUtils.cleanUserData(mContext)
|
||||
EventBus.getDefault().post(EBReuse(PersonalFragment.LOGOUT_TAG))
|
||||
Utils.toast(mContext, "账号过期,请重新登录!")
|
||||
}
|
||||
} else { // 网络错误处理
|
||||
|
||||
Reference in New Issue
Block a user