-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Decompose FileManager (#745)
**Background** Right now we have a lot of bugs for navigation **Changes** - Migrate file manager component to decompose **Test plan** Try open filemanager
- Loading branch information
Showing
33 changed files
with
531 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Changelog | ||
|
||
# 1.6.8 - In progress | ||
|
||
- [Refactor] Migrate file manager to decompose | ||
|
||
# 1.6.7 | ||
|
||
|
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 @@ | ||
/build |
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,11 @@ | ||
plugins { | ||
id("flipper.android-compose") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.ui.decompose" | ||
|
||
dependencies { | ||
implementation(libs.compose.ui) | ||
implementation(libs.compose.foundation) | ||
implementation(libs.lifecycle.viewmodel.ktx) | ||
} |
8 changes: 8 additions & 0 deletions
8
...nts/core/ui/decompose/src/main/java/com/flipperdevices/ui/decompose/DecomposeComponent.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,8 @@ | ||
package com.flipperdevices.ui.decompose | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
interface DecomposeComponent { | ||
@Composable | ||
fun Render() | ||
} |
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
22 changes: 22 additions & 0 deletions
22
components/core/ui/ktx/src/main/java/com/flipperdevices/core/ui/ktx/ViewModelKtx.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,22 @@ | ||
package com.flipperdevices.core.ui.ktx | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
|
||
@Composable | ||
inline fun <reified VM : ViewModel> viewModelWithFactory( | ||
key: String, | ||
crossinline factory: () -> VM | ||
): VM { | ||
return viewModel( | ||
key = key, | ||
factory = object : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
@Suppress("UNCHECKED_CAST") | ||
return factory() as T | ||
} | ||
} | ||
) | ||
} |
8 changes: 3 additions & 5 deletions
8
...nager/api/src/main/java/com/flipperdevices/filemanager/api/navigation/FileManagerEntry.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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package com.flipperdevices.filemanager.api.navigation | ||
|
||
import com.flipperdevices.core.ui.navigation.AggregateFeatureEntry | ||
import com.flipperdevices.core.ui.navigation.ComposableFeatureEntry | ||
import com.flipperdevices.core.ui.navigation.FeatureScreenRootRoute | ||
|
||
private const val DEFAULT_PATH = "/" | ||
|
||
interface FileManagerEntry : AggregateFeatureEntry { | ||
interface FileManagerEntry : ComposableFeatureEntry { | ||
override val ROUTE: FeatureScreenRootRoute | ||
get() = FeatureScreenRootRoute.FILE_MANAGER | ||
|
||
fun fileManagerDestination(path: String = DEFAULT_PATH): String | ||
fun fileManagerDestination(): String | ||
} |
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
22 changes: 0 additions & 22 deletions
22
...manager/impl/src/main/java/com/flipperdevices/filemanager/impl/api/DeeplinkContentType.kt
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...pl/src/main/java/com/flipperdevices/filemanager/impl/api/FileManagerDecomposeComponent.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,78 @@ | ||
package com.flipperdevices.filemanager.impl.api | ||
|
||
import com.arkivanov.decompose.ComponentContext | ||
import com.arkivanov.decompose.router.stack.ChildStack | ||
import com.arkivanov.decompose.router.stack.StackNavigation | ||
import com.arkivanov.decompose.router.stack.childStack | ||
import com.arkivanov.decompose.value.Value | ||
import com.flipperdevices.core.di.AppGraph | ||
import com.flipperdevices.filemanager.impl.model.FileManagerNavigationConfig | ||
import com.flipperdevices.ui.decompose.DecomposeComponent | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
interface FileManagerDecomposeComponent { | ||
val stack: Value<ChildStack<*, DecomposeComponent>> | ||
|
||
fun interface Factory { | ||
operator fun invoke( | ||
componentContext: ComponentContext, | ||
): FileManagerDecomposeComponent | ||
} | ||
} | ||
|
||
class FileManagerDecomposeComponentImpl @AssistedInject constructor( | ||
@Assisted componentContext: ComponentContext, | ||
private val fileManagerListingFactory: FileManagerListingComponent.Factory, | ||
private val fileManagerUploadingFactory: FileManagerUploadingComponent.Factory, | ||
private val fileManagerEditingFactory: FileManagerEditingComponent.Factory, | ||
private val fileManagerDownloadFactory: FileManagerDownloadComponent.Factory | ||
) : FileManagerDecomposeComponent, ComponentContext by componentContext { | ||
private val navigation = StackNavigation<FileManagerNavigationConfig>() | ||
|
||
override val stack: Value<ChildStack<*, DecomposeComponent>> = childStack( | ||
source = navigation, | ||
serializer = FileManagerNavigationConfig.serializer(), | ||
initialConfiguration = FileManagerNavigationConfig.Screen("/"), | ||
handleBackButton = true, | ||
childFactory = ::child, | ||
) | ||
|
||
private fun child( | ||
config: FileManagerNavigationConfig, | ||
componentContext: ComponentContext | ||
): DecomposeComponent = when (config) { | ||
is FileManagerNavigationConfig.Screen -> fileManagerListingFactory( | ||
componentContext, | ||
config, | ||
navigation | ||
) | ||
|
||
is FileManagerNavigationConfig.Uploading -> fileManagerUploadingFactory( | ||
componentContext, | ||
config, | ||
navigation | ||
) | ||
|
||
is FileManagerNavigationConfig.Editing -> fileManagerEditingFactory( | ||
componentContext, | ||
config, | ||
navigation | ||
) | ||
is FileManagerNavigationConfig.Download -> fileManagerDownloadFactory( | ||
componentContext, | ||
config, | ||
navigation | ||
) | ||
} | ||
|
||
@AssistedFactory | ||
@ContributesBinding(AppGraph::class, FileManagerDecomposeComponent.Factory::class) | ||
interface Factory : FileManagerDecomposeComponent.Factory { | ||
override operator fun invoke( | ||
componentContext: ComponentContext, | ||
): FileManagerDecomposeComponentImpl | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...mpl/src/main/java/com/flipperdevices/filemanager/impl/api/FileManagerDownloadComponent.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,53 @@ | ||
package com.flipperdevices.filemanager.impl.api | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import com.arkivanov.decompose.ComponentContext | ||
import com.arkivanov.decompose.router.stack.StackNavigation | ||
import com.arkivanov.decompose.router.stack.pop | ||
import com.flipperdevices.core.ui.ktx.viewModelWithFactory | ||
import com.flipperdevices.filemanager.impl.composable.ComposableFileManagerDownloadScreen | ||
import com.flipperdevices.filemanager.impl.model.FileManagerNavigationConfig | ||
import com.flipperdevices.filemanager.impl.viewmodels.FileManagerViewModel | ||
import com.flipperdevices.filemanager.impl.viewmodels.ShareViewModel | ||
import com.flipperdevices.ui.decompose.DecomposeComponent | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
class FileManagerDownloadComponent @AssistedInject constructor( | ||
private val fileManagerViewModelFactory: FileManagerViewModel.Factory, | ||
private val shareModelFactory: ShareViewModel.Factory, | ||
@Assisted componentContext: ComponentContext, | ||
@Assisted val config: FileManagerNavigationConfig.Download, | ||
@Assisted val navigation: StackNavigation<FileManagerNavigationConfig> | ||
) : DecomposeComponent, | ||
ComponentContext by componentContext { | ||
@Composable | ||
@Suppress("NonSkippableComposable") | ||
override fun Render() { | ||
val fileManagerViewModel = viewModelWithFactory(key = config.path) { | ||
fileManagerViewModelFactory(config.path) | ||
} | ||
val shareViewModel = viewModelWithFactory(key = config.shareFile.toString()) { | ||
shareModelFactory(config.shareFile) | ||
} | ||
val fileManagerState by fileManagerViewModel.getFileManagerState().collectAsState() | ||
val shareState by shareViewModel.getShareState().collectAsState() | ||
ComposableFileManagerDownloadScreen( | ||
fileManagerState = fileManagerState, | ||
shareState = shareState, | ||
onBack = navigation::pop | ||
) | ||
} | ||
|
||
@AssistedFactory | ||
fun interface Factory { | ||
operator fun invoke( | ||
componentContext: ComponentContext, | ||
config: FileManagerNavigationConfig.Download, | ||
navigation: StackNavigation<FileManagerNavigationConfig> | ||
): FileManagerDownloadComponent | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...impl/src/main/java/com/flipperdevices/filemanager/impl/api/FileManagerEditingComponent.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,47 @@ | ||
package com.flipperdevices.filemanager.impl.api | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import com.arkivanov.decompose.ComponentContext | ||
import com.arkivanov.decompose.router.stack.StackNavigation | ||
import com.arkivanov.decompose.router.stack.pop | ||
import com.flipperdevices.core.ui.ktx.viewModelWithFactory | ||
import com.flipperdevices.filemanager.impl.composable.ComposableFileManagerEditorScreen | ||
import com.flipperdevices.filemanager.impl.model.FileManagerNavigationConfig | ||
import com.flipperdevices.filemanager.impl.viewmodels.EditorViewModel | ||
import com.flipperdevices.ui.decompose.DecomposeComponent | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
class FileManagerEditingComponent @AssistedInject constructor( | ||
private val editorViewModelFactory: EditorViewModel.Factory, | ||
@Assisted componentContext: ComponentContext, | ||
@Assisted val config: FileManagerNavigationConfig.Editing, | ||
@Assisted val navigation: StackNavigation<FileManagerNavigationConfig> | ||
) : DecomposeComponent, | ||
ComponentContext by componentContext { | ||
@Composable | ||
@Suppress("NonSkippableComposable") | ||
override fun Render() { | ||
val editorViewModel = viewModelWithFactory(key = config.shareFile.toString()) { | ||
editorViewModelFactory(config.shareFile) | ||
} | ||
val editorState by editorViewModel.getEditorState().collectAsState() | ||
ComposableFileManagerEditorScreen( | ||
editorState = editorState, | ||
onClickSaveButton = editorViewModel::onSaveFile, | ||
onBack = navigation::pop | ||
) | ||
} | ||
|
||
@AssistedFactory | ||
fun interface Factory { | ||
operator fun invoke( | ||
componentContext: ComponentContext, | ||
config: FileManagerNavigationConfig.Editing, | ||
navigation: StackNavigation<FileManagerNavigationConfig> | ||
): FileManagerEditingComponent | ||
} | ||
} |
Oops, something went wrong.