更新登录相关错误码 多设备登录提示优化(没效果)
This commit is contained in:
@ -66,7 +66,19 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -97,28 +109,16 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) return;
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
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");
|
||||
switch (code) {
|
||||
case 40001:
|
||||
Utils.toast(context, "无效的手机号码,手机号码格式错误");
|
||||
break;
|
||||
case 40002:
|
||||
Utils.toast(context, "mobile格式错误");
|
||||
break;
|
||||
case 40003:
|
||||
Utils.toast(context, "一分钟内已发送过验证码");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "未知错误");
|
||||
break;
|
||||
}
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@ -188,71 +188,54 @@ public class LoginUtils {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String syncDeviceID = sp.getString("syncDeviceID", null);
|
||||
if (!TextUtils.isEmpty(syncDeviceID)) {
|
||||
syncUserData(context, syncDeviceID, token, listener);
|
||||
syncUserData(context, syncDeviceID, token, listener, loginTag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
getUserData(context, token, listener);
|
||||
getUserData(context, token, listener, loginTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
|
||||
if (e == null) return;
|
||||
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
switch (code) {
|
||||
case 40000:
|
||||
Utils.toast(context, "参数错误或不完整");
|
||||
case 40004:
|
||||
Utils.toast(context, "缺少mobile参数");
|
||||
break;
|
||||
case 40005:
|
||||
Utils.toast(context, "缺少code参数");
|
||||
break;
|
||||
case 40006:
|
||||
Utils.toast(context, "缺少service_id参数");
|
||||
break;
|
||||
case 40007:
|
||||
Utils.toast(context, "服务已超时");
|
||||
break;
|
||||
case 40008:
|
||||
Utils.toast(context, "验证码已超时");
|
||||
break;
|
||||
case 40009:
|
||||
Utils.toast(context, "验证码错误");
|
||||
break;
|
||||
case 40010:
|
||||
Utils.toast(context, "登录授权失败");
|
||||
break;
|
||||
case 40011:
|
||||
Utils.toast(context, "缺少token参数");
|
||||
break;
|
||||
case 40012:
|
||||
Utils.toast(context, "令牌已过期");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "未知错误");
|
||||
break;
|
||||
}
|
||||
|
||||
Utils.log("login::" + loginTag, "error_message::" + content.getString("message") + "\n error_code::" + code);
|
||||
if (loginTag == LoginTag.refresh && code == 40802) {
|
||||
|
||||
Utils.log("=======40802::" + string);
|
||||
JSONObject device = content.getJSONObject("device");
|
||||
String manufacturer = device.getString("manufacturer");
|
||||
|
||||
String model = device.getString("model");
|
||||
|
||||
DialogUtils.showAlertDialog(context, "你的账号已在另外一台设备登录"
|
||||
, StringUtils.buildString("(", manufacturer, "-", model, ")")
|
||||
, "知道了", null, null, null);
|
||||
|
||||
LoginUtils.cleanUserData(context);
|
||||
// TODO 要不要调用退出登录接口
|
||||
} else {
|
||||
outputErrorHint(context, code);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
cleanUserData(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void syncUserData(final Context context, String syncDeviceID, final String token
|
||||
, final onLoginCallBackListener listener) {
|
||||
, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("device_id", syncDeviceID);
|
||||
@ -264,19 +247,32 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
getUserData(context, token, listener);
|
||||
getUserData(context, token, listener, loginTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
getUserData(context, token, listener);
|
||||
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();
|
||||
}
|
||||
getUserData(context, token, listener, loginTag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 注销登录
|
||||
public static void logout(Context context) {
|
||||
public static void logout(final Context context) {
|
||||
LoginResponseEntity loginToken = getLoginToken(context);
|
||||
if (loginToken == null || loginToken.getAccessToken() == null) return;
|
||||
|
||||
@ -286,6 +282,23 @@ public class LoginUtils {
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cleanUserData(context);
|
||||
@ -310,7 +323,7 @@ public class LoginUtils {
|
||||
LoginResponseEntity.AccessToken accessToken = loginToken.getAccessToken();
|
||||
Long accessExpire = accessToken.getExpire();
|
||||
if (accessExpire != null && accessExpire > Utils.getTime(context)) {
|
||||
getUserData(context, accessToken.getValue(), listener);
|
||||
getUserData(context, accessToken.getValue(), listener, null);
|
||||
} else {
|
||||
LoginResponseEntity.RefreshToken refreshToken = loginToken.getRefreshToken();
|
||||
Long refreshExpire = refreshToken.getExpire();
|
||||
@ -327,7 +340,7 @@ public class LoginUtils {
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
public static void getUserData(final Context context, String token, final onLoginCallBackListener listener) {
|
||||
public static void getUserData(final Context context, String token, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
RetrofitManager
|
||||
.getApi()
|
||||
.getUserInfo(token)
|
||||
@ -339,13 +352,26 @@ public class LoginUtils {
|
||||
super.onResponse(response);
|
||||
saveUserInfo(context, response);
|
||||
if (listener != null) {
|
||||
listener.onLogin(response, null);
|
||||
listener.onLogin(response, loginTag);
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -478,10 +504,157 @@ public class LoginUtils {
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void outputErrorHint(Context context, int code) {
|
||||
|
||||
switch (code) {
|
||||
case 40000:
|
||||
Utils.toast(context, "参数不全");
|
||||
break;
|
||||
case 40001:
|
||||
Utils.toast(context, "已经发送过短信");
|
||||
break;
|
||||
case 40002:
|
||||
Utils.toast(context, "请求第三方开放平台时发生错误");
|
||||
break;
|
||||
case 40003:
|
||||
Utils.toast(context, "上传用户头像时发生错误");
|
||||
break;
|
||||
case 40101:
|
||||
Utils.toast(context, "缺少参数 app_id");
|
||||
break;
|
||||
case 40102:
|
||||
Utils.toast(context, "缺少签名验证的头信息");
|
||||
break;
|
||||
case 40104:
|
||||
Utils.toast(context, "缺少token");
|
||||
break;
|
||||
case 40105:
|
||||
Utils.toast(context, "缺少手机号码");
|
||||
break;
|
||||
case 40106:
|
||||
Utils.toast(context, "缺少用户名");
|
||||
break;
|
||||
case 40107:
|
||||
Utils.toast(context, "缺少密码参数");
|
||||
break;
|
||||
case 40202:
|
||||
Utils.toast(context, "无效的手机号码");
|
||||
break;
|
||||
case 40203:
|
||||
Utils.toast(context, "无效的用户名");
|
||||
break;
|
||||
case 40204:
|
||||
Utils.toast(context, "无效的头像地址");
|
||||
break;
|
||||
case 40205:
|
||||
Utils.toast(context, "无效的性别参数");
|
||||
break;
|
||||
case 40206:
|
||||
Utils.toast(context, "无效的地区参数");
|
||||
break;
|
||||
case 40208:
|
||||
Utils.toast(context, "无效的密码");
|
||||
break;
|
||||
case 40209:
|
||||
Utils.toast(context, "无效的URL 地址");
|
||||
break;
|
||||
case 42000:
|
||||
Utils.toast(context, "无效的app_id");
|
||||
break;
|
||||
case 42001:
|
||||
Utils.toast(context, "无效的app_secret");
|
||||
break;
|
||||
case 42002:
|
||||
Utils.toast(context, "无效的Union_id");
|
||||
break;
|
||||
case 42003:
|
||||
Utils.toast(context, "无效的设备信息");
|
||||
break;
|
||||
case 42004:
|
||||
Utils.toast(context, "无效的请求");
|
||||
break;
|
||||
case 40301:
|
||||
Utils.toast(context, "签名验证失败");
|
||||
break;
|
||||
case 40302:
|
||||
Utils.toast(context, "验证码错误");
|
||||
break;
|
||||
case 40303:
|
||||
Utils.toast(context, "密码错误");
|
||||
break;
|
||||
case 40304:
|
||||
Utils.toast(context, "不支持该种方式登录");
|
||||
break;
|
||||
case 40305:
|
||||
Utils.toast(context, "错误的状态值(应用只有两种状态: working / stop)");
|
||||
break;
|
||||
case 40306:
|
||||
Utils.toast(context, "传递了无法识别的参数");
|
||||
break;
|
||||
case 40401:
|
||||
Utils.toast(context, "token过期");
|
||||
break;
|
||||
case 40402:
|
||||
Utils.toast(context, "Service_id过期,主要原因是:收到手机短信验证码后长时间没有进行登录操作");
|
||||
break;
|
||||
case 40403:
|
||||
Utils.toast(context, "验证码已过期");
|
||||
break;
|
||||
case 40501:
|
||||
Utils.toast(context, "同名应用已经存在");
|
||||
break;
|
||||
case 40502:
|
||||
Utils.toast(context, "用户名已存在");
|
||||
break;
|
||||
case 40503:
|
||||
Utils.toast(context, "名称已经存在");
|
||||
break;
|
||||
case 40601:
|
||||
Utils.toast(context, "应用不存在");
|
||||
break;
|
||||
case 40602:
|
||||
Utils.toast(context, "用户不存在");
|
||||
break;
|
||||
case 40603:
|
||||
Utils.toast(context, "用户系统不存在");
|
||||
break;
|
||||
case 40604:
|
||||
Utils.toast(context, "用户已被冻结");
|
||||
break;
|
||||
case 40605:
|
||||
Utils.toast(context, "用户没有冻结");
|
||||
break;
|
||||
case 40606:
|
||||
Utils.toast(context, "该应用被停止运行了");
|
||||
break;
|
||||
case 40801:
|
||||
Utils.toast(context, "访问过于频繁");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "未知错误");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 更改用户信息回调
|
||||
public interface onChangeUserInfoListener {
|
||||
void onChange();
|
||||
|
||||
@ -38,6 +38,7 @@ import com.gh.common.util.PatternUtils;
|
||||
import com.gh.common.util.SoftInputHidWidgetUtils;
|
||||
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.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -247,6 +248,11 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UserInfoEntity userInfo = LoginUtils.getUserInfo(this);
|
||||
if (userInfo != null && !TextUtils.isEmpty(userInfo.getContact())) {
|
||||
mSuggestEmailEt.setText(userInfo.getContact());
|
||||
}
|
||||
}
|
||||
|
||||
private void initSuggest(int type) {
|
||||
|
||||
@ -23,6 +23,7 @@ import android.widget.Toast;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.adapter.VoteAdapter;
|
||||
@ -113,7 +114,12 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
mAddTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showAddVoteDialog();
|
||||
CheckLoginUtils.checkLogin(VoteActivity.this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
showAddVoteDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -139,8 +145,13 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(String obj) {
|
||||
postVersionVote(obj, false); // 投票
|
||||
public void loadDone(final String obj) {
|
||||
CheckLoginUtils.checkLogin(VoteActivity.this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
postVersionVote(obj, false); // 投票
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -311,6 +322,11 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
|
||||
@Override
|
||||
public void addVote() {
|
||||
showAddVoteDialog();
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
showAddVoteDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,10 +362,10 @@ public class GameFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
if (mPluginList.isEmpty()) {
|
||||
mPluginList = list;
|
||||
initItemCount();
|
||||
notifyItemRangeInserted(1, mPluginList.size() + 1);
|
||||
if (getItemCount() > mPluginList.size() + 2) {
|
||||
notifyItemChanged(mPluginList.size() + 2);
|
||||
}
|
||||
notifyItemRangeInserted(1, 1);
|
||||
// if (getItemCount() > 2) {
|
||||
// notifyItemChanged(2);
|
||||
// }
|
||||
} else {
|
||||
mPluginList = list;
|
||||
notifyDataSetChanged();
|
||||
|
||||
@ -51,9 +51,26 @@ public class KaiFuFragment extends BaseFragment {
|
||||
mFragments = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
KaiFuVpFragment kaiFuVpFragment = new KaiFuVpFragment();
|
||||
Bundle arguments;
|
||||
if (getArguments() != null) {
|
||||
kaiFuVpFragment.setArguments(getArguments());
|
||||
arguments = (Bundle) getArguments().clone();
|
||||
} else {
|
||||
arguments = new Bundle();
|
||||
}
|
||||
String day;
|
||||
switch (i) {
|
||||
case 0:
|
||||
day = "today";
|
||||
break;
|
||||
case 1:
|
||||
day = "tomorrow";
|
||||
break;
|
||||
default:
|
||||
day = "after";
|
||||
break;
|
||||
}
|
||||
arguments.putString("day", day);
|
||||
kaiFuVpFragment.setArguments(arguments);
|
||||
mFragments.add(kaiFuVpFragment);
|
||||
}
|
||||
FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager(), mFragments);
|
||||
|
||||
@ -59,17 +59,20 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
private List<GameEntity> mEntityList;
|
||||
private ArrayMap<String, ArrayList<Integer>> mLocationMap;
|
||||
|
||||
private int mDataCount;
|
||||
private String mGameId;
|
||||
private String mDay;
|
||||
|
||||
private int mDataCount;
|
||||
|
||||
private boolean mIsRemove;
|
||||
private boolean mIsNetworkError;
|
||||
private boolean mIsLoaded;
|
||||
|
||||
public KaiFuVpAdapter(Context context, OnRequestCallBackListener onCallBackListener, String gameId) {
|
||||
public KaiFuVpAdapter(Context context, OnRequestCallBackListener onCallBackListener, String gameId, String day) {
|
||||
super(context);
|
||||
|
||||
mGameId = gameId;
|
||||
mDay = day;
|
||||
mOnCallBackListener = onCallBackListener;
|
||||
mLocationMap = new ArrayMap<>();
|
||||
mEntityList = new ArrayList<>();
|
||||
@ -78,7 +81,7 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
public void addList(int offset) {
|
||||
mIsLoaded = false;
|
||||
RetrofitManager.getApi()
|
||||
.getKaiFuData(mGameId, offset, 20)
|
||||
.getKaiFuData(mGameId, mDay, offset, 20)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameEntity>>(){
|
||||
@ -265,7 +268,8 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
viewHolder.gameDes.setText(String.format("%s %s", gameEntity.getApk().get(0).getSize(), gameEntity.getBrief()));
|
||||
}
|
||||
|
||||
KaiFuUtils.setKaiFuTime(viewHolder.gameTestType, gameEntity.getServerEntity().getTime());
|
||||
// KaiFuUtils.setKaiFuTime(viewHolder.gameTestType, gameEntity.getServerEntity().getTime());
|
||||
viewHolder.gameTestType.setVisibility(View.GONE);
|
||||
|
||||
DownloadItemUtils.setOnClickListener(mContext,
|
||||
viewHolder.gameDownloadBtn, gameEntity, viewHolder.getAdapterPosition(), KaiFuVpAdapter.this,
|
||||
|
||||
@ -62,6 +62,7 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
private RelativeLayout.LayoutParams mLlparams;
|
||||
|
||||
private String mGameId;
|
||||
private String mDay;
|
||||
|
||||
private boolean mIsRefershDownload;
|
||||
|
||||
@ -93,6 +94,7 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments != null) {
|
||||
mDay = arguments.getString("day");
|
||||
mGameId = arguments.getString("gameId", "");
|
||||
} else {
|
||||
mGameId = "";
|
||||
@ -105,7 +107,7 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
((DefaultItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
mLayoutManager = new LinearLayoutManager(getContext());
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mAdapter = new KaiFuVpAdapter(getContext(), this, mGameId);
|
||||
mAdapter = new KaiFuVpAdapter(getContext(), this, mGameId, mDay);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@ -217,7 +219,7 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
mNoConn.setVisibility(View.GONE);
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
mAdapter = new KaiFuVpAdapter(getContext(), this, mGameId);
|
||||
mAdapter = new KaiFuVpAdapter(getContext(), this, mGameId, mDay);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.common.util.ApkActiveUtils;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
@ -34,6 +36,7 @@ import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -395,19 +398,31 @@ public class News2Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
|
||||
@OnClick(R.id.news1_tv_concern)
|
||||
public void concern() { // 关注 推荐关注的游戏
|
||||
ArrayList<GameEntity> list = new ArrayList<>();
|
||||
for (int key : concernMap.keySet()) {
|
||||
if (concernMap.get(key)) {
|
||||
list.add(recommendGameList.get(key));
|
||||
CheckLoginUtils.checkLogin(getContext(), new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
ArrayList<GameEntity> list = new ArrayList<>();
|
||||
for (int key : concernMap.keySet()) {
|
||||
if (concernMap.get(key)) {
|
||||
list.add(recommendGameList.get(key));
|
||||
}
|
||||
}
|
||||
if (list.size() != 0) {
|
||||
if (list.size() == 1) {
|
||||
concernManager.addByEntity(list.get(0));
|
||||
} else {
|
||||
concernManager.addByList(list);
|
||||
}
|
||||
}
|
||||
|
||||
// 同步关注
|
||||
JSONArray data = new JSONArray();
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
data.put(concernInfo.getId());
|
||||
}
|
||||
ConcernUtils.INSTANCE.updateConcernData(getContext(), data);
|
||||
}
|
||||
}
|
||||
if (list.size() != 0) {
|
||||
if (list.size() == 1) {
|
||||
concernManager.addByEntity(list.get(0));
|
||||
} else {
|
||||
concernManager.addByList(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 连接上网络事件
|
||||
|
||||
@ -49,6 +49,7 @@ import com.gh.gamecenter.adapter.viewholder.NewsDetailCommentListViewHolder;
|
||||
import com.gh.gamecenter.db.VoteDao;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.CommentnumEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.NewsDetailEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
@ -66,8 +67,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import retrofit2.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
@ -99,6 +98,8 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
private VoteDao mVoteDao;
|
||||
private int defaultTextZoom = 85;
|
||||
|
||||
private int mCommentNum;
|
||||
|
||||
public NewsDetailAdapter(Context context, OnRequestCallBackListener listener, String entrance) {
|
||||
super(context);
|
||||
mListener = listener;
|
||||
@ -561,7 +562,7 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
|
||||
, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
textView.setText("查看全部评论");
|
||||
textView.setText("查看全部评论(" + mCommentNum + ")");
|
||||
textView.setPadding(0, DisplayUtils.dip2px(mContext, 12), 0, DisplayUtils.dip2px(mContext, 12));
|
||||
textView.setTextColor(Color.parseColor("#00B7FA"));
|
||||
textView.setTextSize(16);
|
||||
@ -607,7 +608,29 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
notifyItemInserted(getItemCount() - 1);
|
||||
}
|
||||
|
||||
getNewsHotComment();
|
||||
getNewsCommentNum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
getNewsCommentNum();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getNewsCommentNum() {
|
||||
RetrofitManager.getComment()
|
||||
.getNewsCommentnum(mNewsDetailEntity.getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<CommentnumEntity>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(List<CommentnumEntity> response) {
|
||||
if (response.size() > 0 && response.get(0).getNum() > 0) {
|
||||
mCommentNum = response.get(0).getNum();
|
||||
getNewsHotComment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -344,7 +344,7 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
|
||||
@Override
|
||||
public void onLogin(UserInfoEntity entity, LoginUtils.LoginTag loginTag) {
|
||||
Utils.log("======登录成功" + entity.getIcon() + "==" + entity.getName());
|
||||
Utils.log("======登录成功" + entity.getIcon() + "==" + entity.getName() + "==" + loginTag);
|
||||
if (loginTag == null) { // loginTag 为空表明不是重新登录 重新登录需要初始化关注以及存号箱
|
||||
mUserInfoEntity = entity;
|
||||
changeLoginState(true);
|
||||
|
||||
@ -184,7 +184,7 @@ public interface ApiService {
|
||||
Observable<ResponseBody> getKaiFuOffset(@Query("type") String type); // 获取开服表偏移量
|
||||
|
||||
@GET("game/server")
|
||||
Observable<List<GameEntity>> getKaiFuData(@Query("type") String type, @Query("offset") int offset, @Query("limit") int limit); // 获取开服表数据
|
||||
Observable<List<GameEntity>> getKaiFuData(@Query("type") String type, @Query("day") String day, @Query("offset") int offset, @Query("limit") int limit); // 获取开服表数据
|
||||
|
||||
@GET("game/{game_id}/article_type")
|
||||
Observable<List<String>> getGameArticleType(@Path("game_id") String gameId); // 获取游戏新闻类型
|
||||
|
||||
@ -2,7 +2,9 @@ package com.gh.gamecenter.retrofit
|
||||
|
||||
import android.content.Context
|
||||
import com.gh.common.util.DeviceUtils
|
||||
import com.gh.common.util.DialogUtils
|
||||
import com.gh.common.util.LoginUtils
|
||||
import com.gh.common.util.StringUtils
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity
|
||||
import com.lightgame.config.CommonDebug
|
||||
import com.lightgame.utils.Utils
|
||||
@ -10,6 +12,7 @@ import okhttp3.*
|
||||
import okhttp3.Response
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
@ -23,7 +26,7 @@ import java.util.*
|
||||
* *
|
||||
* @Time 3:22 PM
|
||||
*/
|
||||
class OkHttpRetryInterceptor internal constructor(context : Context) : Interceptor {
|
||||
class OkHttpRetryInterceptor internal constructor(context: Context) : Interceptor {
|
||||
val mMaxRetryCount: Int = 3
|
||||
val mContext = context
|
||||
|
||||
@ -72,12 +75,40 @@ class OkHttpRetryInterceptor internal constructor(context : Context) : Intercept
|
||||
override fun onResponse(loginResponseEntity: LoginResponseEntity?) {
|
||||
LoginUtils.saveLoginToken(mContext, loginResponseEntity)
|
||||
val newBuilder = request.newBuilder()
|
||||
newBuilder .addHeader("TOKEN", loginResponseEntity?.accessToken?.value)
|
||||
newBuilder.addHeader("TOKEN", loginResponseEntity?.accessToken?.value)
|
||||
request = newBuilder.build()
|
||||
response = doRequest(chain, request)
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
try {
|
||||
val responseBody = e?.response()?.errorBody()
|
||||
val string = responseBody?.string()
|
||||
val content = JSONObject(string)
|
||||
val code = content.getInt("code")
|
||||
Utils.log("=======CODE::" + code + "==" + string)
|
||||
if (code == 40802) { // 其他设备登录了该账号
|
||||
Utils.log("=======40802::" + string)
|
||||
val device = content.getJSONObject("device")
|
||||
|
||||
val manufacturer = device.getString("manufacturer")
|
||||
val model = device.getString("model")
|
||||
|
||||
DialogUtils.showAlertDialog(mContext, "你的账号已在另外一台设备登录"
|
||||
, StringUtils.buildString("(", manufacturer, "-", model, ")")
|
||||
, "知道了", null, null, null)
|
||||
|
||||
LoginUtils.cleanUserData(mContext)
|
||||
// TODO 要不要调用退出登录接口
|
||||
}
|
||||
} catch (e1: Exception) {
|
||||
e1.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
} else{
|
||||
} else {
|
||||
// 重新登录
|
||||
LoginUtils.cleanUserData(mContext)
|
||||
Utils.toast(mContext, "账号过去,请重新登录!")
|
||||
|
||||
Reference in New Issue
Block a user