Merge pull request #3358 from kiwix/Issue#3341

Fixed deprecated constructor of `FileObserver`
This commit is contained in:
Kelson 2023-05-26 17:20:39 +03:00 committed by GitHub
commit 2e749b41cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.zimManager
import android.annotation.SuppressLint
import android.os.Build
import android.os.FileObserver
import io.reactivex.Flowable
import io.reactivex.functions.BiFunction
@ -62,12 +63,20 @@ class Fat32Checker constructor(
)
}
private fun fileObserver(it: String?): FileObserver {
return object : FileObserver(it, MOVED_FROM or DELETE) {
override fun onEvent(event: Int, path: String?) {
requestCheckSystemFileType.onNext(Unit)
}
}.apply { startWatching() }
private fun fileObserver(it: String): FileObserver {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return object : FileObserver(File(it), MOVED_FROM or DELETE) {
override fun onEvent(event: Int, path: String?) {
requestCheckSystemFileType.onNext(Unit)
}
}.apply { startWatching() }
} else {
object : FileObserver(it, FileObserver.MOVED_FROM or FileObserver.DELETE) {
override fun onEvent(event: Int, path: String?) {
requestCheckSystemFileType.onNext(Unit)
}
}.apply { startWatching() }
}
}
private fun toFileSystemState(it: String) =