优化开服表(主要是单个游戏开服点下载是非常卡,修复后还是有点卡),把首页控制台的消息提示红点移到我的光环
This commit is contained in:
@ -85,6 +85,7 @@ public class KaiFuActivity extends BaseActivity {
|
||||
|
||||
private void resetFragment() {
|
||||
mResetTv.setVisibility(View.GONE);
|
||||
mKaiFuFragment.onPause();
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.remove(mGameKaiFuFragment);
|
||||
fragmentTransaction.show(mKaiFuFragment);
|
||||
@ -99,6 +100,7 @@ public class KaiFuActivity extends BaseActivity {
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(mKaiFuFragment);
|
||||
mKaiFuFragment.onPause();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("gameId", reset.getGameId());
|
||||
|
||||
@ -728,7 +728,7 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void checkDevice() {
|
||||
// String deviceId = TokenUtils.getDeviceId(this); // TODO
|
||||
// String deviceId = TokenUtils.getDeviceId(this); // TODO 还要不要这个判断?
|
||||
if (true) {
|
||||
String content = DeviceUtils.getUserDevice(MainActivity.this).toString();
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
|
||||
@ -13,11 +13,8 @@ import com.gh.base.fragment.BaseFragment_ViewPager_Checkable;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.db.KeFuMarkReadDao;
|
||||
import com.gh.gamecenter.db.MessageMarkReadDao;
|
||||
import com.gh.gamecenter.db.info.MessageMarkReadInfo;
|
||||
import com.gh.gamecenter.entity.MessageUnreadEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.message.MessageFragment;
|
||||
@ -94,7 +91,6 @@ public class MainFragment extends BaseFragment_ViewPager_Checkable {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
checkMarkRead(getContext()); // 检查是否有记录已读消息
|
||||
checkMessageUnread(getContext()); // 检查是否有未读消息
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,15 +140,6 @@ public class MainFragment extends BaseFragment_ViewPager_Checkable {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if (MessageFragment.MESSAGE_READ_OVER.equals(reuse.getType())) {
|
||||
if (mMessageHint != null) {
|
||||
mMessageHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getSearchHints() {
|
||||
RetrofitManager.getApi().getSearchHints()
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -173,44 +160,6 @@ public class MainFragment extends BaseFragment_ViewPager_Checkable {
|
||||
});
|
||||
}
|
||||
|
||||
private void checkMessageUnread(final Context context) {
|
||||
if (context == null) return;
|
||||
|
||||
RetrofitManager.getMessage()
|
||||
.getMessageUnread(LoginUtils.getToken(context))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<MessageUnreadEntity>() {
|
||||
@Override
|
||||
public void onResponse(MessageUnreadEntity response) {
|
||||
super.onResponse(response);
|
||||
if (response != null && response.getKefuList() != null && response.getKefuList().size() > 0) {
|
||||
KeFuMarkReadDao dao = new KeFuMarkReadDao(context);
|
||||
for (int i = 0; i < response.getKefuList().size(); i++) {
|
||||
if (dao.isMarkRead(response.getKefuList().get(i))) {
|
||||
response.getKefuList().remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (response.getKefuList() != null && response.getKefuList().size() > 0) {
|
||||
mMessageHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (response != null && response.getComment() > 0) {
|
||||
mMessageHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkMarkRead(Context context) {
|
||||
MessageMarkReadDao readDao = new MessageMarkReadDao(context);
|
||||
List<MessageMarkReadInfo> readInfos = readDao.getAll();
|
||||
|
||||
@ -8,6 +8,7 @@ import android.view.View;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.adapter.FragmentAdapter;
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.gamecenter.R;
|
||||
@ -35,6 +36,8 @@ public class KaiFuFragment extends BaseFragment {
|
||||
@BindView(R.id.kaifu_content_vp)
|
||||
ViewPager mKaifuContentVp;
|
||||
|
||||
private List<Fragment> mFragments;
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@ -45,15 +48,15 @@ public class KaiFuFragment extends BaseFragment {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
List<Fragment> fragments = new ArrayList<>();
|
||||
mFragments = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
KaiFuVpFragment kaiFuVpFragment = new KaiFuVpFragment();
|
||||
if (getArguments() != null) {
|
||||
kaiFuVpFragment.setArguments(getArguments());
|
||||
}
|
||||
fragments.add(kaiFuVpFragment);
|
||||
mFragments.add(kaiFuVpFragment);
|
||||
}
|
||||
FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager(), fragments);
|
||||
FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager(), mFragments);
|
||||
|
||||
setTabbarPosition(0);
|
||||
mKaifuContentVp.setAdapter(fragmentAdapter);
|
||||
@ -69,28 +72,59 @@ public class KaiFuFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
public void onPageScrollStateChanged(final int state) {
|
||||
setPageScrollState(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
for (Fragment fragment : mFragments) {
|
||||
fragment.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
for (Fragment fragment : mFragments) {
|
||||
fragment.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.kaifu_tabbar_today, R.id.kaifu_tabbar_tomorrow, R.id.kaifu_tabbar_future})
|
||||
public void onViewClicked(View view) {
|
||||
int index = 0;
|
||||
switch (view.getId()) {
|
||||
case R.id.kaifu_tabbar_today:
|
||||
setTabbarPosition(0);
|
||||
mKaifuContentVp.setCurrentItem(0);
|
||||
index = 0;
|
||||
break;
|
||||
case R.id.kaifu_tabbar_tomorrow:
|
||||
setTabbarPosition(1);
|
||||
mKaifuContentVp.setCurrentItem(1);
|
||||
index = 1;
|
||||
break;
|
||||
case R.id.kaifu_tabbar_future:
|
||||
setTabbarPosition(2);
|
||||
mKaifuContentVp.setCurrentItem(2);
|
||||
index = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
setTabbarPosition(index);
|
||||
mKaifuContentVp.setCurrentItem(index);
|
||||
setPageScrollState(1);
|
||||
}
|
||||
|
||||
private void setPageScrollState(final int state) {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Fragment fragment : mFragments) {
|
||||
if (fragment.getUserVisibleHint() && fragment instanceof KaiFuVpFragment) {
|
||||
((KaiFuVpFragment) fragment).vpScrollState(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setTabbarPosition(int index) {
|
||||
|
||||
@ -73,7 +73,6 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
mOnCallBackListener = onCallBackListener;
|
||||
mLocationMap = new ArrayMap<>();
|
||||
mEntityList = new ArrayList<>();
|
||||
addList(0);
|
||||
}
|
||||
|
||||
public void addList(int offset) {
|
||||
@ -91,9 +90,6 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
if (mEntityList.size() == 0) { // TODO 获取开服表当前整点时间位置
|
||||
|
||||
}
|
||||
|
||||
if (response.size() < 20) mIsRemove = true;
|
||||
|
||||
GameManager manager = new GameManager(mContext);
|
||||
for (int i = 0; i < response.size(); i++) {
|
||||
// 初始化游戏状态
|
||||
@ -143,6 +139,11 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
mEntityList.addAll(response);
|
||||
notifyItemRangeInserted(mEntityList.size() - response.size(), response.size());
|
||||
|
||||
if (response.size() < 20) {
|
||||
mIsRemove = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
initLocationMap();
|
||||
|
||||
if (mEntityList.size() == 0) {
|
||||
@ -154,15 +155,16 @@ public class KaiFuVpAdapter extends BaseRecyclerAdapter {
|
||||
mIsLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
|
||||
mIsLoaded = true;
|
||||
if (mEntityList.size() == 0) {
|
||||
mOnCallBackListener.loadError();
|
||||
} else {
|
||||
mIsNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.gamecenter.kaifu;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -22,6 +23,7 @@ import com.gh.gamecenter.entity.KaiFuServerEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
@ -30,6 +32,8 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
@ -60,11 +64,14 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
|
||||
private String mGameId;
|
||||
|
||||
private boolean mIsRefershDownload;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
if (locationList != null && mIsRefershDownload) {
|
||||
Utils.log("===============mGameId::" + mGameId);
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = mAdapter.getDataList().get(location);
|
||||
@ -111,6 +118,12 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
&& newState == RecyclerView.SCROLL_STATE_IDLE && !mAdapter.isRemove() && mAdapter.isLoaded()) {
|
||||
mAdapter.addList(mAdapter.getDataListCount());
|
||||
}
|
||||
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
mIsRefershDownload = true;
|
||||
} else {
|
||||
mIsRefershDownload = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,11 +166,46 @@ public class KaiFuVpFragment extends BaseFragment {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (getUserVisibleHint()) {
|
||||
mIsRefershDownload = true;
|
||||
if (mLoading == null) {
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUserVisibleHint(true);
|
||||
}
|
||||
}, 500);
|
||||
} else if (mLoading.getVisibility() == View.VISIBLE) {
|
||||
mAdapter.addList(0);
|
||||
}
|
||||
} else {
|
||||
mIsRefershDownload = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void vpScrollState(int status) {
|
||||
if (status == ViewPager.SCROLL_STATE_IDLE) {
|
||||
if (getUserVisibleHint()) {
|
||||
mIsRefershDownload = true;
|
||||
}
|
||||
} else if (status == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||
if (getUserVisibleHint()) {
|
||||
mIsRefershDownload = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
DownloadManager.getInstance(getContext()).addObserver(dataWatcher);
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
DownloadManager.getInstance(getContext()).addObserver(dataWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter.personal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -29,10 +30,13 @@ import com.gh.gamecenter.ShareGhActivity;
|
||||
import com.gh.gamecenter.SuggestSelectActivity;
|
||||
import com.gh.gamecenter.SuggestionActivity;
|
||||
import com.gh.gamecenter.UserInfoActivity;
|
||||
import com.gh.gamecenter.db.KeFuMarkReadDao;
|
||||
import com.gh.gamecenter.entity.AppEntity;
|
||||
import com.gh.gamecenter.entity.MessageUnreadEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.message.MessageFragment;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
@ -45,6 +49,7 @@ import org.json.JSONObject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import retrofit2.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
@ -153,9 +158,14 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
if (reuse.getType().equals(LOGIN_TAG)) { // 登入
|
||||
mUserInfoEntity = LoginUtils.getUserInfo(getContext());
|
||||
changeLoginState(true);
|
||||
checkMessageUnread(getContext()); // 检查是否有未读消息
|
||||
} else if (reuse.getType().equals(LOGOUT_TAG)) { // 登出
|
||||
changeLoginState(false);
|
||||
mUserInfoEntity = null;
|
||||
} else if (MessageFragment.MESSAGE_READ_OVER.equals(reuse.getType())) { // 消息阅读完成
|
||||
if (mLoginMessgeHint != null) {
|
||||
mLoginMessgeHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,6 +237,44 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMessageUnread(final Context context) {
|
||||
if (context == null) return;
|
||||
|
||||
RetrofitManager.getMessage()
|
||||
.getMessageUnread(LoginUtils.getToken(context))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<MessageUnreadEntity>() {
|
||||
@Override
|
||||
public void onResponse(MessageUnreadEntity response) {
|
||||
super.onResponse(response);
|
||||
if (response != null && response.getKefuList() != null && response.getKefuList().size() > 0) {
|
||||
KeFuMarkReadDao dao = new KeFuMarkReadDao(context);
|
||||
for (int i = 0; i < response.getKefuList().size(); i++) {
|
||||
if (dao.isMarkRead(response.getKefuList().get(i))) {
|
||||
response.getKefuList().remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (response.getKefuList() != null && response.getKefuList().size() > 0) {
|
||||
mLoginMessgeHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (response != null && response.getComment() > 0) {
|
||||
mLoginMessgeHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeLoginState(boolean isLogin) {
|
||||
if (isLogin) {
|
||||
if (mUserInfoEntity != null) {
|
||||
|
||||
Reference in New Issue
Block a user