Merge pull request #6871 from vector-im/feature/eric/new-layout-debug

Debug Icon UX Improvements & Addition in New Layout
This commit is contained in:
Eric Decanini 2022-08-22 14:48:32 +02:00 committed by GitHub
commit 86438cf09c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 6 deletions

1
changelog.d/6871.feature Normal file
View file

@ -0,0 +1 @@
Improves Developer Mode Debug Button UX and adds it to New App Layout

View file

@ -41,6 +41,7 @@ import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.replaceFragment 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.extensions.validateBackPressed
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.platform.VectorMenuProvider import im.vector.app.core.platform.VectorMenuProvider
@ -138,6 +139,8 @@ class HomeActivity :
@Inject lateinit var fcmHelper: FcmHelper @Inject lateinit var fcmHelper: FcmHelper
@Inject lateinit var nightlyProxy: NightlyProxy @Inject lateinit var nightlyProxy: NightlyProxy
private var isNewAppLayoutEnabled: Boolean = false // delete once old app layout is removed
private val createSpaceResultLauncher = registerStartForActivityResult { activityResult -> private val createSpaceResultLauncher = registerStartForActivityResult { activityResult ->
if (activityResult.resultCode == Activity.RESULT_OK) { if (activityResult.resultCode == Activity.RESULT_OK) {
val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data) val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data)
@ -196,6 +199,7 @@ class HomeActivity :
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
isNewAppLayoutEnabled = vectorFeatures.isNewAppLayoutEnabled()
analyticsScreenName = MobileScreen.ScreenName.Home analyticsScreenName = MobileScreen.ScreenName.Home
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false) supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
unifiedPushHelper.register(this) { unifiedPushHelper.register(this) {
@ -560,6 +564,14 @@ class HomeActivity :
// Check nightly // Check nightly
nightlyProxy.onHomeResumed() 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 override fun getMenuRes() = if (vectorFeatures.isNewAppLayoutEnabled()) R.menu.menu_new_home else R.menu.menu_home

View file

@ -113,10 +113,14 @@ class HomeDrawerFragment @Inject constructor(
} }
// Debug menu // Debug menu
views.homeDrawerHeaderDebugView.isVisible = buildMeta.isDebug && vectorPreferences.developerMode()
views.homeDrawerHeaderDebugView.debouncedClicks { views.homeDrawerHeaderDebugView.debouncedClicks {
sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer) sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer)
navigator.openDebug(requireActivity()) navigator.openDebug(requireActivity())
} }
} }
override fun onResume() {
super.onResume()
views.homeDrawerHeaderDebugView.isVisible = buildMeta.isDebug && vectorPreferences.developerMode()
}
} }

View file

@ -22,11 +22,13 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.badge.BadgeDrawable import com.google.android.material.badge.BadgeDrawable
import im.vector.app.R import im.vector.app.R
import im.vector.app.SpaceStateHandler import im.vector.app.SpaceStateHandler
@ -35,6 +37,7 @@ import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider 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.resources.ColorProvider
import im.vector.app.core.ui.views.CurrentCallsView import im.vector.app.core.ui.views.CurrentCallsView
import im.vector.app.core.ui.views.CurrentCallsViewPresenter import im.vector.app.core.ui.views.CurrentCallsViewPresenter
@ -69,6 +72,7 @@ class NewHomeDetailFragment @Inject constructor(
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val spaceStateHandler: SpaceStateHandler, private val spaceStateHandler: SpaceStateHandler,
private val session: Session, private val session: Session,
private val buildMeta: BuildMeta,
) : VectorBaseFragment<FragmentNewHomeDetailBinding>(), ) : VectorBaseFragment<FragmentNewHomeDetailBinding>(),
KeysBackupBanner.Delegate, KeysBackupBanner.Delegate,
CurrentCallsView.Callback, CurrentCallsView.Callback,
@ -123,6 +127,7 @@ class NewHomeDetailFragment @Inject constructor(
setupToolbar() setupToolbar()
setupKeysBackupBanner() setupKeysBackupBanner()
setupActiveCallView() setupActiveCallView()
setupDebugButton()
withState(viewModel) { withState(viewModel) {
// Update the navigation view if needed (for when we restore the tabs) // Update the navigation view if needed (for when we restore the tabs)
@ -190,6 +195,7 @@ class NewHomeDetailFragment @Inject constructor(
updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab()) updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab())
callManager.checkForProtocolsSupportIfNeeded() callManager.checkForProtocolsSupportIfNeeded()
refreshSpaceState() refreshSpaceState()
refreshDebugButtonState()
} }
private fun refreshSpaceState() { private fun refreshSpaceState() {
@ -364,6 +370,21 @@ class NewHomeDetailFragment @Inject constructor(
} }
} }
private fun setupDebugButton() {
views.debugButton.debouncedClicks {
sharedActionViewModel.post(HomeActivitySharedAction.CloseDrawer)
navigator.openDebug(requireActivity())
}
views.appBarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
views.debugButton.isVisible = verticalOffset == 0
})
}
private fun refreshDebugButtonState() {
views.debugButton.isVisible = buildMeta.isDebug && vectorPreferences.developerMode()
}
/* ========================================================================================== /* ==========================================================================================
* KeysBackupBanner Listener * KeysBackupBanner Listener
* ========================================================================================== */ * ========================================================================================== */

View file

@ -1128,10 +1128,10 @@ class VectorPreferences @Inject constructor(
} }
/** /**
* Sets the space backstack that is used for up navigation * Sets the space backstack that is used for up navigation.
* This needs to be persisted because navigating up through spaces should work across sessions * 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<String?>) { fun setSpaceBackstack(spaceBackstack: List<String?>) {
val spaceIdsJoined = spaceBackstack.takeIf { it.isNotEmpty() }?.joinToString(",") 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<String?> { fun getSpaceBackstack(): List<String?> {
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null) val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)

View file

@ -68,12 +68,25 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:padding="6dp"
android:contentDescription="@string/a11y_open_settings" android:contentDescription="@string/a11y_open_settings"
android:padding="6dp"
tools:src="@sample/user_round_avatars" /> tools:src="@sample/user_round_avatars" />
</com.google.android.material.appbar.MaterialToolbar> </com.google.android.material.appbar.MaterialToolbar>
<ImageView
android:id="@+id/debug_button"
style="@style/VectorDebug"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom|end"
android:layout_marginStart="12dp"
android:importantForAccessibility="no"
android:scaleType="center"
android:src="@drawable/ic_settings_x"
app:tint="?colorPrimary"
tools:ignore="MissingPrefix" />
</com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>