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); recyclerView.setAdapter(topicAdapter);
replyFAB = findViewById(R.id.topic_fab); replyFAB = findViewById(R.id.topic_fab);
replyFAB.hide();
bottomNavBar = findViewById(R.id.bottom_navigation_bar); bottomNavBar = findViewById(R.id.bottom_navigation_bar);
if (!sessionManager.isLoggedIn()) replyFAB.hide(); if (!sessionManager.isLoggedIn()) replyFAB.hide();
else { else {
@ -203,12 +202,6 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
toolbarTitle.setText(topicTaskResult.getTopicTitle()); toolbarTitle.setText(topicTaskResult.getTopicTitle());
} }
if (topicTaskResult.getReplyPageUrl() == null) {
replyFAB.hide();
topicAdapter.resetTopic(false);
} else
topicAdapter.resetTopic(true);
if (!postsList.isEmpty()) { if (!postsList.isEmpty()) {
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
postsList.clear(); postsList.clear();
@ -229,6 +222,9 @@ public class TopicActivity extends BaseActivity implements TopicTask.TopicTaskOb
} }
progressBar.setVisibility(ProgressBar.GONE); progressBar.setVisibility(ProgressBar.GONE);
if (topicTaskResult.getReplyPageUrl() == null)
replyFAB.hide();
topicAdapter.resetTopic();
break; break;
case NETWORK_ERROR: case NETWORK_ERROR:
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show(); 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 static final int isQuoteButtonChecked = 1;
private TopicViewModel viewModel; private TopicViewModel viewModel;
private boolean canReply = false;
/** /**
* @param context the context of the {@link RecyclerView} * @param context the context of the {@link RecyclerView}
* @param postsList List of {@link Post} objects to use * @param postsList List of {@link Post} objects to use
@ -452,7 +450,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
//noinspection PointlessBooleanExpression,ConstantConditions //noinspection PointlessBooleanExpression,ConstantConditions
if (!BaseActivity.getSessionManager().isLoggedIn() || !canReply) { if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) {
holder.quoteToggle.setVisibility(View.GONE); holder.quoteToggle.setVisibility(View.GONE);
} else { } else {
if (viewProperties.get(position)[isQuoteButtonChecked]) if (viewProperties.get(position)[isQuoteButtonChecked])
@ -559,8 +557,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} }
} }
void resetTopic(boolean canReply) { void resetTopic() {
this.canReply = canReply;
viewProperties.clear(); viewProperties.clear();
for (int i = 0; i < postsList.size(); ++i) { for (int i = 0; i < postsList.size(); ++i) {
//Initializes properties, array's values will be false by default //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; return postEditedPosition;
} }
public boolean canReply() {
return topicTaskResult.getValue() != null && topicTaskResult.getValue().getReplyPageUrl() != null;
}
public boolean isWritingReply() { public boolean isWritingReply() {
return writingReply; return writingReply;
} }

Loading…
Cancel
Save