Skip to content

Commit

Permalink
Optimize comments order
Browse files Browse the repository at this point in the history
ref #56
  • Loading branch information
mzlogin committed Dec 30, 2018
1 parent 8a74749 commit bbae0fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ public class TopicDetailFragment extends BaseFragment<TopicDetailContract.Presen
@BindView(R.id.comment_view) View mCommentsView;
@BindView(R.id.favorite) ImageView mFavoriteImageView;
@BindView(R.id.follow) Button mFollowButton;
@BindView(R.id.load_more_before) TextView mLoadMoreBeforeTextView;
@BindView(R.id.load_more_after) TextView mLoadMoreAfterTextView;

private TextView mLoadMoreTextView;
@BindView(R.id.load_more) TextView mLoadMoreTextView;

private View mRoot;

Expand Down Expand Up @@ -145,8 +142,6 @@ private void setViewData(TopicDetail topicDetail) {

mAdapter.setData(mTopicDetail.getComments());

mLoadMoreTextView = PrefsUtil.getBoolean(App.getInstance(), ConstantUtil.KEY_COMMENTS_ORDER_DESC, false) ? mLoadMoreBeforeTextView : mLoadMoreAfterTextView;

if (mAdapter.getItemCount() < mTopicDetail.getCommentsCount()) {
mLoadMoreTextView.setVisibility(View.VISIBLE);
mLoadMoreTextView.setEnabled(true);
Expand Down Expand Up @@ -196,7 +191,7 @@ public void onFocusChange(View v, boolean hasFocus) {
mCommentEditText.setParentView(mCommentsView);
}

@OnClick({R.id.load_more_before, R.id.load_more_after, R.id.submit, R.id.author, R.id.avatar,
@OnClick({R.id.load_more, R.id.submit, R.id.author, R.id.avatar,
R.id.node, R.id.edit, R.id.edit_text, R.id.favorite, R.id.share,
R.id.follow})
public void onClick(View v) {
Expand All @@ -205,14 +200,18 @@ public void onClick(View v) {
}

switch (v.getId()) {
case R.id.load_more_before:
case R.id.load_more_after: {
case R.id.load_more: {
mLoadMoreTextView.setEnabled(false);
if (mAdapter.getItemCount() >= mTopicDetail.getCommentsCount()) {
mLoadMoreTextView.setVisibility(View.GONE);
return;
}
int page = mTopicDetail.getComments().size() / ConstantUtil.COMMENTS_PER_PAGE + 1;
int page;
if (PrefsUtil.getBoolean(App.getInstance(), ConstantUtil.KEY_COMMENTS_ORDER_DESC, false)) {
page = (mTopicDetail.getCommentsCount() - mTopicDetail.getComments().size()) / ConstantUtil.COMMENTS_PER_PAGE;
} else {
page = mTopicDetail.getComments().size() / ConstantUtil.COMMENTS_PER_PAGE + 1;
}
mPresenter.getMoreComments(page);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.vdurmont.emoji.EmojiParser;

import org.mazhuang.guanggoo.App;
import org.mazhuang.guanggoo.data.NetworkTaskScheduler;
import org.mazhuang.guanggoo.data.OnResponseListener;
import org.mazhuang.guanggoo.data.entity.TopicDetail;
Expand All @@ -11,6 +12,7 @@
import org.mazhuang.guanggoo.data.task.GetTopicDetailTask;
import org.mazhuang.guanggoo.data.task.VoteCommentTask;
import org.mazhuang.guanggoo.util.ConstantUtil;
import org.mazhuang.guanggoo.util.PrefsUtil;
import org.mazhuang.guanggoo.util.UrlUtil;

/**
Expand All @@ -23,15 +25,19 @@ public class TopicDetailPresenter implements TopicDetailContract.Presenter {

private TopicDetailContract.View mView;

private boolean mCommentsDesc;

public TopicDetailPresenter(TopicDetailContract.View view) {
mView = view;
mView.setPresenter(this);
mCommentsDesc = PrefsUtil.getBoolean(App.getInstance(), ConstantUtil.KEY_COMMENTS_ORDER_DESC, false);
}

@Override
public void getTopicDetail() {
mView.startLoading();
NetworkTaskScheduler.getInstance().execute(new GetTopicDetailTask(UrlUtil.appendPage(getUrl(), 1), new OnResponseListener<TopicDetail>() {
String url = mCommentsDesc ? getUrl() : UrlUtil.appendPage(getUrl(), 1);
NetworkTaskScheduler.getInstance().execute(new GetTopicDetailTask(url, new OnResponseListener<TopicDetail>() {
@Override
public void onSucceed(TopicDetail data) {
mView.stopLoading();
Expand Down
12 changes: 1 addition & 11 deletions app/src/main/res/layout/fragment_topic_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@
android:textColor="@color/minor"
android:textSize="@dimen/font_small"/>

<TextView
android:id="@+id/load_more_before"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="@dimen/normal_margin"
android:text="@string/load_more_comments"
android:textColor="@color/enable_text"
android:visibility="gone" />

<android.support.v7.widget.RecyclerView
android:id="@+id/comments"
android:layout_width="match_parent"
Expand All @@ -73,7 +63,7 @@
android:background="@color/split"/>

<TextView
android:id="@+id/load_more_after"
android:id="@+id/load_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand Down

0 comments on commit bbae0fd

Please sign in to comment.