Skip to content

Commit

Permalink
Merge 5fc9e93 into eadbdba
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mr authored Oct 19, 2024
2 parents eadbdba + 5fc9e93 commit a59ada8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -26,7 +27,7 @@ android {
minSdk = 31
targetSdk = 35
versionCode = 3
versionName = "1.0-alpha-1003"
versionName = "1.0-alpha-1018"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
79 changes: 49 additions & 30 deletions app/src/main/java/top/maary/oblivionis/viewmodel/ActionViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<MediaStoreImage>?, databaseExclusions: List<MediaStoreImage>?) {
databaseMarks?.let { restoreMarkList(it) }
databaseExclusions?.let { restoreExcluded(it) }
}

private fun registerContentObserverIfNeeded() {
if (contentObserver == null) {
contentObserver = getApplication<Application>().contentResolver.registerObserver(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
) {
reloadContentIfNeeded()
}
}
}

if (contentObserver == null) {
contentObserver = getApplication<Application>().contentResolver.registerObserver(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
) {
loadImages()
viewModelScope.launch {
if (!databaseMarks.isNullOrEmpty()) {
restoreMarkList(databaseMarks)
}
}
}
private fun registerVideoContentObserverIfNeeded() {
if (videoContentObserver == null) {
videoContentObserver = getApplication<Application>().contentResolver.registerObserver(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
) {
reloadContentIfNeeded()
}
}
}

if (videoContentObserver == null) {

videoContentObserver =
getApplication<Application>().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<List<Album>>(emptyList())
val albums: StateFlow<List<Album>> get() = _albums

Expand All @@ -123,7 +143,6 @@ class ActionViewModel(
val albumList = getAlbumsFromMediaStore(getApplication<Application>().contentResolver)
_albums.value = albumList
}

}

// Function to fetch album names and paths from MediaStore for both images and videos
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 13 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
kotlin = "1.9.0"
foundation = "1.7.4"
kotlin = "2.0.20"
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"
Expand Down Expand Up @@ -61,10 +62,11 @@ 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]
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" }

0 comments on commit a59ada8

Please sign in to comment.