-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aritra-tech/develop
Settings Screen
- Loading branch information
Showing
30 changed files
with
768 additions
and
16 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
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
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,19 @@ | ||
package com | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
|
||
internal lateinit var applicationContext: Context | ||
private set | ||
|
||
data object ContextProviderInitializer | ||
|
||
class ContextProvider : Initializer<ContextProviderInitializer> { | ||
override fun create(context: Context): ContextProviderInitializer { | ||
applicationContext = context.applicationContext | ||
return ContextProviderInitializer | ||
} | ||
|
||
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList() | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
composeApp/src/androidMain/kotlin/com/aritra/coinify/Coinify.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,11 @@ | ||
package com.aritra.coinify | ||
|
||
import android.app.Application | ||
import utils.ApplicationComponent | ||
|
||
class Coinify : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
ApplicationComponent.init() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
composeApp/src/androidMain/kotlin/data/datastore/DataStorePreferences.android.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,22 @@ | ||
package data.datastore | ||
|
||
import androidx.datastore.core.DataMigration | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler | ||
import androidx.datastore.preferences.core.Preferences | ||
import com.applicationContext | ||
import kotlinx.coroutines.CoroutineScope | ||
import java.io.File | ||
|
||
actual fun dataStorePreferences( | ||
corruptionHandler: ReplaceFileCorruptionHandler<Preferences>?, | ||
coroutineScope: CoroutineScope, | ||
migrations: List<DataMigration<Preferences>> | ||
): DataStore<Preferences> = createDataStoreWithDefaults( | ||
corruptionHandler = corruptionHandler, | ||
migrations = migrations, | ||
coroutineScope = coroutineScope, | ||
path = { | ||
File(applicationContext.filesDir, "datastore/$SETTINGS_PREFERENCES").path | ||
} | ||
) |
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
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
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,54 @@ | ||
package component | ||
|
||
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.material.Text | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun SettingItem( | ||
onClick: () -> Unit, | ||
imageVector: ImageVector, | ||
itemName: String, | ||
itemColor: Color = MaterialTheme.colorScheme.onSurface | ||
) { | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clickable { onClick() } | ||
.padding(16.dp), | ||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Image( | ||
modifier = Modifier.size(24.dp), | ||
imageVector = imageVector, | ||
contentDescription = null, | ||
colorFilter = ColorFilter.tint(color = itemColor) | ||
) | ||
Text( | ||
text = itemName, | ||
style = TextStyle( | ||
color = itemColor, | ||
fontSize = 16.sp, | ||
fontWeight = FontWeight.Normal | ||
) | ||
) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
composeApp/src/commonMain/kotlin/component/ThemeSelectionDialog.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,114 @@ | ||
package component | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
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.width | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.material3.AlertDialogDefaults | ||
import androidx.compose.material3.BasicAlertDialog | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.RadioButtonDefaults | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
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.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import utils.onClick | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun ThemeSelectionDialog( | ||
onThemeChange: (Theme) -> Unit, | ||
onDismissRequest: () -> Unit, | ||
currentTheme: Theme | ||
) { | ||
|
||
var currentSelectedTheme by remember { mutableStateOf(currentTheme) } | ||
|
||
BasicAlertDialog( | ||
onDismissRequest = onDismissRequest, | ||
content = { | ||
Surface( | ||
modifier = Modifier | ||
.wrapContentWidth() | ||
.wrapContentHeight(), | ||
shape = MaterialTheme.shapes.large, | ||
tonalElevation = AlertDialogDefaults.TonalElevation | ||
) { | ||
Column(modifier = Modifier.padding(16.dp)) { | ||
|
||
Text( | ||
text = "Choose a theme", | ||
style = TextStyle(fontSize = 20.sp), | ||
modifier = Modifier.padding(8.dp) | ||
) | ||
|
||
Row( | ||
modifier = Modifier.fillMaxWidth().onClick { currentSelectedTheme = Theme.Light }, | ||
horizontalArrangement = Arrangement.Start, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
RadioButton( | ||
selected = currentSelectedTheme == Theme.Light, | ||
onClick = { currentSelectedTheme = Theme.Light}, | ||
colors = RadioButtonDefaults.colors( | ||
selectedColor = MaterialTheme.colorScheme.primary | ||
) | ||
) | ||
Text(text = "Light Mode") | ||
} | ||
|
||
Row( | ||
modifier = Modifier.fillMaxWidth().onClick { currentSelectedTheme = Theme.Dark }, | ||
horizontalArrangement = Arrangement.Start, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
RadioButton( | ||
selected = currentSelectedTheme == Theme.Dark, | ||
onClick = { currentSelectedTheme = Theme.Dark }, | ||
colors = RadioButtonDefaults.colors( | ||
selectedColor = MaterialTheme.colorScheme.primary | ||
) | ||
) | ||
Text(text = "Dark Mode") | ||
} | ||
|
||
Spacer(modifier = Modifier.height(24.dp)) | ||
|
||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.End | ||
) { | ||
TextButton(onClick = onDismissRequest) { | ||
Text(text = "Cancel") | ||
} | ||
Spacer(modifier = Modifier.width(16.dp)) | ||
TextButton(onClick = { onThemeChange(currentSelectedTheme) }) { | ||
Text(text = "Apply") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
enum class Theme { | ||
Light, Dark | ||
} |
35 changes: 35 additions & 0 deletions
35
composeApp/src/commonMain/kotlin/data/datastore/DataStorePreferences.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,35 @@ | ||
package data.datastore | ||
|
||
import androidx.datastore.core.DataMigration | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.IO | ||
import kotlinx.coroutines.SupervisorJob | ||
import okio.Path.Companion.toPath | ||
|
||
expect fun dataStorePreferences( | ||
corruptionHandler: ReplaceFileCorruptionHandler<Preferences>?, | ||
coroutineScope: CoroutineScope, | ||
migrations: List<DataMigration<Preferences>>, | ||
): DataStore<Preferences> | ||
|
||
internal const val SETTINGS_PREFERENCES = "settings_preferences.preferences_pb" | ||
|
||
internal fun createDataStoreWithDefaults( | ||
corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null, | ||
coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()), | ||
migrations: List<DataMigration<Preferences>> = emptyList(), | ||
path: () -> String, | ||
) = PreferenceDataStoreFactory | ||
.createWithPath( | ||
corruptionHandler = corruptionHandler, | ||
scope = coroutineScope, | ||
migrations = migrations, | ||
produceFile = { | ||
path().toPath() | ||
} | ||
) |
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package di | ||
|
||
import domain.repository.ListingRepository | ||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.dsl.module | ||
import presentation.home.HomeViewModel | ||
import presentation.HomeViewModel | ||
import presentation.SettingsViewModel | ||
import utils.ThemeViewModel | ||
import utils.coreComponent | ||
import utils.viewModelDefinition | ||
|
||
val appModule = module { | ||
single { | ||
ListingRepository() | ||
} | ||
viewModelDefinition { HomeViewModel(get()) } | ||
|
||
single { ListingRepository() } | ||
single { coreComponent.appPreferences } | ||
|
||
viewModelDefinition { HomeViewModel(get()) } | ||
viewModelDefinition { SettingsViewModel(get()) } | ||
viewModelDefinition { ThemeViewModel(get()) } | ||
} |
12 changes: 12 additions & 0 deletions
12
composeApp/src/commonMain/kotlin/navigation/BottomNavScreens.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,12 @@ | ||
package navigation | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Home | ||
import androidx.compose.material.icons.filled.Newspaper | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
|
||
sealed class BottomNavScreens(val route: String, val icon: ImageVector, val title: String) { | ||
object Home: BottomNavScreens(Screens.Home.route, Icons.Default.Home,"Home") | ||
object News: BottomNavScreens(Screens.Settings.route, Icons.Default.Settings, "Settings") | ||
} |
Oops, something went wrong.