Updated project to latest versions and added functionality of wallpaper screen selection album and transition between home and settings page

This commit is contained in:
Anthonyy232 committed 2024-04-06 17:39:46 -07:00
1 parent d6c149ab8c
commit 253cf23b69
44 files changed
+962 -460

No files matched your search

+18 -12
View File
@@ -1,17 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="RFCTA1MRS4H" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-10-07T02:33:59.796363300Z" />
<value>
<entry key="Paperize">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="RFCTA1MRS4H" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-04-04T19:54:45.940456200Z" />
</State>
</entry>
</value>
</component>
</project>
-2
View File
@@ -4,8 +4,6 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
+27 -27
View File
@@ -58,37 +58,37 @@ androidComponents {
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0-alpha03")
implementation("androidx.activity:activity-compose:1.8.0")
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.ui:ui:1.6.0-alpha08")
implementation("androidx.compose.ui:ui-graphics:1.6.0-alpha08")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.0-alpha08")
implementation("androidx.compose.material3:material3:1.2.0-alpha10")
implementation("androidx.navigation:navigation-compose:2.7.4")
implementation("androidx.compose.material:material:1.6.0-alpha08")
implementation("androidx.datastore:datastore:1.1.0-alpha05")
implementation("androidx.datastore:datastore-preferences:1.1.0-alpha05")
implementation("androidx.compose.material:material-icons-extended:1.6.0-alpha08")
implementation("com.google.accompanist:accompanist-adaptive:0.33.2-alpha")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0-rc01")
implementation("androidx.compose.animation:animation:1.6.0-alpha08")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2024.03.00"))
implementation("androidx.compose.ui:ui:1.6.4")
implementation("androidx.compose.ui:ui-graphics:1.6.4")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.4")
implementation("androidx.compose.material3:material3:1.2.1")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.compose.material:material:1.6.4")
implementation("androidx.datastore:datastore:1.1.0-beta02")
implementation("androidx.datastore:datastore-preferences:1.1.0-beta02")
implementation("androidx.compose.material:material-icons-extended:1.6.4")
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
implementation("androidx.compose.animation:animation:1.6.4")
implementation("androidx.core:core-splashscreen:1.1.0-alpha02")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0-alpha03")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
implementation("net.engawapg.lib:zoomable:1.6.0-beta1")
implementation("com.github.skydoves:landscapist-glide:2.2.11")
implementation("net.engawapg.lib:zoomable:1.6.1")
implementation("com.github.skydoves:landscapist-glide:2.3.2")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-alpha01")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.0-alpha08")
debugImplementation("androidx.compose.ui:ui-tooling:1.6.0-alpha08")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.0-alpha08")
implementation("com.google.dagger:hilt-android:2.48.1")
ksp("com.google.dagger:hilt-android-compiler:2.48.1")
implementation("androidx.room:room-runtime:2.6.0")
ksp("androidx.room:room-compiler:2.6.0")
implementation("androidx.room:room-ktx:2.6.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-alpha03")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.4")
debugImplementation("androidx.compose.ui:ui-tooling:1.6.4")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.4")
implementation("com.google.dagger:hilt-android:2.51.1")
ksp("com.google.dagger:hilt-android-compiler:2.51.1")
implementation("androidx.room:room-runtime:2.6.1")
ksp("androidx.room:room-compiler:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
implementation("com.lazygeniouz:dfc:1.0.8")
}
+2 -2
View File
@@ -5,7 +5,7 @@
<uses-feature
android:name="android.software.paperize"
android:required="true" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<application
android:allowBackup="true"
android:name=".App"
@@ -31,7 +31,7 @@
</activity>
<service
android:name=".data.configuration.LiveWallpaperService"
android:name=".data.configuration.PaperizeWallpaperService"
android:enabled="true"
android:permission="android.permission.BIND_WALLPAPER"
android:exported="true">
@@ -8,11 +8,11 @@ import androidx.core.content.ContextCompat.startActivity
@Composable
fun Contact(context: Context) {
val email = "anthonyyla.dev@gmail.com"
val authorEmail = "anthonyyla.dev@gmail.com"
val cc = ""
val subject = "[Contact] Paperize - A Wallpaper Changer"
val bodyText = "This is regarding the Paperize app for Android:\n"
val mailto = "mailto:" + Uri.encode(email) +
val mailto = "mailto:" + Uri.encode(authorEmail) +
"?cc=" + Uri.encode(cc) +
"&subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(bodyText)
@@ -1,23 +0,0 @@
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() {
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)
}
}
}
@@ -6,8 +6,11 @@ import androidx.room.Room
import com.anthonyla.paperize.data.settings.SettingsDataStore
import com.anthonyla.paperize.data.settings.SettingsDataStoreImpl
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDatabase
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDatabase
import com.anthonyla.paperize.feature.wallpaper.data.repository.AlbumRepositoryImpl
import com.anthonyla.paperize.feature.wallpaper.data.repository.SelectedAlbumRepositoryImpl
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -28,6 +31,20 @@ object AppModule {
).build()
}
@Provides
@Singleton
fun provideSelectedAlbumDatabase(app: Application): SelectedAlbumDatabase {
return Room.databaseBuilder(
app,
SelectedAlbumDatabase::class.java,
SelectedAlbumDatabase.DATABASE_NAME
).build()
}
@Provides
@Singleton
fun provideAlbumDao(db: AlbumDatabase) = db.albumDao
@Provides
@Singleton
fun provideAlbumRepository(
@@ -36,6 +53,18 @@ object AppModule {
return AlbumRepositoryImpl(db.albumDao)
}
@Provides
@Singleton
fun provideSelectedAlbumDao(db: SelectedAlbumDatabase) = db.selectedAlbumDao
@Provides
@Singleton
fun provideSelectedAlbumRepository(
db: SelectedAlbumDatabase
): SelectedAlbumRepository {
return SelectedAlbumRepositoryImpl(db.selectedAlbumDao)
}
@Provides
@Singleton
fun provideSettingsDataStore (
@@ -7,9 +7,8 @@ import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import androidx.room.Upsert
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import kotlinx.coroutines.flow.Flow
@@ -19,7 +18,7 @@ interface AlbumDao {
@Transaction
@Query("SELECT * FROM album")
fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>>
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsertAlbum(album: Album)
@@ -1,14 +1,14 @@
package com.anthonyla.paperize.feature.wallpaper.data.data_source
import androidx.room.TypeConverter
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
class Converters {
@TypeConverter
fun listToJsonString(value: List<String>?): String = Gson().toJson(value)
private val gson = Gson()
@TypeConverter
fun jsonStringToList(value: String) = Gson().fromJson(value, Array<String>::class.java).toList()
fun listToJsonString(value: List<String>?): String = gson.toJson(value)
@TypeConverter
fun jsonStringToList(value: String) = gson.fromJson(value, Array<String>::class.java).toList()
}
@@ -0,0 +1,53 @@
package com.anthonyla.paperize.feature.wallpaper.data.data_source
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import kotlinx.coroutines.flow.Flow
@Dao
interface SelectedAlbumDao {
@Transaction
@Query("SELECT * FROM album")
fun getSelectedAlbum(): Flow<List<SelectedAlbum>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsertAlbum(album: Album)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsertWallpaper(wallpaper: Wallpaper)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
@Delete
suspend fun deleteAlbum(album: Album)
@Delete
suspend fun deleteWallpaper(wallpaper: Wallpaper)
@Query("DELETE FROM wallpaper WHERE initialAlbumName=:initialAlbumName")
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
@Query("DELETE FROM album")
suspend fun deleteAllAlbums()
@Query("DELETE FROM wallpaper")
suspend fun deleteAllWallpapers()
@Update
suspend fun updateAlbum(album: Album)
@Transaction
suspend fun deleteAll() {
deleteAllAlbums()
deleteAllWallpapers()
}
}
@@ -0,0 +1,19 @@
package com.anthonyla.paperize.feature.wallpaper.data.data_source
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
@Database(
entities = [Album::class, Wallpaper::class],
version = 1
)
@TypeConverters(Converters::class)
abstract class SelectedAlbumDatabase: RoomDatabase() {
abstract val selectedAlbumDao: SelectedAlbumDao
companion object {
const val DATABASE_NAME = "paperize_selectedAlbum_db"
}
}
@@ -2,7 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.data.repository
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDao
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
@@ -11,14 +11,14 @@ import kotlinx.coroutines.flow.Flow
class AlbumRepositoryImpl(
private val dao: AlbumDao
): AlbumRepository {
override fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>> {
return dao.getAlbumsWithWallpapers()
override fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>> {
return dao.getAlbumsWithWallpaperAndFolder()
}
override suspend fun upsertAlbumWithWallpapers(albumWithWallpaper: AlbumWithWallpaper) {
dao.upsertAlbum(albumWithWallpaper.album)
dao.upsertWallpaperList(albumWithWallpaper.wallpapers)
dao.upsertFolderList(albumWithWallpaper.folders)
override suspend fun upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder) {
dao.upsertAlbum(albumWithWallpaperAndFolder.album)
dao.upsertWallpaperList(albumWithWallpaperAndFolder.wallpapers)
dao.upsertFolderList(albumWithWallpaperAndFolder.folders)
}
override suspend fun upsertAlbum(album: Album) {
@@ -0,0 +1,54 @@
package com.anthonyla.paperize.feature.wallpaper.data.repository
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDao
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
import kotlinx.coroutines.flow.Flow
class SelectedAlbumRepositoryImpl(
private val dao: SelectedAlbumDao
): SelectedAlbumRepository {
override fun getSelectedAlbum(): Flow<List<SelectedAlbum>> {
return dao.getSelectedAlbum()
}
override suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
dao.upsertAlbum(selectedAlbum.album)
dao.upsertWallpaperList(selectedAlbum.wallpapers)
}
override suspend fun upsertAlbum(album: Album) {
dao.upsertAlbum(album)
}
override suspend fun upsertWallpaper(wallpaper: Wallpaper) {
dao.upsertWallpaper(wallpaper)
}
override suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>) {
dao.upsertWallpaperList(wallpapers)
}
override suspend fun updateAlbum(album: Album) {
dao.updateAlbum(album)
}
override suspend fun deleteAlbum(album: Album) {
dao.deleteAlbum(album)
}
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
dao.deleteWallpaper(wallpaper)
}
override suspend fun cascadeDeleteWallpaper(initialAlbumName: String) {
dao.cascadeDeleteWallpaper(initialAlbumName)
}
override suspend fun deleteAll() {
dao.deleteAll()
}
}
@@ -3,7 +3,7 @@ package com.anthonyla.paperize.feature.wallpaper.domain.model
import androidx.room.Embedded
import androidx.room.Relation
data class AlbumWithWallpaper(
data class AlbumWithWallpaperAndFolder(
@Embedded val album: Album,
@Relation(
parentColumn = "initialAlbumName",
@@ -0,0 +1,13 @@
package com.anthonyla.paperize.feature.wallpaper.domain.model
import androidx.room.Embedded
import androidx.room.Relation
data class SelectedAlbum(
@Embedded val album: Album,
@Relation(
parentColumn = "initialAlbumName",
entityColumn = "initialAlbumName",
)
val wallpapers: List<Wallpaper> = emptyList(),
)
@@ -1,14 +1,14 @@
package com.anthonyla.paperize.feature.wallpaper.domain.repository
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import kotlinx.coroutines.flow.Flow
interface AlbumRepository {
fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>>
suspend fun upsertAlbumWithWallpapers(albumWithWallpaper: AlbumWithWallpaper)
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
suspend fun upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder)
suspend fun upsertAlbum(album: Album)
suspend fun deleteAlbum(album: Album)
suspend fun updateAlbum(album: Album)
@@ -0,0 +1,21 @@
package com.anthonyla.paperize.feature.wallpaper.domain.repository
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import kotlinx.coroutines.flow.Flow
interface SelectedAlbumRepository {
fun getSelectedAlbum(): Flow<List<SelectedAlbum>>
suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum)
suspend fun upsertAlbum(album: Album)
suspend fun updateAlbum(album: Album)
suspend fun deleteAlbum(album: Album)
suspend fun upsertWallpaper(wallpaper: Wallpaper)
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
suspend fun deleteWallpaper(wallpaper: Wallpaper)
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
suspend fun deleteAll()
}
@@ -1,5 +1,4 @@
package com.anthonyla.paperize.feature.wallpaper.presentation
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@@ -19,25 +18,26 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val albumsViewModel: AlbumsViewModel by viewModels()
private val settingsViewModel: SettingsViewModel by viewModels()
private val wallpaperScreenViewModel: WallpaperScreenViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
splashScreen.setKeepOnScreenCondition {
settingsViewModel.shouldNotBypassSplashScreen || albumsViewModel.shouldNotBypassSplashScreen
settingsViewModel.shouldNotBypassSplashScreen
|| albumsViewModel.shouldNotBypassSplashScreen
|| wallpaperScreenViewModel.shouldNotBypassSplashScreen
}
setContent {
enableEdgeToEdge()
@@ -45,11 +45,12 @@ class MainActivity : ComponentActivity() {
LaunchedEffect(lifecycleEvent) {
if (lifecycleEvent == Lifecycle.Event.ON_RESUME) {
albumsViewModel.onEvent(AlbumsEvent.RefreshAlbums)
wallpaperScreenViewModel.onEvent(WallpaperEvent.Refresh)
}
}
PaperizeTheme(settingsViewModel.state) {
Surface(tonalElevation = 5.dp) {
PaperizeApp(albumsViewModel, settingsViewModel)
PaperizeApp(albumsViewModel, settingsViewModel, wallpaperScreenViewModel)
}
}
}
@@ -1,18 +1,23 @@
package com.anthonyla.paperize.feature.wallpaper.presentation
import androidx.compose.animation.core.EaseInElastic
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
@@ -30,6 +35,8 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.Set
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen.WallpaperViewScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavScreens
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
@@ -41,19 +48,46 @@ import java.nio.charset.StandardCharsets
@Composable
fun PaperizeApp(
albumsViewModel: AlbumsViewModel,
settingsViewModel: SettingsViewModel
settingsViewModel: SettingsViewModel,
wallpaperScreenViewModel: WallpaperScreenViewModel
) {
val state = albumsViewModel.state.collectAsStateWithLifecycle()
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
/**
* React to albumState changes and change selectedAlbum's details to keep it from being stale
*/
LaunchedEffect(albumState.value.albumsWithWallpapers) {
selectedState.value.selectedAlbum?.let { selectedAlbum ->
albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
?.let { foundAlbum -> wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(foundAlbum)) }
?: wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
}
}
val navController = rememberNavController()
/**
* Contact author popup with email
*/
var toContact by rememberSaveable { mutableStateOf(false) }
if (toContact) { Contact(LocalContext.current) }
if (toContact) {
Contact(LocalContext.current)
toContact = false
}
NavHost(
navController = navController,
startDestination = NavScreens.Home.route,
modifier = Modifier.navigationBarsPadding()
) {
composable(route = NavScreens.Home.route) {
// Navigate to the home screen with the navbar and top bar
composable(
route = NavScreens.Home.route,
exitTransition = {
slideOutHorizontally(targetOffsetX = { fullWidth -> -fullWidth })
}
) {
HomeScreen(
onSettingsClick = { navController.navigate(NavScreens.Settings.route) },
onContactClick = { toContact = true },
@@ -65,21 +99,10 @@ fun PaperizeApp(
}
)
}
// Navigate to the add album screen to create a new album and add wallpapers to it
composable(
route = NavScreens.AddEdit.route.plus("/{initialAlbumName}"),
arguments = listOf(navArgument("initialAlbumName") { type = NavType.StringType }),
enterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
exitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
},
popEnterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
popExitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
}
arguments = listOf(navArgument("initialAlbumName") { type = NavType.StringType })
) {backStackEntry ->
backStackEntry.arguments?.getString("initialAlbumName").let {
if (it != null) {
@@ -100,21 +123,10 @@ fun PaperizeApp(
}
}
}
// Navigate to wallpaper view screen to view individual wallpapers in full screen
composable(
route = NavScreens.WallpaperView.route.plus("/{wallpaperUri}"),
arguments = listOf(navArgument("wallpaperUri") { type = NavType.StringType }),
enterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
exitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
},
popEnterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
popExitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
}
arguments = listOf(navArgument("wallpaperUri") { type = NavType.StringType })
) { backStackEntry ->
backStackEntry.arguments?.getString("wallpaperUri").let { wallpaper ->
if (wallpaper != null) {
@@ -125,25 +137,14 @@ fun PaperizeApp(
}
}
}
// Navigate to folder view screen to view wallpapers in a particular folder
composable(
route = NavScreens.FolderView.route.plus("/{folderUri}/{folderName}/{wallpapers}"),
arguments = listOf(
navArgument("folderUri") { type = NavType.StringType },
navArgument("folderName") { type = NavType.StringType },
navArgument("wallpapers") { type = NavType.StringType }
),
enterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
exitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
},
popEnterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
popExitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
}
)
) { backStackEntry ->
val folderUri = backStackEntry.arguments?.getString("folderUri")
val folderName = backStackEntry.arguments?.getString("folderName")
@@ -151,7 +152,6 @@ fun PaperizeApp(
backStackEntry.arguments?.getString("wallpapers"),
Array<String>::class.java
).toList()
if (folderUri != null) {
FolderViewScreen(
folder = folderUri,
@@ -165,30 +165,19 @@ fun PaperizeApp(
)
}
}
// Navigate to the album view screen to view folders and wallpapers in an album
composable(
route = NavScreens.AlbumView.route.plus("/{initialAlbumName}"),
arguments = listOf(
navArgument("initialAlbumName") { type = NavType.StringType },
),
enterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
exitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
},
popEnterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
},
popExitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
}
)
) { backStackEntry ->
val initialAlbumName = backStackEntry.arguments?.getString("initialAlbumName")
val albumWithWallpaper = state.value.albumWithWallpapers.find { it.album.initialAlbumName == initialAlbumName }
val albumWithWallpaper = albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == initialAlbumName }
if (initialAlbumName != null) {
if (albumWithWallpaper != null) {
AlbumViewScreen(
albumWithWallpaper = albumWithWallpaper,
album = albumWithWallpaper,
onBackClick = { navController.navigateUp() },
onShowWallpaperView = { wallpaper ->
val encodedWallpaper = runBlocking { encodeUri(uri = wallpaper) }
@@ -207,25 +196,38 @@ fun PaperizeApp(
albumsViewModel.onEvent(AlbumsEvent.ChangeAlbumName(title, originalAlbumWithWallpaper))
},
onSelectionDeleted = {
albumsViewModel.onEvent(AlbumsEvent.RefreshAlbumCoverUri(albumWithWallpaper))
albumsViewModel.onEvent(AlbumsEvent.RefreshAlbums)
}
)
}
}
}
// Navigate to the settings screen to change app settings
composable(
route = NavScreens.Settings.route,
enterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
slideInHorizontally(
// Enter by sliding in from offset +fullWidth to 0.
initialOffsetX = { fullWidth -> fullWidth },
)
},
exitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
slideOutHorizontally(
// Exit by sliding out from offset 0 to +fullWidth.
targetOffsetX = { fullWidth -> fullWidth },
)
},
popEnterTransition = {
fadeIn(animationSpec = tween(300, easing = LinearEasing))
slideInHorizontally(
// Pop Enter by sliding in from offset +fullWidth to 0.
initialOffsetX = { fullWidth -> fullWidth },
)
},
popExitTransition = {
fadeOut(animationSpec = tween(300, easing = LinearEasing))
slideOutHorizontally(
// Pop Exit by sliding out from offset 0 to +fullWidth.
targetOffsetX = { fullWidth -> fullWidth },
)
}
) {
SettingsScreen(
@@ -242,6 +244,7 @@ fun PaperizeApp(
}
}
// Encode an URI so it can be passed with navigation
suspend fun encodeUri(uri: String): String =
withContext(Dispatchers.IO) {
URLEncoder.encode(uri, StandardCharsets.UTF_8.toString())
@@ -1,7 +1,5 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
import androidx.compose.runtime.mutableStateListOf
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
@@ -8,7 +8,7 @@ import androidx.core.net.toUri
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
@@ -48,7 +48,7 @@ class AddAlbumViewModel @Inject constructor(
}
}
}
val albumWithWallpaper = AlbumWithWallpaper(
val albumWithWallpaperAndFolder = AlbumWithWallpaperAndFolder(
album = Album(
initialAlbumName = _state.value.initialAlbumName,
displayedAlbumName = _state.value.displayedAlbumName,
@@ -57,7 +57,7 @@ class AddAlbumViewModel @Inject constructor(
wallpapers = _state.value.wallpapers,
folders = _state.value.folders
)
repository.upsertAlbumWithWallpapers(albumWithWallpaper)
repository.upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder)
//Clear viewModel state after adding album
_state.update { it.copy(
@@ -1,19 +1,15 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
sealed class AlbumsEvent {
data object RefreshAlbums: AlbumsEvent()
data class DeleteAlbumWithWallpapers(
val albumWithWallpaper: AlbumWithWallpaper
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
): AlbumsEvent()
data class ChangeAlbumName(
val title: String,
val albumWithWallpaper: AlbumWithWallpaper
): AlbumsEvent()
data class RefreshAlbumCoverUri(
val albumWithWallpaper: AlbumWithWallpaper
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
): AlbumsEvent()
}
@@ -1,9 +1,7 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
data class AlbumsState (
val albumWithWallpapers: List<AlbumWithWallpaper> = emptyList(),
val loaded: Boolean = false
)
val albumsWithWallpapers: List<AlbumWithWallpaperAndFolder> = emptyList()
)
@@ -10,16 +10,14 @@ import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.anthonyla.paperize.core.SettingsConstants
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
import com.lazygeniouz.dfc.file.DocumentFileCompat
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
@@ -52,15 +50,14 @@ class AlbumsViewModel @Inject constructor (
when (event) {
is AlbumsEvent.DeleteAlbumWithWallpapers -> {
viewModelScope.launch {
repository.cascadeDeleteAlbum(event.albumWithWallpaper.album)
refreshAlbums()
repository.cascadeDeleteAlbum(event.albumWithWallpaperAndFolder.album)
}
}
is AlbumsEvent.ChangeAlbumName -> {
viewModelScope.launch {
if (!(_state.value.albumWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
if (!(_state.value.albumsWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
repository.updateAlbum(
event.albumWithWallpaper.album.copy(displayedAlbumName = event.title)
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
)
}
}
@@ -71,79 +68,75 @@ class AlbumsViewModel @Inject constructor (
refreshAlbums()
}
}
is AlbumsEvent.RefreshAlbumCoverUri -> {
viewModelScope.launch {
event.albumWithWallpaper.let { album ->
if (!album.wallpapers.any { it.wallpaperUri == album.album.coverUri }) {
repository.updateAlbum(album.album.copy(
coverUri = null
))
}
}
updateAlbums()
refreshAlbums()
}
}
}
}
// Verify and remove stale data in Room database
/**
* Verify and remove stale data in Room database
*/
private fun updateAlbums() {
viewModelScope.launch {
val albumWithWallpapers = repository.getAlbumsWithWallpapers().first()
var albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
albumWithWallpapers.forEach { albumWithWallpaper ->
if (albumWithWallpaper.album.coverUri != null) {
val albumCoverFile = DocumentFile.fromSingleUri(context, albumWithWallpaper.album.coverUri.toUri())
if (albumCoverFile == null || !albumCoverFile.exists()) {
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = null))
}
}
// Delete wallpaper if the URI is invalid
albumWithWallpaper.wallpapers.forEach { wallpaper ->
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
if (file == null || !file.exists()) { repository.deleteWallpaper(wallpaper) }
file?.exists() == true
}
if (invalidWallpapers.isNotEmpty()) {
repository.deleteWallpaperList(invalidWallpapers)
}
// Update folder cover uri and children uri
albumWithWallpaper.folders.forEach { folder ->
val folderDirectory = DocumentFile.fromTreeUri(context, folder.folderUri.toUri())
if (folderDirectory == null || !folderDirectory.isDirectory) {
repository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCover: String?
if (folder.coverUri != null) {
val folderCoverFile = DocumentFile.fromSingleUri(context, folder.coverUri.toUri())
if (folderCoverFile == null || !folderCoverFile.exists()) {
folderCover = folder.wallpapers.randomOrNull()
} else { folderCover = folder.coverUri }
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
if (!folderDirectory.isDirectory) {
repository.deleteFolder(folder)
} else {
folderCover = wallpapers.randomOrNull()
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
}
}
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
albumWithWallpapers.forEach { albumWithWallpaper ->
// Update album cover uri if null or invalid
val albumCoverFile = albumWithWallpaper.album.coverUri?.toUri()?.let { DocumentFile.fromSingleUri(context, it) }
if (albumCoverFile == null || !albumCoverFile.exists()) {
val newCoverUri = findFirstValidUri(albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
}
}
}
}
// Retrieve albums from database into viewModel
/**
* Retrieve albums from database into viewModel
*/
private fun refreshAlbums() {
viewModelScope.launch {
repository.getAlbumsWithWallpapers().collect { albumWithWallpapers ->
repository.getAlbumsWithWallpaperAndFolder().collect { albumWithWallpapers ->
_state.update { it.copy(
albumWithWallpapers = albumWithWallpapers,
loaded = true
albumsWithWallpapers = albumWithWallpapers
) }
}
}
}
/**
* Retrieve wallpaper URIs from a folder directory URI
*/
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
return listFilesRecursive(folderDocumentFile, context)
}
/**
* Helper function to recursively list files in a directory
*/
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
val files = mutableListOf<String>()
parent?.listFiles()?.forEach { file ->
@@ -159,5 +152,27 @@ class AlbumsViewModel @Inject constructor (
}
return files
}
/**
* Helper function to find the first valid URI from a list of wallpapers
* It will search through all wallpapers of an album first, and then all wallpapers of every folder of an album
*/
private fun findFirstValidUri(wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
wallpapers.forEach { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
if (file?.exists() == true) {
return wallpaper.wallpaperUri
}
}
folders.forEach { folder ->
folder.wallpapers.forEach { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
if (file?.exists() == true) {
return wallpaper
}
}
}
return null
}
}
@@ -1,6 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
import androidx.compose.foundation.BorderStroke
import android.graphics.Bitmap
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -12,11 +12,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -32,65 +29,57 @@ import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlbumItem(
album: Album,
onAlbumViewClick: () -> Unit,
modifier: Modifier = Modifier
) {
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
Card(
elevation = CardDefaults.cardElevation(5.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
modifier = modifier
.fillMaxSize()
.clip(RoundedCornerShape(16.dp)),
shape = RoundedCornerShape(16.dp),
border = BorderStroke(1.dp, bgColor),
onClick = onAlbumViewClick
) {
Surface(
modifier = Modifier.fillMaxSize(),
tonalElevation = 10.dp,
Column(
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Column(
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Box {
GlideImage(
imageModel = { album.coverUri },
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
)
}
Spacer(modifier = Modifier.padding(6.dp))
Text(
text = album.displayedAlbumName,
Box {
GlideImage(
imageModel = { album.coverUri },
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 16.sp
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
)
Spacer(modifier = Modifier.padding(8.dp))
}
Spacer(modifier = Modifier.padding(6.dp))
Text(
text = album.displayedAlbumName,
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 16.sp
)
Spacer(modifier = Modifier.padding(8.dp))
}
}
}
@@ -1,11 +1,7 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.OvalShape
import android.graphics.drawable.shapes.RectShape
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -27,14 +23,12 @@ import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
@@ -69,7 +63,7 @@ fun FolderItem(
val haptics = LocalHapticFeedback.current
val transition = updateTransition(itemSelected, label = "")
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
val iconSelectionColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
val paddingTransition by transition.animateDp(label = "") { selected ->
if (selected) 5.dp else 0.dp
}
@@ -78,7 +72,7 @@ fun FolderItem(
}
Card(
elevation = CardDefaults.cardElevation(5.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
modifier = modifier
.fillMaxSize()
.padding(paddingTransition)
@@ -97,81 +91,75 @@ fun FolderItem(
}
),
shape = RoundedCornerShape(roundedCornerShapeTransition),
border = BorderStroke(1.dp, bgColor)
) {
Surface(
modifier = Modifier.fillMaxSize(),
tonalElevation = 10.dp,
Column(
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Column(
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Box {
if (folder.coverUri != null) {
GlideImage(
imageModel = { folder.coverUri.toUri() },
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.height(configuration.screenHeightDp.dp / 4.0f)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
)
}
if (selectionMode) {
if (itemSelected) {
Icon(
imageVector = Icons.Default.CheckCircle,
contentDescription = stringResource(R.string.image_is_selected),
modifier = Modifier
.padding(4.dp)
.border(2.dp, bgColor, CircleShape)
.clip(CircleShape)
.background(bgColor)
)
} else {
Icon(
imageVector = Icons.Default.RadioButtonUnchecked,
contentDescription = stringResource(R.string.image_is_not_selected),
tint = Color.White.copy(alpha = 0.7f),
modifier = Modifier.padding(6.dp)
)
}
}
}
Spacer(modifier = Modifier.padding(6.dp))
folder.folderName?.let { name ->
Text(
text = name,
Box {
if (folder.coverUri != null) {
GlideImage(
imageModel = { folder.coverUri.toUri() },
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 16.sp
.height(configuration.screenHeightDp.dp / 4.0f)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
)
}
if (selectionMode) {
if (itemSelected) {
Icon(
imageVector = Icons.Default.CheckCircle,
contentDescription = stringResource(R.string.image_is_selected),
modifier = Modifier
.padding(4.dp)
.border(2.dp, iconSelectionColor, CircleShape)
.clip(CircleShape)
.background(iconSelectionColor)
)
} else {
Icon(
imageVector = Icons.Default.RadioButtonUnchecked,
contentDescription = stringResource(R.string.image_is_not_selected),
tint = Color.White.copy(alpha = 0.7f),
modifier = Modifier.padding(6.dp)
)
}
}
}
Spacer(modifier = Modifier.padding(6.dp))
folder.folderName?.let { name ->
Text(
text = folder.wallpapers.size.toString().plus(" wallpapers"),
text = name,
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 12.sp,
color = MaterialTheme.colorScheme.tertiary
fontSize = 16.sp
)
Spacer(modifier = Modifier.padding(8.dp))
}
Text(
text = folder.wallpapers.size.toString().plus(" wallpapers"),
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 12.sp,
color = MaterialTheme.colorScheme.tertiary
)
Spacer(modifier = Modifier.padding(8.dp))
}
}
}
@@ -1,6 +1,7 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.updateTransition
@@ -94,7 +95,6 @@ fun WallpaperItem(
Glide
.with(LocalContext.current)
.asBitmap()
.centerInside()
.transition(withCrossFade())
},
loading = {
@@ -1,15 +1,15 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
sealed class AlbumViewEvent {
data object ClearState: AlbumViewEvent()
data class SelectAll(
val albumsWithWallpaper: AlbumWithWallpaper
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
): AlbumViewEvent()
data object DeselectAll: AlbumViewEvent()
data class DeleteSelected(
val albumsWithWallpaper: AlbumWithWallpaper
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
): AlbumViewEvent()
data class SelectWallpaper(
val wallpaperUri: String
@@ -19,62 +19,62 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
@Composable
fun AlbumViewScreen(
viewModel: AlbumViewScreenViewModel = hiltViewModel(),
albumWithWallpaper: AlbumWithWallpaper,
albumViewModel: AlbumViewScreenViewModel = hiltViewModel(),
album: AlbumWithWallpaperAndFolder,
onBackClick: () -> Unit,
onShowWallpaperView: (String) -> Unit,
onShowFolderView: (String, String?, List<String>) -> Unit,
onDeleteAlbum: () -> Unit,
onTitleChange: (String, AlbumWithWallpaper) -> Unit,
onTitleChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
onSelectionDeleted: () -> Unit
) {
viewModel.onEvent(AlbumViewEvent.SetSize(albumWithWallpaper.wallpapers.size + albumWithWallpaper.folders.size))
albumViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size))
val lazyListState = rememberLazyStaggeredGridState()
val state = viewModel.state.collectAsStateWithLifecycle()
val albumState = albumViewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) }
BackHandler {
if (selectionMode) {
selectionMode = false
viewModel.onEvent(AlbumViewEvent.DeselectAll)
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
} else {
onBackClick()
viewModel.onEvent(AlbumViewEvent.ClearState)
albumViewModel.onEvent(AlbumViewEvent.ClearState)
}
}
Scaffold(
topBar = {
AlbumViewTopBar(
title = albumWithWallpaper.album.displayedAlbumName,
title = album.album.displayedAlbumName,
selectionMode = selectionMode,
albumState = viewModel.state,
albumState = albumViewModel.state,
onBackClick = {
viewModel.onEvent(AlbumViewEvent.ClearState)
albumViewModel.onEvent(AlbumViewEvent.ClearState)
onBackClick()
},
onDeleteAlbum = onDeleteAlbum,
onTitleChange = { onTitleChange(it, albumWithWallpaper) },
onTitleChange = { onTitleChange(it, album) },
onSelectAllClick = {
if (!state.value.allSelected) viewModel.onEvent(AlbumViewEvent.SelectAll(albumWithWallpaper))
else viewModel.onEvent(AlbumViewEvent.DeselectAll)
if (!albumState.value.allSelected) albumViewModel.onEvent(AlbumViewEvent.SelectAll(album))
else albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
},
onDeleteSelected = {
selectionMode = false
viewModel.onEvent(AlbumViewEvent.DeleteSelected(albumWithWallpaper))
viewModel.onEvent(AlbumViewEvent.DeselectAll)
albumViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
onSelectionDeleted()
}
)
},
content = {
content = { it ->
LazyVerticalStaggeredGrid(
state = lazyListState,
modifier = Modifier
@@ -84,16 +84,16 @@ fun AlbumViewScreen(
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
content = {
items (items = albumWithWallpaper.folders, key = { folder -> folder.folderUri.hashCode()}
items (items = album.folders, key = { folder -> folder.folderUri.hashCode() }
) { folder ->
FolderItem(
folder = folder,
itemSelected = state.value.selectedFolders.contains(folder.folderUri),
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
selectionMode = selectionMode,
onActivateSelectionMode = { selectionMode = it },
onItemSelection = {
viewModel.onEvent(
if (!state.value.selectedFolders.contains(folder.folderUri))
albumViewModel.onEvent(
if (!albumState.value.selectedFolders.contains(folder.folderUri))
AlbumViewEvent.SelectFolder(folder.folderUri)
else {
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
@@ -106,16 +106,16 @@ fun AlbumViewScreen(
modifier = Modifier.padding(4.dp)
)
}
items (items = albumWithWallpaper.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
) { wallpaper ->
WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = state.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
selectionMode = selectionMode,
onActivateSelectionMode = { selectionMode = it },
onItemSelection = {
viewModel.onEvent(
if (!state.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
albumViewModel.onEvent(
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
else {
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
@@ -34,8 +34,12 @@ class AlbumViewScreenViewModel @Inject constructor(
event.albumsWithWallpaper.let { album ->
val folders = album.folders.filter { _state.value.selectedFolders.contains(it.folderUri)}
val wallpapers = album.wallpapers.filter { _state.value.selectedWallpapers.contains(it.wallpaperUri)}
val doesContainCover = wallpapers.any { it.wallpaperUri == album.album.coverUri }
repository.deleteFolderList(folders)
repository.deleteWallpaperList(wallpapers)
if (doesContainCover) {
repository.updateAlbum(album.album.copy(coverUri = null))
}
}
}
}
@@ -6,10 +6,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SecondaryTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
@@ -35,12 +37,11 @@ fun HomeScreen(
onSettingsClick: () -> Unit,
onContactClick: () -> Unit,
navigateToAddWallpaperScreen: (String) -> Unit,
onAlbumViewClick: (String) -> Unit
onAlbumViewClick: (String) -> Unit,
) {
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
val pagerState = rememberPagerState { tabItems.size }
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
if (addAlbumDialog) AddAlbumDialog(
onDismissRequest = { addAlbumDialog = false },
@@ -56,13 +57,13 @@ fun HomeScreen(
selectionCount = 0,
)
}
) {padding ->
) { padding ->
LaunchedEffect(tabIndex) { pagerState.animateScrollToPage(tabIndex) }
LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
}
Column(modifier = Modifier.padding(padding)) {
SecondaryTabRow(
TabRow(
selectedTabIndex = tabIndex,
indicator = { tabPositions ->
if (tabIndex < tabPositions.size) {
@@ -99,8 +100,7 @@ fun HomeScreen(
}
HorizontalPager(state = pagerState, beyondBoundsPageCount = 1) { index ->
when(index) {
0 -> WallpaperScreen(
)
0 -> WallpaperScreen()
1 -> LibraryScreen(
onAddNewAlbumClick = { addAlbumDialog = true },
onViewAlbum = { onAlbumViewClick(it) }
@@ -1,72 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.SecondaryTabRow
import androidx.compose.material3.Surface
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.tabItems
@Composable
fun HomeTabRow(
scroll: ScrollState,
smallTopAppBarHeight: Dp,
tabIndex: Int,
modifier: Modifier = Modifier,
onIndexUpdate: (Int) -> Unit
) {
Surface (
modifier = modifier
.graphicsLayer {
translationY = -scroll.value.toFloat() / 2f
alpha = 0f
}
) {
SecondaryTabRow(
selectedTabIndex = tabIndex,
indicator = { tabPositions ->
if (tabIndex < tabPositions.size) {
TabRowDefaults.PrimaryIndicator(
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
shape = RoundedCornerShape(
topStart = 6.dp,
topEnd = 6.dp,
bottomEnd = 0.dp,
bottomStart = 0.dp,
),
width = 60.dp
)
}
}
) {
tabItems.forEachIndexed { index, item ->
Tab(
selected = (index == tabIndex),
onClick = { onIndexUpdate(index) },
text = { Text(text = item.title) },
icon = {
Icon(
imageVector =
if (index == tabIndex)
item.filledIcon
else
item.unfilledIcon,
contentDescription = item.title
)
}
)
}
}
}
}
@@ -55,7 +55,7 @@ fun LibraryScreen(
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
content = {
items (state.value.albumWithWallpapers, key = {album -> album.album.initialAlbumName}
items (state.value.albumsWithWallpapers, key = { album -> album.album.initialAlbumName}
) { album ->
AlbumItem(
album = album.album,
@@ -38,6 +38,8 @@ fun ScrollableSettings(
Spacer(Modifier.height(largeTopAppBarHeightPx))
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(16.dp))
ListSectionTitle("Appearance")
Spacer(modifier = Modifier.height(16.dp))
DarkModeListItem(
@@ -49,5 +51,17 @@ fun ScrollableSettings(
dynamicTheming = state.value.dynamicTheming,
onDynamicThemingClick = { onDynamicThemingClick(it) }
)
Spacer(modifier = Modifier.height(16.dp))
ListSectionTitle("Privacy")
//add crash reporting settings
Spacer(modifier = Modifier.height(16.dp))
DynamicThemingListItem(
dynamicTheming = state.value.dynamicTheming,
onDynamicThemingClick = { onDynamicThemingClick(it) }
)
//GPL and License and link to github etc.
}
}
@@ -4,6 +4,7 @@ import android.app.Activity
import android.graphics.Color.TRANSPARENT
import android.os.Build
import androidx.activity.SystemBarStyle
import androidx.annotation.RequiresApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.lightColorScheme
@@ -0,0 +1,9 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
sealed class WallpaperEvent {
data class UpdateSelectedAlbum(val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder): WallpaperEvent()
object Reset : WallpaperEvent()
object Refresh : WallpaperEvent()
}
@@ -5,23 +5,72 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumState
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
@Composable
fun WallpaperScreen() {
fun WallpaperScreen(
albumsViewModel: AlbumsViewModel = hiltViewModel(),
wallpaperScreenViewModel: WallpaperScreenViewModel = hiltViewModel()
) {
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
Scaffold(
modifier = Modifier.fillMaxSize(),
content = {
content = { it
Column(
modifier = Modifier
.fillMaxSize()
.padding(it),
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
CurrentSelectedAlbum(
selectedAlbum = selectedState.value.selectedAlbum,
onOpenBottomSheet = {
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) openBottomSheet = true
}
)
if (openBottomSheet) {
AlbumBottomSheet(
albums = albumState.value.albumsWithWallpapers,
currentSelectedAlbum = selectedState.value.selectedAlbum,
onDismiss = { openBottomSheet = false },
onSelect = { album ->
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(album))
openBottomSheet = false
}
)
}
}
}
)
}
/*
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
val wallpaperManager = WallpaperManager.getInstance(context)
val inputStream = albumState.value.albumsWithWallpapers.firstOrNull()?.let {
it.album.coverUri?.let { it1 ->
context.contentResolver.openInputStream(
it1.toUri()
)
}
}
val bitmap = BitmapFactory.decodeStream(inputStream)
wallpaperManager.setBitmap(bitmap)
}
*/
@@ -0,0 +1,86 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
import android.app.Application
import android.content.Context
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class WallpaperScreenViewModel @Inject constructor (
application: Application,
private val repository: SelectedAlbumRepository
) : AndroidViewModel(application) {
var shouldNotBypassSplashScreen by mutableStateOf(true)
private val context: Context get() = getApplication<Application>().applicationContext
private var _state = MutableStateFlow(WallpaperState())
val state = _state.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000), WallpaperState()
)
init {
viewModelScope.launch {
refreshAlbums()
shouldNotBypassSplashScreen = false
}
}
fun onEvent(event: WallpaperEvent) {
when (event) {
is WallpaperEvent.UpdateSelectedAlbum -> {
viewModelScope.launch {
repository.getSelectedAlbum().firstOrNull()?.let { repository.deleteAll() }
val wallpapers: MutableList<Wallpaper> = event.albumWithWallpaperAndFolder.wallpapers.toMutableList()
val wallpapersFromFolder = event.albumWithWallpaperAndFolder.folders.flatMap { folder ->
folder.wallpapers.map { wallpaper ->
Wallpaper(
initialAlbumName = event.albumWithWallpaperAndFolder.album.initialAlbumName,
wallpaperUri = wallpaper,
key = wallpaper.hashCode() + event.albumWithWallpaperAndFolder.album.initialAlbumName.hashCode()
)
}
}
wallpapers.addAll(wallpapersFromFolder)
val newSelectedAlbum = SelectedAlbum(
album = event.albumWithWallpaperAndFolder.album,
wallpapers = wallpapers
)
repository.upsertSelectedAlbum(newSelectedAlbum)
}
}
is WallpaperEvent.Refresh -> {
refreshAlbums()
}
is WallpaperEvent.Reset -> {
viewModelScope.launch {
repository.deleteAll()
}
}
}
}
// Retrieve album from database into viewModel
private fun refreshAlbums() {
viewModelScope.launch {
repository.getSelectedAlbum().collect { selectedAlbum ->
_state.update { it.copy(
selectedAlbum = selectedAlbum.firstOrNull()
) }
}
}
}
}
@@ -0,0 +1,7 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
data class WallpaperState (
val selectedAlbum: SelectedAlbum? = null
)
@@ -0,0 +1,128 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.RadioButtonChecked
import androidx.compose.material.icons.filled.RadioButtonUnchecked
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage
import kotlinx.coroutines.launch
/**
* Contains the album bottom sheet that shows from the bottom when the user selects which sets the current rotating album
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlbumBottomSheet(
onDismiss: () -> Unit,
currentSelectedAlbum: SelectedAlbum?,
albums: List<AlbumWithWallpaperAndFolder>,
onSelect: (AlbumWithWallpaperAndFolder) -> Unit
) {
val modalBottomSheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()
ModalBottomSheet(
onDismissRequest = { onDismiss() },
sheetState = modalBottomSheetState,
dragHandle = { BottomSheetDefaults.DragHandle() },
) {
albums.forEach {
ListItem(
modifier = Modifier
.padding(4.dp)
.clickable {
scope.launch {
modalBottomSheetState.hide()
onSelect(it)
onDismiss()
}
},
headlineContent = {
Text(
text = it.album.displayedAlbumName,
style = MaterialTheme.typography.titleMedium
) },
supportingContent = {
Text(
text = (it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size).toString() + stringResource(R.string.wallpaper),
style = MaterialTheme.typography.bodySmall,
overflow = TextOverflow.Ellipsis
)
},
leadingContent = {
Box (
modifier = Modifier.size(60.dp)
) {
GlideImage(
imageModel = { it.album.coverUri },
imageOptions = ImageOptions(
contentScale = ContentScale.FillBounds,
alignment = Alignment.Center,
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(
Alignment.Center))
}
},
modifier = Modifier
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
)
}
},
trailingContent = {
if (currentSelectedAlbum != null) {
if (currentSelectedAlbum.album.initialAlbumName == it.album.initialAlbumName) {
Icon(
contentDescription = stringResource(R.string.currently_selected_album),
imageVector = Icons.Filled.RadioButtonChecked,
)
}
else {
Icon(
contentDescription = stringResource(R.string.currently_selected_album),
imageVector = Icons.Filled.RadioButtonUnchecked,
)
}
}
},
)
}
}
}
@@ -0,0 +1,111 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.RadioButtonUnchecked
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage
/**
* The inner card for the album bottom sheet to represent each album
*/
@Composable
fun CurrentSelectedAlbum(
selectedAlbum: SelectedAlbum?,
onOpenBottomSheet: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxSize()
.padding(24.dp),
) {
ListItem(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.clickable { onOpenBottomSheet() },
headlineContent = {
Text(
text = selectedAlbum?.album?.displayedAlbumName ?: stringResource(R.string.no_album_selected),
style = MaterialTheme.typography.titleMedium
) },
supportingContent = {
if (selectedAlbum != null) {
Text(
text = (selectedAlbum.wallpapers.size.toString()) + stringResource(R.string.wallpaper),
style = MaterialTheme.typography.bodySmall,
overflow = TextOverflow.Ellipsis
)
} },
leadingContent = {
Box (
modifier = Modifier.size(60.dp)
) {
if (selectedAlbum != null) {
GlideImage(
imageModel = { selectedAlbum.album.coverUri },
imageOptions = ImageOptions(
contentScale = ContentScale.FillBounds,
alignment = Alignment.Center,
),
requestBuilder = {
Glide
.with(LocalContext.current)
.asBitmap()
.transition(BitmapTransitionOptions.withCrossFade())
},
loading = {
Box(modifier = Modifier.matchParentSize()) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
)
} else {
Image(
imageVector = Icons.Default.RadioButtonUnchecked,
contentDescription = stringResource(R.string.no_icon),
modifier = Modifier.fillMaxSize()
)
}
}
},
trailingContent = {
Icon(
contentDescription = stringResource(R.string.click_to_select_a_different_album),
imageVector = Icons.Filled.ArrowDropDown,
)
},
tonalElevation = 5.dp
)
}
}
@@ -35,6 +35,9 @@ import com.skydoves.landscapist.glide.GlideImage
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomable
/**
* WallpaperViewScreen shows a zoomable image that the user clicked on. They can zoom in and out of the image using pinch-to-zoom.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun WallpaperViewScreen(
+5
View File
@@ -31,4 +31,9 @@
<string name="folder_view">Folder View</string>
<string name="delete_album">Delete</string>
<string name="change_name">Edit Name</string>
<string name="click_to_select_a_different_album">Click to select a different album</string>
<string name="no_icon">No icon</string>
<string name="no_album_selected">No album selected</string>
<string name="wallpaper">" wallpaper"</string>
<string name="currently_selected_album">Currently selected album</string>
</resources>
+4 -4
View File
@@ -1,15 +1,15 @@
buildscript {
val agp_version by extra("8.1.1")
val agp_version by extra("8.3.1")
repositories {
google()
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.1" apply false
id("com.android.library") version "8.1.1" apply false
id("com.android.application") version "8.3.1" apply false
id("com.android.library") version "8.3.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.google.dagger.hilt.android") version "2.48" apply false
id("com.google.dagger.hilt.android") version "2.50" apply false
id("com.google.devtools.ksp") version "1.9.0-1.0.13" apply false
}