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
|
|
|
|
|
|
|
|
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
|
2019-03-09 02:32:29 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.model.PlaylistSong
|
2019-03-04 03:55:09 +00:00
|
|
|
import code.name.monkey.retromusic.model.Song
|
2018-11-30 01:06:16 +00:00
|
|
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
|
|
|
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
2019-03-28 13:32:53 +00:00
|
|
|
import kotlinx.android.synthetic.main.dialog_delete.*
|
|
|
|
|
2018-11-30 01:06:16 +00:00
|
|
|
|
|
|
|
class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
2019-03-28 13:32:53 +00:00
|
|
|
return inflater.inflate(R.layout.dialog_delete, container, false)
|
2018-11-30 01:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2019-03-04 03:55:09 +00:00
|
|
|
val songs = arguments!!.getParcelableArrayList<Song>("songs")
|
2018-11-30 01:06:16 +00:00
|
|
|
val content: CharSequence
|
2019-01-14 12:17:22 +00:00
|
|
|
if (songs!!.size > 1) {
|
2018-11-30 01:06:16 +00:00
|
|
|
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 {
|
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-03-18 17:46:52 +00:00
|
|
|
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
|
|
|
|
bannerTitle.text = content;
|
2019-01-28 10:45:51 +00:00
|
|
|
actionDelete.apply {
|
2019-03-28 13:32:53 +00:00
|
|
|
setIconResource(R.drawable.ic_delete_white_24dp)
|
|
|
|
setText(R.string.remove_action)
|
2019-01-28 10:45:51 +00:00
|
|
|
setTextColor(ThemeStore.textColorSecondary(context))
|
|
|
|
setOnClickListener {
|
2019-03-05 02:40:57 +00:00
|
|
|
val playlistSongs = ArrayList<PlaylistSong>()
|
|
|
|
playlistSongs.addAll(songs as ArrayList<PlaylistSong>)
|
|
|
|
PlaylistsUtil.removeFromPlaylist(activity!!, playlistSongs)
|
2019-01-28 10:45:51 +00:00
|
|
|
dismiss()
|
|
|
|
}
|
2019-03-09 02:32:29 +00:00
|
|
|
MaterialUtil.setTint(this)
|
2019-01-28 10:45:51 +00:00
|
|
|
}
|
2019-03-18 17:46:52 +00:00
|
|
|
|
2018-12-05 04:29:55 +00:00
|
|
|
|
2019-01-28 10:45:51 +00:00
|
|
|
actionCancel.apply {
|
2019-03-28 13:32:53 +00:00
|
|
|
setIconResource(R.drawable.ic_close_white_24dp)
|
2019-01-28 10:45:51 +00:00
|
|
|
setTextColor(ThemeStore.textColorSecondary(context))
|
|
|
|
setOnClickListener { dismiss() }
|
2019-03-09 02:32:29 +00:00
|
|
|
MaterialUtil.setTint(this, false)
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|