Convert to material dialogs 3

This commit is contained in:
h4h13 2019-05-16 02:25:57 +05:30
parent b94e94a636
commit fb3546cf4b
13 changed files with 360 additions and 307 deletions

View file

@ -21,6 +21,7 @@ import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.smartplaylist.AbsSmartPlaylist
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
class ClearSmartPlaylistDialog : DialogFragment() {
@ -32,7 +33,7 @@ class ClearSmartPlaylistDialog : DialogFragment() {
val content = Html.fromHtml(getString(R.string.clear_playlist_x, playlist!!.name))
return MaterialDialog(activity!!).show {
return MaterialDialog(activity!!, BottomSheet()).show {
title(title)
message(text = content)
positiveButton(R.string.clear_action) {

View file

@ -14,63 +14,105 @@
package code.name.monkey.retromusic.dialogs
import android.content.res.ColorStateList
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.provider.MediaStore
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.layout
import code.name.monkey.retromusic.R.string
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PlaylistsUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_playlist.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
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 : RoundedBottomSheetDialogFragment() {
class CreatePlaylistDialog : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_playlist, container, false)
}
/* override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_playlist, container, false)
}*/
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
/* override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
val accentColor = ThemeStore.accentColor(context!!)
val accentColor = ThemeStore.accentColor(context!!)
MaterialUtil.setTint(actionCreate, true)
MaterialUtil.setTint(actionCancel, false)
MaterialUtil.setTint(actionNewPlaylistContainer, false)
actionNewPlaylist.setHintTextColor(ColorStateList.valueOf(accentColor))
actionNewPlaylist.setTextColor(ThemeStore.textColorPrimary(context!!))
val songs = arguments!!.getParcelableArrayList<Song>("songs")
actionCancel.setOnClickListener { dismiss() }
actionCreate.setOnClickListener {
if (activity == null) {
return@setOnClickListener
}
if (!actionNewPlaylist!!.text!!.toString().trim { it <= ' ' }.isEmpty()) {
val playlistId = PlaylistsUtil.createPlaylist(activity!!, actionNewPlaylist!!.text!!.toString())
if (playlistId != -1 && activity != null) {
if (songs != null) {
PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true)
}
}
}
dismiss()
}
}*/
private lateinit var playlistView: TextInputEditText
private lateinit var actionNewPlaylistContainer: TextInputLayout
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val materialDialog = MaterialDialog(activity!!, BottomSheet())
.show {
title(string.new_playlist_title)
customView(layout.dialog_playlist)
negativeButton(android.R.string.cancel)
positiveButton(string.create_action) {
if (activity == null) {
return@positiveButton
}
val songs = arguments!!.getParcelableArrayList<Song>("songs")
if (playlistView.text!!.toString().trim { it <= ' ' }.isNotEmpty()) {
val playlistId = PlaylistsUtil.createPlaylist(activity!!, playlistView.text!!.toString())
if (playlistId != -1 && activity != null) {
PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true)
}
}
}
getActionButton(WhichButton.POSITIVE).updateTextColor(ThemeStore.accentColor(context))
}
val dialogView = materialDialog.getCustomView()
playlistView = dialogView.findViewById(R.id.actionNewPlaylist)
actionNewPlaylistContainer = dialogView.findViewById(R.id.actionNewPlaylistContainer)
MaterialUtil.setTint(actionCreate, true)
MaterialUtil.setTint(actionCancel, false)
MaterialUtil.setTint(actionNewPlaylistContainer, false)
actionNewPlaylist.setHintTextColor(ColorStateList.valueOf(accentColor))
actionNewPlaylist.setTextColor(ThemeStore.textColorPrimary(context!!))
val songs = arguments!!.getParcelableArrayList<Song>("songs")
actionCancel.setOnClickListener { dismiss() }
actionCreate.setOnClickListener {
if (activity == null) {
return@setOnClickListener
}
if (!actionNewPlaylist!!.text!!.toString().trim { it <= ' ' }.isEmpty()) {
val playlistId = PlaylistsUtil.createPlaylist(activity!!, actionNewPlaylist!!.text!!.toString())
if (playlistId != -1 && activity != null) {
if (songs != null) {
PlaylistsUtil.addToPlaylist(activity!!, songs, playlistId, true)
}
}
}
dismiss()
}
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
playlistView.setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
return materialDialog
}
companion object {
private const val SONGS = "songs"
@JvmOverloads
fun create(song: Song? = null): CreatePlaylistDialog {
val list = ArrayList<Song>()

View file

@ -14,60 +14,48 @@
package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.string
import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.util.PlaylistsUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_delete.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import java.util.*
class DeletePlaylistDialog : RoundedBottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_delete, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
class DeletePlaylistDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val playlists = arguments!!.getParcelableArrayList<Playlist>("playlist")
val title: Int
val content: CharSequence
content = if (playlists!!.size > 1) {
Html.fromHtml(getString(R.string.delete_x_playlists, playlists.size))
//noinspection ConstantConditions
if (playlists!!.size > 1) {
title = string.delete_playlists_title
content = Html.fromHtml(getString(string.delete_x_playlists, playlists.size))
} else {
Html.fromHtml(getString(R.string.delete_playlist_x, playlists[0].name))
title = string.delete_playlist_title
content = Html.fromHtml(getString(string.delete_playlist_x, playlists[0].name))
}
bannerTitle.text = content
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
actionDelete.apply {
setText(R.string.action_delete)
setOnClickListener {
PlaylistsUtil.deletePlaylists(context, playlists)
dismiss()
}
MaterialUtil.setTint(this)
icon = ContextCompat.getDrawable(context, R.drawable.ic_delete_white_24dp)
}
actionCancel.apply {
MaterialUtil.setTint(this, false)
setOnClickListener { dismiss() }
icon = ContextCompat.getDrawable(context, R.drawable.ic_close_white_24dp)
}
return MaterialDialog(activity!!, BottomSheet())
.show {
title(title)
message(text = content)
negativeButton(android.R.string.cancel)
positiveButton(R.string.action_delete) {
if (activity == null)
return@positiveButton
PlaylistsUtil.deletePlaylists(activity!!, playlists)
}
negativeButton(android.R.string.cancel)
}
}
companion object {
fun create(playlist: Playlist): DeletePlaylistDialog {

View file

@ -14,61 +14,43 @@
package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_delete.*
class DeleteSongsDialog : RoundedBottomSheetDialogFragment() {
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
//noinspection unchecked,ConstantConditions
class DeleteSongsDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val songs = arguments!!.getParcelableArrayList<Song>("songs")
val title: Int
val content: CharSequence
if (songs != null) {
content = if (songs.size > 1) {
getString(R.string.delete_x_songs, songs.size)
} else {
getString(R.string.delete_song_x, songs[0].title)
}
bannerTitle.text = Html.fromHtml(content)
if (songs.size > 1) {
title = R.string.delete_songs_title
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size))
} else {
title = R.string.delete_song_title
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title))
}
actionDelete.apply {
setOnClickListener {
if (songs != null) {
MusicUtil.deleteTracks(activity!!, songs)
}
dismiss()
return MaterialDialog(activity!!, BottomSheet()).show {
title(title)
message(text = content)
negativeButton(android.R.string.cancel)
positiveButton(R.string.action_delete) {
if (activity == null)
return@positiveButton
MusicUtil.deleteTracks(activity!!, songs);
}
MaterialUtil.setTint(this)
icon = ContextCompat.getDrawable(context, R.drawable.ic_delete_white_24dp)
}
actionCancel.apply {
MaterialUtil.setTint(this, false)
setOnClickListener { dismiss() }
icon = ContextCompat.getDrawable(context, R.drawable.ic_close_white_24dp)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_delete, container, false)
}
companion object {
fun create(song: Song): DeleteSongsDialog {

View file

@ -14,26 +14,21 @@
package code.name.monkey.retromusic.dialogs
import android.os.Build
import android.app.Dialog
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.appthemehelper.util.MaterialUtil
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.PlaylistSong
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PlaylistsUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_delete.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
class RemoveFromPlaylistDialog : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_delete, container, false)
/*override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(code.name.monkey.retromusic.R.layout.dialog_delete, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -42,18 +37,18 @@ class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
val content: CharSequence
if (songs!!.size > 1) {
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)
Html.fromHtml(getString(code.name.monkey.retromusic.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))
Html.fromHtml(getString(code.name.monkey.retromusic.R.string.remove_x_songs_from_playlist, songs.size))
}
} else {
content = Html.fromHtml(getString(R.string.remove_song_x_from_playlist, songs[0].title))
content = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.remove_song_x_from_playlist, songs[0].title))
}
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
bannerTitle.text = content;
actionDelete.apply {
setIconResource(R.drawable.ic_delete_white_24dp)
setText(R.string.remove_action)
setIconResource(code.name.monkey.retromusic.R.drawable.ic_delete_white_24dp)
setText(code.name.monkey.retromusic.R.string.remove_action)
setTextColor(ThemeStore.textColorSecondary(context))
setOnClickListener {
val playlistSongs = ArrayList<PlaylistSong>()
@ -66,12 +61,39 @@ class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
actionCancel.apply {
setIconResource(R.drawable.ic_close_white_24dp)
setIconResource(code.name.monkey.retromusic.R.drawable.ic_close_white_24dp)
setTextColor(ThemeStore.textColorSecondary(context))
setOnClickListener { dismiss() }
MaterialUtil.setTint(this, false)
}
}
*/
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val songs = arguments!!.getParcelableArrayList<PlaylistSong>("songs")
val title: Int
val content: CharSequence
if (songs.size > 1) {
title = R.string.remove_songs_from_playlist_title
content = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.remove_x_songs_from_playlist, songs.size))
} else {
title = R.string.remove_song_from_playlist_title
content = Html.fromHtml(getString(code.name.monkey.retromusic.R.string.remove_song_x_from_playlist, songs[0].title))
}
return MaterialDialog(activity!!, BottomSheet()).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>)
}
}
}
companion object {

View file

@ -14,31 +14,36 @@
package code.name.monkey.retromusic.dialogs
import android.content.res.ColorStateList
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import android.provider.MediaStore.Audio.Playlists.Members.PLAYLIST_ID
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.layout
import code.name.monkey.retromusic.R.string
import code.name.monkey.retromusic.util.PlaylistsUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_playlist.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
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 RenamePlaylistDialog : RoundedBottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
class RenamePlaylistDialog : DialogFragment() {
/*override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_playlist, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bannerTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
bannerTitle.setText(R.string.rename_playlist_title)
MaterialUtil.setTint(actionNewPlaylistContainer, false)
val accentColor = ThemeStore.accentColor(context!!)
@ -70,6 +75,34 @@ class RenamePlaylistDialog : RoundedBottomSheetDialogFragment() {
MaterialUtil.setTint(this)
icon = ContextCompat.getDrawable(context, R.drawable.ic_edit_white_24dp)
}
}*/
private lateinit var playlistView: TextInputEditText
private lateinit var actionNewPlaylistContainer: TextInputLayout
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val materialDialog = MaterialDialog(activity!!, BottomSheet())
.show {
title(string.rename_playlist_title)
customView(layout.dialog_playlist)
negativeButton(android.R.string.cancel)
positiveButton(string.action_rename) {
if (playlistView.toString().trim { it <= ' ' } != "") {
val playlistId = arguments!!.getLong(PLAYLIST_ID)
PlaylistsUtil.renamePlaylist(context, playlistId, playlistView.text!!.toString())
}
}
getActionButton(WhichButton.POSITIVE).updateTextColor(ThemeStore.accentColor(context))
}
val dialogView = materialDialog.getCustomView()
playlistView = dialogView.findViewById(R.id.actionNewPlaylist)
actionNewPlaylistContainer = dialogView.findViewById(R.id.actionNewPlaylistContainer)
MaterialUtil.setTint(actionNewPlaylistContainer, false)
val playlistId = arguments!!.getLong(PLAYLIST_ID)
playlistView.setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
return materialDialog
}
companion object {
@ -77,7 +110,7 @@ class RenamePlaylistDialog : RoundedBottomSheetDialogFragment() {
fun create(playlistId: Long): RenamePlaylistDialog {
val dialog = RenamePlaylistDialog()
val args = Bundle()
args.putLong("playlist_id", playlistId)
args.putLong(PLAYLIST_ID, playlistId)
dialog.arguments = args
return dialog
}

View file

@ -14,22 +14,27 @@
package code.name.monkey.retromusic.dialogs
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.Html
import android.text.Spanned
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import code.name.monkey.appthemehelper.ThemeStore
import androidx.annotation.NonNull
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.layout
import code.name.monkey.retromusic.R.string
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_file_details.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import org.jaudiotagger.audio.AudioFileIO
import org.jaudiotagger.audio.exceptions.CannotReadException
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
@ -38,79 +43,83 @@ import org.jaudiotagger.tag.TagException
import java.io.File
import java.io.IOException
inline fun ViewGroup.forEach(action: (View) -> Unit) {
for (i in 0 until childCount) {
action(getChildAt(i))
}
}
class SongDetailDialog : RoundedBottomSheetDialogFragment() {
private fun setTextColor(view: ViewGroup) {
view.forEach {
if (it is TextView) {
it.setTextColor(ThemeStore.textColorPrimary(context!!))
}
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_file_details, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val context = context!!
setTextColor(view as ViewGroup)
fileName.text = makeTextWithTitle(context, R.string.label_file_name, "-")
filePath.text = makeTextWithTitle(context, R.string.label_file_path, "-")
fileSize.text = makeTextWithTitle(context, R.string.label_file_size, "-")
fileFormat.text = makeTextWithTitle(context, R.string.label_file_format, "-")
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, "-")
bitrate.text = makeTextWithTitle(context, R.string.label_bit_rate, "-")
samplingRate.text = makeTextWithTitle(context, R.string.label_sampling_rate, "-")
class SongDetailDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context: Activity = activity!!
val song = arguments!!.getParcelable<Song>("song")
val materialDialog = MaterialDialog(context, BottomSheet())
.show {
customView(layout.dialog_file_details,
scrollable = true)
positiveButton(android.R.string.ok)
title(string.action_details)
}
val dialogView = materialDialog.getCustomView()
val fileName: TextView = dialogView.findViewById(R.id.fileName)
val filePath: TextView = dialogView.findViewById(R.id.filePath)
val fileSize: TextView = dialogView.findViewById(R.id.fileSize)
val fileFormat: TextView = dialogView.findViewById(R.id.fileFormat)
val trackLength: TextView = dialogView.findViewById(R.id.trackLength)
val bitRate: TextView = dialogView.findViewById(R.id.bitrate)
val samplingRate: TextView = dialogView.findViewById(R.id.samplingRate)
fileName.text = makeTextWithTitle(context, string.label_file_name, "-")
filePath.text = makeTextWithTitle(context, string.label_file_path, "-")
fileSize.text = makeTextWithTitle(context, string.label_file_size, "-")
fileFormat.text = makeTextWithTitle(context, string.label_file_format, "-")
trackLength.text = makeTextWithTitle(context, string.label_track_length, "-")
bitRate.text = makeTextWithTitle(context, string.label_bit_rate, "-")
samplingRate.text = makeTextWithTitle(context, string.label_sampling_rate, "-")
if (song != null) {
val songFile = File(song.data)
if (songFile.exists()) {
fileName.text = makeTextWithTitle(context, R.string.label_file_name, songFile.name)
filePath.text = makeTextWithTitle(context, R.string.label_file_path, songFile.absolutePath)
fileSize.text = makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length()))
fileName.text = makeTextWithTitle(context, string.label_file_name, songFile.name)
filePath.text = makeTextWithTitle(context, string.label_file_path, songFile.absolutePath)
fileSize.text = makeTextWithTitle(context, string.label_file_size, getFileSizeString(songFile.length()))
try {
val audioFile = AudioFileIO.read(songFile)
val audioHeader = audioFile.audioHeader
fileFormat.text = makeTextWithTitle(context, R.string.label_file_format, audioHeader.format)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString((audioHeader.trackLength * 1000).toLong()))
bitrate.text = makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.bitRate + " kb/s")
samplingRate.text = makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.sampleRate + " Hz")
} catch (e: CannotReadException) {
fileFormat.text = makeTextWithTitle(context, string.label_file_format, audioHeader.format)
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString((audioHeader.trackLength * 1000).toLong()))
bitRate.text = makeTextWithTitle(context, string.label_bit_rate, audioHeader.bitRate + " kb/s")
samplingRate.text = makeTextWithTitle(context, string.label_sampling_rate, audioHeader.sampleRate + " Hz")
} catch (@NonNull e: CannotReadException) {
Log.e(TAG, "error while reading the song file", e)
// fallback
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (e: IOException) {
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (@NonNull e: IOException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (e: TagException) {
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (@NonNull e: TagException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (e: ReadOnlyFileException) {
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (@NonNull e: ReadOnlyFileException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (e: InvalidAudioFrameException) {
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
} catch (@NonNull e: InvalidAudioFrameException) {
Log.e(TAG, "error while reading the song file", e)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
}
} else {
// fallback
fileName.text = makeTextWithTitle(context, R.string.label_file_name, song.title)
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
fileName.text = makeTextWithTitle(context, string.label_file_name, song.title)
trackLength.text = makeTextWithTitle(context, string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
}
}
return materialDialog
}
companion object {

View file

@ -14,58 +14,81 @@
package code.name.monkey.retromusic.dialogs
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
import kotlinx.android.synthetic.main.dialog_file_share.*
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.list.listItems
class SongShareDialog : RoundedBottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_file_share, container, false)
}
class SongShareDialog : DialogFragment() {
/* override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_file_share, container, false)
}
@SuppressLint("StringFormatInvalid")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val song: Song = arguments!!.getParcelable("song") ?: return
@SuppressLint("StringFormatInvalid")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val song: Song = arguments!!.getParcelable("song") ?: return
dialogTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
audioText.apply {
text = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
setTextColor(ThemeStore.textColorSecondary(context!!))
setOnClickListener {
val currentlyListening = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
activity!!.startActivity(Intent.createChooser(Intent().setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
.setType("text/plain"), null))
dismiss()
}
icon = ContextCompat.getDrawable(context, R.drawable.ic_text_fields_black_24dp)
MaterialUtil.setTint(this)
}
dialogTitle.setTextColor(ThemeStore.textColorPrimary(context!!))
audioText.apply {
text = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
setTextColor(ThemeStore.textColorSecondary(context!!))
setOnClickListener {
val currentlyListening = getString(code.name.monkey.retromusic.R.string.currently_listening_to_x_by_x, song.title, song.artistName)
activity!!.startActivity(Intent.createChooser(Intent().setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
.setType("text/plain"), null))
dismiss()
}
icon = ContextCompat.getDrawable(context, code.name.monkey.retromusic.R.drawable.ic_text_fields_black_24dp)
MaterialUtil.setTint(this)
}
audioFile.apply {
setTextColor(ThemeStore.textColorSecondary(context!!))
setOnClickListener {
activity!!.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, context), null))
dismiss()
}
icon = ContextCompat.getDrawable(context, R.drawable.ic_share_white_24dp)
MaterialUtil.setTint(this, false)
}
audioFile.apply {
setTextColor(ThemeStore.textColorSecondary(context!!))
setOnClickListener {
activity!!.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, context), null))
dismiss()
}
icon = ContextCompat.getDrawable(context, code.name.monkey.retromusic.R.drawable.ic_share_white_24dp)
MaterialUtil.setTint(this, false)
}
}*/
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val song: Song = arguments!!.getParcelable("song")
val currentlyListening: String = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
return MaterialDialog(activity!!, BottomSheet())
.title(R.string.what_do_you_want_to_share)
.show {
listItems(items = listOf(getString(code.name.monkey.retromusic.R.string.the_audio_file), "\u201C" + currentlyListening + "\u201D")) { dialog, index, text ->
when (index) {
0 -> {
startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, context), null))
}
1 -> {
activity!!.startActivity(
Intent.createChooser(
Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
.setType("text/plain"),
null
)
)
}
}
}
}
}
companion object {

View file

@ -18,6 +18,14 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.afollestad.materialcab.MaterialCab;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.bottomsheets.BottomSheet;
@ -36,13 +44,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.appthemehelper.common.ATHToolbarActivity;
import code.name.monkey.appthemehelper.util.ATHUtil;
@ -744,14 +745,20 @@ public class FoldersFragment extends AbsMainActivityFragment implements
@Override
protected Dialog createDialog(@NonNull Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.progress_bar, null);
view.setBackgroundColor(ThemeStore.Companion.primaryColor(context));
ProgressBar progressBar = view.findViewById(R.id.progressBar);
ViewUtil.INSTANCE.setProgressDrawable(progressBar, ThemeStore.Companion.accentColor(context));
TintHelper.setTintAuto(progressBar, ThemeStore.Companion.accentColor(context), false);
MaterialDialog materialDialog = new MaterialDialog(context, new BottomSheet());
materialDialog.setContentView(view);
materialDialog.title(R.string.listing_files, "");
materialDialog.setOnCancelListener(dialog -> cancel(false));
materialDialog.setOnDismissListener(dialog -> cancel(false));
materialDialog.negativeButton(android.R.string.cancel, "", materialDialog1 -> {
cancel(false);
return null;
});
return materialDialog;
}
}
}

View file

@ -6,17 +6,6 @@
android:orientation="vertical"
tools:ignore="NewApi,RtlSymmetry">
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@+id/title"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/action_details"
android:textStyle="bold"
tools:ignore="MissingPrefix" />
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@+id/filePath"
android:layout_width="wrap_content"

View file

@ -4,23 +4,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp">
android:padding="16dp">
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@+id/bannerTitle"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/new_playlist_title" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/actionNewPlaylistContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText
@ -32,39 +23,4 @@
android:inputType="textPersonName|textCapWords|text"
android:padding="16dp" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/actionCancel"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:paddingStart="24dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@android:string/cancel"
app:icon="@drawable/ic_close_white_24dp"
app:strokeWidth="2dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/actionCreate"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:paddingStart="24dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@string/create_action"
app:backgroundTint="@color/md_pink_A400"
app:icon="@drawable/ic_playlist_add_white_24dp" />
</LinearLayout>
</LinearLayout>

View file

@ -2,13 +2,13 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"
android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"

View file

@ -150,7 +150,8 @@
<string name="delete_song_x"><![CDATA[Delete the song <b>%1$s</b>?]]></string>
<string name="delete_x_playlists"><![CDATA[Delete <b>%1$d</b> playlists?]]></string>
<string name="delete_x_songs"><![CDATA[Delete <b>%1$d</b> songs?]]></string>
<string name="delete_song_title">Delete song</string>
<string name="delete_songs_title">Delete songs</string>
<string name="deleted_x_songs">Deleted %1$d songs.</string>
<string name="discord_page">Discord</string>