Skip to content

Commit

Permalink
feat: Added theme settings and updated library version
Browse files Browse the repository at this point in the history
- 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
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apptoolkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {

// Google
api(dependencyNotation = libs.play.services.ads)
api(libs.material)
api(dependencyNotation = libs.material)

// Images
api(dependencyNotation = libs.coil.compose)
Expand Down Expand Up @@ -101,7 +101,7 @@ publishing {
register<MavenPublication>("release") {
groupId = "com.github.D4rK7355608"
artifactId = "AppToolkit"
version = "0.0.36"
version = "0.0.37"

afterEvaluate {
from(components["release"])
Expand Down
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))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fun PrivacySettingsList(
PreferenceItem(title = stringResource(id = R.string.license) , summary = stringResource(id = R.string.summary_preference_settings_license) , onClick = { IntentsHelper.openUrl(context , provider.licenseUrl) })
}
}
}
}

0 comments on commit 9362196

Please sign in to comment.