fixed battery issue
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
android:theme="@style/Theme.SMIAttendance"
|
android:theme="@style/Theme.SMIAttendance"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".main.MainApplicationActivity"
|
android:name=".main.MainAppActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@style/Theme.SMIAttendance">
|
android:theme="@style/Theme.SMIAttendance">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.TopComponents
|
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.TopComponents
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.subSetting.AboutSettings
|
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.subSetting.AboutSettings
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.subSetting.Appearance
|
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.subSetting.Developer_settings
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
fun SettingsScreen(
|
||||||
@@ -36,10 +37,8 @@ fun SettingsScreen(
|
|||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
.wrapContentSize()
|
.wrapContentSize()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Appearance(context = context)
|
|
||||||
AboutSettings(context = context)
|
AboutSettings(context = context)
|
||||||
|
Developer_settings(context = context)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
package `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents
|
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
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.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedCard
|
|
||||||
import androidx.compose.material3.RadioButton
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import `in`.sminnovations.attendanceapp.R
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun RadioDialogue(
|
|
||||||
showDialog:Boolean,
|
|
||||||
listOptions:List<String>,
|
|
||||||
headText:String,
|
|
||||||
selectedOption:String,
|
|
||||||
onClose: () -> Unit,
|
|
||||||
gotOption:(String)->Unit
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (showDialog) {
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = { onClose() },
|
|
||||||
DialogProperties(
|
|
||||||
dismissOnBackPress = true,
|
|
||||||
dismissOnClickOutside = true,
|
|
||||||
usePlatformDefaultWidth = true
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
OutlinedCard(
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentSize()
|
|
||||||
.clickable { onClose() },
|
|
||||||
) {
|
|
||||||
BackHandler(onBack = onClose)
|
|
||||||
Box(
|
|
||||||
// modifier = Modifier
|
|
||||||
// .background(MaterialTheme.colorScheme.su)
|
|
||||||
) {
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
text = headText,
|
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.padding(20.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
LazyColumn(
|
|
||||||
modifier =
|
|
||||||
if (listOptions.size <=5) {
|
|
||||||
Modifier
|
|
||||||
.padding(20.dp, 20.dp, 20.dp, 0.dp)
|
|
||||||
.wrapContentSize()
|
|
||||||
}else {
|
|
||||||
Modifier
|
|
||||||
.padding(20.dp, 20.dp, 20.dp, 0.dp)
|
|
||||||
.height(400.dp)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
{
|
|
||||||
items(listOptions) { option ->
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
gotOption(option)
|
|
||||||
onClose()
|
|
||||||
},
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
RadioButtonComponent(value = selectedOption, onValueChange = {
|
|
||||||
gotOption(option)
|
|
||||||
onClose()
|
|
||||||
}, placeholder = option)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.height(10.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row {
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.cancel),
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(0.dp, 0.dp, 40.dp, 20.dp)
|
|
||||||
.clickable { onClose() },
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun RadioButtonComponent(value: String, onValueChange: (String) -> Unit, placeholder: String) {
|
|
||||||
RadioButton(
|
|
||||||
selected = value == placeholder,
|
|
||||||
onClick = { onValueChange(placeholder) }
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = placeholder,
|
|
||||||
modifier = Modifier.padding(start = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents.ClickableCard
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents.RadioDialogue
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun RadioCard(
|
|
||||||
title:String,
|
|
||||||
subtitle:String,
|
|
||||||
icon: ImageVector,
|
|
||||||
radioHeader:String,
|
|
||||||
gotOption:(String)->Unit,
|
|
||||||
listOptions:List<String>,
|
|
||||||
selectedOption:String
|
|
||||||
) {
|
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
|
||||||
ClickableCard(
|
|
||||||
title = title,
|
|
||||||
subtitle = subtitle,
|
|
||||||
onClick = {
|
|
||||||
showDialog = true
|
|
||||||
},
|
|
||||||
icon = icon
|
|
||||||
)
|
|
||||||
RadioDialogue(
|
|
||||||
showDialog = showDialog,
|
|
||||||
listOptions =listOptions,
|
|
||||||
headText =radioHeader ,
|
|
||||||
selectedOption = selectedOption,
|
|
||||||
onClose = { showDialog=false},
|
|
||||||
gotOption = gotOption
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package `in`.sminnovations.attendanceapp.screens.settings.ui.components.subSetting
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedCard
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.res.vectorResource
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import `in`.sminnovations.attendanceapp.R
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.data.SettingsData
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents.RadioCard
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.settings.ui.components.settingsComponents.SwitchCard
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Appearance (context: Context) {
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
val dataStore = SettingsData(context)
|
|
||||||
val dynamicColorsThemeValue = dataStore.getDynamicColorThemeValue.collectAsState(true)
|
|
||||||
val blackThemeValue = dataStore.getBlackThemeValue.collectAsState(initial = false)
|
|
||||||
val theme = dataStore.getThemeMode.collectAsState(initial = "System default")
|
|
||||||
Column(modifier = Modifier.padding(10.dp, 0.dp, 10.dp, 0.dp)) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.appearance),
|
|
||||||
style = MaterialTheme.typography.labelLarge,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.Start)
|
|
||||||
.padding(14.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
|
|
||||||
OutlinedCard{
|
|
||||||
RadioCard(
|
|
||||||
title = stringResource(R.string.theme),
|
|
||||||
subtitle =theme.value ,
|
|
||||||
icon = ImageVector.vectorResource(id = R.drawable.round_color_lens_24),
|
|
||||||
radioHeader = stringResource(R.string.select_theme_mode) ,
|
|
||||||
gotOption = {
|
|
||||||
scope.launch {
|
|
||||||
dataStore.saveThemeMode(it)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
listOptions = listOf("Light", "Dark", "System default"),
|
|
||||||
selectedOption =theme.value
|
|
||||||
)
|
|
||||||
|
|
||||||
SwitchCard(
|
|
||||||
checkedValue = dynamicColorsThemeValue.value!!,
|
|
||||||
title = stringResource(R.string.dynamic_theme),
|
|
||||||
subtitle = stringResource(R.string.theme_based_on_wallpaper_color),
|
|
||||||
onSwitchChange =
|
|
||||||
{
|
|
||||||
scope.launch {
|
|
||||||
dataStore.setDynamicColorThemeValue(it)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon = ImageVector.vectorResource(id = R.drawable.round_auto_mode_24)
|
|
||||||
)
|
|
||||||
SwitchCard(
|
|
||||||
checkedValue = blackThemeValue.value!!,
|
|
||||||
title = stringResource(R.string.black_theme),
|
|
||||||
subtitle = stringResource(R.string.black_theme_description),
|
|
||||||
onSwitchChange =
|
|
||||||
{
|
|
||||||
scope.launch {
|
|
||||||
dataStore.setBlackThemeValue(it)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon = ImageVector.vectorResource(id = R.drawable.round_contrast_24)
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@ fun Developer_settings(context: Context) {
|
|||||||
},
|
},
|
||||||
icon = ImageVector.vectorResource(R.drawable.round_developer_mode_24)
|
icon = ImageVector.vectorResource(R.drawable.round_developer_mode_24)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
ClickableCard(
|
ClickableCard(
|
||||||
title = "Clear the Database",
|
title = "Clear the Database",
|
||||||
@@ -63,14 +64,6 @@ fun Developer_settings(context: Context) {
|
|||||||
icon = ImageVector.vectorResource(R.drawable.round_delete_sweep_24)
|
icon = ImageVector.vectorResource(R.drawable.round_delete_sweep_24)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ClickableCard(
|
|
||||||
title = "Change the language",
|
|
||||||
subtitle = "Current language :English",
|
|
||||||
onClick = {
|
|
||||||
Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show()
|
|
||||||
},
|
|
||||||
icon = ImageVector.vectorResource(R.drawable.round_translate_24)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user