优化掉线问题

This commit is contained in:
kehaoyuan
2017-11-03 19:43:49 +08:00
parent 91ee8362ba
commit 5860ca720e
6 changed files with 33 additions and 10 deletions

View File

@ -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 {
// 重新登录