Skip to content

Commit

Permalink
Tweak download location preference handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 authored and nielsvanvelzen committed Apr 23, 2024
1 parent 7644358 commit a78cd97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
22 changes: 13 additions & 9 deletions app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ class AppPreferences(context: Context) {

var downloadLocation: String
get() {
@Suppress("DEPRECATION")
val defaultStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
val savedStorage = sharedPreferences.getString(Constants.PREF_DOWNLOAD_LOCATION, null)
return if (savedStorage != null && File(savedStorage).parentFile?.isDirectory == true) {
// Saved location is still valid
savedStorage
} else {
// Reset download option if corrupt
sharedPreferences.edit { putString(Constants.PREF_DOWNLOAD_LOCATION, null) }
defaultStorage
if (savedStorage != null) {
if (File(savedStorage).parentFile?.isDirectory == true) {
// Saved location is still valid
return savedStorage
} else {
// Reset download option if corrupt
sharedPreferences.edit {
remove(Constants.PREF_DOWNLOAD_LOCATION)
}
}
}

// Return default storage location
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
}
set(value) {
sharedPreferences.edit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jellyfin.mobile.settings

import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -220,7 +221,9 @@ class SettingsFragment : Fragment(), BackPressInterceptor {
}
singleChoice(Constants.PREF_DOWNLOAD_LOCATION, downloadsDirs) {
titleRes = R.string.pref_download_location
initialSelection = appPreferences.downloadLocation
initialSelection = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.absolutePath
}
}

Expand Down

0 comments on commit a78cd97

Please sign in to comment.