|
|
@@ -6,22 +6,42 @@ import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.support.constraint.ConstraintLayout;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.OrientationHelper;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.jcodecraeer.xrecyclerview.XRecyclerView;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.MessageCenterEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.LogUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.activity.MessageCenterDetailActivity;
|
|
|
+import com.sheep.gamegroup.view.activity.MessageInteractionDetailActivity;
|
|
|
import com.sheep.gamegroup.view.activity.MessageReplyDetailActivity;
|
|
|
import com.sheep.gamegroup.view.adapter.MessageLeftAdapter;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import rx.Scheduler;
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
+
|
|
|
/**
|
|
|
* created on:2018/8/28 on 12:32
|
|
|
* created by: YSL
|
|
|
@@ -31,9 +51,12 @@ import java.util.List;
|
|
|
@SuppressLint("ValidFragment")
|
|
|
public class MessageCenterFragment extends Fragment implements MessageLeftAdapter.ItemOnClickListener {
|
|
|
private Context mContext;
|
|
|
- private RecyclerView recyclerView;
|
|
|
+ private XRecyclerView recyclerView;
|
|
|
+ private ConstraintLayout emptyView;
|
|
|
private MessageLeftAdapter adapter;
|
|
|
- private List<?> mList;
|
|
|
+ private List<MessageCenterEntity> mList = new ArrayList<>();
|
|
|
+ private int per_page;
|
|
|
+ private int page;
|
|
|
|
|
|
|
|
|
public MessageCenterFragment() {
|
|
|
@@ -47,32 +70,131 @@ public class MessageCenterFragment extends Fragment implements MessageLeftAdapte
|
|
|
@Override
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
View view = null;
|
|
|
- if (mList == null || mList.isEmpty()) {
|
|
|
- view=inflater.inflate(R.layout.layout_empty_no_data,null);
|
|
|
- } else {
|
|
|
- view = inflater.inflate(R.layout.fragment_messagecenter, null);
|
|
|
- recyclerView = view.findViewById(R.id.recycle_fragment_message_center);
|
|
|
- }
|
|
|
+ view = inflater.inflate(R.layout.fragment_messagecenter, null);
|
|
|
+ recyclerView = view.findViewById(R.id.recycle_fragment_message_center);
|
|
|
+ emptyView = view.findViewById(R.id.view_empty);
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
- if (mList==null||mList.isEmpty()){
|
|
|
- return;
|
|
|
- }
|
|
|
+ recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh() {
|
|
|
+ refreshData(1, 20);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoadMore() {
|
|
|
+ loadmoreMessage();
|
|
|
+ if (ListUtil.size(mList) >= per_page * page) {
|
|
|
+ page += 1;
|
|
|
+ loadmoreMessage();
|
|
|
+ } else {
|
|
|
+ recyclerView.setNoMore(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // ViewUtil.setBottomLine(recyclerView);
|
|
|
adapter = new MessageLeftAdapter(mContext, mList, this);
|
|
|
LinearLayoutManager manager = new LinearLayoutManager(mContext);
|
|
|
manager.setOrientation(OrientationHelper.VERTICAL);
|
|
|
recyclerView.setLayoutManager(manager);
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
+ loadDatas(1, 20);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载消息
|
|
|
+ *
|
|
|
+ * @param page 页数
|
|
|
+ * @param per_page ,每页加载条数
|
|
|
+ */
|
|
|
+ private void loadDatas(int page, int per_page) {
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getMessageCenter(page, per_page)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ mList.addAll(baseMessage.getDataList(MessageCenterEntity.class));
|
|
|
+ if (mList.isEmpty()) {
|
|
|
+ emptyView.setVisibility(View.VISIBLE);
|
|
|
+ recyclerView.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ emptyView.setVisibility(View.GONE);
|
|
|
+ recyclerView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ recyclerView.getAdapter().notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ emptyView.setVisibility(View.VISIBLE);
|
|
|
+ recyclerView.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新
|
|
|
+ */
|
|
|
+ private void refreshData(int page, int per_page) {
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getMessageCenter(page, per_page)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ if (!mList.isEmpty()) {
|
|
|
+ mList.clear();
|
|
|
+ }
|
|
|
+ mList.addAll(baseMessage.getDataList(MessageCenterEntity.class));
|
|
|
+ if (mList.isEmpty()) {
|
|
|
+ emptyView.setVisibility(View.VISIBLE);
|
|
|
+ recyclerView.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ emptyView.setVisibility(View.GONE);
|
|
|
+ recyclerView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ recyclerView.getAdapter().notifyDataSetChanged();
|
|
|
+ recyclerView.refreshComplete();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ emptyView.setVisibility(View.VISIBLE);
|
|
|
+ recyclerView.setVisibility(View.GONE);
|
|
|
+ recyclerView.refreshComplete();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载更多消息
|
|
|
+ */
|
|
|
+ private void loadmoreMessage() {
|
|
|
+ G.showToast("加载更多");
|
|
|
+ recyclerView.loadMoreComplete();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void itemClick(int position) {
|
|
|
if (getActivity() != null) {
|
|
|
- startActivity(new Intent(getActivity(), MessageReplyDetailActivity.class));
|
|
|
+ Intent intent = new Intent(getActivity(), MessageCenterDetailActivity.class);
|
|
|
+ intent.putExtra("position", position);
|
|
|
+ startActivity(intent);
|
|
|
}
|
|
|
}
|
|
|
}
|