Create playlist added to menu
This commit is contained in:
parent
6e8ff6ab71
commit
51d2c17ad7
5 changed files with 30 additions and 33 deletions
|
@ -12,7 +12,7 @@ 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.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.extraNotNull
|
import code.name.monkey.retromusic.extensions.extra
|
||||||
import code.name.monkey.retromusic.extensions.materialDialog
|
import code.name.monkey.retromusic.extensions.materialDialog
|
||||||
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||||
import code.name.monkey.retromusic.fragments.ReloadType.Playlists
|
import code.name.monkey.retromusic.fragments.ReloadType.Playlists
|
||||||
|
@ -46,7 +46,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val view = LayoutInflater.from(requireActivity()).inflate(R.layout.dialog_playlist, null)
|
val view = LayoutInflater.from(requireActivity()).inflate(R.layout.dialog_playlist, null)
|
||||||
val songs = extraNotNull<List<Song>>(EXTRA_SONG).value
|
val songs: List<Song> = extra<List<Song>>(EXTRA_SONG).value ?: emptyList()
|
||||||
val playlistView: TextInputEditText = view.actionNewPlaylist
|
val playlistView: TextInputEditText = view.actionNewPlaylist
|
||||||
val playlistContainer: TextInputLayout = view.actionNewPlaylistContainer
|
val playlistContainer: TextInputLayout = view.actionNewPlaylistContainer
|
||||||
return materialDialog(R.string.new_playlist_title)
|
return materialDialog(R.string.new_playlist_title)
|
||||||
|
@ -59,7 +59,6 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
if (repository.checkPlaylistExists(playlistName).isEmpty()) {
|
if (repository.checkPlaylistExists(playlistName).isEmpty()) {
|
||||||
val playlistId = repository.createPlaylist(PlaylistEntity(playlistName))
|
val playlistId = repository.createPlaylist(PlaylistEntity(playlistName))
|
||||||
println(playlistId)
|
|
||||||
repository.insertSongs(songs.map { it.toSongEntity(playlistId.toInt()) })
|
repository.insertSongs(songs.map { it.toSongEntity(playlistId.toInt()) })
|
||||||
libraryViewModel.forceReload(Playlists)
|
libraryViewModel.forceReload(Playlists)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package code.name.monkey.retromusic.dialogs
|
||||||
|
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
|
||||||
|
class ImportPlaylist : DialogFragment() {
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,6 @@ import code.name.monkey.appthemehelper.common.ATHToolbarActivity.getToolbarBackg
|
||||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog
|
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog
|
||||||
import code.name.monkey.retromusic.extensions.accentColor
|
|
||||||
import code.name.monkey.retromusic.extensions.findNavController
|
import code.name.monkey.retromusic.extensions.findNavController
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||||
import kotlinx.android.synthetic.main.fragment_library.*
|
import kotlinx.android.synthetic.main.fragment_library.*
|
||||||
|
@ -31,25 +30,12 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
|
||||||
navOptions
|
navOptions
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
addPlaylist.apply {
|
|
||||||
accentColor()
|
|
||||||
setOnClickListener {
|
|
||||||
CreatePlaylistDialog().show(childFragmentManager, "ShowCreatePlaylistDialog")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setupNavigationController()
|
setupNavigationController()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNavigationController() {
|
private fun setupNavigationController() {
|
||||||
val navController = findNavController(R.id.fragment_container)
|
val navController = findNavController(R.id.fragment_container)
|
||||||
NavigationUI.setupWithNavController(mainActivity.getBottomNavigationView(), navController)
|
NavigationUI.setupWithNavController(mainActivity.getBottomNavigationView(), navController)
|
||||||
navController.addOnDestinationChangedListener { _, destination, _ ->
|
|
||||||
if (destination.id == R.id.action_playlist) {
|
|
||||||
addPlaylist.show()
|
|
||||||
} else {
|
|
||||||
addPlaylist.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
|
@ -75,6 +61,10 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
|
||||||
null,
|
null,
|
||||||
navOptions
|
navOptions
|
||||||
)
|
)
|
||||||
|
R.id.action_add_to_playlist -> CreatePlaylistDialog().show(
|
||||||
|
childFragmentManager,
|
||||||
|
"ShowCreatePlaylistDialog"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package code.name.monkey.retromusic.fragments.playlists
|
package code.name.monkey.retromusic.fragments.playlists
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
|
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
|
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
|
||||||
|
import kotlinx.android.synthetic.main.fragment_library.*
|
||||||
|
|
||||||
class PlaylistsFragment : AbsRecyclerViewFragment<PlaylistAdapter, GridLayoutManager>() {
|
class PlaylistsFragment : AbsRecyclerViewFragment<PlaylistAdapter, GridLayoutManager>() {
|
||||||
|
|
||||||
|
@ -36,10 +41,18 @@ class PlaylistsFragment : AbsRecyclerViewFragment<PlaylistAdapter, GridLayoutMan
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
|
super.onPrepareOptionsMenu(menu)
|
||||||
|
ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
fun newInstance(): PlaylistsFragment {
|
menu.removeItem(R.id.action_grid_size)
|
||||||
return PlaylistsFragment()
|
menu.removeItem(R.id.action_layout_type)
|
||||||
}
|
menu.removeItem(R.id.action_sort_order)
|
||||||
|
menu.add(0, R.id.action_add_to_playlist, 0, R.string.new_playlist_title)
|
||||||
|
.setIcon(R.drawable.ic_playlist_add)
|
||||||
|
menu.findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||||
|
super.onCreateOptionsMenu(menu, inflater)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,18 +43,6 @@
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/addPlaylist"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:layout_marginBottom="117dp"
|
|
||||||
android:contentDescription="@string/add_playlist_title"
|
|
||||||
android:src="@drawable/ic_playlist_add"
|
|
||||||
app:layout_dodgeInsetEdges="all"
|
|
||||||
app:useCompatPadding="true" />
|
|
||||||
|
|
||||||
<androidx.fragment.app.FragmentContainerView
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/fragment_container"
|
android:id="@+id/fragment_container"
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
|
|
Loading…
Reference in a new issue