diff --git a/app/build.gradle b/app/build.gradle index 7cd1a94f..7e4817c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ android { vectorDrawables.useSupportLibrary = true applicationId "code.name.monkey.retromusic" - versionCode 435 + versionCode 436 versionName '3.5.300' multiDexEnabled true diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index 368ebedf..582253b0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -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; } } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt index b82149fb..8c0e42f8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt @@ -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) } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt index 173a096c..4e037798 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/artist/ArtistAdapter.kt @@ -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) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt index c510f09f..fadf2db7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt @@ -82,8 +82,6 @@ class AlbumsFragment : albumViewModel.getAlbums() } - override fun setLayoutRes(layoutRes: Int) { - } override fun loadLayoutRes(): Int { return PreferenceUtil.getInstance(requireContext()).albumGridStyle diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistsFragment.kt index 14aa7269..34385c5b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistsFragment.kt @@ -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 } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewCustomGridSizeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewCustomGridSizeFragment.kt index 452b90f4..7b1b060d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewCustomGridSizeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewCustomGridSizeFragment.kt @@ -31,7 +31,6 @@ abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragmentWeakReference; AsyncFileLoader(FoldersFragment foldersFragment) { - super(Objects.requireNonNull(foldersFragment.getActivity())); + super(foldersFragment.requireActivity()); fragmentWeakReference = new WeakReference<>(foldersFragment); } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt index 2b09cdae..926cf19b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt @@ -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) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/songs/SongsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/songs/SongsFragment.kt index f1348342..4b2c0777 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/songs/SongsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/songs/SongsFragment.kt @@ -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(), - 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) { + 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 diff --git a/app/src/main/res/layout/fragment_album_circle_cover.xml b/app/src/main/res/layout/fragment_album_circle_cover.xml index 4cc849e2..ce28ec7c 100644 --- a/app/src/main/res/layout/fragment_album_circle_cover.xml +++ b/app/src/main/res/layout/fragment_album_circle_cover.xml @@ -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" diff --git a/app/src/main/res/layout/fragment_album_cover.xml b/app/src/main/res/layout/fragment_album_cover.xml index c1b38726..7f23f04c 100644 --- a/app/src/main/res/layout/fragment_album_cover.xml +++ b/app/src/main/res/layout/fragment_album_cover.xml @@ -8,9 +8,10 @@ 8dp - 56dp + 48dp 96dp 96dp