Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
n00byara committed Apr 21, 2024
1 parent e3ddb29 commit 3a68a93
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class MainActivity : ComponentActivity() {
val topBarTitleState = remember {
mutableStateOf(topBarTitle)
}
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val topBarModel = TopBarModel(topBarTitleState, scrollBehavior)
val topBarModel = TopBarModel(topBarTitleState)

val navController = rememberNavController()
val bottomNavBarModel = BottomNavBarModel(
Expand All @@ -58,7 +57,6 @@ class MainActivity : ComponentActivity() {
)

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopBar(topBarModel)
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ru.n00byara.notificationcode.ui.components.applicationinfocard

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
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.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.outlined.CheckCircle
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import ru.n00byara.notificationcode.Constants

@Composable
fun ApplicationInfoCheckBox(
applicationInfoCheckBoxModel: ApplicationInfoCheckBoxModel
) {
val checkedState = remember {
mutableStateOf(applicationInfoCheckBoxModel.checked)
}

Card(
modifier =Modifier
.fillMaxWidth()
.padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp)
.clip(RoundedCornerShape(19.dp))
.clickable {
checkedState.value = !checkedState.value
applicationInfoCheckBoxModel.setState(
Constants.APPLICATION_PREF + applicationInfoCheckBoxModel.appInfo.name,
checkedState.value
)
}
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row(
Modifier
.padding(10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Image(
rememberDrawablePainter(applicationInfoCheckBoxModel.appInfo.icon),
null,
Modifier
.size(40.dp)
.clip(CircleShape)
)
Text(
applicationInfoCheckBoxModel.appInfo.name,
Modifier.padding(start = 5.dp)
)
}
Row(
Modifier
.padding(7.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) {
Icon(
if (checkedState.value) Icons.Default.CheckCircle else Icons.Outlined.CheckCircle,
applicationInfoCheckBoxModel.appInfo.name,
Modifier
.size(30.dp)
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ru.n00byara.notificationcode.ui.components.applicationinfocard

import ru.n00byara.notificationcode.applicationinfo.InstalledAppInfo

data class ApplicationInfoCardModel(
data class ApplicationInfoCheckBoxModel(
val appInfo: InstalledAppInfo,
val checked: Boolean,
val setState: (String, Boolean) -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TopBar(topBarModel: TopBarModel) {
val systemUiController = rememberSystemUiController()
systemUiController.setSystemBarsColor(
MaterialTheme.colorScheme.onPrimary,
Color.Transparent,
darkIcons =
if (isSystemInDarkTheme()) false
else true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import androidx.compose.runtime.MutableState

data class TopBarModel @OptIn(ExperimentalMaterial3Api::class) constructor(
val title: MutableState<String>,
val scrollBehavior: TopAppBarScrollBehavior
val scrollBehavior: TopAppBarScrollBehavior? = null
)
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
package ru.n00byara.notificationcode.ui.screens

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import ru.n00byara.notificationcode.Constants
import ru.n00byara.notificationcode.R
import ru.n00byara.notificationcode.ui.components.applicationinfocard.ApplicationInfoCard
import ru.n00byara.notificationcode.ui.components.applicationinfocard.ApplicationInfoCardModel
import ru.n00byara.notificationcode.ui.components.applicationinfocard.ApplicationInfoCheckBox
import ru.n00byara.notificationcode.ui.components.applicationinfocard.ApplicationInfoCheckBoxModel
import ru.n00byara.notificationcode.ui.viewmodels.ApplicationsScreenViewModel

@Composable
Expand All @@ -31,38 +20,16 @@ fun ApplicationsScreen(
topBarTitleState.value = stringResource(R.string.screen_application_title)

LazyColumn {
item {
ApplicationInfoCard()
}

itemsIndexed(
applicationsScreenViewModel.getApplications()
) { _, appInfo ->
val applicationInfoCardModel = ApplicationInfoCardModel(
val applicationInfoCheckBoxModel = ApplicationInfoCheckBoxModel(
appInfo,
applicationsScreenViewModel.getApplicationState(Constants.APPLICATION_PREF + appInfo.name),
applicationsScreenViewModel::setApplicationState
)

ApplicationInfoCard(applicationInfoCardModel)
ApplicationInfoCheckBox(applicationInfoCheckBoxModel)
}
}
}

@Composable
fun ApplicationInfoCard() {
Card(
Modifier
.fillMaxWidth()
.padding(15.dp)
.wrapContentHeight()
.clip(RoundedCornerShape(19.dp))
) {
Text(
stringResource(R.string.applications_card_info),
Modifier.padding(15.dp),
fontSize = 17.sp,
fontWeight = FontWeight.Bold
)
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
<string name="module_status_active">Module is active</string>
<string name="module_status_inactive">Module is inactive</string>
<string name="screen_application_title">Applications</string>
<string name="applications_card_info">Select the applications that will copy the data by simply clicking on them</string>
<string name="module_info_inactive">To configure the module, you need to enable it and then restart SystemUI</string>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
<string name="module_status_active">Модуль включен</string>
<string name="module_status_inactive">Модуль выключен</string>
<string name="screen_application_title">Приложения</string>
<string name="applications_card_info">Выберите приложения которые будут копировать данные, просто кликнув на них</string>
<string name="module_info_inactive">Для настройки модуля, его необходимо включить и после перезапустить SystemUI</string>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<string name="module_status_active">Module is active</string>
<string name="module_status_inactive">Module is inactive</string>
<string name="screen_application_title">Applications</string>
<string name="applications_card_info">Select the applications that will copy the data by simply clicking on them</string>
<string name="module_info_inactive">To configure the module, you need to enable it and then restart SystemUI</string>
</resources>

0 comments on commit 3a68a93

Please sign in to comment.