From 31a0ddd73124f1991138d1cef40c5be7e19b9eca Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Fri, 2 Oct 2020 23:45:33 +0530 Subject: [PATCH] Fix small text in Add to playlist dialog --- .../retromusic/dialogs/AddToPlaylistDialog.kt | 32 ++++++++++++------- app/src/main/res/layout/item_simple_text.xml | 9 ++++++ 2 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/layout/item_simple_text.xml diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt index 53acaa25..fc5d6a58 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToPlaylistDialog.kt @@ -2,6 +2,7 @@ package code.name.monkey.retromusic.dialogs import android.app.Dialog import android.os.Bundle +import android.widget.ArrayAdapter import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope @@ -9,7 +10,6 @@ import code.name.monkey.retromusic.EXTRA_PLAYLISTS import code.name.monkey.retromusic.EXTRA_SONG import code.name.monkey.retromusic.R import code.name.monkey.retromusic.db.PlaylistEntity -import code.name.monkey.retromusic.db.SongEntity import code.name.monkey.retromusic.db.toSongsEntity import code.name.monkey.retromusic.extensions.colorButtons import code.name.monkey.retromusic.extensions.extraNotNull @@ -41,30 +41,40 @@ class AddToPlaylistDialog : DialogFragment() { } } + private fun playlistAdapter(playlists: List): ArrayAdapter { + val adapter = ArrayAdapter(requireContext(), R.layout.item_simple_text, R.id.title) + adapter.addAll(playlists) + return adapter + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val playlistEntities: List = - extraNotNull>(EXTRA_PLAYLISTS).value - val songs: List = extraNotNull>(EXTRA_SONG).value - val playlistNames: MutableList = mutableListOf() + val playlistEntities = extraNotNull>(EXTRA_PLAYLISTS).value + val songs = extraNotNull>(EXTRA_SONG).value + val playlistNames = mutableListOf() playlistNames.add(requireContext().resources.getString(R.string.action_new_playlist)) for (entity: PlaylistEntity in playlistEntities) { playlistNames.add(entity.playlistName) } return materialDialog(R.string.add_playlist_title) - .setItems(playlistNames.toTypedArray()) { _, which -> + .setAdapter( + playlistAdapter(playlistNames) + ) { dialog, which -> if (which == 0) { - CreatePlaylistDialog.create(songs) - .show(requireActivity().supportFragmentManager, "Dialog") + showCreateDialog(songs) } else { lifecycleScope.launch(Dispatchers.IO) { - val songEntities: List = - songs.toSongsEntity(playlistEntities[which - 1]) + val songEntities = songs.toSongsEntity(playlistEntities[which - 1]) libraryViewModel.insertSongs(songEntities) libraryViewModel.forceReload(Playlists) } } - dismiss() + dialog.dismiss() } .create().colorButtons() } + + private fun showCreateDialog(songs: List) { + CreatePlaylistDialog.create(songs).show(requireActivity().supportFragmentManager, "Dialog") + } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_simple_text.xml b/app/src/main/res/layout/item_simple_text.xml new file mode 100644 index 00000000..daf36368 --- /dev/null +++ b/app/src/main/res/layout/item_simple_text.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file