Skip to content

Commit

Permalink
UI Optimisation in appllication catalog (#726)
Browse files Browse the repository at this point in the history
**Background**

Now we have some unstable compose function

**Changes**

* Run compose metrics
* Fix Stable and Immutable value

**Test plan**

Try use catalog
  • Loading branch information
Programistich authored Nov 3, 2023
1 parent bd6d968 commit 1a9c2bb
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 37 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

# 1.6.6

- [FIX] Fix crash gms version on nogms environment
- [Feature] Bump deps
- [Feature] Optimization FapHub by compose metrics
- [FIX] Fix faphub minor version supported suggest to update
- [FIX] Fix faphub manifest minor api version
- [FIX] Fix faphub manifest image base64
- [FIX] Fix crash on appication from unknown source
- [FIX] Fix mfkey32 download process
- [FIX] Fix crash gms version on nogms environment

# 1.6.5

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.flipperdevices.bottombar.api

import android.content.Intent
import androidx.compose.runtime.Immutable
import com.flipperdevices.bottombar.model.BottomBarTab

@Immutable
interface BottomNavigationHandleDeeplink {
fun handleDeepLink(intent: Intent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.flipperdevices.faphub.appcard.composable.AppCard
import com.flipperdevices.faphub.dao.api.model.FapItemShort
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError
import com.flipperdevices.core.ui.res.R as DesignSystem

private const val DEFAULT_FAP_COUNT = 20
Expand Down Expand Up @@ -51,7 +52,7 @@ fun LazyListScope.ComposableFapsList(
with(errorsRenderer) {
ComposableThrowableErrorListItem(
modifier = elementModifier,
throwable = loadState.error,
throwable = loadState.error.toFapHubError(),
onRetry = faps::retry,
fapErrorSize = defaultFapErrorSize
)
Expand Down Expand Up @@ -79,7 +80,7 @@ fun LazyListScope.ComposableFapsList(

is LoadState.Error -> with(errorsRenderer) {
ComposableThrowableErrorListItem(
throwable = loadState.error,
throwable = loadState.error.toFapHubError(),
onRetry = faps::retry,
modifier = elementModifier,
fapErrorSize = FapErrorSize.IN_LIST
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.flipperdevices.faphub.catalogtab.api

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.dao.api.model.FapItemShort

@Immutable
interface CatalogTabApi {
@Composable
fun ComposableCatalogTab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.flipperdevices.faphub.catalogtab.impl.model.CategoriesLoadState
import com.flipperdevices.faphub.dao.api.model.FapCategory
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError

private const val DEFAULT_CATEGORIES_SIZE = 12
private const val COLUMN_COUNT = 3
Expand Down Expand Up @@ -42,7 +43,7 @@ fun LazyListScope.ComposableCategories(
.fillMaxWidth()
.padding(horizontal = 14.dp)
.height(height = 250.dp),
throwable = loadState.throwable,
throwable = loadState.throwable.toFapHubError(),
onRetry = onRetry,
fapErrorSize = FapErrorSize.IN_LIST
)
Expand Down
3 changes: 3 additions & 0 deletions components/faphub/errors/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ dependencies {
implementation(libs.compose.tooling)
implementation(libs.compose.foundation)
implementation(libs.compose.material)

implementation(libs.ktor.serialization)
implementation(libs.ktor.client)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package com.flipperdevices.faphub.errors.api

import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier
import com.flipperdevices.faphub.errors.api.throwable.FapHubError

@Immutable
interface FapHubComposableErrorsRenderer {
@Suppress("FunctionNaming")
fun LazyListScope.ComposableThrowableErrorListItem(
throwable: Throwable,
throwable: FapHubError,
onRetry: () -> Unit,
modifier: Modifier,
fapErrorSize: FapErrorSize
)

@Composable
fun ComposableThrowableError(
throwable: Throwable,
throwable: FapHubError,
onRetry: () -> Unit,
modifier: Modifier,
fapErrorSize: FapErrorSize
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.flipperdevices.faphub.errors.api.throwable

import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.plugins.ServerResponseException
import io.ktor.serialization.JsonConvertException
import java.net.UnknownHostException

enum class FapHubError {
NO_NETWORK,
WRONG_REQUEST,
FLIPPER_NOT_CONNECTED,
NO_SERVER,
GENERAL,
FIRMWARE_NOT_SUPPORTED
}

fun Throwable.toFapHubError(): FapHubError {
return when (this) {
is UnknownHostException -> FapHubError.NO_NETWORK
is FirmwareNotSupported -> FapHubError.FIRMWARE_NOT_SUPPORTED
is JsonConvertException, is ClientRequestException -> FapHubError.WRONG_REQUEST
is FlipperNotConnected -> FapHubError.FLIPPER_NOT_CONNECTED
is ServerResponseException -> FapHubError.NO_SERVER
else -> FapHubError.GENERAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,43 @@ import com.flipperdevices.core.ui.errors.impl.composable.ComposableNoNetworkErro
import com.flipperdevices.core.ui.errors.impl.composable.ComposableNoServerError
import com.flipperdevices.core.ui.errors.impl.composable.ComposableWrongRequestError
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.throwable.FirmwareNotSupported
import com.flipperdevices.faphub.errors.api.throwable.FlipperNotConnected
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.plugins.ServerResponseException
import io.ktor.serialization.JsonConvertException
import java.net.UnknownHostException
import com.flipperdevices.faphub.errors.api.throwable.FapHubError

@Composable
fun ComposableThrowableErrorInternal(
throwable: Throwable,
throwable: FapHubError,
onRetry: () -> Unit,
onOpenDeviceScreen: () -> Unit,
fapErrorSize: FapErrorSize,
modifier: Modifier = Modifier
) {
when (throwable) {
is UnknownHostException -> ComposableNoNetworkError(
FapHubError.NO_NETWORK -> ComposableNoNetworkError(
modifier = modifier,
onRetry = onRetry,
fapErrorSize = fapErrorSize
)

is FirmwareNotSupported -> ComposableFlipperFirmwareNotSupported(
FapHubError.FIRMWARE_NOT_SUPPORTED -> ComposableFlipperFirmwareNotSupported(
modifier = modifier,
onOpenDeviceScreen = onOpenDeviceScreen
)

is JsonConvertException,
is ClientRequestException -> ComposableWrongRequestError(
FapHubError.WRONG_REQUEST -> ComposableWrongRequestError(
modifier = modifier,
onRetry = onRetry,
fapErrorSize = fapErrorSize
)

is FlipperNotConnected -> ComposableFlipperNotConnectedError(
FapHubError.FLIPPER_NOT_CONNECTED -> ComposableFlipperNotConnectedError(
modifier = modifier,
onRetry = onRetry,
fapErrorSize = fapErrorSize
)

is ServerResponseException -> ComposableNoServerError(
FapHubError.NO_SERVER -> ComposableNoServerError(
modifier = modifier,
onRetry = onRetry,
fapErrorSize = fapErrorSize
)

else -> ComposableGeneralError(
FapHubError.GENERAL -> ComposableGeneralError(
modifier = modifier,
onRetry = onRetry,
fapErrorSize = fapErrorSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.ui.errors.impl.ComposableThrowableErrorInternal
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.FapHubError
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject

Expand All @@ -18,7 +19,7 @@ class FapHubComposableErrorsRendererImpl @Inject constructor(
) : FapHubComposableErrorsRenderer {

override fun LazyListScope.ComposableThrowableErrorListItem(
throwable: Throwable,
throwable: FapHubError,
onRetry: () -> Unit,
modifier: Modifier,
fapErrorSize: FapErrorSize
Expand All @@ -41,7 +42,7 @@ class FapHubComposableErrorsRendererImpl @Inject constructor(

@Composable
override fun ComposableThrowableError(
throwable: Throwable,
throwable: FapHubError,
onRetry: () -> Unit,
modifier: Modifier,
fapErrorSize: FapErrorSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.flipperdevices.faphub.appcard.composable.components.AppCardScreenshot
import com.flipperdevices.faphub.dao.api.model.FapItem
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError
import com.flipperdevices.faphub.fapscreen.impl.R
import com.flipperdevices.faphub.fapscreen.impl.composable.description.ComposableFapDescription
import com.flipperdevices.faphub.fapscreen.impl.composable.header.ComposableFapHeader
Expand All @@ -52,7 +53,7 @@ fun ComposableFapScreen(

when (val loadingStateLocal = loadingState) {
is FapScreenLoadingState.Error -> errorsRenderer.ComposableThrowableError(
throwable = loadingStateLocal.throwable,
throwable = loadingStateLocal.throwable.toFapHubError(),
onRetry = viewModel::onRefresh,
modifier = modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.flipperdevices.faphub.installation.button.api

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier

@Immutable
interface FapInstallationUIApi {
@Composable
fun ComposableButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ dependencies {

implementation(libs.kotlin.coroutines)
implementation(libs.annotations)

implementation(libs.compose.ui)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import androidx.annotation.FloatRange
import com.flipperdevices.faphub.installation.manifest.model.FapManifestItem

sealed class FapState {
object NotInitialized : FapState()
data object NotInitialized : FapState()

object RetrievingManifest : FapState()
data object RetrievingManifest : FapState()

object Installed : FapState()
data object Installed : FapState()

object ReadyToInstall : FapState()
object ConnectFlipper : FapState()
data object ReadyToInstall : FapState()
data object ConnectFlipper : FapState()

data class NotAvailableForInstall(val reason: NotAvailableReason) : FapState()

Expand All @@ -29,9 +29,9 @@ sealed class FapState {
val progress: Float
) : FapState()

object Deleting : FapState()
data object Deleting : FapState()

object Canceling : FapState()
data object Canceling : FapState()
}

enum class NotAvailableReason {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.flipperdevices.faphub.installedtab.api

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable

@Immutable
interface FapInstalledApi {
@Composable
fun getUpdatePendingCount(): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.flipperdevices.core.ui.theme.LocalTypography
import com.flipperdevices.faphub.dao.api.model.FapItemShort
import com.flipperdevices.faphub.errors.api.FapErrorSize
import com.flipperdevices.faphub.errors.api.FapHubComposableErrorsRenderer
import com.flipperdevices.faphub.errors.api.throwable.toFapHubError
import com.flipperdevices.faphub.installedtab.impl.R
import com.flipperdevices.faphub.installedtab.impl.composable.button.ComposableUpdateAllButton
import com.flipperdevices.faphub.installedtab.impl.composable.common.ComposableLoadingItemDivider
Expand Down Expand Up @@ -56,7 +57,7 @@ fun ComposableInstalledTabScreen(

when (val stateLocal = state) {
is FapInstalledScreenState.Error -> errorsRenderer.ComposableThrowableError(
throwable = stateLocal.throwable,
throwable = stateLocal.throwable.toFapHubError(),
onRetry = { viewModel.refresh(true) },
modifier = screenModifier
.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.flipperdevices.faphub.maincard.api

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier

@Immutable
interface MainCardApi {
@Composable
fun ComposableMainCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.flipperdevices.faphub.target.model
import com.flipperdevices.core.data.SemVer

sealed class FlipperTarget {
object Unsupported : FlipperTarget()
data object Unsupported : FlipperTarget()

object NotConnected : FlipperTarget()
data object NotConnected : FlipperTarget()

data class Received(
val target: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.flipperdevices.faphub.uninstallbutton.api

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Modifier
import com.flipperdevices.faphub.dao.api.model.FapItem
import com.flipperdevices.faphub.dao.api.model.FapItemShort

@Immutable
interface FapUninstallApi {
@Composable
fun ComposableFapUninstallButton(
Expand Down

0 comments on commit 1a9c2bb

Please sign in to comment.