From cc015c45bd0442718fbcd18e1a7c6a45de2aec99 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Jun 2023 10:34:49 +0930 Subject: [PATCH 1/2] Add 50 dp buffer to isScrolledToBottom (#1228) --- .../org/thoughtcrime/securesms/util/GeneralUtilities.kt | 7 +++++++ .../java/org/session/libsession/utilities/ViewUtils.kt | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt index 00e3e44418..a38c93831e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt @@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.util import android.content.res.Resources import android.os.Build import androidx.annotation.ColorRes +import androidx.recyclerview.widget.RecyclerView +import kotlin.math.max import kotlin.math.roundToInt fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { @@ -30,3 +32,8 @@ fun toDp(px: Float, resources: Resources): Float { val scale = resources.displayMetrics.density return (px / scale) } + +val RecyclerView.isScrolledToBottom: Boolean + get() = computeVerticalScrollOffset().coerceAtLeast(0) + + computeVerticalScrollExtent() + + toPx(50, resources) >= computeVerticalScrollRange() diff --git a/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt b/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt index dfe0c3b451..80c0293238 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt @@ -4,8 +4,6 @@ import android.content.Context import android.util.TypedValue import androidx.annotation.AttrRes import androidx.annotation.ColorInt -import androidx.recyclerview.widget.RecyclerView -import kotlin.math.max @ColorInt fun Context.getColorFromAttr( @@ -16,6 +14,3 @@ fun Context.getColorFromAttr( theme.resolveAttribute(attrColor, typedValue, resolveRefs) return typedValue.data } - -val RecyclerView.isScrolledToBottom: Boolean - get() = max(0, computeVerticalScrollOffset()) + computeVerticalScrollExtent() >= computeVerticalScrollRange() From 92a6447b8a46814cfdd4b0505e3a7cf2cf05e55b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 19 Jun 2023 11:51:14 +0930 Subject: [PATCH 2/2] Add button downstates throughout (#1220) --- .../preferences/BlockedContactsPreference.kt | 19 ++++++-------- .../main/res/color/prominent_button_color.xml | 5 ++++ .../borderless_button_medium_background.xml | 11 ++++++++ ...tructive_dialog_text_button_background.xml | 19 +++++++------- .../filled_button_medium_background.xml | 10 ++++++++ ...minent_filled_button_medium_background.xml | 19 +++++++------- ...mportant_dialog_text_button_background.xml | 19 +++++++------- ...rtant_outline_button_medium_background.xml | 22 ++++++++-------- .../res/layout-sw400dp/activity_landing.xml | 2 +- .../main/res/layout-sw400dp/activity_seed.xml | 9 +++---- app/src/main/res/layout/activity_home.xml | 1 + app/src/main/res/layout/activity_landing.xml | 2 +- app/src/main/res/layout/activity_pn_mode.xml | 2 +- app/src/main/res/layout/activity_seed.xml | 10 ++++---- app/src/main/res/layout/activity_settings.xml | 10 ++++++++ .../layout/blocked_contacts_preference.xml | 9 ++++--- .../main/res/layout/export_logs_widget.xml | 4 +-- .../main/res/layout/fragment_create_group.xml | 21 +++++----------- .../res/layout/fragment_join_community.xml | 5 +++- .../layout/fragment_new_conversation_home.xml | 5 ++++ .../main/res/layout/fragment_new_message.xml | 4 +++ .../res/layout/view_global_search_input.xml | 4 ++- app/src/main/res/values/styles.xml | 25 +++++++------------ 23 files changed, 132 insertions(+), 105 deletions(-) create mode 100644 app/src/main/res/color/prominent_button_color.xml create mode 100644 app/src/main/res/drawable/borderless_button_medium_background.xml create mode 100644 app/src/main/res/drawable/filled_button_medium_background.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsPreference.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsPreference.kt index 254d34978d..e985ba6d4f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsPreference.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsPreference.kt @@ -9,20 +9,15 @@ import androidx.preference.PreferenceViewHolder class BlockedContactsPreference @JvmOverloads constructor( context: Context, - attributeSet: AttributeSet? = null) : PreferenceCategory(context, attributeSet), View.OnClickListener { - - override fun onClick(v: View?) { - if (v is BlockedContactsLayout) { - val intent = Intent(context, BlockedContactsActivity::class.java) - context.startActivity(intent) - } - } + attributeSet: AttributeSet? = null +) : PreferenceCategory(context, attributeSet) { override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) - val itemView = holder.itemView - itemView.setOnClickListener(this) + holder.itemView.setOnClickListener { + val intent = Intent(context, BlockedContactsActivity::class.java) + context.startActivity(intent) + } } - -} \ No newline at end of file +} diff --git a/app/src/main/res/color/prominent_button_color.xml b/app/src/main/res/color/prominent_button_color.xml new file mode 100644 index 0000000000..8f2e692fda --- /dev/null +++ b/app/src/main/res/color/prominent_button_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/borderless_button_medium_background.xml b/app/src/main/res/drawable/borderless_button_medium_background.xml new file mode 100644 index 0000000000..6c72f9e72b --- /dev/null +++ b/app/src/main/res/drawable/borderless_button_medium_background.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/destructive_dialog_text_button_background.xml b/app/src/main/res/drawable/destructive_dialog_text_button_background.xml index 1eff84a69b..f3e13c8000 100644 --- a/app/src/main/res/drawable/destructive_dialog_text_button_background.xml +++ b/app/src/main/res/drawable/destructive_dialog_text_button_background.xml @@ -1,11 +1,10 @@ - - - - - - - - \ No newline at end of file + + + + + + + + diff --git a/app/src/main/res/drawable/filled_button_medium_background.xml b/app/src/main/res/drawable/filled_button_medium_background.xml new file mode 100644 index 0000000000..10eb6de679 --- /dev/null +++ b/app/src/main/res/drawable/filled_button_medium_background.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/prominent_filled_button_medium_background.xml b/app/src/main/res/drawable/prominent_filled_button_medium_background.xml index a06a0d11e5..698a67c0a9 100644 --- a/app/src/main/res/drawable/prominent_filled_button_medium_background.xml +++ b/app/src/main/res/drawable/prominent_filled_button_medium_background.xml @@ -1,11 +1,10 @@ - - - - - - - - \ No newline at end of file + + + + + + + + diff --git a/app/src/main/res/drawable/unimportant_dialog_text_button_background.xml b/app/src/main/res/drawable/unimportant_dialog_text_button_background.xml index 1eff84a69b..f3e13c8000 100644 --- a/app/src/main/res/drawable/unimportant_dialog_text_button_background.xml +++ b/app/src/main/res/drawable/unimportant_dialog_text_button_background.xml @@ -1,11 +1,10 @@ - - - - - - - - \ No newline at end of file + + + + + + + + diff --git a/app/src/main/res/drawable/unimportant_outline_button_medium_background.xml b/app/src/main/res/drawable/unimportant_outline_button_medium_background.xml index 6e0de35a5b..d12f7408d9 100644 --- a/app/src/main/res/drawable/unimportant_outline_button_medium_background.xml +++ b/app/src/main/res/drawable/unimportant_outline_button_medium_background.xml @@ -1,11 +1,13 @@ - - - - - - - - \ No newline at end of file + + + + + + + + + diff --git a/app/src/main/res/layout-sw400dp/activity_landing.xml b/app/src/main/res/layout-sw400dp/activity_landing.xml index 1e89cd967d..5e5a36704a 100644 --- a/app/src/main/res/layout-sw400dp/activity_landing.xml +++ b/app/src/main/res/layout-sw400dp/activity_landing.xml @@ -52,6 +52,7 @@ android:text="@string/activity_landing_restore_button_title" />