光环助手V3.2 RELEASE(20180419-1810)测试问题汇总(三.9和评论未完成)
This commit is contained in:
@ -17,29 +17,10 @@ public class AskErrorResponseUtils {
|
||||
public static void errorResponseControl(Context context, HttpException e) {
|
||||
if (e == null) return;
|
||||
int code = e.code();
|
||||
|
||||
try {
|
||||
JSONObject object = new JSONObject(e.response().errorBody().string());
|
||||
int errorCode = object.getInt("code");
|
||||
if (errorCode == 400) {
|
||||
switch (errorCode) {
|
||||
case 400001:
|
||||
Utils.toast(context, "提交的参数不符合接口的要求");
|
||||
break;
|
||||
case 400003:
|
||||
Utils.toast(context, "客户端提供的expert_id不存在");
|
||||
break;
|
||||
case 400004:
|
||||
Utils.toast(context, "缺少参数");
|
||||
break;
|
||||
case 400005:
|
||||
Utils.toast(context, "用户的评论被墙(黑名单)");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "网络错误");
|
||||
break;
|
||||
}
|
||||
} else if (code == 403) {
|
||||
if (code == 403) {
|
||||
JSONObject object = new JSONObject(e.response().errorBody().string());
|
||||
int errorCode = object.getInt("code");
|
||||
switch (errorCode) {
|
||||
case 403001:
|
||||
Utils.toast(context, "标签名称太长了");
|
||||
@ -90,8 +71,14 @@ public class AskErrorResponseUtils {
|
||||
Utils.toast(context, "网络错误");
|
||||
break;
|
||||
}
|
||||
} else if (code == 401 && errorCode == 404001) {
|
||||
Utils.toast(context, "请求的资源不存在");
|
||||
} else if (code == 401) {
|
||||
JSONObject object = new JSONObject(e.response().errorBody().string());
|
||||
int errorCode = object.getInt("code");
|
||||
if (errorCode == 404001) {
|
||||
Utils.toast(context, "请求的资源不存在");
|
||||
}
|
||||
} else {
|
||||
Utils.toast(context, "网络错误");
|
||||
}
|
||||
|
||||
} catch (Exception e1) {
|
||||
|
||||
@ -5,7 +5,11 @@ import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.LoginActivity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 28/06/17.
|
||||
@ -16,6 +20,11 @@ public class CheckLoginUtils {
|
||||
public static void checkLogin(final Context context, OnLoginListener listener) {
|
||||
// String token = LoginUtils.getToken(context);
|
||||
if (TextUtils.isEmpty(UserManager.getInstance().getToken())) {
|
||||
// 验证登录真实性
|
||||
if (!TextUtils.isEmpty(UserManager.getInstance().getTokenId(context))) {
|
||||
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGIN_RETRY));
|
||||
return;
|
||||
}
|
||||
AskLogUtils.login(context, "dialog", null);
|
||||
DialogUtils.showWarningDialog(context, "登录提示", "需要登录才能使用该功能喔!", "取消", "快速登录",
|
||||
new DialogUtils.ConfirmListener() {
|
||||
|
||||
45
app/src/main/java/com/gh/common/view/FixedSpeedScroller.java
Normal file
45
app/src/main/java/com/gh/common/view/FixedSpeedScroller.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Scroller;
|
||||
|
||||
/**
|
||||
* Created by khy on 20/04/18.
|
||||
*/
|
||||
|
||||
public class FixedSpeedScroller extends Scroller {
|
||||
private int mDuration = 0;
|
||||
|
||||
public FixedSpeedScroller(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public FixedSpeedScroller(Context context, Interpolator interpolator) {
|
||||
super(context, interpolator);
|
||||
}
|
||||
|
||||
public FixedSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) {
|
||||
super(context, interpolator, flywheel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
|
||||
super.startScroll(startX, startY, dx, dy, mDuration);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startScroll(int startX, int startY, int dx, int dy) {
|
||||
super.startScroll(startX, startY, dx, dy, mDuration);
|
||||
}
|
||||
|
||||
public void setmDuration(int time) {
|
||||
mDuration = time;
|
||||
}
|
||||
|
||||
public int getmDuration() {
|
||||
return mDuration;
|
||||
}
|
||||
}
|
||||
@ -59,11 +59,11 @@ public class AskSelectGameAdapter extends ListAdapter<AskGameSelectEntity> {
|
||||
if (i == 0) {
|
||||
AskGameSelectEntity e = new AskGameSelectEntity();
|
||||
if ("opened".equals(entity.getStatus())) {
|
||||
e.setId("已开通");
|
||||
e.setId("已开通的游戏");
|
||||
mEntityList.add(i, e);
|
||||
i++;
|
||||
} else {
|
||||
e.setId("投票中");
|
||||
e.setId("投票中的游戏");
|
||||
mEntityList.add(i, e);
|
||||
break;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public class AskSelectGameAdapter extends ListAdapter<AskGameSelectEntity> {
|
||||
if (!TextUtils.isEmpty(status) && !status.equals(lastEntity.getStatus())) { // 已开通/投票中 断点
|
||||
mTitlePosition = i - 1;
|
||||
AskGameSelectEntity e = new AskGameSelectEntity();
|
||||
e.setId("投票中");
|
||||
e.setId("投票中的游戏");
|
||||
mEntityList.add(i, e);
|
||||
break;
|
||||
}
|
||||
@ -90,7 +90,7 @@ public class AskSelectGameAdapter extends ListAdapter<AskGameSelectEntity> {
|
||||
}
|
||||
|
||||
AskGameSelectEntity entity = mEntityList.get(position);
|
||||
if ("投票中".equals(entity.getId()) || "已开通".equals(entity.getId())) {
|
||||
if ("投票中的游戏".equals(entity.getId()) || "已开通的游戏".equals(entity.getId())) {
|
||||
return ItemViewType.ITEM_TOP;
|
||||
} else {
|
||||
return ItemViewType.ITEM_BODY;
|
||||
|
||||
@ -274,6 +274,7 @@ public class AnswerCommentFragment extends ListFragment<CommentEntity, AnswerCom
|
||||
mCommentDetailCommentEt.setFocusable(true);
|
||||
mCommentDetailCommentEt.setFocusableInTouchMode(true);
|
||||
mCommentDetailCommentEt.requestFocus();
|
||||
mCommentDetailCommentEt.setText("");
|
||||
|
||||
if (mCommentEntity != null && mCommentEntity.getUser() != null) {
|
||||
mCommentDetailCommentEt.setHint(getString(R.string.comment_repty_hint, mCommentEntity.getUser().getName()));
|
||||
|
||||
@ -53,7 +53,7 @@ public class AskQuestionsRecommendsFragment extends ListFragment<AnswerEntity, A
|
||||
@Override
|
||||
protected void handleMessage(Message msg) {
|
||||
if (msg.what == 1) {
|
||||
mRefreshHeight-=2;
|
||||
mRefreshHeight -= 2;
|
||||
if (mRefreshHeight <= 8) {
|
||||
mRefreshHint.setVisibility(View.GONE);
|
||||
return;
|
||||
@ -64,7 +64,7 @@ public class AskQuestionsRecommendsFragment extends ListFragment<AnswerEntity, A
|
||||
mBaseHandler.sendEmptyMessage(1);
|
||||
} else if (msg.what == 0) {
|
||||
if (mRefreshHeight == 8) mRefreshHint.setVisibility(View.VISIBLE);
|
||||
mRefreshHeight+=2;
|
||||
mRefreshHeight += 2;
|
||||
if (mRefreshHeight >= 35) {
|
||||
mBaseHandler.sendEmptyMessageDelayed(1, 1000);
|
||||
return;
|
||||
@ -202,6 +202,7 @@ public class AskQuestionsRecommendsFragment extends ListFragment<AnswerEntity, A
|
||||
}
|
||||
|
||||
public void initList() {
|
||||
provideListAdapter().loadChange(LoadStatus.INIT);
|
||||
mReuseNoConn.setVisibility(View.GONE);
|
||||
mReuseNoData.setVisibility(View.GONE);
|
||||
mListLoading.setVisibility(View.VISIBLE);
|
||||
|
||||
@ -76,7 +76,7 @@ public class AskQuestionsRecommendsViewModel extends ListViewModel<AnswerEntity,
|
||||
}
|
||||
|
||||
private void loadData(boolean isUp, String sequenceId) {
|
||||
if (mIsLoading) return;
|
||||
if (mIsLoading && !TextUtils.isEmpty(sequenceId)) return;
|
||||
mIsLoading = true;
|
||||
String filter;
|
||||
String communityId = UserManager.getInstance().getCommunityId(getApplication());
|
||||
@ -118,6 +118,9 @@ public class AskQuestionsRecommendsViewModel extends ListViewModel<AnswerEntity,
|
||||
} else {
|
||||
if (response.code() != 403) {
|
||||
loadStatusControl(-1, sequenceId, isUp);
|
||||
} else { // 整条时间线都不可用
|
||||
mLiveData.setValue(new ArrayList<>());
|
||||
mLoadStatusLiveData.postValue(LoadStatus.INIT_FAILED);
|
||||
}
|
||||
}
|
||||
mIsLoading = false;
|
||||
@ -197,8 +200,8 @@ public class AskQuestionsRecommendsViewModel extends ListViewModel<AnswerEntity,
|
||||
if (dbData == null || dbData.size() == 0) {
|
||||
loadData(false, null);
|
||||
} else {
|
||||
mLoadStatusLiveData.setValue(LoadStatus.LIST_LOADING);
|
||||
mLiveData.postValue(dbData);
|
||||
mLoadStatusLiveData.postValue(LoadStatus.INIT_LOADED);
|
||||
loadData(true, dbData.get(0).getSequenceId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.CommunitySubjectActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.RecyclingPagerAdapter;
|
||||
@ -43,7 +44,12 @@ public class AskSubjectPageAdapter extends RecyclingPagerAdapter {
|
||||
binding.setEntity(entity);
|
||||
ImageUtils.Companion.getInstance().displayScale(binding.subjectIcon, entity.getThumb(), DisplayUtils.dip2px(mContext, 67));
|
||||
binding.getRoot().setOnClickListener(v -> {
|
||||
mContext.startActivity(CommunitySubjectActivity.getIntent(mContext, entity));
|
||||
if ("answer_list".equals(entity.getType())) {
|
||||
mContext.startActivity(CommunitySubjectActivity.getIntent(mContext, entity));
|
||||
} else {
|
||||
mContext.startActivity(AnswerDetailActivity.getIntent(mContext, entity.getId(), "(问答专题)"));
|
||||
}
|
||||
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
package com.gh.gamecenter.ask;
|
||||
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.common.view.FixedSpeedScroller;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.AskSubjectEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import butterknife.BindView;
|
||||
import cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager;
|
||||
|
||||
@ -23,5 +27,18 @@ public class AskSubjectViewHolder extends BaseRecyclerViewHolder<AskSubjectEntit
|
||||
|
||||
public AskSubjectViewHolder(View view) {
|
||||
super(view);
|
||||
setViewPagerScrollSpeed();
|
||||
}
|
||||
|
||||
private void setViewPagerScrollSpeed() {
|
||||
try {
|
||||
Field mScroller = null;
|
||||
mScroller = ViewPager.class.getDeclaredField("mScroller");
|
||||
mScroller.setAccessible(true);
|
||||
FixedSpeedScroller scroller = new FixedSpeedScroller(mSubjectViewPager.getContext());
|
||||
mScroller.set(mSubjectViewPager, scroller);
|
||||
scroller.setmDuration(2000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ public class QuestionsEditIndexFragment extends ListFragment<QuestionsIndexEntit
|
||||
}
|
||||
|
||||
public void search(String key) {
|
||||
mAdapter.loadChange(LoadStatus.REFRESH);
|
||||
mAdapter.loadChange(LoadStatus.INIT);
|
||||
mSearchKey = key;
|
||||
mAdapter.setSearchKey(key);
|
||||
if (mListViewModel != null) mListViewModel.load(LoadType.REFRESH);
|
||||
|
||||
@ -92,7 +92,7 @@ public class SelectGameFragment extends ListFragment<AskGameSelectEntity, Select
|
||||
|
||||
int position = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if (position == mAdapter.getTitlePosition()) {
|
||||
mRvTitle.setText("已开通");
|
||||
mRvTitle.setText("已开通的游戏");
|
||||
int buttom = mLayoutManager.findViewByPosition(position).getBottom();
|
||||
if (buttom <= mRvTitle.getHeight()) {
|
||||
mParams.topMargin = buttom - mRvTitle.getHeight();
|
||||
@ -105,9 +105,9 @@ public class SelectGameFragment extends ListFragment<AskGameSelectEntity, Select
|
||||
mParams.topMargin = 0;
|
||||
mRvTitle.setLayoutParams(mParams);
|
||||
if (position > mAdapter.getTitlePosition()) {
|
||||
mRvTitle.setText("投票中");
|
||||
mRvTitle.setText("投票中的游戏");
|
||||
} else {
|
||||
mRvTitle.setText("已开通");
|
||||
mRvTitle.setText("已开通的游戏");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@ public class AskSubjectEntity implements Parcelable {
|
||||
|
||||
public final static String TAG = "AskSubjectEntity";
|
||||
|
||||
@SerializedName("_id")
|
||||
@SerializedName("link")
|
||||
private String id;
|
||||
|
||||
private String thumb;
|
||||
|
||||
private String type;
|
||||
|
||||
private String icon;
|
||||
|
||||
private String title;
|
||||
@ -34,6 +36,7 @@ public class AskSubjectEntity implements Parcelable {
|
||||
protected AskSubjectEntity(Parcel in) {
|
||||
id = in.readString();
|
||||
thumb = in.readString();
|
||||
type = in.readString();
|
||||
icon = in.readString();
|
||||
title = in.readString();
|
||||
description = in.readString();
|
||||
@ -68,6 +71,14 @@ public class AskSubjectEntity implements Parcelable {
|
||||
this.thumb = thumb;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
@ -109,6 +120,7 @@ public class AskSubjectEntity implements Parcelable {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(id);
|
||||
dest.writeString(thumb);
|
||||
dest.writeString(type);
|
||||
dest.writeString(icon);
|
||||
dest.writeString(title);
|
||||
dest.writeString(description);
|
||||
|
||||
@ -6,6 +6,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
@ -72,7 +73,8 @@ public class AnswerFoldFragment extends ListFragment<AnswerEntity, NormalListVie
|
||||
|
||||
@Override
|
||||
public Observable<List<AnswerEntity>> provideDataObservable(int page) {
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getQuestionsAnswer(mQuestionsId, true, page);
|
||||
return RetrofitManager.getInstance(getContext()).getApi()
|
||||
.getQuestionsAnswer(mQuestionsId, UrlFilterUtils.getFilterQuery("fold", "true"), page);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -174,11 +174,10 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
|
||||
List<String> tags = mQuestionsDetailEntity.getTags();
|
||||
holder.mTagRl.removeAllViews();
|
||||
addTag(holder.mTagRl, mQuestionsDetailEntity.getCommunityName(), false);
|
||||
for (int i = 0; i < tags.size(); i++) {
|
||||
addTag(holder.mTagRl, tags.get(i), i == tags.size() - 1);
|
||||
addTag(holder.mTagRl, tags.get(i), false);
|
||||
}
|
||||
|
||||
addTag(holder.mTagRl, mQuestionsDetailEntity.getCommunityName(), true);
|
||||
String description = mQuestionsDetailEntity.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
holder.mDesRl.setVisibility(View.GONE);
|
||||
|
||||
@ -26,6 +26,7 @@ import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.AnswerEditActivity;
|
||||
@ -167,7 +168,8 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
|
||||
@Override
|
||||
public Observable<List<AnswerEntity>> provideDataObservable(int page) {
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getQuestionsAnswer(mQuestionsId, false, page);
|
||||
return RetrofitManager.getInstance(getContext()).getApi()
|
||||
.getQuestionsAnswer(mQuestionsId, UrlFilterUtils.getFilterQuery("fold", "false"), page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -338,7 +340,7 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
public void postAnswerSuccess(String answerId) {
|
||||
if (mQuestionsDetailEntity != null) {
|
||||
mQuestionsDetailEntity.getMe().setMyAnswerId(answerId);
|
||||
onRefresh();
|
||||
getQuestionsDetail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
|
||||
import android.app.Application;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.gh.gamecenter.ask.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.baselist.ListViewModel;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by khy on 20/03/18.
|
||||
*/
|
||||
|
||||
public class QuestionsDetailViewModel extends ListViewModel<AnswerEntity, AnswerEntity> {
|
||||
|
||||
public QuestionsDetailViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<AnswerEntity>> provideDataObservable(int page) {
|
||||
return RetrofitManager.getInstance(getApplication()).getApi().getQuestionsAnswer("", false, page);
|
||||
}
|
||||
}
|
||||
@ -104,15 +104,16 @@ public abstract class ListAdapter<DataType> extends BaseRecyclerAdapter {
|
||||
mIsOver = false;
|
||||
mIsNetworkError = true;
|
||||
break;
|
||||
case INIT:
|
||||
case LIST_LOADED:
|
||||
case LIST_LOADING:
|
||||
if (!mIsNetworkError && !mIsOver) return;
|
||||
mIsNetworkError = false;
|
||||
mIsOver = false;
|
||||
break;
|
||||
case REFRESH:
|
||||
case INIT:
|
||||
if (mEntityList != null) mEntityList.clear();
|
||||
mIsNetworkError = false;
|
||||
mIsOver = false;
|
||||
notifyDataSetChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ public class ListRepository<LD> {
|
||||
if (loadType == LoadType.REFRESH) {
|
||||
initLoadParams();
|
||||
} else if (loadType == LoadType.RETRY) {
|
||||
mLoadStatusLiveData.setValue(LoadStatus.INIT);
|
||||
mLoadStatusLiveData.setValue(LoadStatus.LIST_LOADED);
|
||||
}
|
||||
loadData();
|
||||
}
|
||||
|
||||
@ -5,10 +5,6 @@ package com.gh.gamecenter.baselist;
|
||||
*/
|
||||
|
||||
public enum LoadStatus {
|
||||
|
||||
// todo 删除
|
||||
REFRESH,
|
||||
|
||||
//初始化加载状态
|
||||
INIT,
|
||||
INIT_LOADING,
|
||||
|
||||
@ -252,6 +252,7 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL
|
||||
mDownloadView.setVisibility(View.GONE);
|
||||
layoutParams.weight = 0.4f;
|
||||
}
|
||||
mDownloadView.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +101,8 @@ class Libao3FragmentAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder>
|
||||
if (response.size() > 0) {
|
||||
getLibaoStatus(response);
|
||||
}
|
||||
|
||||
mPage++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -509,4 +509,8 @@ class UserRepository {
|
||||
public MediatorLiveData<ApiResponse<UserInfoEntity>> getEditObsUserInfo() {
|
||||
return mEditObsResponseUserInfo;
|
||||
}
|
||||
|
||||
public String getCachedId() {
|
||||
return mCachedId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,11 +5,9 @@ import android.arch.lifecycle.AndroidViewModel;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@ -31,8 +29,6 @@ public class UserViewModel extends AndroidViewModel {
|
||||
public static final String TYPE_PORTRAIT = "icon";
|
||||
public static final String TYPE_REGION = "region";
|
||||
|
||||
private String mCurrentUserId;
|
||||
|
||||
private UserRepository mUserRepository;
|
||||
|
||||
private final LiveData<ApiResponse<UserInfoEntity>> mLoginLiveUserInfo;
|
||||
@ -40,7 +36,6 @@ public class UserViewModel extends AndroidViewModel {
|
||||
|
||||
public UserViewModel(@NonNull Application application, UserRepository repository) {
|
||||
super(application);
|
||||
mCurrentUserId = PreferenceManager.getDefaultSharedPreferences(application).getString(Constants.LOGIN_TOKEN_ID, null);
|
||||
mUserRepository = repository;
|
||||
mLoginLiveUserInfo = repository.getLoginUserInfo();
|
||||
mEditLiveUserInfo = repository.getEditObsUserInfo();
|
||||
@ -63,7 +58,7 @@ public class UserViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return !TextUtils.isEmpty(mCurrentUserId);
|
||||
return !TextUtils.isEmpty(mUserRepository.getCachedId());
|
||||
}
|
||||
|
||||
public void changeUserInfo(String content, String type) {
|
||||
@ -71,14 +66,9 @@ public class UserViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
setCurrentUserId(null);
|
||||
mUserRepository.logout();
|
||||
}
|
||||
|
||||
private void setCurrentUserId(String currentUserId) {
|
||||
mCurrentUserId = currentUserId;
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
@NonNull
|
||||
private final Application mApplication;
|
||||
|
||||
@ -94,7 +94,7 @@ public class RefreshTokenManager {
|
||||
response.setLoginType(loginTokenEntity.getLoginType());
|
||||
response.setId(loginTokenEntity.getId());
|
||||
}
|
||||
savaLoginToken(response, mContext);
|
||||
saveLoginToken(response, mContext);
|
||||
|
||||
refreshUserInfo(callBack, response.getId());
|
||||
}
|
||||
@ -131,7 +131,7 @@ public class RefreshTokenManager {
|
||||
|
||||
private void refreshUserInfo(final refreshCallBack callBack, final String cacheId) {
|
||||
mApiService
|
||||
.getUserInfo(BuildConfig.API_HOST + "users:validate")
|
||||
.getRetryUserInfo(BuildConfig.API_HOST + "users:validate")
|
||||
.subscribe(new Response<UserInfoEntity>() {
|
||||
@Override
|
||||
public void onResponse(UserInfoEntity response) {
|
||||
@ -158,7 +158,7 @@ public class RefreshTokenManager {
|
||||
});
|
||||
}
|
||||
|
||||
private void savaLoginToken(final LoginTokenEntity tokenEntity, final Context context) {
|
||||
private void saveLoginToken(final LoginTokenEntity tokenEntity, final Context context) {
|
||||
UserManager.getInstance().setLoginTokenEntity(tokenEntity);
|
||||
|
||||
SINGLE_EXECUTOR.execute(new Runnable() {
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.gamecenter.entity.LoginTokenEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
|
||||
@ -93,6 +94,10 @@ public class UserManager {
|
||||
return mCommunityName;
|
||||
}
|
||||
|
||||
public String getTokenId(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(Constants.LOGIN_TOKEN_ID, null);
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
mUserInfoEntity = null;
|
||||
mLoginTokenEntity = null;
|
||||
|
||||
@ -116,6 +116,7 @@ public class PersonalFragment extends BaseFragment implements Observer<ApiRespon
|
||||
|
||||
public final static String LOGIN_TAG = "login_tag"; //登入标识
|
||||
public final static String LOGOUT_TAG = "logout_tag"; // 登出标识
|
||||
public final static String LOGIN_RETRY = "login_retry";
|
||||
public final static String MESSAGE_UNREAD_TAG = "message_unread_tag";
|
||||
public final static String MESSAGE_READ_OVER = "MESSAGE_READ_OVER";
|
||||
public static final int REQUEST_MESSAGE = 199;
|
||||
@ -206,6 +207,8 @@ public class PersonalFragment extends BaseFragment implements Observer<ApiRespon
|
||||
}
|
||||
} else if (LOGOUT_TAG.equals(reuse.getType())) {
|
||||
mUserViewModel.logout();
|
||||
} else if (LOGIN_RETRY.equals(reuse.getType())) {
|
||||
mUserViewModel.retryCheckLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,12 +446,23 @@ public class PersonalFragment extends BaseFragment implements Observer<ApiRespon
|
||||
mUnreadViewModel.clean();
|
||||
changeLoginState(false);
|
||||
EventBus.getDefault().post(new EBConcernChanged());
|
||||
isLogin = false;
|
||||
} else {
|
||||
changeLoginState(true);
|
||||
isLogin = true;
|
||||
}
|
||||
|
||||
if (mLoginDialog != null) {
|
||||
mLoginDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// 检验登录一致性
|
||||
if (isLogin && TextUtils.isEmpty(UserManager.getInstance().getToken())) {
|
||||
mUserViewModel.retryCheckLogin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ public class InstallAndUninstallReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Utils.log("InstallAndUninstallReceiver:: onReceive->" + intent.getAction() + "==" + intent.getDataString());
|
||||
// 接收安装广播
|
||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
|
||||
String packageName = intent.getDataString();
|
||||
|
||||
@ -398,8 +398,8 @@ public interface ApiService {
|
||||
Observable<UserInfoEntity> getUserInfo(@Url String url);
|
||||
|
||||
@Headers({"Content-Type: application/json"}) // Headers(Content-Type) 作为区分 userinfo 的唯一标识
|
||||
@GET("users:validate")
|
||||
Observable<UserInfoEntity> getRetryUserInfo(); // 在OkHttpRetryInterceptor使用主要是不允许这个接口重试
|
||||
@POST()
|
||||
Observable<UserInfoEntity> getRetryUserInfo(@Url String url); // 在OkHttpRetryInterceptor使用主要是不允许这个接口重试
|
||||
|
||||
// /**
|
||||
// * 检查手机号码是否可用
|
||||
@ -452,7 +452,7 @@ public interface ApiService {
|
||||
*/
|
||||
@Headers({"Content-Type: application/json", "Accept: application/json"})
|
||||
@PUT("users/{user_id}/packages")
|
||||
Observable<ResponseBody> putPackage(@Path("user_id") String user_id, @Body RequestBody body);
|
||||
Observable<ResponseBody> putPackage(@Path("user_id") String user_id, @Body RequestBody body); // todo
|
||||
|
||||
|
||||
/*********** CommentService ************/
|
||||
@ -710,7 +710,7 @@ public interface ApiService {
|
||||
* 社区问题的回答列表
|
||||
*/
|
||||
@GET("questions/{questions_id}/answers?view=digest")
|
||||
Observable<List<AnswerEntity>> getQuestionsAnswer(@Path("questions_id") String questionsId, @Query("fold") boolean isFold, @Query("page") int page);
|
||||
Observable<List<AnswerEntity>> getQuestionsAnswer(@Path("questions_id") String questionsId, @Query("filter") String filter, @Query("page") int page);
|
||||
|
||||
/**
|
||||
* 获取社区达人列表
|
||||
|
||||
@ -61,7 +61,7 @@ public class SubjectListFragment extends BaseFragment implements OnTitleClickLis
|
||||
private String mListOrder; // 列表排序 最新/最热
|
||||
|
||||
private boolean mIsOrder;
|
||||
private boolean mScorllTop = false;
|
||||
private boolean mScrollTop = false;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
@ -131,8 +131,8 @@ public class SubjectListFragment extends BaseFragment implements OnTitleClickLis
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
int position = mLayoutManager.findFirstCompletelyVisibleItemPosition();
|
||||
if (mScorllTop && position == 0 && newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
mScorllTop = false;
|
||||
if (mScrollTop && position == 0 && newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
mScrollTop = false;
|
||||
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ public class SubjectListFragment extends BaseFragment implements OnTitleClickLis
|
||||
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
|
||||
} else {
|
||||
mLayoutManager.smoothScrollToPosition(mRvSubject, null, 0);
|
||||
mScorllTop = true;
|
||||
mScrollTop = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user