Skip to content

Commit

Permalink
Added folder view for recently modified
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Feb 19, 2019
1 parent 1c11f78 commit a96ded5
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "eu.zderadicka.audioserve"
minSdkVersion 21
targetSdkVersion 28
versionCode 24
versionName "0.7.4"
versionCode 25
versionName "0.7.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/eu/zderadicka/audioserve/AudioService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ class AudioService : MediaBrowserServiceCompat() {
const val RECENTLY_LISTENED_TAG = "__AUDIOSERVE_RECENT"
const val COLLECTION_PREFIX = "__COLLECTION_"
const val SEARCH_PREFIX = "__AUDIOSERVE_SEARCH_"
const val RECENTLY_MODIFIED_PREFIX = "__AUDIOSERVE_MODIFIED_"
const val ITEM_IS_COLLECTION = "is-collection"
}

Expand Down Expand Up @@ -806,8 +807,21 @@ mediaSessionConnector.setErrorMessageProvider(messageProvider);
}

}
} else if (parentId.startsWith(RECENTLY_MODIFIED_PREFIX)) {
result.detach()
val s = parentId.substring(RECENTLY_MODIFIED_PREFIX.length)
val collection = if (s.isNullOrBlank()) 0 else s.toInt()
apiClient.loadRecent(collection, options.getBoolean(AUDIOSERVICE_FORCE_RELOAD))
{ it, err ->
if (it != null) {
result.sendResult(it.getMediaItems(cacheManager))
currentFolder = ArrayList()//it.getPlayableItems(cacheManager)

} else if (parentId.startsWith(SEARCH_PREFIX)) {
} else {
Log.e(LOG_TAG, "Recently modified failed with $err")
}
}
}else if (parentId.startsWith(SEARCH_PREFIX)) {
val s = parentId.substring(SEARCH_PREFIX.length)
val m = SEARCH_RE.matchEntire(s)
if (m == null) {
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MainActivity : AppCompatActivity(),
private lateinit var controllerFragment: ControllerFragment
private var pendingMediaItem: MediaBrowserCompat.MediaItem? = null
private var searchPrefix: String? = null
private var collection: Int? = null
private var folderDetails: Bundle? = null

private val mediaServiceConnectionCallback = object : MediaBrowserCompat.ConnectionCallback() {
Expand Down Expand Up @@ -183,10 +184,17 @@ class MainActivity : AppCompatActivity(),
ctl.prepareFromMediaId(item.mediaId, extras)
}

val collection: Int? = collectionFromFolderId(folderId)?: collectionFromSearchId(folderId)
collection = collectionFromFolderId(folderId)?: collectionFromSearchId(folderId)?: collectionFromModifiedId(folderId)
searchPrefix = if (collection == null || isOffline) null else "${AudioService.SEARCH_PREFIX}${collection}_"
Log.d(LOG_TAG, "Loaded folder ${folderId} in collection ${collection}")
this.folderDetails = folderDetails
invalidateOptionsMenu()
updateDrawerMenu()
}

private fun updateDrawerMenu() {
val menu = nav_view.menu
menu.findItem(R.id.nav_modified).isVisible = collection != null
}

private fun stopPlayback() {
Expand Down Expand Up @@ -518,6 +526,14 @@ class MainActivity : AppCompatActivity(),
}
R.id.nav_bookmarks -> {
openBookmarksFolder()
}
R.id.nav_modified -> {
collection?.let {
val folderId = AudioService.RECENTLY_MODIFIED_PREFIX +it
newFolderFragment(folderId, getString(R.string.recently_modified))
}


}
R.id.nav_sleep -> {
val d = SleepDialogFragment()
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/eu/zderadicka/audioserve/data/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ fun collectionFromSearchId(folderId:String): Int? {
return null
}

fun collectionFromModifiedId(folderId:String): Int? {
if (folderId.startsWith(AudioService.RECENTLY_MODIFIED_PREFIX)) {
val m = BEGIN_NUMBERS_RE.find(folderId.substring(AudioService.RECENTLY_MODIFIED_PREFIX.length))
if (m!=null) {
return m.value.toInt()
}
}
return null
}

fun duplicateMediaItemWithExtrasAssured(item: MediaBrowserCompat.MediaItem):MediaBrowserCompat.MediaItem {
val desc = MediaDescriptionCompat.Builder()
.setMediaId(item.description.mediaId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class FolderFragment : MediaFragment(), BaseFolderFragment {
val view = inflater.inflate(R.layout.fragment_folder, container, false)
folderView = view.findViewById(R.id.folderView)
folderView.layoutManager = LinearLayoutManager(context)
val isSearch = folderId.startsWith(AudioService.SEARCH_PREFIX )
val isSearch = folderId.startsWith(AudioService.SEARCH_PREFIX) || folderId.startsWith(AudioService.RECENTLY_MODIFIED_PREFIX)
adapter = FolderAdapter(context!!, isSearch) {item, action, currentlyPlaying ->
mediaActivity?.onItemClicked(item, action, currentlyPlaying)
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/eu/zderadicka/audioserve/net/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ class ApiClient private constructor(val context: Context) {

}

fun loadRecent(collection: Int, forceReload: Boolean, callback: (AudioFolder?, ApiError?) -> Unit) {
var uri = baseUrl
if (collection > 0) {
uri += "$collection/"
}
uri += "recent"
sendRequest(uri, forceReload, {
val f = parseFolderfromJson(it, "recent", "")
if (collection > 0) {
f.collectionIndex = collection
}
f
}, callback)

}

fun loadCollections(callback: (ArrayList<String>?, ApiError?) -> Unit) {
loadCollections(false, callback)
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_menu_modified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer" />
app:menu="@menu/activity_main_drawer"
app:itemTextAppearance="@style/NavDrawerStyle"/>

</android.support.v4.widget.DrawerLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/activity_main_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
android:id="@+id/nav_bookmarks"
android:icon="@drawable/ic_bookmark"
android:title="@string/action_bookmarks" />
<item
android:id="@+id/nav_modified"
android:icon="@drawable/ic_menu_modified"
android:title="@string/action_modified"
android:visible="false"/>

</group>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
<string name="pref_volume_boost_off_summary">Normal volume limits</string>
<string name="pref_volume_boost_db_summary">If Volume boost switch is on volume will be amplified by %1$s dB (valid values are 1 - 30 dB)</string>
<string name="pitch">Pitch:</string>
<string name="action_modified">Recently Modified</string>
<string name="recently_modified">Recently Modified Folders</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<item name="android:progressBackgroundTint">@android:color/white</item>
</style>

<style name="NavDrawerStyle" parent="Base.TextAppearance.AppCompat">
<item name="android:textSize">18dp</item>
</style>



</resources>

0 comments on commit a96ded5

Please sign in to comment.