Skip to content

Commit

Permalink
Open tools tab one time after start (#978)
Browse files Browse the repository at this point in the history
**Background**

To show users new infrared-remotes feature we should navigate them
somehow into tools tab. This pr changes some proto settings so Tools tab
will be the first after app is intalled/open after update

**Changes**

- Change proto files to open tools tab first

**Test plan**

- Open non-updated app on not-tools tab
- Update up
- Open app and see you are on tools tab
- Reinstall app, and see the first tab is now tools
  • Loading branch information
makeevrserg authored Oct 28, 2024
1 parent e0a2a5b commit 5c36520
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Attention: don't forget to add the flag for F-Droid before release
- [Feature] New File Manager search
- [Feature] Add illustrations, search, hold to dispatch into RemoteControls
- [Feature] Add metrics to infrared remotes
- [Feature] One-time open tools tab
- [Refactor] Load RemoteControls from flipper, emulating animation
- [Refactor] Update to Kotlin 2.0
- [Refactor] Replace Ktorfit with Ktor requests in remote-controls
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("Filename")

import org.gradle.api.Project

fun Project.includeCommonKspConfigurationTo(
Expand All @@ -9,4 +11,4 @@ fun Project.includeCommonKspConfigurationTo(
configurations.getByName(configurationName).extendsFrom(commonKsp)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ configure<SentryPluginExtension> {
autoInstallation.enabled.set(false)
}

includeCommonKspConfigurationTo("ksp")
includeCommonKspConfigurationTo("ksp")
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ configure<BaseExtension> {
commonAndroid(project)
}

includeCommonKspConfigurationTo("ksp")
includeCommonKspConfigurationTo("ksp")
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ kotlin {
}
}

includeCommonKspConfigurationTo("kspAndroid", "kspDesktop")
includeCommonKspConfigurationTo("kspAndroid", "kspDesktop")
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.arkivanov.decompose.router.stack.bringToFront
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.value.Value
import com.arkivanov.essenty.backhandler.BackCallback
import com.arkivanov.essenty.instancekeeper.getOrCreate
import com.flipperdevices.archive.api.ArchiveDecomposeComponent
import com.flipperdevices.bottombar.api.BottomBarDecomposeComponent
import com.flipperdevices.bottombar.handlers.ResetTabDecomposeHandler
Expand All @@ -24,6 +25,7 @@ import com.flipperdevices.bottombar.impl.model.toBottomBarTabEnum
import com.flipperdevices.bottombar.impl.model.toConfig
import com.flipperdevices.bottombar.impl.viewmodel.BottomBarViewModel
import com.flipperdevices.bottombar.impl.viewmodel.InAppNotificationViewModel
import com.flipperdevices.bottombar.impl.viewmodel.SelectedTabViewModel
import com.flipperdevices.connection.api.ConnectionApi
import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.preference.pb.Settings
Expand Down Expand Up @@ -63,13 +65,22 @@ class BottomBarDecomposeComponentImpl @AssistedInject constructor(
private val unhandledExceptionRendererApi: UnhandledExceptionRenderApi,
private val appNotificationApi: FlipperAppNotificationDialogApi,
private val bottomBarViewModelProvider: Provider<BottomBarViewModel>,
private val selectedTabViewModelProvider: Provider<SelectedTabViewModel>,
private val inAppNotificationViewModelFactory: InAppNotificationViewModel.Factory
) : BottomBarDecomposeComponent<BottomBarTabConfig>(), ComponentContext by componentContext {

override val stack: Value<ChildStack<BottomBarTabConfig, DecomposeComponent>> =
childStack(
source = navigation,
serializer = BottomBarTabConfig.serializer(),
initialConfiguration = BottomBarTabConfig.getInitialConfig(settingsDataStore, deeplink),
initialConfiguration = BottomBarTabConfig.getInitialConfig(
getSavedTab = {
instanceKeeper.getOrCreate("bbdc_st_vm") {
selectedTabViewModelProvider.get()
}.getSelectedTab()
},
deeplink = deeplink
),
childFactory = ::child,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.flipperdevices.bottombar.impl.model

import androidx.datastore.core.DataStore
import com.flipperdevices.core.preference.pb.SelectedTab
import com.flipperdevices.core.preference.pb.Settings
import com.flipperdevices.deeplink.model.Deeplink
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable

@Serializable
Expand Down Expand Up @@ -42,7 +37,7 @@ sealed interface BottomBarTabConfig {

companion object {
fun getInitialConfig(
dataStore: DataStore<Settings>,
getSavedTab: () -> BottomBarTabConfig,
deeplink: Deeplink.BottomBar?
): BottomBarTabConfig {
if (deeplink != null) {
Expand All @@ -55,16 +50,7 @@ sealed interface BottomBarTabConfig {
.toConfig()
}
}
return runBlocking {
when (dataStore.data.first().selected_tab) {
SelectedTab.DEVICE,
is SelectedTab.Unrecognized -> Device(null)

SelectedTab.ARCHIVE -> Archive(null)
SelectedTab.APPS -> Apps(null)
SelectedTab.TOOLS -> Tools(null)
}
}
return getSavedTab.invoke()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.flipperdevices.bottombar.impl.viewmodel

import androidx.datastore.core.DataStore
import com.flipperdevices.bottombar.impl.model.BottomBarTabConfig
import com.flipperdevices.bottombar.impl.model.BottomBarTabConfig.Apps
import com.flipperdevices.bottombar.impl.model.BottomBarTabConfig.Archive
import com.flipperdevices.bottombar.impl.model.BottomBarTabConfig.Device
import com.flipperdevices.bottombar.impl.model.BottomBarTabConfig.Tools
import com.flipperdevices.core.preference.pb.SelectedTab
import com.flipperdevices.core.preference.pb.Settings
import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

/**
* Needs to promote infrared remotes feature
* On first update (not first launch) will return tools tab only one time
*/
class SelectedTabViewModel @Inject constructor(
private val settingsDataStore: DataStore<Settings>,
) : DecomposeViewModel() {

private fun toConfig(selectedTab: SelectedTab): BottomBarTabConfig {
return when (selectedTab) {
SelectedTab.DEVICE,
is SelectedTab.Unrecognized -> Device(null)

SelectedTab.ARCHIVE -> Archive(null)
SelectedTab.APPS -> Apps(null)
SelectedTab.TOOLS -> Tools(null)
}
}

private fun setRemoteFeaturePromoted() {
viewModelScope.launch {
settingsDataStore.updateData { it.copy(infrared_remotes_tab_shown = true) }
}
}

fun getSelectedTab(): BottomBarTabConfig {
val settings = runBlocking { settingsDataStore.data.first() }
if (settings.infrared_remotes_tab_shown) {
return toConfig(settings.selected_tab)
}
// wasStartDialogShown indicates that flipper was already connected at least one time
val wasStartDialogShown = settings.notification_dialog_shown
if (!wasStartDialogShown) {
setRemoteFeaturePromoted()
return toConfig(settings.selected_tab)
}
setRemoteFeaturePromoted()
return Tools(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ message Settings {
FileManagerSort file_manager_sort = 31;
bool show_hidden_files_on_flipper = 32;
bool disabled_vibration = 33;
bool infrared_remotes_tab_shown = 34;
}

0 comments on commit 5c36520

Please sign in to comment.