|
@@ -2,10 +2,10 @@ package com.technology.tederen.fragment.home;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Intent;
|
|
|
-import android.media.Image;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
@@ -18,7 +18,6 @@ import com.lzy.okgo.callback.StringCallback;
|
|
|
import com.lzy.okgo.model.Response;
|
|
|
import com.technology.tederen.R;
|
|
|
import com.technology.tederen.activity.article.ArticleDetailsActivity;
|
|
|
-import com.technology.tederen.activity.search.MainBodyTextActivity;
|
|
|
import com.technology.tederen.base.MyApplication;
|
|
|
import com.technology.tederen.base.PresenterFragment;
|
|
|
import com.technology.tederen.fragment.home.adapter.RecommendAdapter;
|
|
@@ -45,208 +44,213 @@ public class RecommendFragment extends PresenterFragment<ArtcleListContract.Pres
|
|
|
BaseQuickAdapter.RequestLoadMoreListener, BaseQuickAdapter.OnItemClickListener
|
|
|
, BaseQuickAdapter.OnItemChildClickListener, ArtcleListContract.View {
|
|
|
|
|
|
- @BindView(R.id.rv_recommend)
|
|
|
- RecyclerView rvRecommend;
|
|
|
- @BindView(R.id.nodata_lay)
|
|
|
- TextView nodataLay;
|
|
|
- RecommendAdapter recommendAdapter;
|
|
|
- ArticleBody body;
|
|
|
- Dialog pbDialog;
|
|
|
- private int groupId;
|
|
|
- private int articleId; // 文章Id
|
|
|
-
|
|
|
- public static RecommendFragment newInstance(int groupId) {
|
|
|
- RecommendFragment recommendFragment = new RecommendFragment();
|
|
|
- Bundle bundle = new Bundle();
|
|
|
- bundle.putInt("groupId", groupId);
|
|
|
- recommendFragment.setArguments(bundle);
|
|
|
- return recommendFragment;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLazyLoad() {
|
|
|
- body = new ArticleBody(pageNum, pageSize, token, groupId, true);
|
|
|
- mPresenter.requestArtclelist(body);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int getContentLayoutId() {
|
|
|
- return R.layout.fragment_recommand;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void initWidget(View root) {
|
|
|
- super.initWidget(root);
|
|
|
- EventBus.getDefault().register(this);
|
|
|
- groupId = getArguments().getInt("groupId");
|
|
|
-
|
|
|
- recommendAdapter = new RecommendAdapter(null);
|
|
|
- recommendAdapter.disableLoadMoreIfNotFullPage(rvRecommend);
|
|
|
- recommendAdapter.setOnLoadMoreListener(this, rvRecommend);
|
|
|
- rvRecommend.setLayoutManager(new LinearLayoutManager(MyApplication.getInstance()));
|
|
|
- recommendAdapter.setOnItemClickListener(this);
|
|
|
- recommendAdapter.setOnItemChildClickListener(this);
|
|
|
- rvRecommend.setAdapter(recommendAdapter);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLoadMoreRequested() {
|
|
|
- body = new ArticleBody(++pageNum, pageSize, token, groupId, false);
|
|
|
- mPresenter.requestArtclelist(body);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
|
|
-
|
|
|
- ArticleList.ItemsBean itemsBean = (ArticleList.ItemsBean) adapter.getData().get(position);
|
|
|
+ @BindView(R.id.rv_recommend)
|
|
|
+ RecyclerView rvRecommend;
|
|
|
+ @BindView(R.id.nodata_lay)
|
|
|
+ TextView nodataLay;
|
|
|
+ RecommendAdapter recommendAdapter;
|
|
|
+ ArticleBody body;
|
|
|
+ Dialog pbDialog;
|
|
|
+ private int groupId;
|
|
|
+ private int articleId; // 文章Id
|
|
|
+
|
|
|
+ public static RecommendFragment newInstance(int groupId) {
|
|
|
+ RecommendFragment recommendFragment = new RecommendFragment();
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putInt("groupId", groupId);
|
|
|
+ recommendFragment.setArguments(bundle);
|
|
|
+ return recommendFragment;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLazyLoad() {
|
|
|
+ body = new ArticleBody(pageNum, pageSize, token, groupId, true);
|
|
|
+ mPresenter.requestArtclelist(body);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getContentLayoutId() {
|
|
|
+ return R.layout.fragment_recommand;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initWidget(View root) {
|
|
|
+ super.initWidget(root);
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ groupId = getArguments().getInt("groupId");
|
|
|
+
|
|
|
+ recommendAdapter = new RecommendAdapter(null);
|
|
|
+ recommendAdapter.disableLoadMoreIfNotFullPage(rvRecommend);
|
|
|
+ recommendAdapter.setOnLoadMoreListener(this, rvRecommend);
|
|
|
+ rvRecommend.setLayoutManager(new LinearLayoutManager(MyApplication.getInstance()));
|
|
|
+ recommendAdapter.setOnItemClickListener(this);
|
|
|
+ recommendAdapter.setOnItemChildClickListener(this);
|
|
|
+ rvRecommend.setAdapter(recommendAdapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoadMoreRequested() {
|
|
|
+ body = new ArticleBody(++pageNum, pageSize, token, groupId, false);
|
|
|
+ mPresenter.requestArtclelist(body);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
|
|
+
|
|
|
+ ArticleList.ItemsBean itemsBean = (ArticleList.ItemsBean) adapter.getData().get(position);
|
|
|
// if (CommonUtils.isFastClick())
|
|
|
// MainBodyTextActivity.tothis(getContext(), itemsBean);
|
|
|
- if (CommonUtils.isFastClick()){
|
|
|
- Intent intent = new Intent(getActivity(), ArticleDetailsActivity.class);
|
|
|
- intent.putExtra("id",itemsBean.getId());
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
|
|
|
- articleId = ((ArticleList.ItemsBean) adapter.getItem(position)).getId();
|
|
|
- if (view.getId() == R.id.iv_close) {
|
|
|
- if (pbDialog != null) {
|
|
|
- pbDialog.show();
|
|
|
- return;
|
|
|
+ if (CommonUtils.isFastClick()) {
|
|
|
+ Intent intent = new Intent(getActivity(), ArticleDetailsActivity.class);
|
|
|
+ intent.putExtra("id", itemsBean.getId());
|
|
|
+ startActivity(intent);
|
|
|
}
|
|
|
- pbDialog = new Dialog(getActivity());
|
|
|
- LayoutInflater inflater = LayoutInflater.from(getActivity());
|
|
|
- View dialogView = inflater.inflate(R.layout.dialog_cancel, null);
|
|
|
- ((TextView) dialogView.findViewById(R.id.content)).setText("对此内容进行操作");
|
|
|
- TextView cannalcxsh = dialogView.findViewById(R.id.cancal);
|
|
|
- TextView submitcxsh = dialogView.findViewById(R.id.submit);
|
|
|
- ImageView close = dialogView.findViewById(R.id.close);
|
|
|
- pbDialog.setContentView(dialogView);
|
|
|
- pbDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
|
|
- pbDialog.show();
|
|
|
- cannalcxsh.setOnClickListener(v -> {
|
|
|
- ArticleBlackAdd articleBlackAdd = new ArticleBlackAdd();
|
|
|
- articleBlackAdd.setArticleId(articleId);
|
|
|
- articleBlackAdd.setBlacklistType(1);
|
|
|
- OkGo.<String>post(Api.BLACK_LIST_ADD)
|
|
|
- .headers(Api.AUTHORIZATION, token)
|
|
|
- .upJson(new Gson().toJson(articleBlackAdd))
|
|
|
- .isMultipart(true)
|
|
|
- .execute(new StringCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Response<String> response) {
|
|
|
- if (response.code() == 200) {
|
|
|
- recommendAdapter.remove(position);
|
|
|
- showToast("操作成功");
|
|
|
- } else {
|
|
|
- ErrorResponse errorResponse = new Gson().fromJson(response.body(), ErrorResponse.class);
|
|
|
- if (errorResponse != null)
|
|
|
- showToast(errorResponse.getMessage());
|
|
|
- }
|
|
|
- pbDialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
- close.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- pbDialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
- submitcxsh.setOnClickListener(v -> {
|
|
|
- ArticleBlackAdd articleBlackAdd = new ArticleBlackAdd();
|
|
|
- articleBlackAdd.setArticleId(articleId);
|
|
|
- articleBlackAdd.setBlacklistType(2);
|
|
|
- OkGo.<String>post(Api.BLACK_LIST_ADD)
|
|
|
- .headers(Api.AUTHORIZATION, token)
|
|
|
- .upJson(new Gson().toJson(articleBlackAdd))
|
|
|
- .isMultipart(true)
|
|
|
- .execute(new StringCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Response<String> response) {
|
|
|
-
|
|
|
- if (response.code() == 200) {
|
|
|
- showToast("操作成功");
|
|
|
- recommendAdapter.remove(position);
|
|
|
- } else {
|
|
|
- ErrorResponse errorResponse = new Gson().fromJson(response.body(), ErrorResponse.class);
|
|
|
- if (errorResponse != null)
|
|
|
- showToast(errorResponse.getMessage());
|
|
|
- }
|
|
|
- pbDialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected RecommendPresenter initPresenter() {
|
|
|
- return new RecommendPresenter(this);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getArtcleListSuccess(ArticleList articleList, boolean isFresh) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
|
|
|
+ articleId = ((ArticleList.ItemsBean) adapter.getItem(position)).getId();
|
|
|
+ if (view.getId() == R.id.iv_close) {
|
|
|
+ if (pbDialog != null) {
|
|
|
+ pbDialog.show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ pbDialog = new Dialog(getActivity());
|
|
|
+ LayoutInflater inflater = LayoutInflater.from(getActivity());
|
|
|
+ View dialogView = inflater.inflate(R.layout.dialog_cancel, null);
|
|
|
+ ((TextView) dialogView.findViewById(R.id.content)).setText("对此内容进行操作");
|
|
|
+ TextView cannalcxsh = dialogView.findViewById(R.id.cancal);
|
|
|
+ TextView submitcxsh = dialogView.findViewById(R.id.submit);
|
|
|
+ ImageView close = dialogView.findViewById(R.id.close);
|
|
|
+ pbDialog.setContentView(dialogView);
|
|
|
+ pbDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
|
|
+ pbDialog.show();
|
|
|
+ cannalcxsh.setOnClickListener(v -> {
|
|
|
+ ArticleBlackAdd articleBlackAdd = new ArticleBlackAdd();
|
|
|
+ articleBlackAdd.setArticleId(articleId);
|
|
|
+ articleBlackAdd.setBlacklistType(1);
|
|
|
+ OkGo.<String>post(Api.BLACK_LIST_ADD)
|
|
|
+ .headers(Api.AUTHORIZATION, token)
|
|
|
+ .upJson(new Gson().toJson(articleBlackAdd))
|
|
|
+ .isMultipart(true)
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Response<String> response) {
|
|
|
+ if (response.code() == 200) {
|
|
|
+ recommendAdapter.remove(position);
|
|
|
+ showToast("操作成功");
|
|
|
+ } else {
|
|
|
+ ErrorResponse errorResponse = new Gson().fromJson(response.body(), ErrorResponse.class);
|
|
|
+ if (errorResponse != null)
|
|
|
+ showToast(errorResponse.getMessage());
|
|
|
+ }
|
|
|
+ pbDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ close.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ pbDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ submitcxsh.setOnClickListener(v -> {
|
|
|
+ ArticleBlackAdd articleBlackAdd = new ArticleBlackAdd();
|
|
|
+ articleBlackAdd.setArticleId(articleId);
|
|
|
+ articleBlackAdd.setBlacklistType(2);
|
|
|
+ OkGo.<String>post(Api.BLACK_LIST_ADD)
|
|
|
+ .headers(Api.AUTHORIZATION, token)
|
|
|
+ .upJson(new Gson().toJson(articleBlackAdd))
|
|
|
+ .isMultipart(true)
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Response<String> response) {
|
|
|
+
|
|
|
+ if (response.code() == 200) {
|
|
|
+ showToast("操作成功");
|
|
|
+ recommendAdapter.remove(position);
|
|
|
+ } else {
|
|
|
+ ErrorResponse errorResponse = new Gson().fromJson(response.body(), ErrorResponse.class);
|
|
|
+ if (errorResponse != null)
|
|
|
+ showToast(errorResponse.getMessage());
|
|
|
+ }
|
|
|
+ pbDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected RecommendPresenter initPresenter() {
|
|
|
+ return new RecommendPresenter(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getArtcleListSuccess(ArticleList articleList, boolean isFresh) {
|
|
|
// EventBus.getDefault().post(new MessageEvent(""));
|
|
|
- for (int i = 0; i < articleList.getItems().size(); i++) {
|
|
|
- ArticleList.ItemsBean itemsBean = articleList.getItems().get(i);
|
|
|
- if (itemsBean.getImageUrls().size() == 0) {
|
|
|
- itemsBean.setLaytype(1);
|
|
|
- } else if (itemsBean.getImageUrls().size() == 1) {
|
|
|
- itemsBean.setLaytype(2);
|
|
|
- } else if (itemsBean.getImageUrls().size() == 3) {
|
|
|
- itemsBean.setLaytype(3);
|
|
|
- }else if (itemsBean.getImageUrls().size() == 2) {
|
|
|
- itemsBean.setLaytype(2);
|
|
|
- } else {
|
|
|
- itemsBean.setLaytype(1);
|
|
|
+ for (int i = 0; i < articleList.getItems().size(); i++) {
|
|
|
+ ArticleList.ItemsBean itemsBean = articleList.getItems().get(i);
|
|
|
+ if (itemsBean.getImageUrls().size() == 0) {
|
|
|
+ itemsBean.setLaytype(1);
|
|
|
+ } else if (itemsBean.getImageUrls().size() == 1) {
|
|
|
+ itemsBean.setLaytype(2);
|
|
|
+ } else if (itemsBean.getImageUrls().size() == 3) {
|
|
|
+ itemsBean.setLaytype(3);
|
|
|
+ } else if (itemsBean.getImageUrls().size() == 2) {
|
|
|
+ itemsBean.setLaytype(2);
|
|
|
+ } else {
|
|
|
+ itemsBean.setLaytype(1);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (isFresh) {
|
|
|
- if (articleList.getItems().size() < 10) {
|
|
|
- recommendAdapter.replaceData(articleList.getItems());
|
|
|
- recommendAdapter.loadMoreEnd();
|
|
|
+ if (isFresh) {
|
|
|
+ if (articleList.getItems().size() < 10) {
|
|
|
+ recommendAdapter.replaceData(articleList.getItems());
|
|
|
+ recommendAdapter.loadMoreEnd();
|
|
|
+ } else {
|
|
|
+ recommendAdapter.replaceData(articleList.getItems());
|
|
|
+ recommendAdapter.loadMoreComplete();
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
- recommendAdapter.replaceData(articleList.getItems());
|
|
|
- recommendAdapter.loadMoreComplete();
|
|
|
+ recommendAdapter.addData(articleList.getItems());
|
|
|
+ if (articleList.getItems().size() < 10) {
|
|
|
+ recommendAdapter.loadMoreEnd();
|
|
|
+ } else {
|
|
|
+ recommendAdapter.loadMoreComplete();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- recommendAdapter.addData(articleList.getItems());
|
|
|
- if (articleList.getItems().size() < 10) {
|
|
|
- recommendAdapter.loadMoreEnd();
|
|
|
+ if (recommendAdapter.getData().size() == 0) {
|
|
|
+ nodataLay.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
|
- recommendAdapter.loadMoreComplete();
|
|
|
+ nodataLay.setVisibility(View.GONE);
|
|
|
}
|
|
|
- }
|
|
|
- if(recommendAdapter.getData().size()==0){
|
|
|
- nodataLay.setVisibility(View.VISIBLE);
|
|
|
- }else{
|
|
|
- nodataLay.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void showMsg(String msg) {
|
|
|
- showToast(msg);
|
|
|
- }
|
|
|
-
|
|
|
- @Subscriber
|
|
|
- public void Event(MessageEvent messageEvent) {
|
|
|
- if (messageEvent.getMessage().equals("更新")) {
|
|
|
- pageNum = 1;
|
|
|
- body = new ArticleBody(pageNum, pageSize, token, messageEvent.getGroupId(), true);
|
|
|
- mPresenter.requestArtclelist(body);
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showMsg(String msg) {
|
|
|
+ showToast(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscriber
|
|
|
+ public void Event(MessageEvent messageEvent) {
|
|
|
+ if (messageEvent.getMessage().equals("更新")) {
|
|
|
+ if (messageEvent.getGroupId() == groupId) {
|
|
|
+ Log.e("groupId",groupId+"");
|
|
|
+ pageNum = 1;
|
|
|
+ body = new ArticleBody(pageNum, pageSize, token, messageEvent.getGroupId(), true);
|
|
|
+ mPresenter.requestArtclelist(body);
|
|
|
+// mPresenter.requestArtclelist(body);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Subscriber
|
|
|
- public void Eventtop(TopAllEvent messageEvent) {
|
|
|
- rvRecommend.scrollToPosition(0);
|
|
|
- }
|
|
|
+ @Subscriber
|
|
|
+ public void Eventtop(TopAllEvent messageEvent) {
|
|
|
+ rvRecommend.scrollToPosition(0);
|
|
|
+ }
|
|
|
}
|