Browse Source

remove unnecessary canReply variable in topicAdapter

pull/34/head
Thodoris1999 7 years ago
parent
commit
531ff96557
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

10
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -169,7 +169,6 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
recyclerView.setAdapter(topicAdapter);
replyFAB = findViewById(R.id.topic_fab);
replyFAB.hide();
bottomNavBar = findViewById(R.id.bottom_navigation_bar);
if (!sessionManager.isLoggedIn()) replyFAB.hide();
else {
@ -203,12 +202,6 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
toolbarTitle.setText(topicTaskResult.getTopicTitle());
}
if (topicTaskResult.getReplyPageUrl() == null) {
replyFAB.hide();
topicAdapter.resetTopic(false);
} else
topicAdapter.resetTopic(true);
if (!postsList.isEmpty()) {
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
postsList.clear();
@ -229,6 +222,9 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
}
progressBar.setVisibility(ProgressBar.GONE);
if (topicTaskResult.getReplyPageUrl() == null)
replyFAB.hide();
topicAdapter.resetTopic();
break;
case NETWORK_ERROR:
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show();

7
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -88,8 +88,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int isQuoteButtonChecked = 1;
private TopicViewModel viewModel;
private boolean canReply = false;
/**
* @param context the context of the {@link RecyclerView}
* @param postsList List of {@link Post} objects to use
@ -452,7 +450,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
});
//noinspection PointlessBooleanExpression,ConstantConditions
if (!BaseActivity.getSessionManager().isLoggedIn() || !canReply) {
if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) {
holder.quoteToggle.setVisibility(View.GONE);
} else {
if (viewProperties.get(position)[isQuoteButtonChecked])
@ -559,8 +557,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
}
void resetTopic(boolean canReply) {
this.canReply = canReply;
void resetTopic() {
viewProperties.clear();
for (int i = 0; i < postsList.size(); ++i) {
//Initializes properties, array's values will be false by default

4
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -95,6 +95,10 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
return postEditedPosition;
}
public boolean canReply() {
return topicTaskResult.getValue() != null && topicTaskResult.getValue().getReplyPageUrl() != null;
}
public boolean isWritingReply() {
return writingReply;
}

Loading…
Cancel
Save