Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "Hide compose button while scrolling" setting with bottom padding #4486

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/TuskyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class TuskyApplication : Application(), Configuration.Provider {
editor.remove(PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS)
}

if (oldVersion < 2024060201) {
editor.remove(PrefKeys.Deprecated.FAB_HIDE)
}

editor.putInt(PrefKeys.SCHEMA_VERSION, newVersion)
editor.apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide
private var animateAvatar: Boolean = false
private var animateEmojis: Boolean = false

// fields for scroll animation
private var hideFab: Boolean = false
// for scroll animation
private var oldOffset: Int = 0

@ColorInt
Expand Down Expand Up @@ -170,7 +169,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide

animateAvatar = preferences.getBoolean(PrefKeys.ANIMATE_GIF_AVATARS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)

handleWindowInsets()
setupToolbar()
Expand Down Expand Up @@ -364,15 +362,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide
supportActionBar?.setDisplayShowTitleEnabled(false)
}

if (hideFab && !blocking) {
if (verticalOffset > oldOffset) {
binding.accountFloatingActionButton.show()
}
if (verticalOffset < oldOffset) {
binding.accountFloatingActionButton.hide()
}
}

val scaledAvatarSize = (avatarSize + verticalOffset) / avatarSize

binding.accountAvatarImageView.scaleX = scaledAvatarSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
import com.keylesspalace.tusky.components.account.AccountActivity
import com.keylesspalace.tusky.databinding.FragmentTimelineBinding
import com.keylesspalace.tusky.fragment.SFragment
import com.keylesspalace.tusky.interfaces.ActionButtonActivity
import com.keylesspalace.tusky.interfaces.ReselectableFragment
import com.keylesspalace.tusky.interfaces.StatusActionListener
import com.keylesspalace.tusky.settings.PrefKeys
Expand Down Expand Up @@ -86,8 +85,6 @@ class ConversationsFragment :

private var adapter: ConversationAdapter? = null

private var hideFab = false

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)

Expand Down Expand Up @@ -173,24 +170,6 @@ class ConversationsFragment :
}
})

hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(view: RecyclerView, dx: Int, dy: Int) {
val composeButton = (activity as ActionButtonActivity).actionButton
if (composeButton != null) {
if (hideFab) {
if (dy > 0 && composeButton.isShown) {
composeButton.hide() // hides the button if we're scrolling down
} else if (dy < 0 && !composeButton.isShown) {
composeButton.show() // shows it if we are scrolling up
}
} else if (!composeButton.isShown) {
composeButton.show()
}
}
}
})

viewLifecycleOwner.lifecycleScope.launch {
viewModel.conversationFlow.collectLatest { pagingData ->
adapter.submitData(pagingData)
Expand Down Expand Up @@ -407,10 +386,6 @@ class ConversationsFragment :

private fun onPreferenceChanged(adapter: ConversationAdapter, key: String) {
when (key) {
PrefKeys.FAB_HIDE -> {
hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
}

PrefKeys.MEDIA_PREVIEW_ENABLED -> {
val enabled = accountManager.activeAccount!!.mediaPreviewEnabled
val oldMediaPreviewEnabled = adapter.mediaPreviewEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import com.keylesspalace.tusky.BaseActivity
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.ActivityFiltersBinding
Expand Down Expand Up @@ -51,6 +52,10 @@ class FiltersActivity : BaseActivity(), FiltersListener {

setTitle(R.string.pref_title_timeline_filters)

binding.filtersList.addItemDecoration(
DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
)

observeViewModel()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import at.connyduck.calladapter.networkresult.fold
import com.google.android.material.snackbar.Snackbar
Expand All @@ -24,7 +23,6 @@ import com.keylesspalace.tusky.components.compose.ComposeAutoCompleteAdapter
import com.keylesspalace.tusky.databinding.ActivityFollowedTagsBinding
import com.keylesspalace.tusky.interfaces.HashtagActionListener
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.copyToClipboard
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.show
Expand Down Expand Up @@ -85,19 +83,6 @@ class FollowedTagsActivity :
DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
)
(binding.followedTagsView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false

val hideFab = sharedPreferences.getBoolean(PrefKeys.FAB_HIDE, false)
if (hideFab) {
binding.followedTagsView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (dy > 0 && binding.fab.isShown) {
binding.fab.hide()
} else if (dy < 0 && !binding.fab.isShown) {
binding.fab.show()
}
}
})
}
}

private fun setupAdapter(): FollowedTagsAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import com.keylesspalace.tusky.databinding.NotificationsFilterBinding
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.fragment.SFragment
import com.keylesspalace.tusky.interfaces.AccountActionListener
import com.keylesspalace.tusky.interfaces.ActionButtonActivity
import com.keylesspalace.tusky.interfaces.ReselectableFragment
import com.keylesspalace.tusky.interfaces.StatusActionListener
import com.keylesspalace.tusky.settings.PrefKeys
Expand Down Expand Up @@ -100,7 +99,6 @@ class NotificationsFragment :

private var adapter: NotificationsPagingAdapter? = null

private var hideFab: Boolean = false
private var showNotificationsFilterBar: Boolean = true
private var readingOrder: ReadingOrder = ReadingOrder.NEWEST_FIRST

Expand Down Expand Up @@ -180,26 +178,8 @@ class NotificationsFragment :
DividerItemDecoration(context, DividerItemDecoration.VERTICAL)
)

hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
readingOrder = ReadingOrder.from(preferences.getString(PrefKeys.READING_ORDER, null))

binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(view: RecyclerView, dx: Int, dy: Int) {
val composeButton = (activity as ActionButtonActivity).actionButton
if (composeButton != null) {
if (hideFab) {
if (dy > 0 && composeButton.isShown) {
composeButton.hide() // hides the button if we're scrolling down
} else if (dy < 0 && !composeButton.isShown) {
composeButton.show() // shows it if we are scrolling up
}
} else if (!composeButton.isShown) {
composeButton.show()
}
}
}
})

adapter.addLoadStateListener { loadState ->
if (loadState.refresh != LoadState.Loading && loadState.source.refresh != LoadState.Loading) {
binding.swipeRefreshLayout.isRefreshing = false
Expand Down Expand Up @@ -481,10 +461,6 @@ class NotificationsFragment :

private fun onPreferenceChanged(adapter: NotificationsPagingAdapter, key: String) {
when (key) {
PrefKeys.FAB_HIDE -> {
hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
}

PrefKeys.MEDIA_PREVIEW_ENABLED -> {
val enabled = accountManager.activeAccount!!.mediaPreviewEnabled
val oldMediaPreviewEnabled = adapter.mediaPreviewEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@ class PreferencesFragment : PreferenceFragmentCompat() {
isSingleLineTitle = false
}

switchPreference {
setDefaultValue(false)
key = PrefKeys.FAB_HIDE
setTitle(R.string.pref_title_hide_follow_button)
isSingleLineTitle = false
}

switchPreference {
setDefaultValue(false)
key = PrefKeys.ABSOLUTE_TIME_VIEW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.view.View
import android.view.accessibility.AccessibilityManager
import androidx.core.content.getSystemService
import androidx.core.view.MenuProvider
import androidx.core.view.updatePadding
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -109,7 +110,6 @@ class TimelineFragment :
private var adapter: TimelinePagingAdapter? = null

private var isSwipeToRefreshEnabled = true
private var hideFab = false

/**
* Adapter position of the placeholder that was most recently clicked to "Load more". If null
Expand Down Expand Up @@ -279,26 +279,6 @@ class TimelineFragment :
}
}

if (actionButtonPresent()) {
hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(view: RecyclerView, dx: Int, dy: Int) {
val composeButton = (activity as ActionButtonActivity).actionButton
if (composeButton != null) {
if (hideFab) {
if (dy > 0 && composeButton.isShown) {
composeButton.hide() // hides the button if we're scrolling down
} else if (dy < 0 && !composeButton.isShown) {
composeButton.show() // shows it if we are scrolling up
}
} else if (!composeButton.isShown) {
composeButton.show()
}
}
}
})
}

viewLifecycleOwner.lifecycleScope.launch {
eventHub.events.collect { event ->
when (event) {
Expand Down Expand Up @@ -411,6 +391,14 @@ class TimelineFragment :
val divider = DividerItemDecoration(context, RecyclerView.VERTICAL)
binding.recyclerView.addItemDecoration(divider)

val recyclerViewBottomPadding = if ((activity as? ActionButtonActivity?)?.actionButton != null) {
resources.getDimensionPixelSize(R.dimen.recyclerview_bottom_padding_actionbutton)
} else {
resources.getDimensionPixelSize(R.dimen.recyclerview_bottom_padding_no_actionbutton)
}

binding.recyclerView.updatePadding(bottom = recyclerViewBottomPadding)

// CWs are expanded without animation, buttons animate itself, we don't need it basically
(binding.recyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
binding.recyclerView.adapter = adapter
Expand Down Expand Up @@ -573,10 +561,6 @@ class TimelineFragment :

private fun onPreferenceChanged(adapter: TimelinePagingAdapter, key: String) {
when (key) {
PrefKeys.FAB_HIDE -> {
hideFab = preferences.getBoolean(PrefKeys.FAB_HIDE, false)
}

PrefKeys.MEDIA_PREVIEW_ENABLED -> {
val enabled = accountManager.activeAccount!!.mediaPreviewEnabled
val oldMediaPreviewEnabled = adapter.mediaPreviewEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ object PrefKeys {

const val SCHEMA_VERSION: String = "schema_version"
const val APP_THEME = "appTheme"
const val FAB_HIDE = "fabHide"
const val LANGUAGE = "language"
const val STATUS_TEXT_SIZE = "statusTextSize"
const val READING_ORDER = "readingOrder"
Expand Down Expand Up @@ -112,4 +111,8 @@ object PrefKeys {

/** UI text scaling factor, stored as float, 100 = 100% = no scaling */
const val UI_TEXT_SCALE_RATIO = "uiTextScaleRatio"

object Deprecated {
const val FAB_HIDE = "fabHide"
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout-sw640dp/fragment_timeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2023 Tusky Contributors
~
~ This file is a part of Tusky.
Expand Down Expand Up @@ -85,7 +84,9 @@
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground" />
android:background="?android:attr/colorBackground"
android:clipToPadding="false"
android:paddingBottom="@dimen/recyclerview_bottom_padding_actionbutton" />

<com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/statusView"
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/layout-sw640dp/fragment_view_thread.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
android:layout_height="0dp"
android:layout_weight="1"
android:background="?android:attr/colorBackground"
android:clipToPadding="false"
android:paddingBottom="@dimen/recyclerview_bottom_padding_no_actionbutton"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical" />

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/threadProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:contentDescription="@string/a11y_label_loading_thread"
android:indeterminate="true"
android:contentDescription="@string/a11y_label_loading_thread" />
android:visibility="gone" />

<com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/statusView"
Expand All @@ -47,9 +50,9 @@
android:id="@+id/initialProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:indeterminate="true"
android:layout_gravity="center"
android:contentDescription="@string/a11y_label_loading_thread" />
android:contentDescription="@string/a11y_label_loading_thread"
android:indeterminate="true"
android:visibility="gone" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_announcements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/announcementsList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/recyclerview_bottom_padding_no_actionbutton" />

<com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/errorMessageView"
Expand Down
Loading
Loading