Skip to content

Commit

Permalink
feat(architecture): basic clean architecture setup (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kikin81 authored May 17, 2024
1 parent 5820b18 commit c92616b
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.material3)
lintChecks(libs.slack.compose.lint)
testImplementation(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package us.kikin.android.gamingbacklog.data.manager

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager
import us.kikin.android.gamingbacklog.utils.Constants
import us.kikin.android.gamingbacklog.utils.Constants.USER_SETTINGS


class LocalUserManagerImpl(
private val context: Context
) : LocalUserManager {

override suspend fun saveAppEntry() {
context.dataStore.edit { settings ->
settings[PreferencesKeys.APP_ENTRY] = true
}
}

override fun readAppEntry(): Flow<Boolean> {
return context.dataStore.data.map { settings ->
settings[PreferencesKeys.APP_ENTRY] ?: false
}
}
}

private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = USER_SETTINGS)

private object PreferencesKeys {
val APP_ENTRY = booleanPreferencesKey(name = Constants.APP_ENTRY)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package us.kikin.android.gamingbacklog.domain.manager

import kotlinx.coroutines.flow.Flow

interface LocalUserManager {

suspend fun saveAppEntry()

fun readAppEntry(): Flow<Boolean>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package us.kikin.android.gamingbacklog.domain.usecase

import kotlinx.coroutines.flow.Flow
import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager

class ReadAppEntry(
private val localUserManager: LocalUserManager
) {

suspend operator fun invoke(): Flow<Boolean> =
localUserManager.readAppEntry()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package us.kikin.android.gamingbacklog.domain.usecase

import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager

class SaveAppEntry(
private val localUserManager: LocalUserManager
) {

suspend operator fun invoke() {
localUserManager.saveAppEntry()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import us.kikin.android.gamingbacklog.ui.theme.AppTheme

@Composable
fun PageIndicator(
pageSize: Int,
selectedPage: Int,
modifier: Modifier = Modifier,
selectedColor: Color = MaterialTheme.colorScheme.primary,
unselectedColor: Color = Color.Blue
unselectedColor: Color = MaterialTheme.colorScheme.secondary
) {
Row(
modifier = modifier,
Expand All @@ -37,3 +39,11 @@ fun PageIndicator(
}
}
}

@Composable
@Preview(showBackground = true)
internal fun PageIndicatorPreview() {
AppTheme {
PageIndicator(pageSize = 4, selectedPage = 2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package us.kikin.android.gamingbacklog.utils

object Constants {
const val USER_SETTINGS: String = "user_settings"
const val APP_ENTRY: String = "app_entry"
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
slack-compose-lint = { group = "com.slack.lint.compose", name = "compose-lint-checks", version = "1.3.1" }
androidx-ui-text-google-fonts = { group = "androidx.compose.ui", name = "ui-text-google-fonts", version = "1.6.7" }
androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version = "1.0.1" }
androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version = "1.1.1" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down

0 comments on commit c92616b

Please sign in to comment.