Skip to content

Commit

Permalink
neaten config screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Outlet7493 committed Jan 22, 2024
1 parent a7a5a5f commit e2b447c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConfigScreenViewModel @Inject constructor(
) : ViewModel(), ConfigViewModel {
private val configList = buildList {

add(ConfigItem.Hint())
add(ConfigItem.Hint)

add(ConfigItem.Category(R.string.config_playback))

Expand Down Expand Up @@ -109,11 +109,11 @@ class ConfigScreenViewModel @Inject constructor(

add(ConfigItem.Category(R.string.config_about))

add(ConfigItem.Preference(R.string.app_name, { ctx, _ ->
add(ConfigItem.InfoItem(R.string.app_name) { ctx ->
ctx.getString(
R.string.about_version, BuildConfig.VERSION_NAME
)
}, {}))
})

add(ConfigItem.Preference(R.string.about_sources, { ctx, _ -> "" }, {
it.openInBrowser("https://github.com/iTaysonLab/jetispot")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bruhcollective.itaysonlab.jetispot.ui.screens.config

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand All @@ -13,7 +14,14 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -22,8 +30,27 @@ import androidx.compose.material.icons.outlined.Translate
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.EnergySavingsLeaf
import androidx.compose.material.icons.rounded.Info
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Slider
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand Down Expand Up @@ -53,6 +80,7 @@ interface ConfigViewModel {
fun isRoot(): Boolean = false
}

@SuppressLint("BatteryLife")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BaseConfigScreen(
Expand Down Expand Up @@ -118,6 +146,10 @@ fun BaseConfigScreen(
ConfigInfo(stringResource(item.text))
}

is ConfigItem.InfoItem -> {
ConfigInfoItem(stringResource(item.title), item.subtitle(context))
}

is ConfigItem.Preference -> {
ConfigPreference(
stringResource(item.title),
Expand Down Expand Up @@ -288,6 +320,24 @@ fun ConfigRadio(
}
}

@Composable
fun ConfigInfoItem(
title: String,
subtitle: String
) {
Column(modifier = Modifier
.fillMaxWidth()
.padding(16.dp)) {
Text(text = title, color = MaterialTheme.colorScheme.onBackground, fontSize = 18.sp)
if (subtitle.isNotEmpty()) Text(
text = subtitle,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontSize = 14.sp,
modifier = Modifier.padding(top = 4.dp)
)
}
}

@Composable
fun ConfigPreference(
title: String,
Expand Down Expand Up @@ -415,6 +465,11 @@ sealed class ConfigItem {
class Category(@StringRes val title: Int) : ConfigItem()
class Info(@StringRes val text: Int) : ConfigItem()

class InfoItem(
@StringRes val title: Int,
val subtitle: (Context) -> String
): ConfigItem()

class Preference(
@StringRes val title: Int,
val subtitle: (Context, AppConfig) -> String,
Expand Down Expand Up @@ -451,6 +506,5 @@ sealed class ConfigItem {
val modify: AppConfig.Builder.(Int) -> Unit
) : ConfigItem()

class Hint(
) : ConfigItem()
data object Hint : ConfigItem()
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ fun StorageScreen(

// 2-3. Header
item("storageact") {
Spacer(Modifier.size(8.dp))
ConfigCategory(text = stringResource(id = R.string.storage_actions))
}

Expand All @@ -131,15 +132,17 @@ fun StorageScreen(
}

@Composable
fun StorageComponentDetail(
private fun StorageComponentDetail(
type: StorageViewModel.StorageFileKind,
size: String,
) {
Row(
Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.padding(top = 16.dp)) {
.padding(top = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(imageVector = type.icon, contentDescription = null, modifier = Modifier.size(28.dp))

Column(Modifier.padding(start = 16.dp)) {
Expand All @@ -151,7 +154,7 @@ fun StorageComponentDetail(
}

@Composable
fun StorageHeader(
private fun StorageHeader(
state: StorageViewModel.UiState.Ready
) {
Column(Modifier.padding(horizontal = 16.dp)) {
Expand Down Expand Up @@ -191,7 +194,7 @@ fun StorageHeader(
.height(16.dp), state.takenTotal, state.others, state.internalStorage.total
)

Row(Modifier.padding(top = 4.dp, bottom = 8.dp)) {
Row(Modifier.padding(top = 8.dp, bottom = 8.dp)) {
ProgressIndicatorLegend(
modifier = Modifier.align(Alignment.CenterVertically),
color = MaterialTheme.colorScheme.primary,
Expand All @@ -211,7 +214,7 @@ fun StorageHeader(
}

@Composable
fun ProgressIndicatorLegend(
private fun ProgressIndicatorLegend(
modifier: Modifier = Modifier,
color: Color,
text: String
Expand All @@ -233,7 +236,7 @@ fun ProgressIndicatorLegend(
}

@Composable
fun MultiStateProgressIndicator(
private fun MultiStateProgressIndicator(
modifier: Modifier,
application: Long,
others: Long,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<string name="plan_includes">Plan includes</string>
<string name="plan_others">See other plans</string>

<string name="about_version">version %s</string>
<string name="about_version">Version %s</string>
<string name="about_sources">Show source code</string>
<string name="about_channel">Open Telegram channel</string>

Expand Down

0 comments on commit e2b447c

Please sign in to comment.