|
@@ -1,197 +0,0 @@
|
|
|
-package com.sheep.gamegroup.view.fragment;
|
|
|
|
|
-
|
|
|
|
|
-import android.annotation.SuppressLint;
|
|
|
|
|
-import android.content.Context;
|
|
|
|
|
-import android.content.Intent;
|
|
|
|
|
-import android.os.Bundle;
|
|
|
|
|
-import android.support.annotation.NonNull;
|
|
|
|
|
-import android.support.annotation.Nullable;
|
|
|
|
|
-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.view.LayoutInflater;
|
|
|
|
|
-import android.view.View;
|
|
|
|
|
-import android.view.ViewGroup;
|
|
|
|
|
-
|
|
|
|
|
-import com.google.gson.Gson;
|
|
|
|
|
-import com.jcodecraeer.xrecyclerview.XRecyclerView;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.MessageCenterEntity;
|
|
|
|
|
-import com.sheep.gamegroup.model.entity.MessageReplyEntity;
|
|
|
|
|
-import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
-import com.sheep.gamegroup.util.ListUtil;
|
|
|
|
|
-import com.sheep.gamegroup.util.LogUtil;
|
|
|
|
|
-import com.sheep.gamegroup.view.activity.MessageInteractionDetailActivity;
|
|
|
|
|
-import com.sheep.gamegroup.view.adapter.MessageLeftAdapter;
|
|
|
|
|
-import com.sheep.gamegroup.view.adapter.MessageRightAdapter;
|
|
|
|
|
-import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
-
|
|
|
|
|
-import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
-
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
-import rx.android.schedulers.AndroidSchedulers;
|
|
|
|
|
-import rx.schedulers.Schedulers;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * created on:2018/8/29 on 9:58
|
|
|
|
|
- * created by: YSL
|
|
|
|
|
- * 描述:
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-@SuppressLint("ValidFragment")
|
|
|
|
|
-public class MessageReplyFragment extends Fragment implements MessageRightAdapter.ItemOnClickListener {
|
|
|
|
|
- private Context mContext;
|
|
|
|
|
- private XRecyclerView recyclerView;
|
|
|
|
|
- private MessageRightAdapter adapter;
|
|
|
|
|
- private List<MessageReplyEntity> mList = new ArrayList<>();
|
|
|
|
|
- private View emptyView;
|
|
|
|
|
- private int per_page;
|
|
|
|
|
- private int page;
|
|
|
|
|
-
|
|
|
|
|
- public MessageReplyFragment() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public MessageReplyFragment(Context mContext) {
|
|
|
|
|
- this.mContext = mContext;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Nullable
|
|
|
|
|
- @Override
|
|
|
|
|
- public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
- View view = null;
|
|
|
|
|
- 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);
|
|
|
|
|
- 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 MessageRightAdapter(mContext, mList, this);
|
|
|
|
|
- LinearLayoutManager manager = new LinearLayoutManager(mContext);
|
|
|
|
|
- manager.setOrientation(OrientationHelper.VERTICAL);
|
|
|
|
|
- recyclerView.setLayoutManager(manager);
|
|
|
|
|
- recyclerView.setAdapter(adapter);
|
|
|
|
|
- loadDatas(1, 20);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 刷新
|
|
|
|
|
- */
|
|
|
|
|
- private void refreshData(int page, int per_page) {
|
|
|
|
|
- SheepApp.getInstance()
|
|
|
|
|
- .getNetComponent()
|
|
|
|
|
- .getApiService()
|
|
|
|
|
- .getMessageReply(page, per_page)
|
|
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
- LogUtil.logI("返回格式---" + new Gson().toJson(baseMessage));
|
|
|
|
|
- if (!mList.isEmpty()) {
|
|
|
|
|
- EventBus.getDefault().post("right_unread");
|
|
|
|
|
- mList.clear();
|
|
|
|
|
- mList.addAll(baseMessage.getDataList(MessageReplyEntity.class));
|
|
|
|
|
- }
|
|
|
|
|
- if (mList.isEmpty()) {
|
|
|
|
|
- EventBus.getDefault().post("right_read");
|
|
|
|
|
- emptyView.setVisibility(View.VISIBLE);
|
|
|
|
|
- recyclerView.setVisibility(View.GONE);
|
|
|
|
|
- } else {
|
|
|
|
|
- emptyView.setVisibility(View.GONE);
|
|
|
|
|
- recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
- }
|
|
|
|
|
- recyclerView.refreshComplete();
|
|
|
|
|
- recyclerView.getAdapter().notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
|
|
- /* emptyView.setVisibility(View.VISIBLE);
|
|
|
|
|
- recyclerView.setVisibility(View.GONE);*/
|
|
|
|
|
- recyclerView.refreshComplete();
|
|
|
|
|
- LogUtil.logI("返回格式错误---" + new Gson().toJson(baseMessage));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 加载更多
|
|
|
|
|
- */
|
|
|
|
|
- private void loadmoreMessage() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 加载消息
|
|
|
|
|
- *
|
|
|
|
|
- * @param page 页数
|
|
|
|
|
- * @param per_page ,每页加载条数
|
|
|
|
|
- */
|
|
|
|
|
- private void loadDatas(int page, int per_page) {
|
|
|
|
|
- SheepApp.getInstance()
|
|
|
|
|
- .getNetComponent()
|
|
|
|
|
- .getApiService()
|
|
|
|
|
- .getMessageReply(page, per_page)
|
|
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
- LogUtil.logI("返回格式---" + new Gson().toJson(baseMessage));
|
|
|
|
|
- mList.addAll(baseMessage.getDataList(MessageReplyEntity.class));
|
|
|
|
|
- if (mList.isEmpty()) {
|
|
|
|
|
- emptyView.setVisibility(View.VISIBLE);
|
|
|
|
|
- recyclerView.setVisibility(View.GONE);
|
|
|
|
|
- EventBus.getDefault().post("right_read");
|
|
|
|
|
- } else {
|
|
|
|
|
- EventBus.getDefault().post("right_unread");
|
|
|
|
|
- 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);*/
|
|
|
|
|
- LogUtil.logI("返回格式错误---" + new Gson().toJson(baseMessage));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void itemClick(int position) {
|
|
|
|
|
- refreshData(1, 20);
|
|
|
|
|
- if (getActivity() != null) {
|
|
|
|
|
- Intent intent = new Intent(getActivity(), MessageInteractionDetailActivity.class);
|
|
|
|
|
- intent.putExtra("position", position);
|
|
|
|
|
- LogUtil.logI("loadData-----id---post--" + position);
|
|
|
|
|
- startActivity(new Intent(intent));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|