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

Debug Icon UX Improvements & Addition in New Layout #6871

Merged
1 change: 1 addition & 0 deletions changelog.d/6871.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improves Developer Mode Debug Button UX and adds it to New App Layout
12 changes: 12 additions & 0 deletions vector/src/main/java/im/vector/app/features/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,6 +139,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (merge without addressing): better reference a line of code or issue, so it will be possible to check this condition. Here it could be an app layout flag


private val createSpaceResultLauncher = registerStartForActivityResult { activityResult ->
if (activityResult.resultCode == Activity.RESULT_OK) {
val spaceId = SpaceCreationActivity.getCreatedSpaceId(activityResult.data)
Expand Down Expand Up @@ -196,6 +199,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) {
Expand Down Expand Up @@ -560,6 +564,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ 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
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
Expand All @@ -35,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
Expand Down Expand Up @@ -69,6 +72,7 @@ class NewHomeDetailFragment @Inject constructor(
private val vectorPreferences: VectorPreferences,
private val spaceStateHandler: SpaceStateHandler,
private val session: Session,
private val buildMeta: BuildMeta,
) : VectorBaseFragment<FragmentNewHomeDetailBinding>(),
KeysBackupBanner.Delegate,
CurrentCallsView.Callback,
Expand Down Expand Up @@ -123,6 +127,7 @@ class NewHomeDetailFragment @Inject constructor(
setupToolbar()
setupKeysBackupBanner()
setupActiveCallView()
setupDebugButton()

withState(viewModel) {
// Update the navigation view if needed (for when we restore the tabs)
Expand Down Expand Up @@ -190,6 +195,7 @@ class NewHomeDetailFragment @Inject constructor(
updateTabVisibilitySafely(R.id.bottom_action_notification, vectorPreferences.labAddNotificationTab())
callManager.checkForProtocolsSupportIfNeeded()
refreshSpaceState()
refreshDebugButtonState()
}

private fun refreshSpaceState() {
Expand Down Expand Up @@ -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
* ========================================================================================== */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,18 +1128,18 @@ 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<String?>) {
val spaceIdsJoined = spaceBackstack.takeIf { it.isNotEmpty() }?.joinToString(",")
defaultPrefs.edit().putString(SETTINGS_PERSISTED_SPACE_BACKSTACK, spaceIdsJoined).apply()
}

/**
* Gets the space backstack used for up navigation
* Gets the space backstack used for up navigation.
*/
fun getSpaceBackstack(): List<String?> {
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)
Expand Down
15 changes: 14 additions & 1 deletion vector/src/main/res/layout/fragment_new_home_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,25 @@
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" />

</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.AppBarLayout>
Expand Down