This commit is contained in:
Hemanth S 2020-05-17 22:18:36 +05:30
parent 6d9860016e
commit 563ae8a699
16 changed files with 63 additions and 50 deletions

View file

@ -24,7 +24,7 @@ android {
vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic"
versionCode 435
versionCode 436
versionName '3.5.300'
multiDexEnabled true

View file

@ -101,15 +101,10 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
public static final String EXPAND_PANEL = "expand_panel";
private static final int APP_UPDATE_REQUEST_CODE = 9002;
private final IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
private MainActivityFragmentCallbacks currentFragment;
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction();
Log.i(TAG, "onReceive: " + action);
if (action != null && action.equals(MusicService.MEDIA_STORE_CHANGED)) {
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG, true);
}
if (action != null && action.equals(Intent.ACTION_SCREEN_OFF)) {
if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) {
final Intent activity = new Intent(context, LockScreenActivity.class);
@ -120,6 +115,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
}
}
};
private MainActivityFragmentCallbacks currentFragment;
private boolean blockRequestPermissions = false;
private MaterialCab cab;
private AppBarLayout mAppBarLayout;
@ -415,14 +411,12 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener);
}
public void setCurrentFragment(@NonNull Fragment fragment, @NonNull String tag, boolean force) {
public void setCurrentFragment(@NonNull Fragment fragment, @NonNull String tag) {
String currentTag = null;
if (getSupportFragmentManager().findFragmentByTag(tag) != null) {
currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag();
}
if (force) {
currentTag = null;
}
if (!tag.equals(currentTag)) {
getSupportFragmentManager()
.beginTransaction()
@ -525,6 +519,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
layoutRes = R.layout.item_image_gradient;
break;
}
Log.i(TAG, "handleLayoutResType: " + layoutRes);
if (layoutRes != -1) {
item.setChecked(true);
fragment.setAndSaveLayoutRes(layoutRes);
@ -686,29 +681,29 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
private void selectedFragment(final int itemId) {
switch (itemId) {
case R.id.action_album:
setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG, false);
setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG);
break;
case R.id.action_artist:
setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG, false);
setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG);
break;
case R.id.action_playlist:
setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG, false);
setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG);
break;
case R.id.action_genre:
setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG, false);
setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG);
break;
case R.id.action_playing_queue:
setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG, false);
setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG);
break;
case R.id.action_song:
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG, false);
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG);
break;
case R.id.action_folder:
setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG, false);
setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG);
break;
default:
case R.id.action_home:
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG,false);
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG);
break;
}
}

View file

@ -47,6 +47,11 @@ open class AlbumAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
itemLayoutRes = if (itemLayoutRes >= -1) {
itemLayoutRes
} else {
R.layout.item_grid
}
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
return createViewHolder(view, viewType)
}

View file

@ -47,6 +47,11 @@ class ArtistAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
itemLayoutRes = if (itemLayoutRes >= -1) {
itemLayoutRes
} else {
R.layout.item_grid_circle
}
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
return createViewHolder(view)
}

View file

@ -82,8 +82,6 @@ class AlbumsFragment :
albumViewModel.getAlbums()
}
override fun setLayoutRes(layoutRes: Int) {
}
override fun loadLayoutRes(): Int {
return PreferenceUtil.getInstance(requireContext()).albumGridStyle

View file

@ -88,9 +88,6 @@ class ArtistsFragment :
PreferenceUtil.getInstance(requireContext()).artistSortOrder = sortOrder
}
override fun setLayoutRes(layoutRes: Int) {
}
override fun loadLayoutRes(): Int {
return PreferenceUtil.getInstance(requireContext()).artistGridStyle
}

View file

@ -31,7 +31,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
fun setAndSaveLayoutRes(layoutRes: Int) {
setLayoutRes(layoutRes)
saveLayoutRes(layoutRes)
invalidateAdapter()
}
@ -108,8 +107,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A : RecyclerVie
protected abstract fun setSortOrder(sortOrder: String)
protected abstract fun setLayoutRes(layoutRes: Int)
protected abstract fun loadSortOrder(): String
protected abstract fun saveSortOrder(sortOrder: String)

View file

@ -50,7 +50,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.appthemehelper.util.ATHUtil;
@ -596,7 +595,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private WeakReference<FoldersFragment> fragmentWeakReference;
AsyncFileLoader(FoldersFragment foldersFragment) {
super(Objects.requireNonNull(foldersFragment.getActivity()));
super(foldersFragment.requireActivity());
fragmentWeakReference = new WeakReference<>(foldersFragment);
}

View file

@ -275,7 +275,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(), View.OnLayoutChangeListener,
playerContainer.setBackgroundColor(color.backgroundColor)
songInfo.setTextColor(color.primaryTextColor)
player_queue_sub_header.setTextColor(color.backgroundColor)
player_queue_sub_header.setTextColor(color.primaryTextColor)
songCurrentProgress.setTextColor(lastPlaybackControlsColor)
songTotalTime.setTextColor(lastPlaybackControlsColor)

View file

@ -3,7 +3,6 @@ package code.name.monkey.retromusic.fragments.songs
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
@ -11,13 +10,19 @@ import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
import code.name.monkey.retromusic.adapter.song.SongAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.mvp.presenter.SongPresenter
import code.name.monkey.retromusic.mvp.presenter.SongView
import code.name.monkey.retromusic.util.PreferenceUtil
import java.util.*
import javax.inject.Inject
class SongsFragment :
AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>(),
MainActivityFragmentCallbacks {
SongView, MainActivityFragmentCallbacks {
private lateinit var songViewModel: SongsViewModel
@Inject
lateinit var songPresenter: SongPresenter
override val emptyMessage: Int
get() = R.string.no_songs
@ -25,22 +30,15 @@ class SongsFragment :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.musicComponent.inject(this)
retainInstance = true
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
songViewModel = ViewModelProvider(this).get(SongsViewModel::class.java)
songViewModel.songs.observe(viewLifecycleOwner,
androidx.lifecycle.Observer { songs ->
if (songs.isNotEmpty())
adapter?.swapDataSet(songs)
else
adapter?.swapDataSet(listOf())
})
songPresenter.attachView(this)
}
override fun createLayoutManager(): GridLayoutManager {
println("createLayoutManager: ${getGridSize()}")
return GridLayoutManager(requireActivity(), getGridSize()).apply {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
@ -64,8 +62,12 @@ class SongsFragment :
)
}
override fun songs(songs: List<Song>) {
adapter?.swapDataSet(songs)
}
override fun onMediaStoreChanged() {
//songPresenter.loadSongs()
songPresenter.loadSongs()
}
override fun loadGridSize(): Int {
@ -88,6 +90,20 @@ class SongsFragment :
adapter?.notifyDataSetChanged()
}
override fun onResume() {
super.onResume()
if (adapter?.dataSet.isNullOrEmpty())
songPresenter.loadSongs()
}
override fun onDestroyView() {
super.onDestroyView()
songPresenter.detachView()
}
override fun showEmptyView() {
adapter?.swapDataSet(ArrayList())
}
override fun loadSortOrder(): String {
return PreferenceUtil.getInstance(requireContext()).songSortOrder
@ -98,7 +114,7 @@ class SongsFragment :
}
override fun setSortOrder(sortOrder: String) {
songViewModel.loadSongs()
songPresenter.loadSongs()
}
companion object {
@ -109,16 +125,12 @@ class SongsFragment :
@JvmStatic
fun newInstance(): SongsFragment {
val args = Bundle()
val fragment =
SongsFragment()
val fragment = SongsFragment()
fragment.arguments = args
return fragment
}
}
override fun setLayoutRes(@LayoutRes layoutRes: Int) {
}
@LayoutRes
override fun loadLayoutRes(): Int {
return PreferenceUtil.getInstance(requireContext()).songGridStyle

View file

@ -12,6 +12,7 @@
android:scaleType="centerCrop"
app:civ_border="false"
app:civ_shadow="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View file

@ -8,9 +8,10 @@
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="12dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View file

@ -10,6 +10,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View file

@ -11,6 +11,7 @@
android:layout_height="0dp"
android:layout_margin="16dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View file

@ -37,6 +37,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="2"
android:paddingHorizontal="8dp"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:textAppearance="@style/TextViewSubtitle1"

View file

@ -14,7 +14,7 @@
<dimen name="list_item_image_icon_padding">8dp</dimen>
<dimen name="mini_player_height">56dp</dimen>
<dimen name="mini_player_height">48dp</dimen>
<dimen name="app_widget_classic_height">96dp</dimen>
<dimen name="app_widget_classic_image_size">96dp</dimen>