From 3ce258ec5f7fc7a7c936977bc31c5d71a3ebc423 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 19 Nov 2018 19:35:15 +0200 Subject: [PATCH] Minor polls patch --- .../mthmmy/activities/topic/TopicAdapter.java | 28 ++++++++++--------- .../mthmmy/viewmodel/TopicViewModel.java | 17 ++++++----- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 7aa43428..168b04ea 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -277,7 +277,9 @@ class TopicAdapter extends RecyclerView.Adapter { int finalSum = totalVotes; barData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> { 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) + ")"; }); holder.voteChart.setData(barData); @@ -427,11 +429,11 @@ class TopicAdapter extends RecyclerView.Adapter { holder.personalText.setVisibility(View.VISIBLE); } else holder.personalText.setVisibility(View.GONE); - if (mUserColor != USER_COLOR_YELLOW) { + if (mUserColor != USER_COLOR_YELLOW) holder.username.setTextColor(mUserColor); - } else { + else holder.username.setTextColor(USER_COLOR_WHITE); - } + if (mNumberOfStars > 0) { holder.stars.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); @@ -551,9 +553,9 @@ class TopicAdapter extends RecyclerView.Adapter { Drawable editStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_edit_white_24dp); 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); - } else { + else { editPostButton.setOnClickListener(v -> { viewModel.prepareForEdit(position, currentPost.getPostEditURL()); popUp.dismiss(); @@ -562,9 +564,9 @@ class TopicAdapter extends RecyclerView.Adapter { 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); - } else { + else { Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp); deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null); popUpContent.findViewById(R.id.delete_post).setOnClickListener(v -> { @@ -583,9 +585,9 @@ class TopicAdapter extends RecyclerView.Adapter { }); //noinspection PointlessBooleanExpression,ConstantConditions - if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) { + if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) holder.quoteToggle.setVisibility(View.GONE); - } else { + else { if (viewModel.getToQuoteList().contains(currentPost.getPostIndex())) holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked_accent_24dp); else @@ -642,11 +644,11 @@ class TopicAdapter extends RecyclerView.Adapter { }); holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null)); - if (reply.getContent() != null) { + if (reply.getContent() != null) 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()); - } else { + else { SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key), Context.MODE_PRIVATE); holder.replyEditor.setText(drafts.getString(String.valueOf(viewModel.getTopicId()), "")); diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index aa669185..eebd1ad6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/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 */ public void resetPage() { @@ -182,9 +182,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa } 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!"); - } + PrepareForReplyResult replyForm = prepareForReplyResult.getValue(); boolean includeAppSignature = true; SessionManager sessionManager = BaseActivity.getSessionManager(); @@ -263,9 +263,8 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa topicItems.setValue(result.getNewPostsList()); focusedPostIndex.setValue(result.getFocusedPostIndex()); isUserExtraInfoVisibile.clear(); - for (int i = 0; i < result.getNewPostsList().size(); i++) { + for (int i = 0; i < result.getNewPostsList().size(); i++) isUserExtraInfoVisibile.add(false); - } } topicTaskResultCode.setValue(result.getResultCode()); } @@ -285,9 +284,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (pageIndicatorIndex.getValue() == null) throw new NullPointerException("No page has been loaded yet!"); int oldIndicatorIndex = pageIndicatorIndex.getValue(); - if (oldIndicatorIndex <= pageCount - step) { + if (oldIndicatorIndex <= pageCount - step) pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() + step); - } else + else pageIndicatorIndex.setValue(pageCount); if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated(); } @@ -296,9 +295,9 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (pageIndicatorIndex.getValue() == null) throw new NullPointerException("No page has been loaded yet!"); int oldIndicatorIndex = pageIndicatorIndex.getValue(); - if (oldIndicatorIndex > step) { + if (oldIndicatorIndex > step) pageIndicatorIndex.setValue(pageIndicatorIndex.getValue() - step); - } else + else pageIndicatorIndex.setValue(1); if (changePage && oldIndicatorIndex != pageIndicatorIndex.getValue()) loadPageIndicated(); }