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 478903d7..f39c1660 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 @@ -49,6 +49,7 @@ import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment; import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment; import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment; import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment; import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment; import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.SearchQueryHelper; @@ -65,6 +66,7 @@ import code.name.monkey.retromusic.service.MusicService; import code.name.monkey.retromusic.util.AppRater; import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.PreferenceUtil; +import code.name.monkey.retromusic.util.RetroColorUtil; import code.name.monkey.retromusic.util.RetroUtil; import com.afollestad.materialcab.MaterialCab; import com.afollestad.materialcab.MaterialCab.Callback; @@ -92,6 +94,8 @@ public class MainActivity extends AbsSlidingMusicPanelActivity private boolean blockRequestPermissions = false; + private MaterialCab cab; + private AppBarLayout mAppBarLayout; private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @@ -134,7 +138,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity }); if (savedInstanceState == null) { - selectedFragment(PreferenceUtil.getInstance(this).getLastPage()); + setMusicChooser(PreferenceUtil.getInstance(this).getLastMusicChooser()); } else { restoreCurrentFragment(); } @@ -189,6 +193,15 @@ public class MainActivity extends AbsSlidingMusicPanelActivity return mAppBarLayout.getTotalScrollRange(); } + @Override + public boolean handleBackPress() { + if (cab != null && cab.isActive()) { + cab.finish(); + return true; + } + return super.handleBackPress() || (currentFragment != null && currentFragment.handleBackPress()); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); @@ -275,7 +288,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity key.equals(PreferenceUtil.USER_NAME) || key.equals(PreferenceUtil.TOGGLE_FULL_SCREEN) || key.equals(PreferenceUtil.TOGGLE_VOLUME) || key.equals(PreferenceUtil.ROUND_CORNERS) || key.equals(PreferenceUtil.CAROUSEL_EFFECT) || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID || - key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH || + key == PreferenceUtil.TOGGLE_GENRE || key.equals(PreferenceUtil.BANNER_IMAGE_PATH) || key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART || key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE || key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS || @@ -290,7 +303,17 @@ public class MainActivity extends AbsSlidingMusicPanelActivity @NotNull @Override public MaterialCab openCab(final int menuRes, @NotNull final Callback callback) { - return null; + if (cab != null && cab.isActive()) { + cab.finish(); + } + cab = new MaterialCab(this, R.id.cab_stub) + .setMenu(menuRes) + .setCloseDrawableRes(R.drawable.ic_close_white_24dp) + .setBackgroundColor( + RetroColorUtil.shiftBackgroundColorForLightText( + ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface))) + .start(callback); + return cab; } public void removeOnAppBarOffsetChangedListener( @@ -298,12 +321,42 @@ public class MainActivity extends AbsSlidingMusicPanelActivity mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener); } + public void setCurrentFragment(Fragment fragment, String tag) { + String currentTag = null; + if (getSupportFragmentManager().findFragmentByTag(tag) != null) { + currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag(); + } + + if (!tag.equals(currentTag)) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, fragment, tag) + .commit(); + currentFragment = (MainActivityFragmentCallbacks) fragment; + } + } + + public void setMusicChooser(final int option) { + PreferenceUtil.getInstance(this).setLastMusicChooser(option); + if (option == OptionsSheetDialogFragment.FOLDER) { + setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG); + } else { + selectedFragment(PreferenceUtil.getInstance(this).getLastPage()); + } + } + @NotNull @Override protected View createContentView() { return wrapSlidingMusicPanel(R.layout.activity_main_content); } + @Override + protected void requestPermissions() { + if (!blockRequestPermissions) { + super.requestPermissions(); + } + } + private void checkShowChangelog() { try { final PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); @@ -563,20 +616,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity } } - private void setCurrentFragment(Fragment fragment, String tag) { - String currentTag = null; - if (getSupportFragmentManager().findFragmentByTag(tag) != null) { - currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag(); - } - - if (!tag.equals(currentTag)) { - getSupportFragmentManager().beginTransaction() - .replace(R.id.fragment_container, fragment, tag) - .commit(); - currentFragment = (MainActivityFragmentCallbacks) fragment; - } - } - private void setUpGridSizeMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu gridSizeMenu) { @@ -702,7 +741,17 @@ public class MainActivity extends AbsSlidingMusicPanelActivity .makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar)); NavigationUtil.goToSearch(this, options); }); + mToolbar.setNavigationOnClickListener( - v -> OptionsSheetDialogFragment.newInstance().show(getSupportFragmentManager(), "Main_Menu")); + v -> { + Fragment fragment = getCurrentFragment(); + if (fragment instanceof FoldersFragment) { + OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.FOLDER) + .show(getSupportFragmentManager(), "Main_Menu"); + } else { + OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.LIBRARY) + .show(getSupportFragmentManager(), "Main_Menu"); + } + }); } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt index 780feb96..0c06a8f4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt @@ -37,10 +37,8 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener { override fun onClick(view: View) { val mainActivity = activity as MainActivity? ?: return when (view.id) { - R.id.actionFolders -> { - }//mainActivity.setMusicChooser(MainActivity.FOLDER) - R.id.actionLibrary -> { - }//mainActivity.setMusicChooser(MainActivity.LIBRARY) + R.id.actionFolders -> mainActivity.setMusicChooser(FOLDER) + R.id.actionLibrary -> mainActivity.setMusicChooser(LIBRARY) R.id.actionSettings -> NavigationUtil.goToSettings(mainActivity) R.id.actionDriveMode -> NavigationUtil.gotoDriveMode(mainActivity) R.id.actionRate -> NavigationUtil.goToPlayStore(mainActivity) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java index 1ddef96f..9d6c30ba 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java @@ -1,9 +1,7 @@ package code.name.monkey.retromusic.fragments.mainactivity.folders; -import android.app.ActivityOptions; import android.app.Dialog; import android.content.Context; -import android.content.res.ColorStateList; import android.media.MediaScannerConnection; import android.os.Bundle; import android.os.Environment; @@ -20,18 +18,14 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import code.name.monkey.appthemehelper.ThemeStore; -import code.name.monkey.appthemehelper.common.ATHToolbarActivity; import code.name.monkey.appthemehelper.util.ATHUtil; -import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.adapter.SongFileAdapter; -import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment; import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.menu.SongMenuHelper; @@ -43,17 +37,13 @@ import code.name.monkey.retromusic.misc.DialogAsyncTask; import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListener; import code.name.monkey.retromusic.misc.WrappedAsyncTaskLoader; import code.name.monkey.retromusic.model.Song; -import code.name.monkey.retromusic.util.DensityUtil; import code.name.monkey.retromusic.util.FileUtil; -import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.RetroColorUtil; import code.name.monkey.retromusic.util.ThemedFastScroller; import code.name.monkey.retromusic.views.BreadCrumbLayout; import code.name.monkey.retromusic.views.ScrollingViewOnApplyWindowInsetsListener; import com.afollestad.materialcab.MaterialCab; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.card.MaterialCardView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import java.io.File; @@ -71,7 +61,7 @@ import me.zhanghai.android.fastscroll.FastScroller; public class FoldersFragment extends AbsMainActivityFragment implements MainActivityFragmentCallbacks, CabHolder, BreadCrumbLayout.SelectionCallback, SongFileAdapter.Callbacks, - AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks> { + LoaderManager.LoaderCallbacks> { public static class ListPathsAsyncTask extends ListingFilesDialogAsyncTask { @@ -327,8 +317,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private SongFileAdapter adapter; - private AppBarLayout appBarLayout; - private BreadCrumbLayout breadCrumbs; private MaterialCab cab; @@ -350,9 +338,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private RecyclerView recyclerView; - private Toolbar toolbar; - - private MaterialCardView toolbarContainer; public static File getDefaultStartDirectory() { File musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); @@ -434,12 +419,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements } - @Override - public void onDestroyView() { - appBarLayout.removeOnOffsetChangedListener(this); - super.onDestroyView(); - } - @Override public boolean handleBackPress() { if (cab != null && cab.isActive()) { @@ -463,8 +442,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_folders, menu); - ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, - ATHToolbarActivity.getToolbarBackgroundColor(toolbar)); } @Override @@ -590,13 +567,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements .execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator())); } - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop(), - recyclerView.getPaddingRight(), DensityUtil.dip2px(requireContext(), 52f) + - this.appBarLayout.getTotalScrollRange() + verticalOffset); - } - @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { @@ -617,11 +587,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements return super.onOptionsItemSelected(item); } - @Override - public void onPrepareOptionsMenu(Menu menu) { - super.onPrepareOptionsMenu(menu); - ToolbarContentTintHelper.handleOnPrepareOptionsMenu(getActivity(), toolbar); - } @NonNull @Override @@ -661,11 +626,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements private void initViews(View view) { coordinatorLayout = view.findViewById(R.id.coordinatorLayout); - toolbarContainer = view.findViewById(R.id.toolbarContainer); recyclerView = view.findViewById(R.id.recyclerView); - appBarLayout = view.findViewById(R.id.appBarLayout); breadCrumbs = view.findViewById(R.id.breadCrumbs); - toolbar = view.findViewById(R.id.toolbar); empty = view.findViewById(android.R.id.empty); emojiText = view.findViewById(R.id.emptyEmoji); } @@ -703,7 +665,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements } private void setUpAdapter() { - adapter = new SongFileAdapter(getMainActivity(), new LinkedList(), R.layout.item_list, + adapter = new SongFileAdapter(getMainActivity(), new LinkedList<>(), R.layout.item_list, this, this); adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override @@ -717,26 +679,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements } private void setUpAppbarColor() { - int primaryColor = ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface); - getMainActivity().setSupportActionBar(toolbar); - toolbar.setBackgroundTintList(ColorStateList.valueOf(primaryColor)); - toolbarContainer.setCardBackgroundColor(ColorStateList.valueOf(primaryColor)); - toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); - toolbar.setNavigationOnClickListener(v -> { - showMainMenu(OptionsSheetDialogFragment.FOLDER); - }); breadCrumbs.setActivatedContentColor( ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorPrimary)); breadCrumbs.setDeactivatedContentColor( ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorSecondary)); - appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity() - .setLightStatusbar(!ATHUtil.INSTANCE.isWindowBackgroundDark(requireContext()))); - toolbar.setOnClickListener(v -> { - ActivityOptions options = ActivityOptions - .makeSceneTransitionAnimation(getMainActivity(), toolbarContainer, - getString(R.string.transition_toolbar)); - NavigationUtil.goToSearch(getMainActivity(), options); - }); } private void setUpBreadCrumbs() { @@ -745,7 +691,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private void setUpRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); - appBarLayout.addOnOffsetChangedListener(this); FastScroller fastScroller = ThemedFastScroller.INSTANCE.create(recyclerView); recyclerView.setOnApplyWindowInsetsListener( new ScrollingViewOnApplyWindowInsetsListener(recyclerView, fastScroller)); 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 0c033f63..f6eb9e29 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 @@ -29,6 +29,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; import androidx.viewpager.widget.ViewPager; import code.name.monkey.retromusic.R; +import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.AlbumCoverStyle; import code.name.monkey.retromusic.fragments.NowPlayingScreen; import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment; @@ -584,6 +585,14 @@ public final class PreferenceUtil { return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1); } + public final int getLastMusicChooser() { + return mPreferences.getInt(LAST_MUSIC_CHOOSER, OptionsSheetDialogFragment.LIBRARY); + } + + public void setLastMusicChooser(int value) { + mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply(); + } + public final int getLastPage() { return mPreferences.getInt(LAST_PAGE, R.id.action_song); } diff --git a/app/src/main/res/layout/fragment_folder.xml b/app/src/main/res/layout/fragment_folder.xml index 91f06b7e..df1ed7fc 100644 --- a/app/src/main/res/layout/fragment_folder.xml +++ b/app/src/main/res/layout/fragment_folder.xml @@ -1,80 +1,53 @@ - + android:background="?attr/colorSurface"> - + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> - + - + + - + android:orientation="vertical"> - - - - - - - - - - - - - - - - - + android:layout_height="@dimen/tab_height" + android:paddingStart="60dp" + android:paddingEnd="8dp" + app:layout_collapseMode="pin" /> - - - - - - - - - \ No newline at end of file + + \ No newline at end of file