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
|
|
|
|
|
2020-05-23 21:47:23 +00:00
|
|
|
import android.annotation.SuppressLint
|
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.Audio.Playlists.Members.PLAYLIST_ID
|
2020-05-23 21:47:23 +00:00
|
|
|
import android.view.LayoutInflater
|
2019-05-15 20:55:57 +00:00
|
|
|
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
|
2020-07-19 11:21:15 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.colorButtons
|
2020-05-23 21:47:23 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.extraNotNull
|
2020-07-19 14:39:04 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.materialDialog
|
2018-12-05 04:29:55 +00:00
|
|
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
2019-05-15 20:55:57 +00:00
|
|
|
import com.google.android.material.textfield.TextInputEditText
|
|
|
|
import com.google.android.material.textfield.TextInputLayout
|
2018-12-05 04:29:55 +00:00
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
class RenamePlaylistDialog : DialogFragment() {
|
|
|
|
|
2020-05-23 09:27:55 +00:00
|
|
|
|
2020-05-23 21:47:23 +00:00
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
override fun onCreateDialog(
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): Dialog {
|
|
|
|
val layout = LayoutInflater.from(requireContext())
|
|
|
|
.inflate(R.layout.dialog_playlist, null)
|
|
|
|
val inputEditText: TextInputEditText = layout.findViewById(R.id.actionNewPlaylist)
|
|
|
|
val nameContainer: TextInputLayout =
|
|
|
|
layout.findViewById(R.id.actionNewPlaylistContainer)
|
|
|
|
MaterialUtil.setTint(nameContainer, false)
|
|
|
|
|
2020-07-19 14:39:04 +00:00
|
|
|
return materialDialog(R.string.rename_playlist_title)
|
2020-05-23 21:47:23 +00:00
|
|
|
.setView(layout)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.action_rename) { _, _ ->
|
|
|
|
val name = inputEditText.text.toString()
|
|
|
|
if (name.isNotEmpty()) {
|
|
|
|
PlaylistsUtil.renamePlaylist(
|
|
|
|
requireContext(),
|
|
|
|
extraNotNull<Long>(PLAYLIST_ID).value,
|
|
|
|
name
|
|
|
|
)
|
2019-05-15 20:55:57 +00:00
|
|
|
}
|
2020-02-01 17:53:26 +00:00
|
|
|
}
|
2020-05-23 21:47:23 +00:00
|
|
|
.create()
|
2020-07-19 11:21:15 +00:00
|
|
|
.colorButtons()
|
2018-12-05 04:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
fun create(playlistId: Long): RenamePlaylistDialog {
|
|
|
|
val dialog = RenamePlaylistDialog()
|
|
|
|
val args = Bundle()
|
2019-05-15 20:55:57 +00:00
|
|
|
args.putLong(PLAYLIST_ID, playlistId)
|
2018-12-05 04:29:55 +00:00
|
|
|
dialog.arguments = args
|
|
|
|
return dialog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|