From 2bc99776d2088ea0573483deb870b04e322a9675 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 26 Apr 2018 10:48:23 +0200 Subject: [PATCH] Parallel downloads preference --- .../eu/zderadicka/audioserve/SettingsActivity.kt | 10 +++++++++- .../zderadicka/audioserve/net/DownloadService.kt | 9 ++++++--- app/src/main/res/values/arrays.xml | 7 +++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings.xml | 15 ++++++++++++++- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt b/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt index f0037b8..65206d6 100644 --- a/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt +++ b/app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt @@ -141,7 +141,7 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen activity.externalMediaDirs.forEachIndexed { index, file -> if (Environment.getExternalStorageState(file) == Environment.MEDIA_MOUNTED) { - val name = getString(R.string.storage_external, index) + val name = getString(R.string.storage_external, index.toString()) l.add(Pair(name+ " (${fileSize(file.freeSpace)})",file.absolutePath)) } } @@ -205,6 +205,14 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen val name = if (idx>=0) pref.entries.get(idx) else "" pref.summary = "$name : $value" } + "pref_downloads" -> { + if (pref !is ListPreference) return + val p = sps.getString("pref_downloads", null) ?: return + pref.summary = getString(R.string.pref_downloads_summary, p) + + } + + } } diff --git a/app/src/main/java/eu/zderadicka/audioserve/net/DownloadService.kt b/app/src/main/java/eu/zderadicka/audioserve/net/DownloadService.kt index 27762a1..49c5b98 100644 --- a/app/src/main/java/eu/zderadicka/audioserve/net/DownloadService.kt +++ b/app/src/main/java/eu/zderadicka/audioserve/net/DownloadService.kt @@ -4,6 +4,7 @@ import android.app.* import android.content.Context import android.content.Intent import android.os.* +import android.preference.PreferenceManager import android.support.annotation.RequiresApi import android.support.v4.app.NotificationCompat import android.support.v4.media.MediaBrowserCompat @@ -110,14 +111,16 @@ class DownloadService : Service() { doneCount = 0 failedCount = 0 - startLoaders() + val numLoaders = PreferenceManager.getDefaultSharedPreferences(this) + .getString("pref_downloads", "2").toInt() + startLoaders(numLoaders) } - private fun startLoaders() { + private fun startLoaders(numLoaders: Int) { if (downloadThreads.size > 0) { throw IllegalStateException("Loaders already started") } - val numLoaders = 2 + for (i in 1..numLoaders) { val loader = FileLoader(queue = queue, context = this, token = apiClient.token!!) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1ed1ae2..cab916c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -8,6 +8,13 @@ 5 + + 1 + 2 + 3 + 4 + + l m diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6c47c83..dfd25a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,4 +67,7 @@ Folder Image Image about current folder Player not ready - probably not connected to server + TRANSCODING + When dowloading folder %1$s files will download in parallell. + Assure you have enough transcoding slots on the server diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 393662d..a79241f 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -52,7 +52,7 @@ + android:title="@string/transcoding"> + + + + \ No newline at end of file