Refactored project for MVVM, added dagger hilt di, partially implemented room database for album-images relationship

This commit is contained in:
Anthony La committed 2023-08-11 10:29:32 -07:00
1 parent 0570efec53
commit 81a008f776
53 files changed
+678 -197

No files matched your search

@@ -1,8 +1,23 @@
package com.anthonyla.paperize.data.configuration
import android.graphics.Color
import android.graphics.Paint
import android.service.wallpaper.WallpaperService
import android.view.SurfaceHolder
class LiveWallpaperService : WallpaperService() {
override fun onCreateEngine(): Engine = WallpaperEngine()
inner class WallpaperEngine : WallpaperService.Engine() {}
inner class WallpaperEngine: WallpaperService.Engine() {
override fun onSurfaceCreated(holder: SurfaceHolder) {
val canvas = holder.lockCanvas()
val paint = Paint().apply {
color = Color.GRAY
style = Paint.Style.FILL
}
canvas.drawPaint(paint)
holder.unlockCanvasAndPost(canvas)
}
}
}
@@ -1,21 +0,0 @@
package com.anthonyla.paperize.data.navigation
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AddToPhotos
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.AddToPhotos
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import com.anthonyla.paperize.R
/**
* List of screens for the bottom navigation bar
*/
sealed class BottomNavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
object Wallpaper : BottomNavScreens("wallpaper", R.string.wallpaper, Icons.Outlined.Home, Icons.Filled.Home)
object Library : BottomNavScreens("library", R.string.library, Icons.Outlined.AddToPhotos, Icons.Filled.AddToPhotos)
object Configure : BottomNavScreens("configure", R.string.configure, Icons.Outlined.Settings, Icons.Filled.Settings)
}
@@ -1,26 +0,0 @@
package com.anthonyla.paperize.data.navigation
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import com.google.accompanist.navigation.animation.composable
import com.google.accompanist.navigation.animation.navigation
import com.anthonyla.paperize.ui.screens.Library.Library
import com.anthonyla.paperize.ui.screens.Configure
import com.anthonyla.paperize.ui.screens.Settings
import com.anthonyla.paperize.ui.screens.Wallpaper
/**
* The Nav graph builder links the routes for the different screens in the app
*/
@ExperimentalAnimationApi
fun NavGraphBuilder.navGraph(navController: NavController, modifier: Modifier = Modifier) {
navigation(startDestination = BottomNavScreens.Wallpaper.route, route = "bottomNavigation") {
composable(BottomNavScreens.Wallpaper.route) { Wallpaper(navController) }
composable(BottomNavScreens.Library.route) { Library(navController) }
composable(BottomNavScreens.Configure.route) { Configure(navController) }
composable(SettingsNavScreens.Settings.route) { Settings(navController) }
}
}
@@ -1,15 +0,0 @@
package com.anthonyla.paperize.data.navigation
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import com.anthonyla.paperize.R
/**
* List of screens for app settings
*/
sealed class SettingsNavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
object Settings : SettingsNavScreens("settings", R.string.settings, Icons.Outlined.Settings, Icons.Filled.Settings)
}
@@ -1,26 +0,0 @@
package com.anthonyla.paperize.data.settings
import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object SettingsAppModule {
@Singleton
@Provides
fun providesSettingsDataStore (
@ApplicationContext context: Context
): SettingsDataStore = SettingsDataStoreImpl(context)
@Provides
fun provideContext(
@ApplicationContext context: Context,
): Context {
return context
}
}
@@ -1,7 +0,0 @@
package com.anthonyla.paperize.data.settings
object SettingsConstants {
const val SETTINGS_DATASTORE = "settings_datastore"
const val DARK_MODE_TYPE = "dark_mode_type"
const val DYNAMIC_THEME_TYPE = "dynamic_theme_type"
}
@@ -7,7 +7,7 @@ import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.anthonyla.paperize.data.settings.SettingsConstants.SETTINGS_DATASTORE
import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE
import kotlinx.coroutines.flow.first
import javax.inject.Inject
@@ -1,57 +0,0 @@
package com.anthonyla.paperize.data.settings
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.lifecycle.ViewModel
import com.anthonyla.paperize.data.settings.SettingsConstants.DARK_MODE_TYPE
import com.anthonyla.paperize.data.settings.SettingsConstants.DYNAMIC_THEME_TYPE
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@HiltViewModel
class SettingsViewModel @Inject constructor (private val settingsDataStoreImpl: SettingsDataStoreImpl): ViewModel() {
fun setDarkMode(status: Boolean?) = runBlocking {
when (status) {
true -> { settingsDataStoreImpl.putBoolean(DARK_MODE_TYPE, true) }
false -> { settingsDataStoreImpl.putBoolean(DARK_MODE_TYPE, false) }
null -> { settingsDataStoreImpl.deleteBoolean(DARK_MODE_TYPE) }
}
}
private fun getDarkMode() = runBlocking {
return@runBlocking settingsDataStoreImpl.getBoolean(DARK_MODE_TYPE)
}
fun setDynamic (status: Boolean?) = runBlocking {
when (status) {
true -> { settingsDataStoreImpl.putBoolean(DYNAMIC_THEME_TYPE, true) }
false -> { settingsDataStoreImpl.putBoolean(DYNAMIC_THEME_TYPE, false) }
null -> { settingsDataStoreImpl.deleteBoolean(DYNAMIC_THEME_TYPE) }
}
}
private fun getDynamicTheme() = runBlocking {
return@runBlocking settingsDataStoreImpl.getBoolean(DYNAMIC_THEME_TYPE)
}
fun resetSettings() = runBlocking {
settingsDataStoreImpl.clearPreferences()
}
@Composable
fun isDarkMode(): Boolean {
return when (getDarkMode()) {
true -> true
false -> false
null -> isSystemInDarkTheme()
}
}
fun isDynamicTheming(): Boolean {
return when (getDynamicTheme()) {
true, null -> true
false -> false
}
}
}