@ -6,7 +6,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.Intent
import android.os.Bundle
import android.os.Bundle
import android.os.Environment
import android.os.Environment
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.core.net.toUri
import androidx.core.text.buildSpannedString
import androidx.core.text.buildSpannedString
import androidx.preference.PreferenceScreen
import androidx.preference.PreferenceScreen
@ -210,7 +209,7 @@ class SettingsDownloadController : SettingsController() {
override fun onCreateDialog ( savedViewState : Bundle ? ) : Dialog {
override fun onCreateDialog ( savedViewState : Bundle ? ) : Dialog {
val activity = activity !!
val activity = activity !!
val currentDir = preferences . downloadsDirectory ( ) . get ( )
val currentDir = preferences . downloadsDirectory ( ) . get ( )
val externalDirs = ( getExternalDirs ( ) + File ( activity . getString ( R . string . custom _dir ) ) ) . map ( File :: toString )
val externalDirs = listOf ( getDefaultDownloadDir ( ) , File ( activity . getString ( R . string . custom _dir ) ) ) . map ( File :: toString )
var selectedIndex = externalDirs . indexOfFirst { it in currentDir }
var selectedIndex = externalDirs . indexOfFirst { it in currentDir }
return MaterialAlertDialogBuilder ( activity )
return MaterialAlertDialogBuilder ( activity )
@ -229,13 +228,12 @@ class SettingsDownloadController : SettingsController() {
. create ( )
. create ( )
}
}
private fun get ExternalDirs( ) : List < File > {
private fun get DefaultDownloadDir( ) : File {
val defaultDir = Environment . getExternalStorageDirectory ( ) . absolutePath +
val defaultDir = Environment . getExternalStorageDirectory ( ) . absolutePath +
File . separator + resources ?. getString ( R . string . app _name ) +
File . separator + resources ?. getString ( R . string . app _name ) +
File . separator + " downloads "
File . separator + " downloads "
return mutableListOf ( File ( defaultDir ) ) +
return File ( defaultDir )
ContextCompat . getExternalFilesDirs ( activity !! , " " ) . filterNotNull ( )
}
}
}
}