Skip to content

Commit

Permalink
Move more filemngr modules to mpp (#976)
Browse files Browse the repository at this point in the history
**Background**

Some modules of new file manager can be moved to multiplatform, so
here's this transition

**Changes**

- Move all filemngr modules to MPP (except upload - it depends on
deeplinks)
- Move coil to MPP with coil3 & ktor3 for server-image loading

**Test plan**

- See CI is ok
- Open flipper app and see images loading
- Open new file manager see it's working

---------

Co-authored-by: Nikita Kulikov <[email protected]>
  • Loading branch information
makeevrserg and LionZXY authored Oct 28, 2024
1 parent 1e2564a commit 18a6549
Show file tree
Hide file tree
Showing 137 changed files with 1,090 additions and 572 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Attention: don't forget to add the flag for F-Droid before release
- [Refactor] Migrate filemanager to new ble api
- [Refactor] Migrate more core:ui modules into multiplatform
- [FIX] Small UI fixes for mfkey32 feature
- [Refactor] Migrate filemengr modules into MPP
- [FIX] Distinct fap items by id in paging sources
- [FIX] Battery level charge
- [FIX] Button arrow tint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.flipperdevices.archive.model.CategoryType
import com.flipperdevices.bridge.dao.api.delegates.key.DeleteKeyApi
import com.flipperdevices.bridge.dao.api.delegates.key.SimpleKeyApi
import com.flipperdevices.bridge.dao.api.model.FlipperKeyType
import com.flipperdevices.bridge.dao.api.model.icon
import com.flipperdevices.bridge.dao.api.model.iconId
import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
Expand All @@ -19,7 +19,6 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import java.util.TreeMap
import javax.inject.Inject

Expand All @@ -32,7 +31,7 @@ class CategoryViewModel @Inject constructor(

private val categoriesMapFlow = MutableStateFlow<Map<FlipperKeyType, CategoryItem>>(
FlipperKeyType.entries.map {
it to CategoryItem(it.icon, it.humanReadableName, null, CategoryType.ByFileType(it))
it to CategoryItem(it.iconId, it.humanReadableName, null, CategoryType.ByFileType(it))
}.toMap(TreeMap())
)
private val categoriesFlow = MutableStateFlow<PersistentList<CategoryItem>>(persistentListOf())
Expand Down Expand Up @@ -70,7 +69,7 @@ class CategoryViewModel @Inject constructor(
categoriesMapFlow.update {
val mutableMap = TreeMap(it)
mutableMap[fileType] = CategoryItem(
fileType.icon,
fileType.iconId,
fileType.humanReadableName,
keys.size,
categoryType = CategoryType.ByFileType(fileType)
Expand Down
5 changes: 1 addition & 4 deletions components/bridge/dao/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ compose.resources {
commonDependencies {
implementation(projects.components.core.kmpparcelize)
implementation(projects.components.core.ui.theme)
implementation(projects.components.core.ui.res)
implementation(projects.components.core.ktx)

implementation(libs.kotlin.coroutines)
implementation(libs.kotlin.serialization.json)
implementation(libs.kotlin.immutable.collections)
}

androidDependencies {
implementation(projects.components.core.ui.res)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.flipperdevices.bridge.dao.api.model

import androidx.annotation.DrawableRes
import com.flipperdevices.core.ui.res.R as DesignSystem

val FlipperKeyType.icon: Int
val FlipperKeyType.iconId: Int
@DrawableRes
get() = when (this) {
FlipperKeyType.SUB_GHZ -> DesignSystem.drawable.ic_fileformat_sub
FlipperKeyType.RFID -> DesignSystem.drawable.ic_fileformat_rf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.flipperdevices.bridge.dao.api.model

import flipperapp.components.core.ui.res.generated.resources.ic_fileformat_ibutton
import flipperapp.components.core.ui.res.generated.resources.ic_fileformat_ir
import flipperapp.components.core.ui.res.generated.resources.ic_fileformat_nfc
import flipperapp.components.core.ui.res.generated.resources.ic_fileformat_rf
import flipperapp.components.core.ui.res.generated.resources.ic_fileformat_sub
import org.jetbrains.compose.resources.DrawableResource
import flipperapp.components.core.ui.res.generated.resources.Res as DesignSystem

val FlipperKeyType.iconResource: DrawableResource
get() = when (this) {
FlipperKeyType.SUB_GHZ -> DesignSystem.drawable.ic_fileformat_sub
FlipperKeyType.RFID -> DesignSystem.drawable.ic_fileformat_rf
FlipperKeyType.NFC -> DesignSystem.drawable.ic_fileformat_nfc
FlipperKeyType.INFRARED -> DesignSystem.drawable.ic_fileformat_ir
FlipperKeyType.I_BUTTON -> DesignSystem.drawable.ic_fileformat_ibutton
}
8 changes: 5 additions & 3 deletions components/core/ui/ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ android.namespace = "com.flipperdevices.core.ui.ktx"
commonDependencies {
implementation(projects.components.bridge.dao.api)
implementation(projects.components.core.ui.theme)
implementation(projects.components.core.ui.res)

// Compose
implementation(libs.lifecycle.viewmodel.ktx)
implementation(libs.lifecycle.compose)
implementation(libs.compose.placeholder)

implementation(libs.coil.compose)
implementation(libs.coil.svg)
implementation(libs.coil.network)

implementation(libs.decompose)
}

androidDependencies {
implementation(projects.components.core.ui.res)
implementation(libs.image.lottie)
implementation(libs.coil.compose)
implementation(libs.coil.svg)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.flipperdevices.core.ui.ktx

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.flipperdevices.core.ui.theme.FlipperThemeInternal
import com.flipperdevices.core.ui.theme.LocalPalletV2

@Composable
fun OrangeAppBar(
@StringRes titleId: Int,
modifier: Modifier = Modifier,
onBack: (() -> Unit)? = null,
endBlock: (@Composable (Modifier) -> Unit)? = null
) {
OrangeAppBar(
modifier = modifier,
title = stringResource(titleId),
onBack = onBack,
endBlock = endBlock
)
}

@Composable
fun OrangeAppBarWithIcon(
@StringRes titleId: Int,
@DrawableRes endIconId: Int,
onBack: (() -> Unit)? = null,
onEndClick: () -> Unit
) {
OrangeAppBarWithIcon(
title = stringResource(titleId),
onBack = onBack,
endIconId = endIconId,
onEndClick = onEndClick
)
}

@Composable
fun OrangeAppBarWithIcon(
title: String,
@DrawableRes endIconId: Int,
modifier: Modifier = Modifier,
onBack: (() -> Unit)? = null,
onEndClick: () -> Unit
) {
OrangeAppBarWithIcon(
title = title,
endIconPainter = painterResource(endIconId),
modifier = modifier,
onBack = onBack,
onEndClick = onEndClick
)
}

@Preview
@Composable
private fun OrangeAppBarPreview() {
FlipperThemeInternal {
OrangeAppBar(
title = "Screenname",
onBack = {}
)
}
}

@Preview
@Composable
private fun OrangeAppBarEndBlockPreview() {
FlipperThemeInternal {
OrangeAppBar(
title = "Screenname",
onBack = {},
endBlock = {
Icon(
modifier = Modifier
.padding(end = 14.dp)
.size(24.dp),
painter = rememberVectorPainter(Icons.Filled.Settings),
contentDescription = null,
tint = LocalPalletV2.current.icon.blackAndWhite.default
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.flipperdevices.bridge.dao.api.model.FlipperKeyType
import com.flipperdevices.bridge.dao.api.model.FlipperKeyType.Companion.colorByFlipperKeyType
import com.flipperdevices.bridge.dao.api.model.icon
import com.flipperdevices.bridge.dao.api.model.iconId
import com.flipperdevices.core.ui.ktx.R
import com.flipperdevices.core.ui.ktx.placeholderByLocalProvider
import com.flipperdevices.core.ui.theme.FlipperThemeInternal
Expand All @@ -35,7 +35,7 @@ fun ComposableKeyType(
colorKey: Color = colorByFlipperKeyType(type),
minWidth: Dp? = 110.dp
) {
val icon = type?.icon ?: DesignSystem.drawable.ic_fileformat_unknown
val icon = type?.iconId ?: DesignSystem.drawable.ic_fileformat_unknown
val title = type?.humanReadableName
?: stringResource(R.string.ktx_fileformat_unknown)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import coil.compose.AsyncImage
import coil.compose.AsyncImagePainter
import coil.request.CachePolicy
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.compose.AsyncImagePainter
import coil3.request.CachePolicy
import coil3.request.ImageRequest
import coil3.request.transformations

@Composable
fun FlipperAsyncImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.flipperdevices.core.ui.ktx.image

import android.graphics.Bitmap
import android.graphics.Color
import coil.size.Size
import coil.transform.Transformation
import coil3.size.Size
import coil3.transform.Transformation

class WhiteToAlphaTransformation : Transformation {
class WhiteToAlphaTransformation : Transformation() {
override val cacheKey: String = javaClass.name

override suspend fun transform(input: Bitmap, size: Size): Bitmap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.flipperdevices.core.ui.ktx

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
Expand All @@ -13,22 +11,17 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.flipperdevices.core.ui.theme.FlipperThemeInternal
import com.flipperdevices.core.ui.theme.LocalPalletV2
import com.flipperdevices.core.ui.theme.LocalTypography
import com.flipperdevices.core.ui.res.R as DesignSystem
import flipperapp.components.core.ui.res.generated.resources.ic_back
import org.jetbrains.compose.resources.painterResource
import flipperapp.components.core.ui.res.generated.resources.Res as CoreUiRes

@Composable
fun OrangeAppBar(
Expand Down Expand Up @@ -67,7 +60,7 @@ fun OrangeAppBar(
.padding(top = 11.dp, bottom = 11.dp, start = 16.dp, end = 2.dp)
.size(24.dp)
.clickableRipple(bounded = false, onClick = onBack),
painter = painterResource(DesignSystem.drawable.ic_back),
painter = painterResource(CoreUiRes.drawable.ic_back),
contentDescription = null
)
}
Expand Down Expand Up @@ -117,82 +110,3 @@ fun OrangeAppBarWithIcon(
}
)
}

@Composable
fun OrangeAppBar(
@StringRes titleId: Int,
modifier: Modifier = Modifier,
onBack: (() -> Unit)? = null,
endBlock: (@Composable (Modifier) -> Unit)? = null
) {
OrangeAppBar(
modifier = modifier,
title = stringResource(titleId),
onBack = onBack,
endBlock = endBlock
)
}

@Composable
fun OrangeAppBarWithIcon(
@StringRes titleId: Int,
@DrawableRes endIconId: Int,
onBack: (() -> Unit)? = null,
onEndClick: () -> Unit
) {
OrangeAppBarWithIcon(
title = stringResource(titleId),
onBack = onBack,
endIconId = endIconId,
onEndClick = onEndClick
)
}

@Composable
fun OrangeAppBarWithIcon(
title: String,
@DrawableRes endIconId: Int,
modifier: Modifier = Modifier,
onBack: (() -> Unit)? = null,
onEndClick: () -> Unit
) {
OrangeAppBarWithIcon(
title = title,
endIconPainter = painterResource(endIconId),
modifier = modifier,
onBack = onBack,
onEndClick = onEndClick
)
}

@Preview
@Composable
private fun OrangeAppBarPreview() {
FlipperThemeInternal {
OrangeAppBar(
title = "Screenname",
onBack = {}
)
}
}

@Preview
@Composable
private fun OrangeAppBarEndBlockPreview() {
FlipperThemeInternal {
OrangeAppBar(
title = "Screenname",
onBack = {},
endBlock = {
Icon(
modifier = Modifier
.padding(end = 14.dp)
.size(24.dp),
painter = rememberVectorPainter(Icons.Filled.Settings),
contentDescription = null,
tint = LocalPalletV2.current.icon.blackAndWhite.blackOnColor
)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16.2142,3.2169C15.722,2.7055 14.9239,2.7055 14.4317,3.2169L6.8692,11.074C6.377,11.5854 6.377,12.4146 6.8692,12.926L14.4317,20.7831C14.9239,21.2945 15.722,21.2945 16.2142,20.7831C16.7064,20.2717 16.7064,19.4426 16.2142,18.9311L9.543,12L16.2142,5.0688C16.7064,4.5574 16.7064,3.7283 16.2142,3.2169Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
Loading

0 comments on commit 18a6549

Please sign in to comment.