Fix small text in Add to playlist dialog
This commit is contained in:
parent
3af3a89ba5
commit
31a0ddd731
2 changed files with 30 additions and 11 deletions
|
@ -2,6 +2,7 @@ package code.name.monkey.retromusic.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
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.EXTRA_SONG
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.db.PlaylistEntity
|
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.db.toSongsEntity
|
||||||
import code.name.monkey.retromusic.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.extraNotNull
|
import code.name.monkey.retromusic.extensions.extraNotNull
|
||||||
|
@ -41,30 +41,40 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun playlistAdapter(playlists: List<String>): ArrayAdapter<String> {
|
||||||
|
val adapter = ArrayAdapter<String>(requireContext(), R.layout.item_simple_text, R.id.title)
|
||||||
|
adapter.addAll(playlists)
|
||||||
|
return adapter
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val playlistEntities: List<PlaylistEntity> =
|
val playlistEntities = extraNotNull<List<PlaylistEntity>>(EXTRA_PLAYLISTS).value
|
||||||
extraNotNull<List<PlaylistEntity>>(EXTRA_PLAYLISTS).value
|
val songs = extraNotNull<List<Song>>(EXTRA_SONG).value
|
||||||
val songs: List<Song> = extraNotNull<List<Song>>(EXTRA_SONG).value
|
val playlistNames = mutableListOf<String>()
|
||||||
val playlistNames: MutableList<String> = mutableListOf()
|
|
||||||
playlistNames.add(requireContext().resources.getString(R.string.action_new_playlist))
|
playlistNames.add(requireContext().resources.getString(R.string.action_new_playlist))
|
||||||
for (entity: PlaylistEntity in playlistEntities) {
|
for (entity: PlaylistEntity in playlistEntities) {
|
||||||
playlistNames.add(entity.playlistName)
|
playlistNames.add(entity.playlistName)
|
||||||
}
|
}
|
||||||
return materialDialog(R.string.add_playlist_title)
|
return materialDialog(R.string.add_playlist_title)
|
||||||
.setItems(playlistNames.toTypedArray()) { _, which ->
|
.setAdapter(
|
||||||
|
playlistAdapter(playlistNames)
|
||||||
|
) { dialog, which ->
|
||||||
if (which == 0) {
|
if (which == 0) {
|
||||||
CreatePlaylistDialog.create(songs)
|
showCreateDialog(songs)
|
||||||
.show(requireActivity().supportFragmentManager, "Dialog")
|
|
||||||
} else {
|
} else {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val songEntities: List<SongEntity> =
|
val songEntities = songs.toSongsEntity(playlistEntities[which - 1])
|
||||||
songs.toSongsEntity(playlistEntities[which - 1])
|
|
||||||
libraryViewModel.insertSongs(songEntities)
|
libraryViewModel.insertSongs(songEntities)
|
||||||
libraryViewModel.forceReload(Playlists)
|
libraryViewModel.forceReload(Playlists)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.create().colorButtons()
|
.create().colorButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showCreateDialog(songs: List<Song>) {
|
||||||
|
CreatePlaylistDialog.create(songs).show(requireActivity().supportFragmentManager, "Dialog")
|
||||||
|
}
|
||||||
}
|
}
|
9
app/src/main/res/layout/item_simple_text.xml
Normal file
9
app/src/main/res/layout/item_simple_text.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:textAppearance="@style/TextViewBody1"
|
||||||
|
tools:text="@tools:sample/full_names" />
|
Loading…
Reference in a new issue