Browse Source

Minor polls patch

pull/61/merge
Ezerous 6 years ago
parent
commit
3ce258ec5f
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 28
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  2. 17
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

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

@ -277,7 +277,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
int finalSum = totalVotes; int finalSum = totalVotes;
barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> { barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> {
DecimalFormat format = new DecimalFormat("###.#%"); DecimalFormat format = new DecimalFormat("###.#%");
double percentage = ((double) value / (double) finalSum); double percentage = 0;
if(finalSum!=0)
percentage = ((double) value / (double) finalSum);
return "" + (int) value + " (" + format.format(percentage) + ")"; return "" + (int) value + " (" + format.format(percentage) + ")";
}); });
holder.voteChart.setData(barData); holder.voteChart.setData(barData);
@ -427,11 +429,11 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.personalText.setVisibility(View.VISIBLE); holder.personalText.setVisibility(View.VISIBLE);
} else } else
holder.personalText.setVisibility(View.GONE); holder.personalText.setVisibility(View.GONE);
if (mUserColor != USER_COLOR_YELLOW) { if (mUserColor != USER_COLOR_YELLOW)
holder.username.setTextColor(mUserColor); holder.username.setTextColor(mUserColor);
} else { else
holder.username.setTextColor(USER_COLOR_WHITE); holder.username.setTextColor(USER_COLOR_WHITE);
}
if (mNumberOfStars > 0) { if (mNumberOfStars > 0) {
holder.stars.setTypeface(Typeface.createFromAsset(context.getAssets() holder.stars.setTypeface(Typeface.createFromAsset(context.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
@ -551,9 +553,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Drawable editStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_edit_white_24dp); Drawable editStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_edit_white_24dp);
editPostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(editStartDrawable, null, null, null); editPostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(editStartDrawable, null, null, null);
if (viewModel.isEditingPost() || currentPost.getPostEditURL() == null || currentPost.getPostEditURL().equals("")) { if (viewModel.isEditingPost() || currentPost.getPostEditURL() == null || currentPost.getPostEditURL().equals(""))
editPostButton.setVisibility(View.GONE); editPostButton.setVisibility(View.GONE);
} else { else {
editPostButton.setOnClickListener(v -> { editPostButton.setOnClickListener(v -> {
viewModel.prepareForEdit(position, currentPost.getPostEditURL()); viewModel.prepareForEdit(position, currentPost.getPostEditURL());
popUp.dismiss(); popUp.dismiss();
@ -562,9 +564,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
TextView deletePostButton = popUpContent.findViewById(R.id.delete_post); TextView deletePostButton = popUpContent.findViewById(R.id.delete_post);
if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")) { if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals(""))
deletePostButton.setVisibility(View.GONE); deletePostButton.setVisibility(View.GONE);
} else { else {
Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp); Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp);
deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null); deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null);
popUpContent.findViewById(R.id.delete_post).setOnClickListener(v -> { popUpContent.findViewById(R.id.delete_post).setOnClickListener(v -> {
@ -583,9 +585,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
//noinspection PointlessBooleanExpression,ConstantConditions //noinspection PointlessBooleanExpression,ConstantConditions
if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) { if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply())
holder.quoteToggle.setVisibility(View.GONE); holder.quoteToggle.setVisibility(View.GONE);
} else { else {
if (viewModel.getToQuoteList().contains(currentPost.getPostIndex())) if (viewModel.getToQuoteList().contains(currentPost.getPostIndex()))
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked_accent_24dp); holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked_accent_24dp);
else else
@ -642,11 +644,11 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null)); holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null));
if (reply.getContent() != null) { if (reply.getContent() != null)
holder.replyEditor.setText(reply.getContent()); holder.replyEditor.setText(reply.getContent());
} else if (viewModel.getBuildedQuotes() != null && !viewModel.getBuildedQuotes().isEmpty()) { else if (viewModel.getBuildedQuotes() != null && !viewModel.getBuildedQuotes().isEmpty())
holder.replyEditor.setText(viewModel.getBuildedQuotes()); holder.replyEditor.setText(viewModel.getBuildedQuotes());
} else { else {
SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key), SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key),
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
holder.replyEditor.setText(drafts.getString(String.valueOf(viewModel.getTopicId()), "")); holder.replyEditor.setText(drafts.getString(String.valueOf(viewModel.getTopicId()), ""));

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

@ -116,7 +116,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
} }
/** /**
* In contrasto to {@link TopicViewModel#reloadPage()} this method gets rid of any arguements * In contrast to {@link TopicViewModel#reloadPage()} this method gets rid of any arguments
* in the url before refreshing * in the url before refreshing
*/ */
public void resetPage() { public void resetPage() {
@ -182,9 +182,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
} }
public void postReply(Context context, String subject, String reply) { public void postReply(Context context, String subject, String reply) {
if (prepareForReplyResult.getValue() == null) { if (prepareForReplyResult.getValue() == null)
throw new NullPointerException("Reply preparation was not found!"); throw new NullPointerException("Reply preparation was not found!");
}
PrepareForReplyResult replyForm = prepareForReplyResult.getValue(); PrepareForReplyResult replyForm = prepareForReplyResult.getValue();
boolean includeAppSignature = true; boolean includeAppSignature = true;
SessionManager sessionManager = BaseActivity.getSessionManager(); SessionManager sessionManager = BaseActivity.getSessionManager();
@ -263,10 +263,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
topicItems.setValue(result.getNewPostsList()); topicItems.setValue(result.getNewPostsList());
focusedPostIndex.setValue(result.getFocusedPostIndex()); focusedPostIndex.setValue(result.getFocusedPostIndex());
isUserExtraInfoVisibile.clear(); isUserExtraInfoVisibile.clear();
for (int i = 0; i < result.getNewPostsList().size(); i++) { for (int i = 0; i < result.getNewPostsList().size(); i++)
isUserExtraInfoVisibile.add(false); isUserExtraInfoVisibile.add(false);
} }
}
topicTaskResultCode.setValue(result.getResultCode()); topicTaskResultCode.setValue(result.getResultCode());
} }
@ -285,9 +284,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
if (pageIndicatorIndex.getValue() == null) if (pageIndicatorIndex.getValue() == null)
throw new NullPointerException("No page has been loaded yet!"); throw new NullPointerException("No page has been loaded yet!");
int oldIndicatorIndex = pageIndicatorIndex.getValue(); int oldIndicatorIndex = pageIndicatorIndex.getValue();
if (oldIndicatorIndex <= pageCount - step) { if (oldIndicatorIndex <= pageCount - step)
pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() + step); pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() + step);
} else else
pageIndicatorIndex.setValue(pageCount); pageIndicatorIndex.setValue(pageCount);
if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated(); if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated();
} }
@ -296,9 +295,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
if (pageIndicatorIndex.getValue() == null) if (pageIndicatorIndex.getValue() == null)
throw new NullPointerException("No page has been loaded yet!"); throw new NullPointerException("No page has been loaded yet!");
int oldIndicatorIndex = pageIndicatorIndex.getValue(); int oldIndicatorIndex = pageIndicatorIndex.getValue();
if (oldIndicatorIndex > step) { if (oldIndicatorIndex > step)
pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() - step); pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() - step);
} else else
pageIndicatorIndex.setValue(1); pageIndicatorIndex.setValue(1);
if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated(); if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated();
} }

Loading…
Cancel
Save