Skip to content

Commit

Permalink
perf: Optimize UI
Browse files Browse the repository at this point in the history
Change-Id: Ic393a11656663ce4e105ce695473420bf6325e31
  • Loading branch information
XayahSuSuSu committed Jul 6, 2024
1 parent df5b433 commit 04310c9
Show file tree
Hide file tree
Showing 30 changed files with 474 additions and 111 deletions.
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-bs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<string name="data_only">Samo podaci</string>
<string name="in_use">Koristi se</string>
<string name="clear_all">Izbriši sve</string>
<string name="batching_select">Serijski odabir</string>
<string name="batch_select">Serijski odabir</string>
<string name="existing_files">Postojeće datoteke</string>
<string name="overall_config">Općenita konfiguracija</string>
<string name="test_connection">Testiraj vezu</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<string name="password">Contraseña</string>
<string name="recursive_mode">Modo recursivo</string>
<string name="follow_symlinks">Seguir enlaces simbólicos</string>
<string name="batching_select">Selección múltiple</string>
<string name="batch_select">Selección múltiple</string>
<string name="apk_only">Solo APK</string>
<string name="in_use">En uso</string>
<string name="test_connection">Probar la conexión</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<string name="recursive_mode">Rekurzivni način</string>
<string name="please_set_up_backup_dir">Postavi direktorij sigurnosnih kopija</string>
<string name="follow_symlinks_desc">Arhivirajte i ispišite datoteke na koje se upućuje</string>
<string name="batching_select">Serijski odabir</string>
<string name="batch_select">Serijski odabir</string>
<string name="remain">Ostani</string>
<string name="in_use">Koristi se</string>
<string name="overall_config">Općenita konfiguracija</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<string name="shared_dir">Delt mappe</string>
<string name="allow_empty">Tillat tomme</string>
<string name="domain">Domene</string>
<string name="batching_select">Knippeutvalg</string>
<string name="batch_select">Knippeutvalg</string>
<string name="remain">Gjenstår</string>
<string name="overall_config">Gjennomgående oppsett</string>
<string name="remote_not_set">Fjernenhet ikke satt</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<string name="finished">Finalizado</string>
<string name="type">Tipo</string>
<string name="remote_not_set">Diretório remoto não definido</string>
<string name="batching_select">Seleção de lote</string>
<string name="batch_select">Seleção de lote</string>
<string name="welcome_to_use">Bem-vindo ao DataBackup</string>
<string name="directory">Armazenamento</string>
<string name="log">Logs</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<string name="clear_all">Очистить все</string>
<string name="processing">Обработка</string>
<string name="data_only">Только данные</string>
<string name="batching_select">Пакетный выбор</string>
<string name="batch_select">Пакетный выбор</string>
<string name="in_use">Используется</string>
<string name="overall_config">Общая конфигурация</string>
<string name="connection_established">Связь успешно установлена</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-sr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<string name="recursive_mode">Rekurzivni način</string>
<string name="follow_symlinks">Pratite linkove</string>
<string name="follow_symlinks_desc">Arhivirajte i ispišite datoteke na koje se upućuje</string>
<string name="batching_select">Serijski odabir</string>
<string name="batch_select">Serijski odabir</string>
<string name="remain">Ostani</string>
<string name="apk_only">Samo APK</string>
<string name="data_only">Samo podaci</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<string name="not_selected">Seçilmedi</string>
<string name="url">URL</string>
<string name="cloud_server_disconnected">Bulut sunucusunun bağlantısı kesildi</string>
<string name="batching_select">Toplu seçim</string>
<string name="batch_select">Toplu seçim</string>
<string name="account">Hesap</string>
<string name="main_account">Ana hesap</string>
<string name="in_use">Kullanımda</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<string name="clear_all">Очистити все</string>
<string name="processing">Обробка</string>
<string name="data_only">Тільки дані</string>
<string name="batching_select">Пакетний вибір</string>
<string name="batch_select">Пакетний вибір</string>
<string name="local">Локально</string>
<string name="in_use">Використовується</string>
<string name="overall_config">Загальні налаштування</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<string name="recursive_mode">递归模式</string>
<string name="follow_symlinks">跟随符号链接</string>
<string name="follow_symlinks_desc">将符号链接替换为其指向的文件</string>
<string name="batching_select">批量选择</string>
<string name="batch_select">批量选择</string>
<string name="remain">剩余</string>
<string name="apk_only">仅安装包</string>
<string name="data_only">仅数据</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<string name="recursive_mode">遞迴模式</string>
<string name="follow_symlinks">跟隨符號鏈接</string>
<string name="follow_symlinks_desc">將符號連結替換為其指向的文件</string>
<string name="batching_select">大量選擇</string>
<string name="batch_select">大量選擇</string>
<string name="remain">剩餘</string>
<string name="apk_only">僅安裝套件</string>
<string name="data_only">僅數據</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<string name="recursive_mode">遞迴模式</string>
<string name="follow_symlinks">跟隨符號鏈接</string>
<string name="follow_symlinks_desc">將符號連結替換為其指向的文件</string>
<string name="batching_select">大量選擇</string>
<string name="batch_select">大量選擇</string>
<string name="remain">剩餘</string>
<string name="apk_only">僅安裝套件</string>
<string name="data_only">僅數據</string>
Expand Down
2 changes: 1 addition & 1 deletion source/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<string name="recursive_mode">Recursive mode</string>
<string name="follow_symlinks">Follow symlinks</string>
<string name="follow_symlinks_desc">Archive and dump the files they point to</string>
<string name="batching_select">Batch select</string>
<string name="batch_select">Batch select</string>
<string name="remain">Remain</string>
<string name="apk_only">APK only</string>
<string name="data_only">Data only</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ data class PackageEntity(
val mediaSelected: Boolean
get() = dataStates.mediaState == DataState.Selected

val dataSelectedCount: Int
get() = run {
var count = 0
if (userSelected) count++
if (userDeSelected) count++
if (dataSelected) count++
if (obbSelected) count++
if (mediaSelected) count++
count
}

val permissionSelected: Boolean
get() = dataStates.permissionState == DataState.Selected

Expand Down
165 changes: 165 additions & 0 deletions source/core/ui/src/main/kotlin/com/xayah/core/ui/component/Chip.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package com.xayah.core.ui.component

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.rounded.KeyboardArrowDown
import androidx.compose.material.icons.rounded.KeyboardArrowUp
import androidx.compose.material3.AssistChip
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.FilterChipDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -23,18 +34,25 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import com.xayah.core.model.DataType
import com.xayah.core.model.SortType
import com.xayah.core.model.util.formatSize
import com.xayah.core.ui.R
import com.xayah.core.ui.material3.CardDefaults
import com.xayah.core.ui.material3.toColor
import com.xayah.core.ui.material3.tokens.ColorSchemeKeyTokens
import com.xayah.core.ui.model.ImageVectorToken
import com.xayah.core.ui.model.StringResourceToken
import com.xayah.core.ui.token.ModalMenuTokens
import com.xayah.core.ui.token.PaddingTokens
import com.xayah.core.ui.token.SizeTokens
import com.xayah.core.ui.util.fromDrawable
import com.xayah.core.ui.util.fromString
import com.xayah.core.ui.util.fromVector
import com.xayah.core.ui.util.icon
import com.xayah.core.ui.util.value

@Composable
Expand Down Expand Up @@ -244,3 +262,150 @@ fun ChipRow(horizontalSpace: Dp = SizeTokens.Level16, chipGroup: @Composable ()
Spacer(modifier = Modifier.size(PaddingTokens.Level0))
}
}

@Composable
fun FilterChip(
modifier: Modifier = Modifier,
label: StringResourceToken,
trailingIcon: ImageVectorToken? = null,
selected: Boolean,
onClick: () -> Unit
) {
FilterChip(
modifier = modifier,
onClick = onClick,
label = {
Text(text = label.value, maxLines = 1)
},
selected = selected,
leadingIcon = if (selected) {
{
Icon(
imageVector = Icons.Filled.Done,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize)
)
}
} else {
null
},
trailingIcon = if (trailingIcon != null) {
{
Icon(
imageVector = trailingIcon.value,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize)
)
}
} else {
null
},
)
}

@ExperimentalMaterial3Api
@ExperimentalFoundationApi
@Composable
fun DataChip(
modifier: Modifier = Modifier,
enabled: Boolean,
title: StringResourceToken,
subtitle: StringResourceToken?,
leadingIcon: ImageVectorToken,
trailingIcon: ImageVectorToken?,
shape: Shape = AssistChipDefaults.shape,
border: BorderStroke? = outlinedCardBorder(),
color: ColorSchemeKeyTokens = ColorSchemeKeyTokens.Primary,
containerColor: ColorSchemeKeyTokens = ColorSchemeKeyTokens.Transparent,
onClick: () -> Unit,
) {
Card(
modifier = modifier,
enabled = enabled,
onClick = onClick,
onLongClick = {},
border = border,
shape = shape,
colors = if (enabled) CardDefaults.cardColors(containerColor = containerColor.toColor(), contentColor = color.toColor()) else CardDefaults.cardColors()
) {
Row(
modifier = Modifier
.paddingHorizontal(PaddingTokens.Level2)
.heightIn(min = SizeTokens.Level52),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(PaddingTokens.Level2)
) {
Icon(
imageVector = leadingIcon.value,
tint = if (enabled) color.toColor() else LocalContentColor.current,
contentDescription = null,
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
Column(
modifier = Modifier
.weight(1f)
.paddingVertical(PaddingTokens.Level2)
) {
LabelLargeText(modifier = Modifier.basicMarquee(), text = title.value, maxLines = 1)
if (subtitle != null)
LabelSmallText(modifier = Modifier.basicMarquee(), text = subtitle.value, maxLines = 1)
}
if (trailingIcon != null) {
Icon(
imageVector = trailingIcon.value,
tint = if (enabled) color.toColor() else LocalContentColor.current,
contentDescription = null,
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
}
}
}
}

@ExperimentalMaterial3Api
@ExperimentalFoundationApi
@Composable
fun PackageDataChip(modifier: Modifier = Modifier, enabled: Boolean = true, dataType: DataType, selected: Boolean, dataBytes: Double? = null, onClick: () -> Unit) {
DataChip(
modifier = modifier,
enabled = enabled,
title = StringResourceToken.fromString(dataType.type.uppercase()),
subtitle = if (dataBytes == null) null else StringResourceToken.fromString(dataBytes.formatSize()),
leadingIcon = dataType.icon,
trailingIcon = if (selected) ImageVectorToken.fromDrawable(R.drawable.ic_rounded_check_circle) else null,
border = if (selected) null else outlinedCardBorder(),
color = if (selected) ColorSchemeKeyTokens.OnSecondaryContainer else ColorSchemeKeyTokens.OnSurfaceVariant,
containerColor = if (selected) ColorSchemeKeyTokens.SecondaryContainer else ColorSchemeKeyTokens.Transparent,
onClick = onClick
)
}

@ExperimentalMaterial3Api
@ExperimentalFoundationApi
@Composable
fun PackageDataChip(modifier: Modifier = Modifier, enabled: Boolean = true, dataType: DataType, selected: Boolean, subtitle: StringResourceToken? = null, onClick: () -> Unit) {
DataChip(
modifier = modifier,
enabled = enabled,
title = StringResourceToken.fromString(dataType.type.uppercase()),
subtitle = subtitle,
leadingIcon = dataType.icon,
trailingIcon = if (selected) ImageVectorToken.fromDrawable(R.drawable.ic_rounded_check_circle) else null,
border = if (selected) null else outlinedCardBorder(),
color = if (selected) ColorSchemeKeyTokens.OnSecondaryContainer else ColorSchemeKeyTokens.OnSurfaceVariant,
containerColor = if (selected) ColorSchemeKeyTokens.SecondaryContainer else ColorSchemeKeyTokens.Transparent,
onClick = onClick
)
}

@Composable
fun RoundChip(modifier: Modifier = Modifier, label: @Composable () -> Unit) {
Box(
modifier = modifier
.clip(CircleShape)
.background(ColorSchemeKeyTokens.PrimaryContainer.toColor()),
contentAlignment = Alignment.Center
) {
label.invoke()
}
}
Loading

0 comments on commit 04310c9

Please sign in to comment.