From 7289b271dc7a30cdf4f3c30e6b1fa978d1047628 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Sun, 8 Dec 2019 20:48:08 +0530 Subject: [PATCH] Added now playnig queue --- .../retromusic/activities/MainActivity.kt | 29 +---- .../mainactivity/LibraryFragment.java | 3 + .../mainactivity/PlayingQueueFragment.kt | 122 ++++++++++++++++++ .../monkey/retromusic/model/CategoryInfo.java | 5 +- .../preferences/LibraryPreference.kt | 7 +- .../retromusic/util/PreferenceUtil.java | 3 +- .../drawable/ic_playlist_play_white_24dp.xml | 11 +- app/src/main/res/drawable/toggle_playlist.xml | 18 +++ app/src/main/res/values/ids.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 164 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlayingQueueFragment.kt create mode 100644 app/src/main/res/drawable/toggle_playlist.xml diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt index 0a88458f..ac724d2e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -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) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java index 33fd1bd4..e62659bb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java @@ -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; } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlayingQueueFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlayingQueueFragment.kt new file mode 100644 index 00000000..e498b996 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlayingQueueFragment.kt @@ -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() { + + 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() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/CategoryInfo.java b/app/src/main/java/code/name/monkey/retromusic/model/CategoryInfo.java index 3916f1f9..7c3999ff 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/CategoryInfo.java +++ b/app/src/main/java/code/name/monkey/retromusic/model/CategoryInfo.java @@ -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; diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/LibraryPreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/LibraryPreference.kt index 1903463e..bce32754 100644 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/LibraryPreference.kt +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/LibraryPreference.kt @@ -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 - if (savedInstanceState != null) { - categoryInfos = savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES)!! + val categoryInfos: List = if (savedInstanceState != null) { + savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES)!! } else { - categoryInfos = PreferenceUtil.getInstance(requireContext()).libraryCategoryInfos + PreferenceUtil.getInstance(requireContext()).libraryCategoryInfos } adapter = CategoryInfoAdapter(categoryInfos) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index 428c0efe..324eb5ed 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -885,13 +885,14 @@ public final class PreferenceUtil { @NonNull public List getDefaultLibraryCategoryInfos() { - List defaultCategoryInfos = new ArrayList<>(6); + List 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; } diff --git a/app/src/main/res/drawable/ic_playlist_play_white_24dp.xml b/app/src/main/res/drawable/ic_playlist_play_white_24dp.xml index 1eb1b442..1bae1b2d 100644 --- a/app/src/main/res/drawable/ic_playlist_play_white_24dp.xml +++ b/app/src/main/res/drawable/ic_playlist_play_white_24dp.xml @@ -1,12 +1,9 @@ - - - + android:viewportWidth="24.0" + android:viewportHeight="24.0"> - \ No newline at end of file + android:pathData="M19,9L2,9v2h17L19,9zM19,5L2,5v2h17L19,5zM2,15h13v-2L2,13v2zM17,13v6l5,-3 -5,-3z" /> + diff --git a/app/src/main/res/drawable/toggle_playlist.xml b/app/src/main/res/drawable/toggle_playlist.xml new file mode 100644 index 00000000..6540a249 --- /dev/null +++ b/app/src/main/res/drawable/toggle_playlist.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 9f93a55c..a6e2fa36 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -3,6 +3,7 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ebce84b..1552c10a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -812,4 +812,5 @@ Your account data is only used for authentication. Advanced Blacklist + No songs playing