Skip to content

Commit

Permalink
Merge pull request #1987 from PaulWoitaschek/onboarding
Browse files Browse the repository at this point in the history
Add an Onboarding
  • Loading branch information
PaulWoitaschek authored Jun 12, 2023
2 parents 6fe92b0 + 3abcb60 commit 1927cdc
Show file tree
Hide file tree
Showing 48 changed files with 1,344 additions and 307 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ dependencies {
implementation(projects.search)
implementation(projects.cover)
implementation(projects.documentfile)
implementation(projects.onboarding)

implementation(libs.appCompat)
implementation(libs.recyclerView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import voice.bookOverview.views.BookOverviewPreview
import voice.common.BookId
import voice.common.compose.ImmutableFile
import voice.common.formatTime
import voice.folderPicker.folderPicker.FolderPickerPreview
import voice.folderPicker.folderPicker.FolderOverviewPreview
import voice.logging.core.Logger
import voice.settings.views.Settings
import java.io.File
Expand Down Expand Up @@ -144,7 +144,7 @@ class ScreenshotCapture {
)
},
Screenshot("settings") { Settings() },
Screenshot("folder_picker") { FolderPickerPreview() },
Screenshot("folder_picker") { FolderOverviewPreview() },
)
}

Expand Down
66 changes: 47 additions & 19 deletions app/src/main/kotlin/voice/app/AppController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ package voice.app

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.datastore.core.DataStore
import dev.olshevski.navigation.reimagined.AnimatedNavHost
import dev.olshevski.navigation.reimagined.NavBackHandler
import dev.olshevski.navigation.reimagined.NavController
import dev.olshevski.navigation.reimagined.navigate
import dev.olshevski.navigation.reimagined.pop
import dev.olshevski.navigation.reimagined.rememberNavController
import dev.olshevski.navigation.reimagined.replaceLast
import voice.app.injection.appComponent
import voice.bookOverview.views.BookOverviewScreen
import voice.common.BookId
import voice.common.compose.ComposeController
import voice.common.navigation.Destination
import voice.common.navigation.NavigationCommand
import voice.common.navigation.Navigator
import voice.common.pref.CurrentBook
import voice.cover.SelectCoverFromInternet
import voice.folderPicker.folderPicker.FolderPicker
import voice.folderPicker.addcontent.AddContent
import voice.folderPicker.folderPicker.FolderOverview
import voice.folderPicker.selectType.SelectFolderType
import voice.migration.views.Migration
import voice.onboarding.OnboardingExplanation
import voice.onboarding.OnboardingWelcome
import voice.onboarding.completion.OnboardingCompletion
import voice.settings.views.Settings
import javax.inject.Inject

Expand All @@ -29,33 +32,30 @@ class AppController : ComposeController() {
appComponent.inject(this)
}

@field:[
Inject
CurrentBook
]
lateinit var currentBookIdPref: DataStore<BookId?>
@Inject
lateinit var startDestinationProvider: StartDestinationProvider

@Inject
lateinit var navigator: Navigator

@Composable
override fun Content() {
val navController = rememberNavController<Destination.Compose>(
startDestination = Destination.BookOverview,
val navController: NavController<Destination.Compose> = rememberNavController(
startDestination = startDestinationProvider(),
)
NavBackHandler(navController)
AnimatedNavHost(
navController,
transitionSpec = { action, _, _ ->
navTransition(action)
transitionSpec = { action, destination, _ ->
navTransition(action, destination)
},
) { screen ->
when (screen) {
) { destination ->
when (destination) {
Destination.BookOverview -> {
BookOverviewScreen()
}
Destination.FolderPicker -> {
FolderPicker(
FolderOverview(
onCloseClick = {
navController.pop()
},
Expand All @@ -65,17 +65,38 @@ class AppController : ComposeController() {
Migration()
}
is Destination.SelectFolderType -> {
SelectFolderType(uri = screen.uri)
SelectFolderType(
uri = destination.uri,
mode = destination.mode,
)
}
Destination.Settings -> {
Settings()
}
is Destination.CoverFromInternet -> {
SelectCoverFromInternet(
bookId = screen.bookId,
bookId = destination.bookId,
onCloseClick = { navController.pop() },
)
}
is Destination.AddContent -> AddContent(destination.mode)

Destination.OnboardingCompletion -> OnboardingCompletion()
Destination.OnboardingExplanation -> OnboardingExplanation(
onNext = {
navController.navigate(
Destination.AddContent(
mode = Destination.AddContent.Mode.Onboarding,
),
)
},
onBack = {
navController.pop()
},
)
Destination.OnboardingWelcome -> OnboardingWelcome(
onNext = { navController.navigate(Destination.OnboardingExplanation) },
)
}
}

Expand All @@ -85,7 +106,11 @@ class AppController : ComposeController() {
is NavigationCommand.GoTo -> {
when (val destination = command.destination) {
is Destination.Compose -> {
navController.navigate(destination)
if (command.replace) {
navController.replaceLast(destination)
} else {
navController.navigate(destination)
}
}
else -> {
// no-op
Expand All @@ -95,6 +120,9 @@ class AppController : ComposeController() {
NavigationCommand.GoBack -> {
navController.pop()
}
is NavigationCommand.Execute -> {
command.action(navController)
}
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/kotlin/voice/app/NavTransition.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package voice.app

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.with
import dev.olshevski.navigation.reimagined.NavAction
import voice.common.navigation.Destination

internal fun navTransition(action: NavAction) = when (action) {
internal fun navTransition(action: NavAction, destination: Destination.Compose) = when (action) {
NavAction.Navigate -> {
fadeIn(tween(700))
.plus(slideInHorizontally { it / 2 })
.with(fadeOut())
val enter = if (destination is Destination.AddContent) {
// we come from the system activity, don't show a transition here
EnterTransition.None
} else {
fadeIn(tween(700))
.plus(slideInHorizontally { it / 2 })
}
val exit = fadeOut()
enter with exit
}
NavAction.Pop -> {
fadeIn(tween(700))
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/kotlin/voice/app/StartDestinationProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package voice.app

import androidx.datastore.core.DataStore
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import voice.common.navigation.Destination
import voice.common.pref.OnboardingCompleted
import voice.data.folders.AudiobookFolders
import javax.inject.Inject

class StartDestinationProvider
@Inject constructor(
@OnboardingCompleted
private val onboardingCompleted: DataStore<Boolean>,
private val audiobookFolders: AudiobookFolders,
) {

operator fun invoke(): Destination.Compose {
return runBlocking {
if (showOnboarding()) {
Destination.OnboardingWelcome
} else {
Destination.BookOverview
}
}
}

private suspend fun showOnboarding(): Boolean {
return when {
onboardingCompleted.data.first() -> false
audiobookFolders.hasAnyFolders() -> false
else -> true
}
}
}
11 changes: 7 additions & 4 deletions app/src/main/kotlin/voice/app/features/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
import androidx.datastore.core.DataStore
import androidx.lifecycle.lifecycleScope
import com.bluelinelabs.conductor.ChangeHandlerFrameLayout
import com.bluelinelabs.conductor.Conductor
import com.bluelinelabs.conductor.Router
import com.bluelinelabs.conductor.RouterTransaction
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import voice.app.AppController
import voice.app.databinding.ActivityBookBinding
import voice.app.features.bookOverview.EditCoverDialogController
import voice.app.features.bookmarks.BookmarkController
import voice.app.injection.appComponent
Expand Down Expand Up @@ -57,10 +57,10 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
appComponent.inject(this)
super.onCreate(savedInstanceState)
val binding = ActivityBookBinding.inflate(layoutInflater)
setContentView(binding.root)
val root = ChangeHandlerFrameLayout(this)
setContentView(root)

router = Conductor.attachRouter(this, binding.root, savedInstanceState)
router = Conductor.attachRouter(this, root, savedInstanceState)
.setOnBackPressedDispatcherEnabled(true)
.setPopRootControllerMode(Router.PopRootControllerMode.NEVER)
if (!router.hasRootController()) {
Expand Down Expand Up @@ -106,6 +106,9 @@ class MainActivity : AppCompatActivity() {
}
}
}
is NavigationCommand.Execute -> {
// handled in AppController
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/kotlin/voice/app/injection/PrefsModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import voice.common.BookId
import voice.common.grid.GridMode
import voice.common.pref.AuthorAudiobookFolders
import voice.common.pref.CurrentBook
import voice.common.pref.OnboardingCompleted
import voice.common.pref.PrefKeys
import voice.common.pref.RootAudiobookFolders
import voice.common.pref.SingleFileAudiobookFolders
Expand Down Expand Up @@ -98,6 +99,13 @@ object PrefsModule {
return prefs.enum(PrefKeys.GRID_MODE, GridMode.FOLLOW_DEVICE)
}

@Provides
@Singleton
@OnboardingCompleted
fun onboardingCompleted(factory: VoiceDataStoreFactory): DataStore<Boolean> {
return factory.boolean("onboardingCompleted", defaultValue = false)
}

@Provides
@Singleton
@RootAudiobookFolders
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/activity_book.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import androidx.compose.material3.ListItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import voice.bookOverview.overview.BookOverviewLayoutMode
import voice.bookOverview.views.GridBook
import voice.bookOverview.views.ListBookRow
import voice.bookOverview.views.gridColumnCount
import voice.common.BookId
import voice.common.compose.plus
import voice.strings.R as StringsR

@Composable
internal fun BookSearchContent(
Expand All @@ -47,7 +49,7 @@ internal fun BookSearchContent(
leadingContent = {
Icon(
imageVector = Icons.Outlined.History,
contentDescription = null,
contentDescription = stringResource(id = StringsR.string.cover_search_icon_recent),
)
},
)
Expand All @@ -59,7 +61,7 @@ internal fun BookSearchContent(
leadingContent = {
Icon(
imageVector = Icons.Outlined.SentimentSatisfied,
contentDescription = null,
contentDescription = stringResource(id = StringsR.string.cover_search_author),
)
},
)
Expand Down
28 changes: 0 additions & 28 deletions common/src/main/kotlin/voice/common/Combine.kt

This file was deleted.

Loading

0 comments on commit 1927cdc

Please sign in to comment.