Removed library fragment

This commit is contained in:
h4h13 2020-02-19 13:23:53 +05:30
parent d03d4e4505
commit f11c392b8d
5 changed files with 118 additions and 173 deletions

View file

@ -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");
}
});
}
}

View file

@ -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)

View file

@ -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<List<File>> {
LoaderManager.LoaderCallbacks<List<File>> {
public static class ListPathsAsyncTask extends
ListingFilesDialogAsyncTask<ListPathsAsyncTask.LoadingInfo, String, String[]> {
@ -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<File>(), 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));

View file

@ -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);
}

View file

@ -1,90 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
tools:ignore="UnusedAttribute">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleMarginStart="0dp"
app:titleTextAppearance="@style/ToolbarTextAppearanceSearch"
tools:ignore="UnusedAttribute" />
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
android:layout_height="48dp" />
</FrameLayout>
<code.name.monkey.retromusic.views.BreadCrumbLayout
android:id="@+id/breadCrumbs"
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:paddingStart="60dp"
android:paddingEnd="8dp"
app:layout_collapseMode="pin" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:scrollbars="none"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
@ -114,5 +36,27 @@
tools:visibility="visible" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<code.name.monkey.retromusic.views.BreadCrumbLayout
android:id="@+id/breadCrumbs"
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:paddingStart="60dp"
android:paddingEnd="8dp"
app:layout_collapseMode="pin" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:scrollbars="none"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</LinearLayout>
</FrameLayout>