PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt

83 lines
3.1 KiB
Kotlin
Raw Normal View History

2019-03-03 09:20:15 +00:00
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
2018-11-30 01:06:16 +00:00
package code.name.monkey.retromusic.dialogs
2019-05-15 20:55:57 +00:00
import android.app.Dialog
2018-11-30 01:06:16 +00:00
import android.os.Bundle
import android.text.Html
2019-05-15 20:55:57 +00:00
import androidx.fragment.app.DialogFragment
2018-11-30 01:06:16 +00:00
import code.name.monkey.retromusic.R
2020-02-01 17:53:26 +00:00
import code.name.monkey.retromusic.R.string
2018-11-30 01:06:16 +00:00
import code.name.monkey.retromusic.model.PlaylistSong
import code.name.monkey.retromusic.util.PlaylistsUtil
2019-09-17 19:36:13 +00:00
import code.name.monkey.retromusic.util.PreferenceUtil
import com.afollestad.materialdialogs.LayoutMode
2019-05-15 20:55:57 +00:00
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
2019-05-15 20:55:57 +00:00
class RemoveFromPlaylistDialog : DialogFragment() {
2019-06-02 06:15:03 +00:00
2019-05-15 20:55:57 +00:00
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val songs = arguments!!.getParcelableArrayList<PlaylistSong>("songs")
2019-08-04 10:08:34 +00:00
var title = 0
var content: CharSequence = ""
if (songs != null) {
if (songs.size > 1) {
title = R.string.remove_songs_from_playlist_title
2020-02-01 17:53:26 +00:00
content = Html.fromHtml(getString(string.remove_x_songs_from_playlist, songs.size))
2019-08-04 10:08:34 +00:00
} else {
title = R.string.remove_song_from_playlist_title
2020-02-01 17:53:26 +00:00
content = Html.fromHtml(
getString(
code.name.monkey.retromusic.R.string.remove_song_x_from_playlist,
songs[0].title
)
)
2019-08-04 10:08:34 +00:00
}
2019-05-15 20:55:57 +00:00
}
2019-09-17 19:36:13 +00:00
return MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
2020-02-01 17:53:26 +00:00
.show {
title(title)
message(text = content)
negativeButton(android.R.string.cancel)
positiveButton(R.string.remove_action) {
if (activity == null)
return@positiveButton
PlaylistsUtil.removeFromPlaylist(activity!!, songs as MutableList<PlaylistSong>)
2019-06-02 06:15:03 +00:00
}
2020-02-01 17:53:26 +00:00
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
}
2019-05-15 20:55:57 +00:00
}
2018-11-30 01:06:16 +00:00
companion object {
fun create(song: PlaylistSong): RemoveFromPlaylistDialog {
val list = ArrayList<PlaylistSong>()
list.add(song)
return create(list)
}
fun create(songs: ArrayList<PlaylistSong>): RemoveFromPlaylistDialog {
val dialog = RemoveFromPlaylistDialog()
val args = Bundle()
args.putParcelableArrayList("songs", songs)
dialog.arguments = args
return dialog
}
}
}