Skip to content

Commit

Permalink
Parallel downloads preference
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Apr 26, 2018
1 parent e4dd783 commit 2bc9977
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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)

}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!!)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<item>5</item>
</string-array>

<string-array name="pref_downloads_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

<string-array name="pref_transcoding_values">
<item>l</item>
<item>m</item>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@
<string name="folder_image">Folder Image</string>
<string name="image_about_current_folder">Image about current folder</string>
<string name="player_not_ready">Player not ready - probably not connected to server</string>
<string name="transcoding">TRANSCODING</string>
<string name="pref_downloads_summary">When dowloading folder %1$s files will download in parallell.
Assure you have enough transcoding slots on the server</string>
</resources>
15 changes: 14 additions & 1 deletion app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<PreferenceCategory
android:key="prefs_transcoding"
android:title="TRANSCODING">
android:title="@string/transcoding">
<ListPreference
android:defaultValue="m"
android:entries="@array/pref_transcoding_names"
Expand All @@ -61,6 +61,19 @@
android:title="@string/pref_transcoding_title" />

</PreferenceCategory>
<PreferenceCategory
android:key="prefs_downloads"
android:title="DOWNLOADS"
>
<ListPreference
android:key="pref_downloads"
android:title="Parallel Downloads"
android:entries="@array/pref_downloads_values"
android:entryValues="@array/pref_downloads_values"
android:defaultValue="2"
/>
</PreferenceCategory>



</PreferenceScreen>

0 comments on commit 2bc9977

Please sign in to comment.