From 825bebb6966cd08311144df6a59f11dabf50dcb9 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 3 Sep 2020 11:38:35 +0300 Subject: [PATCH 1/6] WebView enhancements (no horizontal scrolling, no autoscroll to top on link/image click) --- app/src/main/assets/style.css | 1 + app/src/main/res/layout/activity_topic.xml | 1 + app/src/main/res/layout/fragment_profile_latest_posts.xml | 3 ++- app/src/main/res/layout/fragment_shoutbox.xml | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/style.css b/app/src/main/assets/style.css index 501e1320..27c7f39f 100644 --- a/app/src/main/assets/style.css +++ b/app/src/main/assets/style.css @@ -107,6 +107,7 @@ body { background: #3C3F41; margin: 0; padding: 0; + word-wrap: break-word; } diff --git a/app/src/main/res/layout/activity_topic.xml b/app/src/main/res/layout/activity_topic.xml index 24793374..e8752417 100644 --- a/app/src/main/res/layout/activity_topic.xml +++ b/app/src/main/res/layout/activity_topic.xml @@ -48,6 +48,7 @@ android:paddingTop="4dp" android:paddingBottom="4dp" android:scrollbars="none" + android:descendantFocusability="blocksDescendants" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity" /> diff --git a/app/src/main/res/layout/fragment_profile_latest_posts.xml b/app/src/main/res/layout/fragment_profile_latest_posts.xml index 6827530d..f5e3ba3b 100644 --- a/app/src/main/res/layout/fragment_profile_latest_posts.xml +++ b/app/src/main/res/layout/fragment_profile_latest_posts.xml @@ -11,6 +11,7 @@ android:layout_height="match_parent" android:padding="4dp" android:clipToPadding = "false" - android:scrollbars="none"> + android:scrollbars="none" + android:descendantFocusability="blocksDescendants"> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index a3982068..70439ee5 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -22,6 +22,7 @@ android:layout_height="0dp" android:layout_weight="1" android:paddingBottom="8dp" + android:descendantFocusability="blocksDescendants" tools:listitem="@layout/fragment_shoutbox_shout_row" /> Date: Mon, 7 Sep 2020 18:59:13 +0300 Subject: [PATCH 2/6] LatestPostsFragment crash fix (when viewing profiles with no posts) --- .../latestPosts/LatestPostsAdapter.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index e42e4095..3e82c5df 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -19,6 +19,7 @@ import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.views.ReactiveWebView; +import timber.log.Timber; /** * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the @@ -61,22 +62,24 @@ class LatestPostsAdapter extends RecyclerView.Adapter { @SuppressLint("ClickableViewAccessibility") @Override public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) { - PostSummary topic = parsedTopicSummaries.get(position); - final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder; - latestPostViewHolder.postTitle.setText(topic.getSubject()); - latestPostViewHolder.postDate.setText(topic.getDateTime()); - latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); - latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" - , topic.getPost(), "text/html", "UTF-8", null); + if (holder instanceof LatestPostViewHolder){ + PostSummary topic = parsedTopicSummaries.get(position); + final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder; + latestPostViewHolder.postTitle.setText(topic.getSubject()); + latestPostViewHolder.postDate.setText(topic.getDateTime()); + latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); + latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" + , topic.getPost(), "text/html", "UTF-8", null); - latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { - if (interactionListener != null) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that a post has been selected. - interactionListener.onLatestPostsFragmentInteraction( - parsedTopicSummaries.get(holder.getAdapterPosition())); - } - }); + latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { + if (interactionListener != null) { + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that a post has been selected. + interactionListener.onLatestPostsFragmentInteraction( + parsedTopicSummaries.get(holder.getAdapterPosition())); + } + }); + } } @Override From c04ce7073de52bcd780041fcbe73ccac12dda82e Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 8 Sep 2020 21:33:25 +0300 Subject: [PATCH 3/6] Update README badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96b10849..598072af 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # mTHMMY -[![GitHub release](https://img.shields.io/github/release/ThmmyNoLife/mTHMMY.svg)](https://github.com/ThmmyNoLife/mTHMMY/releases) +[![GitHub release](https://img.shields.io/github/release/ThmmyNoLife/mTHMMY.svg?color=orange)](https://github.com/ThmmyNoLife/mTHMMY/releases) [![API](https://img.shields.io/badge/API-19%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=19) -[![Discord Channel](https://img.shields.io/badge/discord-public@mTHMMY-738bd7.svg?style=flat)][discord-server] +[![Discord Channel](https://img.shields.io/discord/252539000571559947?style=flat&color=738bd7&label=discord)][discord-server] ![Last Commit](https://img.shields.io/github/last-commit/ThmmyNoLife/mTHMMY/develop.svg?style=flat) ![mTHMMY logo](app/src/main/res/mipmap-xhdpi/ic_launcher_round.png) From c41250b12b15ed06367fe91eafbb9d979b282e8b Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 12 Sep 2020 14:15:09 +0300 Subject: [PATCH 4/6] WebView minor fix --- app/build.gradle | 4 ++-- app/src/main/res/layout-v21/activity_topic_post_row.xml | 5 ++--- app/src/main/res/layout/activity_topic.xml | 1 - app/src/main/res/layout/activity_topic_post_row.xml | 5 ++--- app/src/main/res/layout/fragment_profile_latest_posts.xml | 3 +-- .../main/res/layout/fragment_profile_latest_posts_row.xml | 3 ++- app/src/main/res/layout/fragment_shoutbox.xml | 1 - app/src/main/res/layout/fragment_shoutbox_shout_row.xml | 3 ++- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 10c07e6e..0c95158c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId "gr.thmmy.mthmmy" minSdkVersion 19 targetSdkVersion 29 - versionCode 27 - versionName "1.8.4" + versionCode 28 + versionName "1.8.5" archivesBaseName = "mTHMMY-v$versionName" buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 6d27a5a9..01d3fb6d 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -223,7 +223,8 @@ + android:layout_marginBottom="16dp" + android:descendantFocusability="blocksDescendants"> diff --git a/app/src/main/res/layout/activity_topic.xml b/app/src/main/res/layout/activity_topic.xml index e8752417..24793374 100644 --- a/app/src/main/res/layout/activity_topic.xml +++ b/app/src/main/res/layout/activity_topic.xml @@ -48,7 +48,6 @@ android:paddingTop="4dp" android:paddingBottom="4dp" android:scrollbars="none" - android:descendantFocusability="blocksDescendants" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity" /> diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index a0df17df..ee728e71 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -223,7 +223,8 @@ + android:layout_marginBottom="16dp" + android:descendantFocusability="blocksDescendants"> diff --git a/app/src/main/res/layout/fragment_profile_latest_posts.xml b/app/src/main/res/layout/fragment_profile_latest_posts.xml index f5e3ba3b..6827530d 100644 --- a/app/src/main/res/layout/fragment_profile_latest_posts.xml +++ b/app/src/main/res/layout/fragment_profile_latest_posts.xml @@ -11,7 +11,6 @@ android:layout_height="match_parent" android:padding="4dp" android:clipToPadding = "false" - android:scrollbars="none" - android:descendantFocusability="blocksDescendants"> + android:scrollbars="none"> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_profile_latest_posts_row.xml b/app/src/main/res/layout/fragment_profile_latest_posts_row.xml index bf992123..6c1a8d25 100644 --- a/app/src/main/res/layout/fragment_profile_latest_posts_row.xml +++ b/app/src/main/res/layout/fragment_profile_latest_posts_row.xml @@ -68,7 +68,8 @@ android:paddingStart="10dp" android:paddingEnd="10dp" android:paddingTop="6dp" - android:paddingBottom="8dp"> + android:paddingBottom="8dp" + android:descendantFocusability="blocksDescendants"> + card_view:cardUseCompatPadding="true" + android:descendantFocusability="blocksDescendants"> Date: Sat, 12 Sep 2020 18:13:46 +0300 Subject: [PATCH 5/6] TopicAdapter hotfix --- .../mthmmy/activities/topic/TopicAdapter.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 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 9d0d4556..0f0b544c 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 @@ -693,13 +693,13 @@ class TopicAdapter extends RecyclerView.Adapter { } holder.replyEditor.setText(replyText); holder.replyEditor.getEditText().setSelection(holder.replyEditor.getText().length()); - holder.replyEditor.getEditText().addTextChangedListener(createTextWatcher(holder)); + holder.replyEditor.getEditText().addTextChangedListener(createTextWatcher(holder, TextWatcherType.CONTENT)); if (backPressHidden) { holder.replyEditor.requestEditTextFocus(); backPressHidden = false; } - holder.quickReplySubject.addTextChangedListener(createTextWatcher(holder)); + holder.quickReplySubject.addTextChangedListener(createTextWatcher(holder, TextWatcherType.SUBJECT)); } else if (currentHolder instanceof EditMessageViewHolder) { final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder; @@ -735,8 +735,8 @@ class TopicAdapter extends RecyclerView.Adapter { viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editEditor.getText().toString()); }); - holder.editSubject.addTextChangedListener(createTextWatcher(holder)); - holder.editEditor.getEditText().addTextChangedListener(createTextWatcher(holder)); + holder.editSubject.addTextChangedListener(createTextWatcher(holder, TextWatcherType.SUBJECT)); + holder.editEditor.getEditText().addTextChangedListener(createTextWatcher(holder, TextWatcherType.CONTENT)); if (backPressHidden) { holder.editEditor.requestEditTextFocus(); @@ -746,7 +746,10 @@ class TopicAdapter extends RecyclerView.Adapter { } } - private TextWatcher createTextWatcher(@NonNull final RecyclerView.ViewHolder holder){ + private enum TextWatcherType { + CONTENT, SUBJECT + } + private TextWatcher createTextWatcher(@NonNull final RecyclerView.ViewHolder holder, TextWatcherType type){ return new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @@ -754,8 +757,13 @@ class TopicAdapter extends RecyclerView.Adapter { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { int position = holder.getAdapterPosition(); - if (position >= 0 && position < topicItems.size()) - ((Post) topicItems.get(position)).setBbContent(charSequence.toString()); + if (position >= 0 && position < topicItems.size()){ + Post post = ((Post) topicItems.get(position)); + if(type == TextWatcherType.CONTENT) + post.setBbContent(charSequence.toString()); + else if(type == TextWatcherType.SUBJECT) + post.setSubject(charSequence.toString()); + } } @Override From 5fe9af78f9540a3cafaa2c7b2ac33e43e922b2d6 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 12 Sep 2020 20:23:35 +0300 Subject: [PATCH 6/6] TopicActivity fix (propagation of touch events to Viewholders) --- .../latestPosts/LatestPostsAdapter.java | 1 - .../mthmmy/views/CustomRecyclerView.java | 5 +- .../mthmmy/views/ScrollAwareRecyclerView.java | 48 +++++++++++++++++++ app/src/main/res/layout/activity_topic.xml | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index 3e82c5df..b052dc32 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -19,7 +19,6 @@ import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.views.ReactiveWebView; -import timber.log.Timber; /** * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java b/app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java index 1b605cdd..964eaa81 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java @@ -5,10 +5,9 @@ import android.util.AttributeSet; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; //Custom RecyclerView, so EdgeEffect and SwipeRefresh both work -public class CustomRecyclerView extends RecyclerView { +public class CustomRecyclerView extends ScrollAwareRecyclerView { private volatile boolean enableRefreshing = true; public CustomRecyclerView(Context context) { @@ -40,7 +39,6 @@ public class CustomRecyclerView extends RecyclerView { else if (((LinearLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition() != 0) enableRefreshing = false; - super.onScrollStateChanged(state); } @@ -51,5 +49,4 @@ public class CustomRecyclerView extends RecyclerView { else return super.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, 0, offsetInWindow); } - } diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java b/app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java new file mode 100644 index 00000000..ee11a673 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java @@ -0,0 +1,48 @@ +package gr.thmmy.mthmmy.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import androidx.recyclerview.widget.RecyclerView; + +// Based on https://stackoverflow.com/a/46453825 +// Not needed in LatestPostsFragment as there are no other ScrollAware Behaviors to steal touch events +public class ScrollAwareRecyclerView extends RecyclerView { + public ScrollAwareRecyclerView(Context context) { + super(context); + } + + public ScrollAwareRecyclerView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ScrollAwareRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + final int scrollState = getScrollState(); + boolean requestCancelDisallowInterceptTouchEvent + = ((scrollState == SCROLL_STATE_SETTLING) || (scrollState == SCROLL_STATE_IDLE)); + boolean consumed = super.onInterceptTouchEvent(event); + final int action = event.getActionMasked(); + + if (action == MotionEvent.ACTION_DOWN) { + if (requestCancelDisallowInterceptTouchEvent) { + getParent().requestDisallowInterceptTouchEvent(false); + + // only if it touched the top or the bottom + if (!canScrollVertically(-1) || !canScrollVertically(1)) { + // stop scroll to enable child view to get the touch event + stopScroll(); + // do not consume the event + return false; + } + } + } + return consumed; + } + +} diff --git a/app/src/main/res/layout/activity_topic.xml b/app/src/main/res/layout/activity_topic.xml index 24793374..69fb3954 100644 --- a/app/src/main/res/layout/activity_topic.xml +++ b/app/src/main/res/layout/activity_topic.xml @@ -37,7 +37,7 @@ -