From a59011ffd241a0c08f37a72f03ee15297f54f752 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 17 Aug 2022 23:33:31 +0200 Subject: [PATCH 1/6] Adds debug button to new app layout --- .../app/features/home/NewHomeDetailFragment.kt | 16 ++++++++++++++++ .../main/res/layout/fragment_new_home_detail.xml | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt index 4e429c4bf9..1acbeccc28 100644 --- a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt @@ -22,6 +22,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.activityViewModel @@ -36,6 +37,7 @@ import im.vector.app.core.platform.OnBackPressed import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorMenuProvider +import im.vector.app.core.resources.BuildMeta import im.vector.app.core.resources.ColorProvider import im.vector.app.core.ui.views.CurrentCallsView import im.vector.app.core.ui.views.CurrentCallsViewPresenter @@ -71,6 +73,7 @@ class NewHomeDetailFragment @Inject constructor( private val vectorPreferences: VectorPreferences, private val spaceStateHandler: SpaceStateHandler, private val session: Session, + private val buildMeta: BuildMeta, ) : VectorBaseFragment(), KeysBackupBanner.Delegate, CurrentCallsView.Callback, @@ -125,6 +128,7 @@ class NewHomeDetailFragment @Inject constructor( setupToolbar() setupKeysBackupBanner() setupActiveCallView() + setupDebugButton() withState(viewModel) { // Update the navigation view if needed (for when we restore the tabs) @@ -192,6 +196,7 @@ class NewHomeDetailFragment @Inject constructor( updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab()) callManager.checkForProtocolsSupportIfNeeded() refreshSpaceState() + refreshDebugButtonState() } private fun refreshSpaceState() { @@ -367,6 +372,17 @@ class NewHomeDetailFragment @Inject constructor( } } + private fun setupDebugButton() { + views.debugButton.debouncedClicks { + sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer) + navigator.openDebug(requireActivity()) + } + } + + private fun refreshDebugButtonState() { + views.debugButton.isVisible = buildMeta.isDebug && vectorPreferences.developerMode() + } + /* ========================================================================================== * KeysBackupBanner Listener * ========================================================================================== */ diff --git a/vector/src/main/res/layout/fragment_new_home_detail.xml b/vector/src/main/res/layout/fragment_new_home_detail.xml index 8066ab1bd9..eae8a7ba30 100644 --- a/vector/src/main/res/layout/fragment_new_home_detail.xml +++ b/vector/src/main/res/layout/fragment_new_home_detail.xml @@ -74,6 +74,19 @@ + + From fc76d08186bdf02c80d627f4de602b3d35e1afeb Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 18 Aug 2022 09:22:37 +0200 Subject: [PATCH 2/6] Makes home activity restart if app layout flag change is detected --- .../java/im/vector/app/features/home/HomeActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 12cdaecdf9..16ee0c1958 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -41,6 +41,7 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.replaceFragment +import im.vector.app.core.extensions.restart import im.vector.app.core.extensions.validateBackPressed import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorMenuProvider @@ -136,6 +137,8 @@ class HomeActivity : @Inject lateinit var fcmHelper: FcmHelper @Inject lateinit var nightlyProxy: NightlyProxy + private var isNewAppLayoutEnabled: Boolean = false // delete once old app layout is removed + private val createSpaceResultLauncher = registerStartForActivityResult { activityResult -> if (activityResult.resultCode == Activity.RESULT_OK) { val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data) @@ -193,6 +196,7 @@ class HomeActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + isNewAppLayoutEnabled = vectorFeatures.isNewAppLayoutEnabled() analyticsScreenName = MobileScreen.ScreenName.Home supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false) unifiedPushHelper.register(this) { @@ -556,6 +560,14 @@ class HomeActivity : // Check nightly nightlyProxy.onHomeResumed() + + checkNewAppLayoutFlagChange() + } + + private fun checkNewAppLayoutFlagChange() { + if (buildMeta.isDebug && vectorFeatures.isNewAppLayoutEnabled() != isNewAppLayoutEnabled) { + restart() + } } override fun getMenuRes() = if (vectorFeatures.isNewAppLayoutEnabled()) R.menu.menu_new_home else R.menu.menu_home From 0b8c68739e2148dd744295a02b12c018fa469fe9 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 18 Aug 2022 09:43:29 +0200 Subject: [PATCH 3/6] Makes debug settings refresh state onResume in old app layout --- .../java/im/vector/app/features/home/HomeDrawerFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt index 535f38e68e..c10027cc3f 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDrawerFragment.kt @@ -113,10 +113,14 @@ class HomeDrawerFragment @Inject constructor( } // Debug menu - views.homeDrawerHeaderDebugView.isVisible = buildMeta.isDebug && vectorPreferences.developerMode() views.homeDrawerHeaderDebugView.debouncedClicks { sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer) navigator.openDebug(requireActivity()) } } + + override fun onResume() { + super.onResume() + views.homeDrawerHeaderDebugView.isVisible = buildMeta.isDebug && vectorPreferences.developerMode() + } } From 2e323e6f2e52401176d086b702fae3d188697933 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 18 Aug 2022 10:09:32 +0200 Subject: [PATCH 4/6] Makes debug icon hide when collapsing toolbar --- .../im/vector/app/features/home/NewHomeDetailFragment.kt | 5 +++++ vector/src/main/res/layout/fragment_new_home_detail.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt index 1acbeccc28..760b6d8a4f 100644 --- a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt @@ -28,6 +28,7 @@ import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState +import com.google.android.material.appbar.AppBarLayout import com.google.android.material.badge.BadgeDrawable import im.vector.app.R import im.vector.app.SpaceStateHandler @@ -377,6 +378,10 @@ class NewHomeDetailFragment @Inject constructor( sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer) navigator.openDebug(requireActivity()) } + + views.appBarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> + views.debugButton.isVisible = verticalOffset == 0 + }) } private fun refreshDebugButtonState() { diff --git a/vector/src/main/res/layout/fragment_new_home_detail.xml b/vector/src/main/res/layout/fragment_new_home_detail.xml index eae8a7ba30..d54d799a62 100644 --- a/vector/src/main/res/layout/fragment_new_home_detail.xml +++ b/vector/src/main/res/layout/fragment_new_home_detail.xml @@ -68,8 +68,8 @@ android:id="@+id/avatar" android:layout_width="36dp" android:layout_height="36dp" - android:padding="6dp" android:contentDescription="@string/a11y_open_settings" + android:padding="6dp" tools:src="@sample/user_round_avatars" /> From 136ca4bafbdf24bb4fb6693b14f6c73e51a799fe Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 18 Aug 2022 10:16:54 +0200 Subject: [PATCH 5/6] Adds changelog file --- changelog.d/6871.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6871.feature diff --git a/changelog.d/6871.feature b/changelog.d/6871.feature new file mode 100644 index 0000000000..313be1a602 --- /dev/null +++ b/changelog.d/6871.feature @@ -0,0 +1 @@ +Improves Developer Mode Debug Button UX and adds it to New App Layout From 1bd46e902bacd053b8999276644606c1fbf32cec Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 19 Aug 2022 14:33:10 +0200 Subject: [PATCH 6/6] Fixes documentation lint errors --- vector/src/main/java/im/vector/app/SpaceStateHandler.kt | 2 +- .../im/vector/app/features/settings/VectorPreferences.kt | 8 ++++---- .../app/features/navigation/DefaultNavigatorTest.kt | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/app/SpaceStateHandler.kt b/vector/src/main/java/im/vector/app/SpaceStateHandler.kt index acc2279d1a..39ed9bf4f6 100644 --- a/vector/src/main/java/im/vector/app/SpaceStateHandler.kt +++ b/vector/src/main/java/im/vector/app/SpaceStateHandler.kt @@ -53,7 +53,7 @@ interface SpaceStateHandler : DefaultLifecycleObserver { ) /** - * Gets the Space ID of the space on top of the backstack + * Gets the Space ID of the space on top of the backstack. * * May return null to indicate the All Chats space */ diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 32638f5efc..cefbe64d9d 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -1128,10 +1128,10 @@ class VectorPreferences @Inject constructor( } /** - * Sets the space backstack that is used for up navigation - * This needs to be persisted because navigating up through spaces should work across sessions + * Sets the space backstack that is used for up navigation. + * This needs to be persisted because navigating up through spaces should work across sessions. * - * Only the IDs of the spaces are stored + * Only the IDs of the spaces are stored. */ fun setSpaceBackstack(spaceBackstack: List) { val spaceIdsJoined = spaceBackstack.takeIf { it.isNotEmpty() }?.joinToString(",") @@ -1139,7 +1139,7 @@ class VectorPreferences @Inject constructor( } /** - * Gets the space backstack used for up navigation + * Gets the space backstack used for up navigation. */ fun getSpaceBackstack(): List { val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null) diff --git a/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt index 79c514083c..6301fe1549 100644 --- a/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt @@ -48,8 +48,8 @@ internal class DefaultNavigatorTest { ) /** - * The below tests are by no means all that we want to test in [DefaultNavigator] - * Please add relevant tests as you make changes to or related to other functions in the class + * The below tests are by no means all that we want to test in [DefaultNavigator]. + * Please add relevant tests as you make changes to or related to other functions in the class. */ @Test