show push migration snackbar above floating action button (#2598)

This commit is contained in:
Konrad Pozniak 2022-06-30 20:49:27 +02:00 committed by GitHub
parent 379435c804
commit 9dcb1b666c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View file

@ -703,7 +703,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
NotificationHelper.createNotificationChannelsForAccount(accountManager.activeAccount!!, this) NotificationHelper.createNotificationChannelsForAccount(accountManager.activeAccount!!, this)
// Setup push notifications // Setup push notifications
showMigrationNoticeIfNecessary(this, binding.root, accountManager) showMigrationNoticeIfNecessary(this, binding.mainCoordinatorLayout, binding.composeButton, accountManager)
if (NotificationHelper.areNotificationsEnabled(this, accountManager)) { if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {
lifecycleScope.launch { lifecycleScope.launch {
enablePushNotificationsWithFallback(this@MainActivity, mastodonApi, accountManager) enablePushNotificationsWithFallback(this@MainActivity, mastodonApi, accountManager)

View file

@ -51,7 +51,12 @@ private fun accountNeedsMigration(account: AccountEntity): Boolean =
fun currentAccountNeedsMigration(accountManager: AccountManager): Boolean = fun currentAccountNeedsMigration(accountManager: AccountManager): Boolean =
accountManager.activeAccount?.let(::accountNeedsMigration) ?: false accountManager.activeAccount?.let(::accountNeedsMigration) ?: false
fun showMigrationNoticeIfNecessary(context: Context, parent: View, accountManager: AccountManager) { fun showMigrationNoticeIfNecessary(
context: Context,
parent: View,
anchorView: View?,
accountManager: AccountManager
) {
// No point showing anything if we cannot enable it // No point showing anything if we cannot enable it
if (!isUnifiedPushAvailable(context)) return if (!isUnifiedPushAvailable(context)) return
if (!anyAccountNeedsMigration(accountManager)) return if (!anyAccountNeedsMigration(accountManager)) return
@ -59,10 +64,10 @@ fun showMigrationNoticeIfNecessary(context: Context, parent: View, accountManage
val pm = PreferenceManager.getDefaultSharedPreferences(context) val pm = PreferenceManager.getDefaultSharedPreferences(context)
if (pm.getBoolean(KEY_MIGRATION_NOTICE_DISMISSED, false)) return if (pm.getBoolean(KEY_MIGRATION_NOTICE_DISMISSED, false)) return
Snackbar.make(parent, R.string.tips_push_notification_migration, Snackbar.LENGTH_INDEFINITE).apply { Snackbar.make(parent, R.string.tips_push_notification_migration, Snackbar.LENGTH_INDEFINITE)
setAction(R.string.action_details) { showMigrationExplanationDialog(context, accountManager) } .setAnchorView(anchorView)
show() .setAction(R.string.action_details) { showMigrationExplanationDialog(context, accountManager) }
} .show()
} }
private fun showMigrationExplanationDialog(context: Context, accountManager: AccountManager) { private fun showMigrationExplanationDialog(context: Context, accountManager: AccountManager) {

View file

@ -8,6 +8,7 @@
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/mainCoordinatorLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.keylesspalace.tusky.MainActivity"> tools:context="com.keylesspalace.tusky.MainActivity">