From 43fafbc7471d98f6f2dd61359068e60ec62e8ec9 Mon Sep 17 00:00:00 2001 From: len Date: Thu, 12 May 2016 16:45:35 +0200 Subject: [PATCH] Fix a crash when trying to change the downloads directory on some devices --- .../tachiyomi/ui/setting/SettingsDownloadsFragment.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt index 9a3eb43bb..5b75577ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadsFragment.kt @@ -40,13 +40,13 @@ class SettingsDownloadsFragment : SettingsNestedFragment() { downloadDirPref.setOnPreferenceClickListener { val currentDir = preferences.downloadsDirectory().getOrDefault() - val externalDirs = getExternalFilesDirs() + val externalDirs = getExternalFilesDirs() + getString(R.string.custom_dir) val selectedIndex = externalDirs.indexOf(File(currentDir)) MaterialDialog.Builder(activity) - .items(externalDirs + getString(R.string.custom_dir)) + .items(externalDirs) .itemsCallbackSingleChoice(selectedIndex, { dialog, view, which, text -> - if (which == externalDirs.size) { + if (which == externalDirs.lastIndex) { // Custom dir selected, open directory selector val i = Intent(activity, CustomLayoutPickerActivity::class.java) i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false) @@ -80,7 +80,8 @@ class SettingsDownloadsFragment : SettingsNestedFragment() { File.separator + getString(R.string.app_name) + File.separator + "downloads" - return mutableListOf(File(defaultDir)) + ContextCompat.getExternalFilesDirs(activity, "") + return mutableListOf(File(defaultDir)) + + ContextCompat.getExternalFilesDirs(activity, "").filterNotNull() } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {