From f4ea76b036edb412bc5279bab87015b001f95193 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Tue, 27 Aug 2024 17:52:23 +0200 Subject: [PATCH] The "More" button no longer appears when the category description is short. Now, whenever the UI state changes, the number of lines in the description is checked, and the visibility of the "More" button is determined based on that. https://github.com/organicmaps/organicmaps/issues/5502 Signed-off-by: Mikhail Mitrofanov --- .../bookmarks/BookmarkListAdapter.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkListAdapter.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkListAdapter.java index a690997658..cc5d48f821 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkListAdapter.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkListAdapter.java @@ -524,30 +524,37 @@ public class BookmarkListAdapter extends RecyclerView.Adapter - { - final int lineCount = text.getLineCount(); - if (lineCount > MAX_VISIBLE_LINES) - { - text.setMaxLines(MAX_VISIBLE_LINES); - moreBtn.setVisibility(View.VISIBLE); - } - else - moreBtn.setVisibility(View.GONE); - }); + text.post(() -> setShortModeDescription(text, moreBtn)); } - private void onMoreButtonClicked(TextView text, TextView moreBtn) + private void onMoreButtonClicked(TextView textView, TextView moreBtn) { - if (text.getMaxLines() == MAX_VISIBLE_LINES) + if (isShortModeDescription(textView)) { - text.setMaxLines(Integer.MAX_VALUE); - moreBtn.setVisibility(View.GONE); + setExpandedModeDescription(textView, moreBtn); } else { - text.setMaxLines(MAX_VISIBLE_LINES); - moreBtn.setVisibility(View.VISIBLE); + setShortModeDescription(textView, moreBtn); } } + + private boolean isShortModeDescription(TextView text) + { + return text.getMaxLines() == MAX_VISIBLE_LINES; + } + + private void setExpandedModeDescription(TextView textView, TextView moreBtn) + { + textView.setMaxLines(Integer.MAX_VALUE); + moreBtn.setVisibility(View.GONE); + } + + private void setShortModeDescription(TextView textView, TextView moreBtn) + { + textView.setMaxLines(MAX_VISIBLE_LINES); + + boolean isDescriptionTooLong = textView.getLineCount() > MAX_VISIBLE_LINES; + moreBtn.setVisibility(isDescriptionTooLong ? View.VISIBLE : View.GONE); + } }