mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-02 11:58:27 +00:00
Added playlist renaming to Android client UI.
This commit is contained in:
parent
c8c9d94f9a
commit
a01603d200
@ -143,6 +143,8 @@ class CategoryBrowseActivity : BaseActivity(), Filterable {
|
||||
private val contextMenuListener = object: ItemContextMenuMixin.EventListener() {
|
||||
override fun onPlaylistDeleted(id: Long) = requery()
|
||||
|
||||
override fun onPlaylistUpdated(id: Long) = requery()
|
||||
|
||||
override fun onPlaylistCreated(id: Long) =
|
||||
if (navigationType == NavigationType.Select) navigateToSelect(id) else requery()
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
}
|
||||
|
||||
fun createPlaylist() =
|
||||
EnterPlaylistNameDialog.show(activity, this)
|
||||
EnterPlaylistNameDialog.showForCreate(activity, this)
|
||||
|
||||
fun createPlaylist(playlistName: String) {
|
||||
provider.createPlaylist(playlistName).subscribeBy(
|
||||
@ -107,6 +107,22 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
})
|
||||
}
|
||||
|
||||
fun renamePlaylist(newName: String, id: Long) {
|
||||
provider.renamePlaylist(id, newName).subscribeBy(
|
||||
onNext = { success ->
|
||||
if (success) {
|
||||
listener?.onPlaylistUpdated(id)
|
||||
showSuccess(activity.getString(R.string.playlist_renamed, newName))
|
||||
}
|
||||
else {
|
||||
showError(activity.getString(R.string.playlist_not_renamed, newName))
|
||||
}
|
||||
},
|
||||
onError = {
|
||||
showError(activity.getString(R.string.playlist_not_renamed, newName))
|
||||
})
|
||||
}
|
||||
|
||||
fun addToPlaylist(track: ITrack) =
|
||||
addToPlaylist(listOf(track))
|
||||
|
||||
@ -197,6 +213,9 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
R.id.menu_playlist_delete -> {
|
||||
ConfirmDeletePlaylistDialog.show(activity, this, playlistName, playlistId)
|
||||
}
|
||||
R.id.menu_playlist_rename -> {
|
||||
EnterPlaylistNameDialog.showForRename(activity, this, playlistName, playlistId)
|
||||
}
|
||||
R.id.menu_playlist_play -> {
|
||||
val playback = PlaybackServiceFactory.instance(Application.instance!!)
|
||||
playback.play(Messages.Category.PLAYLISTS, playlistId)
|
||||
@ -357,18 +376,33 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
}
|
||||
|
||||
class EnterPlaylistNameDialog: BaseDialogFragment() {
|
||||
enum class Action { Create, Rename }
|
||||
private lateinit var mixin: ItemContextMenuMixin
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val editText = EditText(activity)
|
||||
val action = arguments.getSerializable(EXTRA_ACTION)
|
||||
val name = arguments.getString(EXTRA_NAME, "")
|
||||
val id = arguments.getLong(EXTRA_ID, -1)
|
||||
|
||||
val buttonId = if (action == Action.Rename)
|
||||
R.string.button_rename else R.string.button_create
|
||||
|
||||
if (name.isNotBlank()) {
|
||||
editText.setText(name)
|
||||
editText.selectAll()
|
||||
}
|
||||
|
||||
val dlg = AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.playlist_name_title)
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.setPositiveButton(R.string.button_create, { _: DialogInterface, _: Int ->
|
||||
.setPositiveButton(buttonId, { _: DialogInterface, _: Int ->
|
||||
val playlistName = editText.text.toString()
|
||||
if (playlistName.isNotBlank()) {
|
||||
mixin.createPlaylist(playlistName)
|
||||
when (action) {
|
||||
Action.Create -> mixin.createPlaylist(playlistName)
|
||||
Action.Rename -> mixin.renamePlaylist(playlistName, id)
|
||||
}
|
||||
}
|
||||
else {
|
||||
mixin.showError(R.string.playlist_name_error_empty)
|
||||
@ -396,14 +430,34 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
|
||||
companion object {
|
||||
val TAG = "EnterPlaylistNameDialog"
|
||||
private val EXTRA_ACTION = "extra_action"
|
||||
private val EXTRA_NAME = "extra_name"
|
||||
private val EXTRA_ID = "extra_id"
|
||||
|
||||
fun rebind(activity: AppCompatActivity, mixin: ItemContextMenuMixin) {
|
||||
find<EnterPlaylistNameDialog>(activity, TAG)?.mixin = mixin
|
||||
}
|
||||
|
||||
fun show(activity: AppCompatActivity, mixin: ItemContextMenuMixin) {
|
||||
fun showForCreate(activity: AppCompatActivity, mixin: ItemContextMenuMixin) {
|
||||
dismiss(activity, TAG)
|
||||
val bundle = Bundle()
|
||||
bundle.putSerializable(EXTRA_ACTION, Action.Create)
|
||||
show(activity, mixin, bundle)
|
||||
}
|
||||
|
||||
fun showForRename(activity: AppCompatActivity, mixin: ItemContextMenuMixin, name: String, id: Long) {
|
||||
dismiss(activity, TAG)
|
||||
val bundle = Bundle()
|
||||
bundle.putSerializable(EXTRA_ACTION, Action.Rename)
|
||||
bundle.putString(EXTRA_NAME, name)
|
||||
bundle.putLong(EXTRA_ID, id)
|
||||
show(activity, mixin, bundle)
|
||||
}
|
||||
|
||||
private fun show(activity: AppCompatActivity, mixin: ItemContextMenuMixin, bundle: Bundle) {
|
||||
dismiss(activity, TAG)
|
||||
val dialog = EnterPlaylistNameDialog()
|
||||
dialog.arguments = bundle
|
||||
dialog.mixin = mixin
|
||||
dialog.show(activity.supportFragmentManager, TAG)
|
||||
}
|
||||
|
@ -4,6 +4,10 @@
|
||||
android:id="@+id/menu_playlist_play"
|
||||
android:title="@string/menu_play_playlist"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_playlist_rename"
|
||||
android:title="@string/menu_rename_playlist"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_playlist_delete"
|
||||
android:title="@string/menu_delete_playlist"/>
|
||||
|
@ -46,6 +46,7 @@
|
||||
<string name="button_del">delete</string>
|
||||
<string name="button_save_as">save as</string>
|
||||
<string name="button_load">load</string>
|
||||
<string name="button_rename">rename</string>
|
||||
<string name="button_learn_more">learn more</string>
|
||||
<string name="invalid_password_dialog_title">invalid password</string>
|
||||
<string name="invalid_password_dialog_message">the server rejected your password.\n\nchange the password in the settings screen.</string>
|
||||
@ -75,6 +76,7 @@
|
||||
<string name="menu_show_artist_tracks">artist songs</string>
|
||||
<string name="menu_show_genres">genres</string>
|
||||
<string name="menu_delete_playlist">delete</string>
|
||||
<string name="menu_rename_playlist">rename</string>
|
||||
<string name="menu_play_playlist">play now</string>
|
||||
<string name="unknown_value"><unknown></string>
|
||||
<string name="snackbar_streaming_enabled">switched to streaming mode</string>
|
||||
@ -137,6 +139,8 @@
|
||||
<string name="playlist_name_title">playlist name</string>
|
||||
<string name="playlist_created">playlist \'%s\' created</string>
|
||||
<string name="playlist_not_created">could not create playlist \'%s\'</string>
|
||||
<string name="playlist_renamed">playlist \'%s\' renamed</string>
|
||||
<string name="playlist_not_renamed">playlist \'%s\' not renamed</string>
|
||||
<string name="playlist_deleted">playlist \'%s\' deleted</string>
|
||||
<string name="playlist_not_deleted">could not delete playlist \'%s\'</string>
|
||||
<string name="spotlight_playback_mode_title">playback mode</string>
|
||||
|
Loading…
Reference in New Issue
Block a user