mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-18 18:17:43 +03:00
Merge branch 'root' into 'develop'
Avoid rare NPE See merge request ultrasonic/ultrasonic!1073
This commit is contained in:
commit
7209779b64
@ -306,7 +306,7 @@ class NavigationActivity : AppCompatActivity() {
|
|||||||
Storage.reset()
|
Storage.reset()
|
||||||
|
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
Storage.ensureRootIsAvailable()
|
Storage.checkForErrorsWithCustomRoot()
|
||||||
}
|
}
|
||||||
|
|
||||||
setMenuForServerCapabilities()
|
setMenuForServerCapabilities()
|
||||||
|
@ -344,7 +344,7 @@ class SettingsFragment :
|
|||||||
// Clear download queue.
|
// Clear download queue.
|
||||||
mediaPlayerManager.clear()
|
mediaPlayerManager.clear()
|
||||||
Storage.reset()
|
Storage.reset()
|
||||||
Storage.ensureRootIsAvailable()
|
Storage.checkForErrorsWithCustomRoot()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setDebugLogToFile(writeLog: Boolean) {
|
private fun setDebugLogToFile(writeLog: Boolean) {
|
||||||
|
@ -22,19 +22,23 @@ import timber.log.Timber
|
|||||||
object Storage {
|
object Storage {
|
||||||
|
|
||||||
val mediaRoot: ResettableLazy<AbstractFile> = ResettableLazy {
|
val mediaRoot: ResettableLazy<AbstractFile> = ResettableLazy {
|
||||||
getRoot()!!
|
val ret = getRoot()
|
||||||
|
rootNotFoundError = ret.second
|
||||||
|
ret.first
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rootNotFoundError: Boolean = false
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
StorageFile.storageFilePathDictionary.clear()
|
StorageFile.storageFilePathDictionary.clear()
|
||||||
StorageFile.notExistingPathDictionary.clear()
|
StorageFile.notExistingPathDictionary.clear()
|
||||||
mediaRoot.reset()
|
mediaRoot.reset()
|
||||||
|
rootNotFoundError = false
|
||||||
Timber.i("StorageFile caches were reset")
|
Timber.i("StorageFile caches were reset")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ensureRootIsAvailable() {
|
fun checkForErrorsWithCustomRoot() {
|
||||||
val root = getRoot()
|
if (rootNotFoundError) {
|
||||||
if (root == null) {
|
|
||||||
Settings.customCacheLocation = false
|
Settings.customCacheLocation = false
|
||||||
Settings.cacheLocationUri = ""
|
Settings.cacheLocationUri = ""
|
||||||
Util.toast(UApp.applicationContext(), R.string.settings_cache_location_error)
|
Util.toast(UApp.applicationContext(), R.string.settings_cache_location_error)
|
||||||
@ -98,18 +102,25 @@ object Storage {
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRoot(): AbstractFile? {
|
private fun getRoot(): Pair<AbstractFile, Boolean> {
|
||||||
return if (Settings.customCacheLocation) {
|
return if (Settings.customCacheLocation) {
|
||||||
if (Settings.cacheLocationUri.isBlank()) return null
|
if (Settings.cacheLocationUri.isBlank()) return Pair(getDefaultRoot(), true)
|
||||||
val documentFile = DocumentFile.fromTreeUri(
|
val documentFile = DocumentFile.fromTreeUri(
|
||||||
UApp.applicationContext(),
|
UApp.applicationContext(),
|
||||||
Uri.parse(Settings.cacheLocationUri)
|
Uri.parse(Settings.cacheLocationUri)
|
||||||
) ?: return null
|
) ?: return Pair(getDefaultRoot(), true)
|
||||||
if (!documentFile.exists()) return null
|
if (!documentFile.exists()) return Pair(getDefaultRoot(), true)
|
||||||
StorageFile(null, documentFile.uri, documentFile.name!!, documentFile.isDirectory)
|
Pair(
|
||||||
|
StorageFile(null, documentFile.uri, documentFile.name!!, documentFile.isDirectory),
|
||||||
|
false
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
val file = File(FileUtil.defaultMusicDirectory.path)
|
Pair(getDefaultRoot(), false)
|
||||||
JavaFile(null, file)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDefaultRoot(): JavaFile {
|
||||||
|
val file = File(FileUtil.defaultMusicDirectory.path)
|
||||||
|
return JavaFile(null, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user