diff --git a/app/build.gradle b/app/build.gradle
index 5e48668..109a418 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -18,8 +18,8 @@ android {
applicationId "eu.zderadicka.audioserve"
minSdkVersion 21
targetSdkVersion 28
- versionCode 27
- versionName "0.7.7"
+ versionCode 28
+ versionName "0.7.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
diff --git a/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt b/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt
index 7e0f30b..d663f38 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/AudioService.kt
@@ -63,6 +63,7 @@ private const val REWIND_PLAY_REPEAT = 1_000L
const val AUDIOSERVICE_ACTION_PAUSE = "eu.zderadicka.audioserve.ACTION_PAUSE"
const val AUDIOSERVICE_FORCE_RELOAD = "eu.zderadicka.audioserve.FORCE_RELOAD"
const val AUDIOSERVICE_DONT_PRELOAD_LATEST = "eu.zderadicka.audioserve.NO_PRELOAD_LATEST"
+const val AUDIOSERVE_ORDERING = "eu.zderadicka.audioserve.ORDERING"
private const val AUDIOSERVICE_ACTION_SELF_START = "eu.zderadicka.audioserve.SELF_START"
private const val PAUSE_DELAYED_TASK_SAVE_POSITION = "pause_task_save_position"
private const val PAUSE_DELAYED_TASK_STOP_FOREGROUND = "pause_task_stop_fg"
@@ -878,7 +879,9 @@ mediaSessionConnector.setErrorMessageProvider(messageProvider);
val query = m.groups.get(2)?.value ?: ""
result.detach()
- apiClient.loadSearch(query, collection, options.getBoolean(AUDIOSERVICE_FORCE_RELOAD))
+ apiClient.loadSearch(query, collection,
+ options.getBoolean(AUDIOSERVICE_FORCE_RELOAD),
+ options.getString(AUDIOSERVE_ORDERING))
{ it, err ->
if (it != null) {
result.sendResult(it.getMediaItems(cacheManager))
@@ -902,7 +905,9 @@ mediaSessionConnector.setErrorMessageProvider(messageProvider);
}
result.detach()
- apiClient.loadFolder(folder, index, options.getBoolean(AUDIOSERVICE_FORCE_RELOAD))
+ apiClient.loadFolder(folder, index,
+ options.getBoolean(AUDIOSERVICE_FORCE_RELOAD),
+ options.getString(AUDIOSERVE_ORDERING))
{ it, err ->
checkError(it, err)
{
diff --git a/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt b/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
index a691607..5688350 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
@@ -496,6 +496,24 @@ class MainActivity : AppCompatActivity(),
val searchView = menu.findItem(R.id.action_search).actionView as SearchView
searchView.setSearchableInfo(
searchManager.getSearchableInfo(componentName))
+ val orderingMenu = menu.findItem(R.id.submenu_ordering)
+ if (searchPrefix != null) {
+ orderingMenu.isVisible = true
+
+ val ordering = PreferenceManager
+ .getDefaultSharedPreferences(this)
+ .getString("pref_ordering", FoldersOrdering.Alphabetical.letter)
+ when (ordering) {
+ FoldersOrdering.Alphabetical.letter -> {
+ menu.findItem(R.id.action_ordering_alphabetical).isChecked = true
+ }
+ FoldersOrdering.RecentFirst.letter -> {
+ menu.findItem(R.id.action_ordering_recent).isChecked = true
+ }
+ }
+ } else {
+ orderingMenu.isVisible = false
+ }
return true
}
@@ -525,11 +543,34 @@ class MainActivity : AppCompatActivity(),
true
}
+ R.id.action_ordering_alphabetical -> {
+ item.isChecked = true
+ changeOrdering(FoldersOrdering.Alphabetical)
+ true
+ }
+ R.id.action_ordering_recent -> {
+ changeOrdering(FoldersOrdering.RecentFirst)
+ item.isChecked = true
+ true
+ }
+
else -> return super.onOptionsItemSelected(item)
}
}
+ private fun changeOrdering(ord: FoldersOrdering) {
+
+ val prefs = PreferenceManager.getDefaultSharedPreferences(this)
+ val current = prefs.getString("pref_ordering", FoldersOrdering.Alphabetical.letter)
+ if (ord.letter != current) {
+ Log.d(LOG_TAG, "Changed ordering to ${ord.letter}")
+ prefs.edit().putString("pref_ordering", ord.letter).apply()
+ folderFragment?.reload()
+ }
+
+ }
+
private fun openInitialFolder(folderId: String, folderName: String) {
//
for (i in 0..supportFragmentManager.backStackEntryCount) {
diff --git a/app/src/main/java/eu/zderadicka/audioserve/data/FoldersOrdering.kt b/app/src/main/java/eu/zderadicka/audioserve/data/FoldersOrdering.kt
new file mode 100644
index 0000000..51e1618
--- /dev/null
+++ b/app/src/main/java/eu/zderadicka/audioserve/data/FoldersOrdering.kt
@@ -0,0 +1,7 @@
+package eu.zderadicka.audioserve.data
+
+enum class FoldersOrdering(val letter: String) {
+ Alphabetical("a"),
+ RecentFirst("m")
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/eu/zderadicka/audioserve/fragments/FolderFragment.kt b/app/src/main/java/eu/zderadicka/audioserve/fragments/FolderFragment.kt
index 66e604e..1066ff8 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/fragments/FolderFragment.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/fragments/FolderFragment.kt
@@ -14,6 +14,7 @@ import android.text.format.DateUtils
import android.util.Log
import eu.zderadicka.audioserve.utils.ifStoppedOrDead
import android.os.Parcelable
+import android.preference.PreferenceManager
import android.support.v4.content.ContextCompat
import android.view.*
import android.widget.*
@@ -467,6 +468,9 @@ class FolderFragment : MediaFragment(), BaseFolderFragment {
private fun startLoading(forceReload:Boolean=false) {
val options = Bundle()
+ val ordering = PreferenceManager.getDefaultSharedPreferences(context)
+ .getString("pref_ordering", FoldersOrdering.Alphabetical.letter)
+ options.putString(AUDIOSERVE_ORDERING, ordering)
if (willPrepare) {
willPrepare = false
options.putBoolean(AUDIOSERVICE_DONT_PRELOAD_LATEST, true)
diff --git a/app/src/main/java/eu/zderadicka/audioserve/net/ApiClient.kt b/app/src/main/java/eu/zderadicka/audioserve/net/ApiClient.kt
index 0fd8f22..578bb5a 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/net/ApiClient.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/net/ApiClient.kt
@@ -185,17 +185,23 @@ class ApiClient private constructor(val context: Context) {
}
fun loadFolder(folder: String = "", collection: Int, callback: (AudioFolder?, ApiError?) -> Unit) {
- loadFolder(folder, collection, false, callback)
+ loadFolder(folder, collection, false, null, callback)
}
- fun loadFolder(folder: String = "", collection: Int, forceReload: Boolean, callback: (AudioFolder?, ApiError?) -> Unit) {
+ fun loadFolder(folder: String = "", collection: Int, forceReload: Boolean,
+ ordering: String?,
+ callback: (AudioFolder?, ApiError?) -> Unit) {
var uri = baseUrl
if (collection > 0) {
uri += "$collection/"
}
uri += folder
- sendRequest(uri, forceReload, {
+ val builder = Uri.parse(uri).buildUpon()
+ addOrdering(builder, ordering)
+ val folderUri = builder.build().toString()
+
+ sendRequest(folderUri, forceReload, {
val f = parseFolderfromJson(it, "", folder)
if (collection > 0) {
f.collectionIndex = collection
@@ -205,18 +211,30 @@ class ApiClient private constructor(val context: Context) {
}
fun loadSearch(query: String, collection: Int, callback: (AudioFolder?, ApiError?) -> Unit) {
- loadSearch(query, collection, false, callback)
+ loadSearch(query, collection, false, null, callback)
+ }
+
+ private fun addOrdering(builder: Uri.Builder, ordering: String?) {
+ ordering?.let {
+ if (it != "a") {
+ builder.appendQueryParameter("ord", it)
+ }
+ }
}
- fun loadSearch(query: String, collection: Int, forceReload: Boolean, callback: (AudioFolder?, ApiError?) -> Unit) {
+ fun loadSearch(query: String, collection: Int, forceReload: Boolean,
+ ordering: String?,
+ callback: (AudioFolder?, ApiError?) -> Unit) {
var uri = baseUrl
if (collection > 0) {
uri += "$collection/"
}
uri += "search"
- val queryUri = Uri.parse(uri).buildUpon().appendQueryParameter("q", query).build()
- sendRequest(queryUri.toString(), forceReload, {
+ val queryBuilder = Uri.parse(uri).buildUpon().appendQueryParameter("q", query)
+ addOrdering(queryBuilder, ordering)
+ val queryUri = queryBuilder.build().toString()
+ sendRequest(queryUri, forceReload, {
val f = parseFolderfromJson(it, "search", "")
if (collection > 0) {
f.collectionIndex = collection
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index bf6ab49..d072f63 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -19,6 +19,20 @@
app:showAsAction="ifRoom"
android:icon="@drawable/ic_info"
/>
+ -
+
+
- Recently Modified Folders
Start Sleep Timer
Press Back again to exit
+ Folders Ordering
+ Alphabetical
+ Recent First