From 23eecbeb4d21510ef83dee43b0a57720762bdbe0 Mon Sep 17 00:00:00 2001 From: Maary <24504742+Steve-Mr@users.noreply.github.com> Date: Fri, 18 Oct 2024 22:26:20 +0800 Subject: [PATCH 1/3] [fix]entryscreen auto update album list --- .../oblivionis/viewmodel/ActionViewModel.kt | 79 ++++++++++++------- gradle/libs.versions.toml | 21 ++--- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/top/maary/oblivionis/viewmodel/ActionViewModel.kt b/app/src/main/java/top/maary/oblivionis/viewmodel/ActionViewModel.kt index 180a686..b940613 100644 --- a/app/src/main/java/top/maary/oblivionis/viewmodel/ActionViewModel.kt +++ b/app/src/main/java/top/maary/oblivionis/viewmodel/ActionViewModel.kt @@ -77,44 +77,64 @@ class ActionViewModel( _images.value = imageList val databaseMarks = imageRepository.allMarks?.firstOrNull() - if (!databaseMarks.isNullOrEmpty()) { - restoreMarkList(databaseMarks) - } val databaseExclusions = imageRepository.allExcludes?.firstOrNull() - if (!databaseExclusions.isNullOrEmpty()) { - restoreExcluded(databaseExclusions) + + restoreData(databaseMarks, databaseExclusions) + + registerContentObserverIfNeeded() + registerVideoContentObserverIfNeeded() + } + } + + private fun restoreData(databaseMarks: List?, databaseExclusions: List?) { + databaseMarks?.let { restoreMarkList(it) } + databaseExclusions?.let { restoreExcluded(it) } + } + + private fun registerContentObserverIfNeeded() { + if (contentObserver == null) { + contentObserver = getApplication().contentResolver.registerObserver( + MediaStore.Images.Media.EXTERNAL_CONTENT_URI + ) { + reloadContentIfNeeded() } + } + } - if (contentObserver == null) { - contentObserver = getApplication().contentResolver.registerObserver( - MediaStore.Images.Media.EXTERNAL_CONTENT_URI - ) { - loadImages() - viewModelScope.launch { - if (!databaseMarks.isNullOrEmpty()) { - restoreMarkList(databaseMarks) - } - } - } + private fun registerVideoContentObserverIfNeeded() { + if (videoContentObserver == null) { + videoContentObserver = getApplication().contentResolver.registerObserver( + MediaStore.Video.Media.EXTERNAL_CONTENT_URI + ) { + reloadContentIfNeeded() } + } + } - if (videoContentObserver == null) { - - videoContentObserver = - getApplication().contentResolver.registerObserver( - MediaStore.Video.Media.EXTERNAL_CONTENT_URI - ) { - loadImages() - viewModelScope.launch { - if (!databaseMarks.isNullOrEmpty()) { - restoreMarkList(databaseMarks) - } - } - } + private var isReloading = false + + private fun reloadContentIfNeeded() { + if (!isReloading) { + isReloading = true + viewModelScope.launch { + reloadContent() + isReloading = false // 加载完成后重置标记位 } } } + private fun reloadContent() { + loadImages() + loadAlbums() + viewModelScope.launch { + val databaseMarks = imageRepository.allMarks?.firstOrNull() + val databaseExclusions = imageRepository.allExcludes?.firstOrNull() + restoreData(databaseMarks, databaseExclusions) + } + } + + + private val _albums = MutableStateFlow>(emptyList()) val albums: StateFlow> get() = _albums @@ -123,7 +143,6 @@ class ActionViewModel( val albumList = getAlbumsFromMediaStore(getApplication().contentResolver) _albums.value = albumList } - } // Function to fetch album names and paths from MediaStore for both images and videos diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4aee46a..c920f22 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,27 +1,28 @@ [versions] accompanistPermissions = "0.36.0" agp = "8.6.1" -coil = "3.0.0-alpha10" -coilCompose = "3.0.0-alpha10" -coilVideoVersion = "3.0.0-alpha10" +coil = "3.0.0-rc01" +coilCompose = "3.0.0-rc01" +coilVideoVersion = "3.0.0-rc01" composeVideo = "1.2.0" -constraintlayoutCompose = "1.1.0-beta01" +constraintlayoutCompose = "1.1.0-rc01" datastorePreferences = "1.1.1" -foundation = "1.7.3" +foundation = "1.7.4" kotlin = "1.9.0" coreKtx = "1.13.1" junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" lifecycleRuntimeKtx = "2.8.6" -activityCompose = "1.9.2" -composeBom = "2024.09.03" -materialIconsExtended = "1.7.3" +activityCompose = "1.9.3" +composeBom = "2024.10.00" +material3 = "1.3.0" +materialIconsExtended = "1.7.4" media3Exoplayer = "1.4.1" media3ExoplayerDash = "1.4.1" media3Session = "1.4.1" media3Ui = "1.4.1" -navigationCompose = "2.8.2" +navigationCompose = "2.8.3" roomCompiler = "2.6.1" roomKtx = "2.6.1" roomRuntime = "2.6.1" @@ -61,7 +62,7 @@ androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } -androidx-material3 = { group = "androidx.compose.material3", name = "material3" } +androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3"} androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" } [plugins] From ba60db5a8681c302b42cc6ee28ad97639cbc4ab0 Mon Sep 17 00:00:00 2001 From: Maary <24504742+Steve-Mr@users.noreply.github.com> Date: Fri, 18 Oct 2024 22:34:07 +0800 Subject: [PATCH 2/3] bump kotlin version & app version --- app/build.gradle.kts | 2 +- build.gradle.kts | 2 +- gradle/libs.versions.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0212b18..fa51a57 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -26,7 +26,7 @@ android { minSdk = 31 targetSdk = 35 versionCode = 3 - versionName = "1.0-alpha-1003" + versionName = "1.0-alpha-1018" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/build.gradle.kts b/build.gradle.kts index 43421fa..9da7668 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,5 +2,5 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false - id("com.google.devtools.ksp") version "1.9.0-1.0.13" apply false + id("com.google.devtools.ksp") version "2.0.20-1.0.24" apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c920f22..f0c0e54 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ composeVideo = "1.2.0" constraintlayoutCompose = "1.1.0-rc01" datastorePreferences = "1.1.1" foundation = "1.7.4" -kotlin = "1.9.0" +kotlin = "2.0.20" coreKtx = "1.13.1" junit = "4.13.2" junitVersion = "1.2.1" From 5fc9e933e061458ab6bee8d867335bfc95bf252d Mon Sep 17 00:00:00 2001 From: Maary <24504742+Steve-Mr@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:05:33 +0800 Subject: [PATCH 3/3] compose compiler gradle plugin --- .idea/kotlinc.xml | 2 +- app/build.gradle.kts | 1 + gradle/libs.versions.toml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fdf8d99..d4b7acc 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fa51a57..b25ab0a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,6 +4,7 @@ import java.util.Properties plugins { alias(libs.plugins.android.application) alias(libs.plugins.jetbrains.kotlin.android) + alias(libs.plugins.compose.compiler) id("com.google.devtools.ksp") } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f0c0e54..1bd478f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -68,4 +68,5 @@ androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx" [plugins] android-application = { id = "com.android.application", version.ref = "agp" } jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }