2018-11-30 01:06:16 +00:00
|
|
|
package code.name.monkey.retromusic.dialogs
|
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.text.Html
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import code.name.monkey.appthemehelper.ThemeStore
|
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.model.PlaylistSong
|
|
|
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
|
|
|
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
2018-12-05 04:29:55 +00:00
|
|
|
import kotlinx.android.synthetic.main.dialog_remove_from_playlist.*
|
2018-11-30 01:06:16 +00:00
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
return inflater.inflate(R.layout.dialog_remove_from_playlist, container, false)
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
|
|
val songs = arguments!!.getParcelableArrayList<PlaylistSong>("songs")
|
|
|
|
val title: Int
|
|
|
|
val content: CharSequence
|
2019-01-14 12:17:22 +00:00
|
|
|
if (songs!!.size > 1) {
|
2018-11-30 01:06:16 +00:00
|
|
|
title = R.string.remove_songs_from_playlist_title
|
|
|
|
content = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
Html.fromHtml(getString(R.string.remove_x_songs_from_playlist, songs.size), Html.FROM_HTML_MODE_LEGACY)
|
|
|
|
} else {
|
|
|
|
Html.fromHtml(getString(R.string.remove_x_songs_from_playlist, songs.size))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
title = R.string.remove_song_from_playlist_title
|
2019-01-14 12:17:22 +00:00
|
|
|
content = Html.fromHtml(getString(R.string.remove_song_x_from_playlist, songs[0].title))
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
2019-01-28 10:45:51 +00:00
|
|
|
actionDelete.apply {
|
|
|
|
text = content
|
|
|
|
setTextColor(ThemeStore.textColorSecondary(context))
|
|
|
|
setOnClickListener {
|
|
|
|
PlaylistsUtil.removeFromPlaylist(activity!!, songs)
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bannerTitle.apply {
|
|
|
|
setText(title)
|
|
|
|
setTextColor(ThemeStore.textColorPrimary(context))
|
|
|
|
}
|
2018-12-05 04:29:55 +00:00
|
|
|
|
2019-01-28 10:45:51 +00:00
|
|
|
actionCancel.apply {
|
|
|
|
setTextColor(ThemeStore.textColorSecondary(context))
|
|
|
|
setOnClickListener { dismiss() }
|
2018-12-05 04:29:55 +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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|