-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added theme settings and updated library version
- Added a new `ThemeSettingsList` composable for managing app themes. - Implemented functionality to switch between "follow system", "dark mode", and "light mode" themes. - Added an option to enable or disable AMOLED mode. - Included a summary text to describe dark mode. - Updated the library version to 0.0.37. - Reformatted `PrivacySettingsProvider.kt`.
- Loading branch information
Mihai-Cristian Condrea
committed
Jan 25, 2025
1 parent
b8f46b2
commit 9362196
Showing
3 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...a/com/d4rk/android/libs/apptoolkit/ui/screens/settings/display/theme/ThemeSettingsList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.d4rk.android.libs.apptoolkit.ui.screens.settings.display.theme | ||
|
||
import android.content.Context | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Info | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.d4rk.android.libs.apptoolkit.R | ||
import com.d4rk.android.libs.apptoolkit.data.datastore.CommonDataStore | ||
import com.d4rk.android.libs.apptoolkit.ui.components.modifiers.bounceClick | ||
import com.d4rk.android.libs.apptoolkit.ui.components.preferences.SwitchCardComposable | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun ThemeSettingsList(paddingValues : PaddingValues) { | ||
val context : Context = LocalContext.current | ||
val dataStore : CommonDataStore = CommonDataStore.getInstance(context = context) | ||
val coroutineScope : CoroutineScope = rememberCoroutineScope() | ||
val themeMode : String = dataStore.themeMode.collectAsState(initial = "follow_system").value | ||
val isAmoledMode : State<Boolean> = dataStore.amoledMode.collectAsState(initial = false) | ||
|
||
val themeOptions : List<String> = listOf( | ||
stringResource(id = R.string.follow_system) , | ||
stringResource(id = R.string.dark_mode) , | ||
stringResource(id = R.string.light_mode) , | ||
) | ||
|
||
Box(modifier = Modifier.fillMaxSize()) { | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues = paddingValues) , | ||
) { | ||
item { | ||
SwitchCardComposable( | ||
title = stringResource(id = R.string.amoled_mode) , | ||
switchState = isAmoledMode | ||
) { isChecked -> | ||
coroutineScope.launch { | ||
dataStore.saveAmoledMode(isChecked = isChecked) | ||
} | ||
} | ||
} | ||
item { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(24.dp) | ||
) { | ||
themeOptions.forEach { text -> | ||
Row( | ||
Modifier.fillMaxWidth() , | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
RadioButton(modifier = Modifier.bounceClick() , | ||
selected = (text == themeMode) , | ||
onClick = { | ||
coroutineScope.launch { | ||
dataStore.saveThemeMode(mode = text) | ||
dataStore.themeModeState.value = text | ||
} | ||
}) | ||
Text( | ||
text = text , | ||
style = MaterialTheme.typography.bodyMedium.merge() , | ||
modifier = Modifier.padding(start = 16.dp) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
item { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(all = 24.dp) | ||
) { | ||
Icon(imageVector = Icons.Outlined.Info , contentDescription = null) | ||
Spacer(modifier = Modifier.height(height = 24.dp)) | ||
Text(text = stringResource(id = R.string.summary_dark_theme)) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters