|
@@ -2,6 +2,7 @@ package com.kfzs.duanduan.fragment;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
|
+import android.os.Handler;
|
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
@@ -16,6 +17,7 @@ import com.mdad.sdk.mdsdk.AdManager;
|
|
|
import com.mdad.sdk.mdsdk.GetAdListListener;
|
|
import com.mdad.sdk.mdsdk.GetAdListListener;
|
|
|
import com.mdad.sdk.mdsdk.RewardListener;
|
|
import com.mdad.sdk.mdsdk.RewardListener;
|
|
|
import com.mdad.sdk.mdsdk.common.AdData;
|
|
import com.mdad.sdk.mdsdk.common.AdData;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.AdDataSon;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.GameAgencyRechargePlatformEntity;
|
|
import com.sheep.gamegroup.model.entity.GameAgencyRechargePlatformEntity;
|
|
|
import com.sheep.gamegroup.model.entity.RecyleObj;
|
|
import com.sheep.gamegroup.model.entity.RecyleObj;
|
|
@@ -29,6 +31,7 @@ import com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
@@ -56,9 +59,9 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
private AdListAdapter adListAdapter;
|
|
private AdListAdapter adListAdapter;
|
|
|
private int pageNo = 1;
|
|
private int pageNo = 1;
|
|
|
private int pageSize = 30;
|
|
private int pageSize = 30;
|
|
|
- private List<AdData> listData = ListUtil.emptyList();
|
|
|
|
|
|
|
+ private List<AdDataSon> listData = ListUtil.emptyList();
|
|
|
|
|
|
|
|
- public static FgtMiDong newInstance(int type){
|
|
|
|
|
|
|
+ public static FgtMiDong newInstance(int type) {
|
|
|
FgtMiDong fgtMiDong = new FgtMiDong();
|
|
FgtMiDong fgtMiDong = new FgtMiDong();
|
|
|
Bundle bundle = new Bundle();
|
|
Bundle bundle = new Bundle();
|
|
|
bundle.putInt("type", type);
|
|
bundle.putInt("type", type);
|
|
@@ -70,7 +73,7 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
Bundle bundle = getArguments();
|
|
Bundle bundle = getArguments();
|
|
|
- if(bundle != null){
|
|
|
|
|
|
|
+ if (bundle != null) {
|
|
|
type = bundle.getInt("type", 0);
|
|
type = bundle.getInt("type", 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -83,7 +86,8 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
initView();
|
|
initView();
|
|
|
initData(false);
|
|
initData(false);
|
|
|
}
|
|
}
|
|
|
- private void initView(){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private void initView() {
|
|
|
title.setVisibility(View.GONE);
|
|
title.setVisibility(View.GONE);
|
|
|
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
@Override
|
|
@Override
|
|
@@ -119,24 +123,34 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
initListen();
|
|
initListen();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initData(boolean isRefresh){
|
|
|
|
|
|
|
+ private void initData(final boolean isRefresh) {
|
|
|
empty_view.setVisibility(View.INVISIBLE);
|
|
empty_view.setVisibility(View.INVISIBLE);
|
|
|
SysAppUtil.checkNet(new Action1<Integer>() {
|
|
SysAppUtil.checkNet(new Action1<Integer>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void call(Integer result) {
|
|
public void call(Integer result) {
|
|
|
- if(result != 0){//无网络
|
|
|
|
|
- if(check_net_ll != null)
|
|
|
|
|
|
|
+ if (result != 0) {//无网络
|
|
|
|
|
+ if (check_net_ll != null)
|
|
|
check_net_ll.setVisibility(View.VISIBLE);
|
|
check_net_ll.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
} else {
|
|
|
- if(check_net_ll != null)
|
|
|
|
|
|
|
+ if (check_net_ll != null)
|
|
|
check_net_ll.setVisibility(View.GONE);
|
|
check_net_ll.setVisibility(View.GONE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- loadData(false, isRefresh);
|
|
|
|
|
|
|
+ try{
|
|
|
|
|
+ loadData(false, isRefresh);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ loadData(false, isRefresh);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void notifyDataSetChanged(){
|
|
|
|
|
|
|
+ private void notifyDataSetChanged() {
|
|
|
CommonUtil.getInstance().updateEmptyView(empty_view, listData.isEmpty());
|
|
CommonUtil.getInstance().updateEmptyView(empty_view, listData.isEmpty());
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
adListAdapter.notifyDataSetChanged();
|
|
adListAdapter.notifyDataSetChanged();
|
|
@@ -150,15 +164,21 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
pageNo++;
|
|
pageNo++;
|
|
|
else
|
|
else
|
|
|
pageNo = 1;
|
|
pageNo = 1;
|
|
|
- if(type == 0){
|
|
|
|
|
|
|
+ if (type == 0) {
|
|
|
AdManager.getInstance(activity).getAdListAsync(activity, new GetAdListListener() {
|
|
AdManager.getInstance(activity).getAdListAsync(activity, new GetAdListListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onLoadAdSuccess(List<AdData> list) {
|
|
public void onLoadAdSuccess(List<AdData> list) {
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
if (list != null) {
|
|
if (list != null) {
|
|
|
- if(pageNo == 1)
|
|
|
|
|
|
|
+ if (pageNo == 1)
|
|
|
listData.clear();
|
|
listData.clear();
|
|
|
- listData.addAll(list);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for (AdData adData : list) {
|
|
|
|
|
+ AdDataSon adDataSon = new AdDataSon();
|
|
|
|
|
+ adDataSon.setAdData(adData);
|
|
|
|
|
+ listData.add(adDataSon);
|
|
|
|
|
+ }
|
|
|
|
|
+// listData.addAll((Collection<? extends AdDataSon>) list);
|
|
|
adListAdapter.setData(listData);
|
|
adListAdapter.setData(listData);
|
|
|
}
|
|
}
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
@@ -167,21 +187,21 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
@Override
|
|
@Override
|
|
|
public void onLoadAdFailure() {
|
|
public void onLoadAdFailure() {
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
- if(isRefresh)
|
|
|
|
|
|
|
+ if (isRefresh)
|
|
|
G.showToast(activity, "网络异常,请稍后再试", Toast.LENGTH_SHORT);
|
|
G.showToast(activity, "网络异常,请稍后再试", Toast.LENGTH_SHORT);
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onAdEmpty() {
|
|
public void onAdEmpty() {
|
|
|
- if(isRefresh)
|
|
|
|
|
|
|
+ if (isRefresh)
|
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}, pageNo, pageSize);
|
|
}, pageNo, pageSize);
|
|
|
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
/**
|
|
/**
|
|
|
* 异步获取签到任务,回调是在主线程,可以直接更新UI,加载更多的逻辑只需更新pageNo和pageSize即可。
|
|
* 异步获取签到任务,回调是在主线程,可以直接更新UI,加载更多的逻辑只需更新pageNo和pageSize即可。
|
|
|
*/
|
|
*/
|
|
@@ -190,12 +210,16 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
public void onLoadAdSuccess(List<AdData> list) {
|
|
public void onLoadAdSuccess(List<AdData> list) {
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
if (list != null && list.size() > 0) {
|
|
if (list != null && list.size() > 0) {
|
|
|
- if(pageNo == 1)
|
|
|
|
|
|
|
+ if (pageNo == 1)
|
|
|
listData.clear();
|
|
listData.clear();
|
|
|
- listData.addAll(list);
|
|
|
|
|
|
|
+ for (AdData adData : list) {
|
|
|
|
|
+ AdDataSon adDataSon = new AdDataSon();
|
|
|
|
|
+ adDataSon.setAdData(adData);
|
|
|
|
|
+ listData.add(adDataSon);
|
|
|
|
|
+ }
|
|
|
adListAdapter.setData(listData);
|
|
adListAdapter.setData(listData);
|
|
|
} else {
|
|
} else {
|
|
|
- if(isRefresh)
|
|
|
|
|
|
|
+ if (isRefresh)
|
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
|
}
|
|
}
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
@@ -204,7 +228,7 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
@Override
|
|
@Override
|
|
|
public void onLoadAdFailure() {
|
|
public void onLoadAdFailure() {
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
- if(isRefresh)
|
|
|
|
|
|
|
+ if (isRefresh)
|
|
|
G.showToast(activity, "网络异常,请稍后再试", Toast.LENGTH_SHORT);
|
|
G.showToast(activity, "网络异常,请稍后再试", Toast.LENGTH_SHORT);
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
}
|
|
}
|
|
@@ -212,7 +236,7 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
@Override
|
|
@Override
|
|
|
public void onAdEmpty() {
|
|
public void onAdEmpty() {
|
|
|
refresh.setRefreshing(false);
|
|
refresh.setRefreshing(false);
|
|
|
- if(isRefresh)
|
|
|
|
|
|
|
+ if (isRefresh)
|
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
G.showToast(activity, "暂无数据", Toast.LENGTH_SHORT);
|
|
|
notifyDataSetChanged();
|
|
notifyDataSetChanged();
|
|
|
|
|
|
|
@@ -222,15 +246,15 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initListen(){
|
|
|
|
|
|
|
+ private void initListen() {
|
|
|
recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
super.onScrollStateChanged(recyclerView, newState);
|
|
super.onScrollStateChanged(recyclerView, newState);
|
|
|
- if(newState == RecyclerView.SCROLL_STATE_IDLE){//滑动到了底部
|
|
|
|
|
- if(listData.size() >= pageNo*pageSize){
|
|
|
|
|
|
|
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {//滑动到了底部
|
|
|
|
|
+ if (listData.size() >= pageNo * pageSize) {
|
|
|
loadData(true, false);
|
|
loadData(true, false);
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
// G.showToast("没有更多数据了");
|
|
// G.showToast("没有更多数据了");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -238,11 +262,12 @@ public class FgtMiDong extends BaseCompatFragment {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 刷新数据
|
|
* 刷新数据
|
|
|
*/
|
|
*/
|
|
|
public void refreshData() {
|
|
public void refreshData() {
|
|
|
- if(adListAdapter != null)
|
|
|
|
|
|
|
+ if (adListAdapter != null)
|
|
|
adListAdapter.notifyDataSetChanged();
|
|
adListAdapter.notifyDataSetChanged();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|