Removed extra actions

This commit is contained in:
h4h13 2020-02-20 21:02:13 +05:30
parent 05b3c18848
commit d2284f410d
12 changed files with 29 additions and 218 deletions

View file

@ -1,16 +1,12 @@
package code.name.monkey.retromusic.adapter.song package code.name.monkey.retromusic.adapter.song
import android.view.View import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatImageView
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder
import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PreferenceUtil import com.google.android.material.button.MaterialButton
import com.google.android.material.textview.MaterialTextView
class ShuffleButtonSongAdapter( class ShuffleButtonSongAdapter(
activity: AppCompatActivity, activity: AppCompatActivity,
@ -32,77 +28,14 @@ class ShuffleButtonSongAdapter(
viewHolder.shuffleAction?.setOnClickListener { viewHolder.shuffleAction?.setOnClickListener {
MusicPlayerRemote.openAndShuffleQueue(dataSet, true) MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
} }
val songCount = activity.resources.getQuantityString(R.plurals.songCount, dataSet.size, dataSet.size)
viewHolder.songCount?.text = songCount
viewHolder.sortAction?.setOnClickListener {
showSortPopupMenu(it)
}
} else { } else {
super.onBindViewHolder(holder, position - 1) super.onBindViewHolder(holder, position - 1)
} }
} }
private fun showGridPopupMenu(view: View) {
val popupMenu = PopupMenu(activity, view)
popupMenu.menuInflater.inflate(R.menu.menu_grid_options, popupMenu.menu)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_grid_size_1 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(1)
}
R.id.action_grid_size_2 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(2)
}
R.id.action_grid_size_3 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(3)
}
R.id.action_grid_size_4 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(4)
}
}
return@setOnMenuItemClickListener true
}
popupMenu.show()
}
private fun showSortPopupMenu(view: View) {
val popupMenu = PopupMenu(activity, view)
popupMenu.menuInflater.inflate(R.menu.menu_song_sort, popupMenu.menu)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_song_sort_order_asc -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_A_Z
}
R.id.action_song_sort_order_desc -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_Z_A
}
R.id.action_song_sort_order_artist -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ARTIST
}
R.id.action_song_sort_order_album -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ALBUM
}
R.id.action_song_sort_order_date -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_DATE
}
R.id.action_song_sort_order_composer -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.COMPOSER
}
R.id.action_song_sort_order_year -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_YEAR
}
}
return@setOnMenuItemClickListener true
}
popupMenu.show()
}
inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) { inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
val playAction: AppCompatImageView? = itemView.findViewById(R.id.playAction) val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
val shuffleAction: AppCompatImageView? = itemView.findViewById(R.id.shuffleAction) val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
val sortAction: AppCompatImageView? = itemView.findViewById(R.id.sortAction)
val songCount: MaterialTextView? = itemView.findViewById(R.id.songCount)
override fun onClick(v: View?) { override fun onClick(v: View?) {
if (itemViewType == OFFSET_ITEM) { if (itemViewType == OFFSET_ITEM) {

View file

@ -1,7 +1,5 @@
package code.name.monkey.retromusic.fragments.mainactivity package code.name.monkey.retromusic.fragments.mainactivity
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
@ -20,7 +18,7 @@ import java.util.ArrayList
import javax.inject.Inject import javax.inject.Inject
class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, LinearLayoutManager>(), class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, LinearLayoutManager>(),
SongView, MainActivityFragmentCallbacks, OnSharedPreferenceChangeListener { SongView, MainActivityFragmentCallbacks {
@Inject @Inject
lateinit var songPresenter: SongPresenter lateinit var songPresenter: SongPresenter
@ -84,13 +82,11 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
super.onResume() super.onResume()
if (adapter?.dataSet.isNullOrEmpty()) if (adapter?.dataSet.isNullOrEmpty())
songPresenter.loadSongs() songPresenter.loadSongs()
PreferenceUtil.getInstance(requireContext()).registerOnSharedPreferenceChangedListener(this)
} }
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
songPresenter.detachView() songPresenter.detachView()
PreferenceUtil.getInstance(requireContext()).unregisterOnSharedPreferenceChangedListener(this)
} }
override fun showEmptyView() { override fun showEmptyView() {
@ -137,10 +133,4 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
override fun handleBackPress(): Boolean { override fun handleBackPress(): Boolean {
return false return false
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
if (key == PreferenceUtil.SONG_SORT_ORDER || key == PreferenceUtil.SONG_GRID_SIZE) {
songPresenter.loadSongs()
}
}
} }

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp" />
<solid android:color="?attr/colorSurface" />
</shape>

View file

@ -14,44 +14,33 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="16dp" android:paddingStart="8dp"
android:paddingEnd="0dp"> android:paddingEnd="8dp">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.button.MaterialButton
android:id="@+id/songCount" android:id="@+id/playAction"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_weight="1" android:layout_weight="1"
android:textAppearance="@style/TextViewSubtitle1" android:text="@string/action_play_all"
android:textStyle="bold" /> app:backgroundTint="?attr/colorSurface"
app:icon="@drawable/ic_play_arrow_white_24dp" />
<com.google.android.material.button.MaterialButton
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/shuffleAction" android:id="@+id/shuffleAction"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_marginStart="4dp"
android:background="?attr/roundSelector" android:layout_marginEnd="4dp"
android:padding="16dp" android:layout_weight="1"
app:srcCompat="@drawable/ic_shuffle_white_24dp" android:text="@string/shuffle"
app:tint="?attr/colorControlNormal" app:backgroundTint="?attr/colorSurface"
tools:tint="@color/black_color" /> app:icon="@drawable/ic_shuffle_white_24dp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sortAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="?attr/roundSelector"
android:padding="16dp"
app:srcCompat="@drawable/ic_sort_white_24dp"
app:tint="?attr/colorControlNormal"
tools:tint="@color/black_color" />
</LinearLayout> </LinearLayout>

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 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.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_grid_size_1"
android:title="@string/grid_size_1" />
<item
android:id="@+id/action_grid_size_2"
android:title="@string/grid_size_2" />
<item
android:id="@+id/action_grid_size_3"
android:title="@string/grid_size_3" />
<item
android:id="@+id/action_grid_size_4"
android:title="@string/grid_size_4" />
</menu>

View file

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 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.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_song_sort_order_asc"
android:title="@string/sort_order_a_z" />
<item
android:id="@+id/action_song_sort_order_desc"
android:title="@string/sort_order_z_a" />
<item
android:id="@+id/action_song_sort_order_artist"
android:title="@string/sort_order_artist" />
<item
android:id="@+id/action_song_sort_order_album"
android:title="@string/sort_order_album" />
<item
android:id="@+id/action_song_sort_order_date"
android:title="@string/sort_order_date" />
<item
android:id="@+id/action_song_sort_order_year"
android:title="@string/sort_order_year" />
<item
android:id="@+id/action_song_sort_order_composer"
android:title="@string/sort_order_composer" />
</menu>

View file

@ -34,7 +34,6 @@
<item name="android:windowLightNavigationBar">false</item> <item name="android:windowLightNavigationBar">false</item>
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
</resources> </resources>

View file

@ -34,6 +34,5 @@
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorPrimary">@color/darkColorPrimary</item> <item name="colorPrimary">@color/darkColorPrimary</item>
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
</resources> </resources>

View file

@ -31,8 +31,7 @@
<item name="rectSelector">@drawable/rect_selector</item> <item name="rectSelector">@drawable/rect_selector</item>
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item> <item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="android:windowLightNavigationBar">true</item> <item name="android:windowLightNavigationBar">true</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
@ -57,8 +56,7 @@
<item name="android:windowLightNavigationBar">false</item> <item name="android:windowLightNavigationBar">false</item>
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
@ -80,7 +78,6 @@
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item> <item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item> <item name="materialButtonStyle">@style/MaterialButtonTheme</item>
<item name="android:windowLightNavigationBar">false</item> <item name="android:windowLightNavigationBar">false</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
</resources> </resources>

View file

@ -827,8 +827,4 @@
<string name="retro_music_player">Retro Music Player</string> <string name="retro_music_player">Retro Music Player</string>
<string name="pro">Pro</string> <string name="pro">Pro</string>
<string name="free">Free</string> <string name="free">Free</string>
<plurals name="songCount">
<item quantity="one">%d Song</item>
<item quantity="other">%d Songs</item>
</plurals>
</resources> </resources>

View file

@ -183,9 +183,4 @@
<item name="android:windowBackground">@drawable/splash</item> <item name="android:windowBackground">@drawable/splash</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
</style> </style>
<style name="RetroPopupTheme">
<item name="android:popupBackground">@drawable/popup_background</item>
<item name="android:popupElevation">4dp</item>
</style>
</resources> </resources>

View file

@ -17,8 +17,7 @@
<item name="roundSelector">@drawable/round_selector</item> <item name="roundSelector">@drawable/round_selector</item>
<item name="rectSelector">@drawable/rect_selector</item> <item name="rectSelector">@drawable/rect_selector</item>
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item> <item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
@ -43,8 +42,7 @@
<!--Manual setting colors--> <!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item> <item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Black" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base.Black" parent="Theme.MaterialComponents.NoActionBar">
@ -65,8 +63,7 @@
<item name="colorOnBackground">@color/blackColorSurface</item> <item name="colorOnBackground">@color/blackColorSurface</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="mcab_popup_theme">@style/ThemeOverlay.AppCompat.Dark</item> <item name="mcab_popup_theme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
@ -87,8 +84,7 @@
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item> <item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item> <item name="materialButtonStyle">@style/MaterialButtonTheme</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style> </style>