|
|
|
@@ -1,21 +1,27 @@
|
|
|
|
|
package com.yizhuan.erban.home.fragment;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
|
|
import com.coorchice.library.utils.LogUtils;
|
|
|
|
|
import com.yizhuan.erban.R;
|
|
|
|
|
import com.yizhuan.erban.base.BaseFragment;
|
|
|
|
|
import com.yizhuan.erban.home.adapter.HomePlayAdapter;
|
|
|
|
|
import com.yizhuan.erban.home.event.HomeScrollEvent;
|
|
|
|
|
import com.yizhuan.xchat_android_core.home.bean.HomePlayInfo;
|
|
|
|
|
import com.yizhuan.xchat_android_core.home.event.HomeDynamicEvent;
|
|
|
|
|
import com.yizhuan.xchat_android_core.home.event.RefreshHomeDataEvent;
|
|
|
|
|
import com.yizhuan.xchat_android_core.home.model.GameHomeModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.initial.InitialModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.user.event.LoadLoginUserInfoEvent;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.SizeUtils;
|
|
|
|
@@ -42,7 +48,9 @@ public class HomePlayFragment extends BaseFragment{
|
|
|
|
|
RecyclerView recyclerView;
|
|
|
|
|
// @BindView(R.id.refresh_layout)
|
|
|
|
|
// SwipeRefreshLayout refreshLayout;
|
|
|
|
|
|
|
|
|
|
private Handler handler = new Handler();
|
|
|
|
|
private Runnable runnable;
|
|
|
|
|
private List<HomePlayInfo> homePlayList;
|
|
|
|
|
private boolean isLoading = false;
|
|
|
|
|
|
|
|
|
|
private HomePlayAdapter playAdapter;
|
|
|
|
@@ -101,24 +109,54 @@ public class HomePlayFragment extends BaseFragment{
|
|
|
|
|
getHomPlay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
private void getHomPlay(){
|
|
|
|
|
GameHomeModel.get().getHomePlay().subscribe((serviceResult, throwable) -> {
|
|
|
|
|
if (throwable != null) {
|
|
|
|
|
isLoading = false;
|
|
|
|
|
} else {
|
|
|
|
|
isLoading = false;
|
|
|
|
|
List<HomePlayInfo> info = serviceResult;
|
|
|
|
|
if (ListUtils.isListEmpty(info)) {
|
|
|
|
|
homePlayList = serviceResult;
|
|
|
|
|
if (ListUtils.isListEmpty(homePlayList)) {
|
|
|
|
|
showNoData(R.drawable.icon_common_failure, "这里什么都没有");
|
|
|
|
|
}else {
|
|
|
|
|
hideStatus();
|
|
|
|
|
playAdapter.setNewData(homePlayList);
|
|
|
|
|
refreshData();
|
|
|
|
|
}
|
|
|
|
|
playAdapter.setNewData(info);
|
|
|
|
|
playAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void refreshData(){
|
|
|
|
|
int REFRESH_SPEED = InitialModel.get().getDynamicRefresh() > 0?InitialModel.get().getDynamicRefresh()*1000:3000;//默认3秒
|
|
|
|
|
|
|
|
|
|
LogUtils.e("REFRESH_SPEED"+REFRESH_SPEED);
|
|
|
|
|
if (ListUtils.isListEmpty(homePlayList) || runnable != null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
runnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (getActivity() != null) {
|
|
|
|
|
playAdapter.addData(0,homePlayList.get(homePlayList.size()-1));
|
|
|
|
|
playAdapter.remove(homePlayList.size()-1);
|
|
|
|
|
handler.postDelayed(this, REFRESH_SPEED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
handler.postDelayed(runnable,REFRESH_SPEED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
public void onAutoRunningEvent(HomeDynamicEvent event) {
|
|
|
|
|
if (event.isRunning()){
|
|
|
|
|
stopTimer();
|
|
|
|
|
}else {
|
|
|
|
|
refreshData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReloadData() {
|
|
|
|
|
loadData();
|
|
|
|
@@ -151,4 +189,20 @@ public class HomePlayFragment extends BaseFragment{
|
|
|
|
|
unbinder.unbind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stopTimer(){
|
|
|
|
|
handler.removeCallbacks(runnable);
|
|
|
|
|
runnable = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
stopTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
stopTimer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|