-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open tools tab one time after start (#978)
**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
1 parent
e0a2a5b
commit 5c36520
Showing
9 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ar/impl/src/main/java/com/flipperdevices/bottombar/impl/viewmodel/SelectedTabViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters