Skip to content

Commit

Permalink
[WEAR] Add settings for apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgurgul committed Jan 7, 2025
1 parent fe15e06 commit efe9bd6
Showing 1 changed file with 64 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

package com.kgurgul.cpuinfo.wear.features.applications

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.runtime.Composable
Expand All @@ -26,6 +30,7 @@ import androidx.wear.compose.foundation.SwipeToDismissBoxState
import androidx.wear.compose.foundation.edgeSwipeToDismiss
import androidx.wear.compose.foundation.lazy.items
import androidx.wear.compose.foundation.rememberRevealState
import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.ExperimentalWearMaterialApi
import androidx.wear.compose.material.Icon
Expand All @@ -35,6 +40,8 @@ import androidx.wear.compose.material.SwipeToRevealDefaults
import androidx.wear.compose.material.SwipeToRevealPrimaryAction
import androidx.wear.compose.material.SwipeToRevealSecondaryAction
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleButton
import androidx.wear.compose.material.ToggleButtonDefaults
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.ImageRequest
Expand All @@ -45,19 +52,25 @@ import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
import com.google.android.horologist.compose.layout.ScreenScaffold
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
import com.google.android.horologist.compose.material.Button
import com.google.android.horologist.compose.material.ButtonSize
import com.google.android.horologist.compose.material.Confirmation
import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding
import com.google.android.horologist.compose.material.ResponsiveListHeader
import com.kgurgul.cpuinfo.features.applications.ApplicationsViewModel
import com.kgurgul.cpuinfo.features.applications.registerUninstallListener
import com.kgurgul.cpuinfo.shared.Res
import com.kgurgul.cpuinfo.shared.applications
import com.kgurgul.cpuinfo.shared.apps_show_system_apps
import com.kgurgul.cpuinfo.shared.apps_sort_order
import com.kgurgul.cpuinfo.shared.apps_uninstall
import com.kgurgul.cpuinfo.shared.ic_apk_document_filled
import com.kgurgul.cpuinfo.shared.ic_apk_document_outlined
import com.kgurgul.cpuinfo.shared.refresh
import com.kgurgul.cpuinfo.shared.settings
import com.kgurgul.cpuinfo.wear.ui.components.WearCpuChip
import com.kgurgul.cpuinfo.wear.ui.components.WearCpuProgressIndicator
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

Expand Down Expand Up @@ -94,27 +107,6 @@ fun WearApplicationsScreen(
onAppSettingsClicked: (id: String) -> Unit,
onSystemAppsSwitched: (enabled: Boolean) -> Unit,
onSortOrderChange: (ascending: Boolean) -> Unit,
) {
ApplicationsList(
uiState = uiState,
swipeToDismissBoxState = swipeToDismissBoxState,
onAppClicked = onAppClicked,
onRefreshApplications = onRefreshApplications,
onSnackbarDismissed = onSnackbarDismissed,
onAppUninstallClicked = onAppUninstallClicked,
onAppSettingsClicked = onAppSettingsClicked,
)
}

@Composable
private fun ApplicationsList(
uiState: ApplicationsViewModel.UiState,
swipeToDismissBoxState: SwipeToDismissBoxState,
onAppClicked: (packageName: String) -> Unit,
onRefreshApplications: () -> Unit,
onSnackbarDismissed: () -> Unit,
onAppUninstallClicked: (id: String) -> Unit,
onAppSettingsClicked: (id: String) -> Unit,
) {
val columnState = rememberResponsiveColumnState(
contentPadding = ScalingLazyColumnDefaults.padding(
Expand All @@ -124,7 +116,7 @@ private fun ApplicationsList(
)
ScreenScaffold(scrollState = columnState) {
ScalingLazyColumn(
columnState = columnState
columnState = columnState,
) {
item(key = "__header") {
ResponsiveListHeader(contentPadding = firstItemPadding()) {
Expand Down Expand Up @@ -211,13 +203,57 @@ private fun ApplicationsList(
}
}
if (!uiState.isLoading) {
item(key = "__refresh") {
Button(
imageVector = Icons.Default.Refresh,
contentDescription = stringResource(Res.string.refresh),
onClick = onRefreshApplications,
item(key = "__buttons") {
Row(
horizontalArrangement = Arrangement
.spacedBy(12.dp, Alignment.CenterHorizontally),
modifier = Modifier.padding(top = 12.dp),
)
) {
Button(
imageVector = Icons.Default.Refresh,
contentDescription = stringResource(Res.string.refresh),
onClick = onRefreshApplications,
buttonSize = ButtonSize.Small,
)
ToggleButton(
checked = uiState.withSystemApps,
onCheckedChange = { onSystemAppsSwitched(!uiState.withSystemApps) },
modifier = Modifier.size(ButtonDefaults.SmallButtonSize),
) {
val systemAppIcon = if (uiState.withSystemApps) {
Res.drawable.ic_apk_document_filled
} else {
Res.drawable.ic_apk_document_outlined
}
Icon(
painter = painterResource(systemAppIcon),
contentDescription = stringResource(
Res.string.apps_show_system_apps
),
modifier = Modifier
.size(ToggleButtonDefaults.SmallIconSize)
.wrapContentSize(align = Alignment.Center),
)
}
ToggleButton(
checked = uiState.isSortAscending,
onCheckedChange = { onSortOrderChange(!uiState.isSortAscending) },
modifier = Modifier.size(ButtonDefaults.SmallButtonSize),
) {
val sortingIcon = if (uiState.isSortAscending) {
Icons.Default.KeyboardArrowDown
} else {
Icons.Default.KeyboardArrowUp
}
Icon(
imageVector = sortingIcon,
contentDescription = stringResource(Res.string.apps_sort_order),
modifier = Modifier
.size(ToggleButtonDefaults.SmallIconSize)
.wrapContentSize(align = Alignment.Center),
)
}
}
}
}
}
Expand Down Expand Up @@ -255,59 +291,3 @@ private fun AppOpeningConfirmation(
)
}
}

/*@Composable
private fun TopBar(
withSystemApps: Boolean,
onSystemAppsSwitched: (enabled: Boolean) -> Unit,
isSortAscending: Boolean,
onSortOrderChange: (ascending: Boolean) -> Unit,
) {
var showMenu by remember { mutableStateOf(false) }
PrimaryTopAppBar(
title = stringResource(Res.string.applications),
actions = {
IconButton(onClick = { showMenu = !showMenu }) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = null,
)
}
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
) {
DropdownMenuItem(
text = {
CpuSwitchBox(
text = stringResource(Res.string.apps_show_system_apps),
isChecked = withSystemApps,
onCheckedChange = { onSystemAppsSwitched(!withSystemApps) },
)
},
onClick = { onSystemAppsSwitched(!withSystemApps) },
)
DropdownMenuItem(
text = {
Text(
text = stringResource(Res.string.apps_sort_order),
style = MaterialTheme.typography.bodyMedium,
)
},
onClick = { onSortOrderChange(!isSortAscending) },
trailingIcon = {
val icon = if (isSortAscending) {
Icons.Default.KeyboardArrowDown
} else {
Icons.Default.KeyboardArrowUp
}
Icon(
imageVector = icon,
contentDescription = null,
)
},
)
}
},
)
}*/

0 comments on commit efe9bd6

Please sign in to comment.