Added now playnig queue
This commit is contained in:
parent
4d6286401b
commit
7289b271dc
10 changed files with 164 additions and 36 deletions
|
@ -223,30 +223,15 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP
|
|||
|
||||
}
|
||||
|
||||
private fun showPromotionalOffer() {
|
||||
/*MaterialDialog(this).show {
|
||||
positiveButton(text = "Buy") { startActivity(Intent(this@MainActivity, PurchaseActivity::class.java)) }
|
||||
negativeButton(android.R.string.cancel)
|
||||
customView(R.layout.dialog_promotional_offer)
|
||||
onDismiss {
|
||||
PreferenceManager.getDefaultSharedPreferences(this@MainActivity)
|
||||
.edit()
|
||||
.putBoolean("shown", true)
|
||||
.apply()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun selectedFragment(itemId: Int) {
|
||||
when (itemId) {
|
||||
R.id.action_album, R.id.action_artist, R.id.action_playlist, R.id.action_genre, R.id.action_song -> setCurrentFragment(
|
||||
LibraryFragment.newInstance(itemId),
|
||||
itemId.toString()
|
||||
)
|
||||
R.id.action_home -> setCurrentFragment(
|
||||
BannerHomeFragment.newInstance(),
|
||||
BannerHomeFragment.TAG
|
||||
)
|
||||
R.id.action_album,
|
||||
R.id.action_artist,
|
||||
R.id.action_playlist,
|
||||
R.id.action_genre,
|
||||
R.id.action_playing_queue,
|
||||
R.id.action_song -> setCurrentFragment(LibraryFragment.newInstance(itemId), itemId.toString())
|
||||
R.id.action_home -> setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG)
|
||||
else -> {
|
||||
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG)
|
||||
}
|
||||
|
|
|
@ -136,6 +136,9 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
case R.id.action_genre:
|
||||
selectedFragment(GenresFragment.Companion.newInstance());
|
||||
break;
|
||||
case R.id.action_playing_queue:
|
||||
selectedFragment(PlayingQueueFragment.Companion.newInstance());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package code.name.monkey.retromusic.fragments.mainactivity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter
|
||||
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
||||
import kotlinx.android.synthetic.main.activity_playing_queue.*
|
||||
|
||||
/**
|
||||
* Created by hemanths on 2019-12-08.
|
||||
*/
|
||||
class PlayingQueueFragment : AbsLibraryPagerRecyclerViewFragment<PlayingQueueAdapter, LinearLayoutManager>() {
|
||||
|
||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupRecyclerView()
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
||||
val animator = RefactoredDefaultItemAnimator()
|
||||
|
||||
wrappedAdapter = recyclerViewDragDropManager?.createWrappedAdapter(createAdapter())
|
||||
|
||||
|
||||
recyclerView.apply {
|
||||
layoutManager = createLayoutManager()
|
||||
adapter = wrappedAdapter
|
||||
itemAnimator = animator
|
||||
recyclerViewDragDropManager?.attachRecyclerView(this)
|
||||
}
|
||||
createLayoutManager().scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(requireContext(), recyclerView)
|
||||
}
|
||||
|
||||
override fun createLayoutManager(): LinearLayoutManager {
|
||||
return LinearLayoutManager(requireContext())
|
||||
}
|
||||
|
||||
override fun createAdapter(): PlayingQueueAdapter {
|
||||
return PlayingQueueAdapter(requireActivity() as AppCompatActivity, MusicPlayerRemote.playingQueue, MusicPlayerRemote.position, R.layout.item_queue)
|
||||
}
|
||||
|
||||
override fun onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
updateQueue()
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
updateQueuePosition()
|
||||
}
|
||||
|
||||
private fun updateQueuePosition() {
|
||||
adapter?.setCurrent(MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
}
|
||||
|
||||
private fun updateQueue() {
|
||||
adapter?.swapDataSet(MusicPlayerRemote.playingQueue, MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
}
|
||||
|
||||
private fun resetToCurrentPosition() {
|
||||
recyclerView.stopScroll()
|
||||
createLayoutManager().scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
recyclerViewDragDropManager?.cancelDrag()
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override val emptyMessage: Int
|
||||
get() = R.string.no_playing_queue
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.release()
|
||||
recyclerViewDragDropManager = null
|
||||
}
|
||||
|
||||
if (wrappedAdapter != null) {
|
||||
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
||||
wrappedAdapter = null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val TAG: String = PlayingQueueFragment::class.java.simpleName
|
||||
|
||||
fun newInstance(): PlayingQueueFragment {
|
||||
return PlayingQueueFragment()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,8 +59,9 @@ public class CategoryInfo implements Parcelable {
|
|||
SONGS(R.id.action_song, R.string.songs, R.drawable.toggle_audiotrack),
|
||||
ALBUMS(R.id.action_album, R.string.albums, R.drawable.toggle_album),
|
||||
ARTISTS(R.id.action_artist, R.string.artists, R.drawable.toggle_artist),
|
||||
PLAYLISTS(R.id.action_playlist, R.string.playlists, R.drawable.toggle_queue_music),
|
||||
GENRES(R.id.action_genre, R.string.genres, R.drawable.toggle_guitar);
|
||||
PLAYLISTS(R.id.action_playlist, R.string.playlists, R.drawable.toggle_playlist),
|
||||
GENRES(R.id.action_genre, R.string.genres, R.drawable.toggle_guitar),
|
||||
QUEUE(R.id.action_playing_queue, R.string.queue, R.drawable.toggle_queue_music);
|
||||
|
||||
public final int stringRes;
|
||||
public final int id;
|
||||
|
|
|
@ -61,11 +61,10 @@ class LibraryPreferenceDialog : PreferenceDialogFragmentCompat() {
|
|||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = requireActivity().layoutInflater.inflate(R.layout.preference_dialog_library_categories, null)
|
||||
|
||||
val categoryInfos: List<CategoryInfo>
|
||||
if (savedInstanceState != null) {
|
||||
categoryInfos = savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES)!!
|
||||
val categoryInfos: List<CategoryInfo> = if (savedInstanceState != null) {
|
||||
savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES)!!
|
||||
} else {
|
||||
categoryInfos = PreferenceUtil.getInstance(requireContext()).libraryCategoryInfos
|
||||
PreferenceUtil.getInstance(requireContext()).libraryCategoryInfos
|
||||
}
|
||||
adapter = CategoryInfoAdapter(categoryInfos)
|
||||
|
||||
|
|
|
@ -885,13 +885,14 @@ public final class PreferenceUtil {
|
|||
|
||||
@NonNull
|
||||
public List<CategoryInfo> getDefaultLibraryCategoryInfos() {
|
||||
List<CategoryInfo> defaultCategoryInfos = new ArrayList<>(6);
|
||||
List<CategoryInfo> defaultCategoryInfos = new ArrayList<>(7);
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.HOME, true));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.SONGS, true));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.ALBUMS, true));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.ARTISTS, true));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.PLAYLISTS, true));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.GENRES, false));
|
||||
defaultCategoryInfos.add(new CategoryInfo(CategoryInfo.Category.QUEUE, false));
|
||||
return defaultCategoryInfos;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/md_white_1000"
|
||||
android:pathData="M4 10h12v2H4zm0-4h12v2H4zm0 8h8v2H4zm10 0v6l5-3z" />
|
||||
</vector>
|
||||
android:pathData="M19,9L2,9v2h17L19,9zM19,5L2,5v2h17L19,5zM2,15h13v-2L2,13v2zM17,13v6l5,-3 -5,-3z" />
|
||||
</vector>
|
||||
|
|
18
app/src/main/res/drawable/toggle_playlist.xml
Normal file
18
app/src/main/res/drawable/toggle_playlist.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/ic_playlist_play_white_24dp" android:state_checked="true" />
|
||||
<item android:drawable="@drawable/ic_playlist_play_white_24dp" />
|
||||
</selector>
|
|
@ -3,6 +3,7 @@
|
|||
<item name="action_new_playlist" type="id" />
|
||||
<item name="action_show_lyrics" type="id" />
|
||||
<item name="action_genre" type="id" />
|
||||
<item name="action_playing_queue" type="id" />
|
||||
<item name="action_album_sort_order_asc" type="id" />
|
||||
<item name="action_album_sort_order_desc" type="id" />
|
||||
<item name="action_album_sort_order_artist" type="id" />
|
||||
|
|
|
@ -812,4 +812,5 @@
|
|||
<string name="your_account_data_is_only_used_for_authentication">Your account data is only used for authentication.</string>
|
||||
<string name="pref_header_advanced">Advanced</string>
|
||||
<string name="pref_header_blacklist">Blacklist</string>
|
||||
<string name="no_playing_queue">No songs playing</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue