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-12-05 04:29:55 +00:00
|
|
|
package code.name.monkey.retromusic.dialogs
|
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
import android.app.Dialog
|
2018-12-05 04:29:55 +00:00
|
|
|
import android.os.Bundle
|
2019-05-15 20:55:57 +00:00
|
|
|
import android.provider.MediaStore
|
|
|
|
import android.widget.TextView
|
|
|
|
import androidx.fragment.app.DialogFragment
|
2018-12-05 04:29:55 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
|
|
|
import code.name.monkey.retromusic.R
|
2019-05-15 20:55:57 +00:00
|
|
|
import code.name.monkey.retromusic.R.layout
|
|
|
|
import code.name.monkey.retromusic.R.string
|
2019-07-30 21:46:50 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.appHandleColor
|
2018-12-05 04:29:55 +00:00
|
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
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
|
|
|
|
import com.afollestad.materialdialogs.customview.customView
|
|
|
|
import com.afollestad.materialdialogs.customview.getCustomView
|
|
|
|
import com.google.android.material.textfield.TextInputEditText
|
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
|
|
|
|
|
|
|
|
|
|
|
class CreatePlaylistDialog : DialogFragment() {
|
|
|
|
|
|
|
|
private lateinit var playlistView: TextInputEditText
|
|
|
|
private lateinit var actionNewPlaylistContainer: TextInputLayout
|
|
|
|
|
2019-08-01 08:27:05 +00:00
|
|
|
override fun onCreateDialog(
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): Dialog {
|
2019-09-17 19:36:13 +00:00
|
|
|
val materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
|
2019-05-15 20:55:57 +00:00
|
|
|
.show {
|
2019-09-17 19:36:13 +00:00
|
|
|
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
|
2019-05-15 20:55:57 +00:00
|
|
|
title(string.new_playlist_title)
|
|
|
|
customView(layout.dialog_playlist)
|
|
|
|
negativeButton(android.R.string.cancel)
|
|
|
|
positiveButton(string.create_action) {
|
|
|
|
if (activity == null) {
|
|
|
|
return@positiveButton
|
|
|
|
}
|
2019-08-01 08:27:05 +00:00
|
|
|
val songs = arguments?.getParcelableArrayList<Song>("songs")
|
|
|
|
?: return@positiveButton
|
2019-05-15 20:55:57 +00:00
|
|
|
|
2019-08-01 08:27:05 +00:00
|
|
|
if (playlistView.text.toString().trim { it <= ' ' }.isNotEmpty()) {
|
|
|
|
val playlistId = PlaylistsUtil.createPlaylist(requireContext(), playlistView.text.toString())
|
2019-05-15 20:55:57 +00:00
|
|
|
if (playlistId != -1 && activity != null) {
|
2019-08-01 08:27:05 +00:00
|
|
|
PlaylistsUtil.addToPlaylist(requireContext(), songs, playlistId, true)
|
2019-05-15 20:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 13:32:53 +00:00
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
val dialogView = materialDialog.getCustomView()
|
|
|
|
playlistView = dialogView.findViewById(R.id.actionNewPlaylist)
|
|
|
|
actionNewPlaylistContainer = dialogView.findViewById(R.id.actionNewPlaylistContainer)
|
2019-03-04 03:55:09 +00:00
|
|
|
|
2019-03-18 17:46:52 +00:00
|
|
|
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
2018-12-05 04:29:55 +00:00
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
|
2019-10-12 19:05:17 +00:00
|
|
|
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE)
|
2019-05-15 20:55:57 +00:00
|
|
|
return materialDialog
|
2018-12-05 04:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
@JvmOverloads
|
|
|
|
fun create(song: Song? = null): CreatePlaylistDialog {
|
|
|
|
val list = ArrayList<Song>()
|
|
|
|
if (song != null) {
|
|
|
|
list.add(song)
|
|
|
|
}
|
|
|
|
return create(list)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun create(songs: ArrayList<Song>): CreatePlaylistDialog {
|
|
|
|
val dialog = CreatePlaylistDialog()
|
|
|
|
val args = Bundle()
|
|
|
|
args.putParcelableArrayList("songs", songs)
|
|
|
|
dialog.arguments = args
|
|
|
|
return dialog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|