Made progress with the folder feature.
This commit is contained in:
parent
56d3a2dbce
commit
1e6ac6a227
38 changed files with 1423 additions and 148 deletions
|
|
@ -66,6 +66,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
@Bind(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
|
||||
@Nullable
|
||||
MainActivityFragmentCallbacks currentFragment;
|
||||
|
||||
@Nullable
|
||||
|
|
@ -88,7 +89,11 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
|
||||
setUpDrawerLayout();
|
||||
|
||||
setMusicChooser(PreferenceUtil.getInstance(this).getLastMusicChooser());
|
||||
if (savedInstanceState == null) {
|
||||
setMusicChooser(PreferenceUtil.getInstance(this).getLastMusicChooser());
|
||||
} else {
|
||||
restoreCurrentFragment();
|
||||
}
|
||||
|
||||
if (!checkShowIntro()) {
|
||||
checkShowChangelog();
|
||||
|
|
@ -100,20 +105,24 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
switch (key) {
|
||||
case LIBRARY:
|
||||
navigationView.setCheckedItem(R.id.nav_library);
|
||||
setCurrentFragment(new LibraryFragment());
|
||||
setCurrentFragment(LibraryFragment.newInstance());
|
||||
break;
|
||||
case FOLDERS:
|
||||
navigationView.setCheckedItem(R.id.nav_folders);
|
||||
setCurrentFragment(new FolderFragment());
|
||||
setCurrentFragment(FolderFragment.newInstance());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentFragment(Fragment fragment) {
|
||||
private void setCurrentFragment(@SuppressWarnings("NullableProblems") Fragment fragment) {
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, LibraryFragment.TAG).commit();
|
||||
currentFragment = (MainActivityFragmentCallbacks) fragment;
|
||||
}
|
||||
|
||||
private void restoreCurrentFragment() {
|
||||
currentFragment = (MainActivityFragmentCallbacks) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
|
@ -254,12 +263,13 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) drawerLayout.closeDrawers();
|
||||
else if (currentFragment == null || !currentFragment.onBackPressed())
|
||||
super.onBackPressed();
|
||||
public boolean handleBackPress() {
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) {
|
||||
drawerLayout.closeDrawers();
|
||||
return true;
|
||||
}
|
||||
return super.handleBackPress() || (currentFragment != null && currentFragment.handleBackPress());
|
||||
}
|
||||
|
||||
private void handlePlaybackIntent(@Nullable Intent intent) {
|
||||
|
|
@ -391,6 +401,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
}
|
||||
|
||||
public interface MainActivityFragmentCallbacks {
|
||||
boolean onBackPressed();
|
||||
boolean handleBackPress();
|
||||
}
|
||||
}
|
||||
|
|
@ -173,13 +173,18 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!handleBackPress())
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
public boolean handleBackPress() {
|
||||
if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed())
|
||||
return;
|
||||
return true;
|
||||
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
|
||||
collapsePanel();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
super.onBackPressed();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,24 +1,141 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
import com.kabouzeid.appthemehelper.util.ToolbarContentTintHelper;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.SongFileAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.loader.SortedCursor;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.kabouzeid.gramophone.views.BreadCrumbLayout;
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
public class FolderFragment extends AbsMainActivityFragment implements MainActivity.MainActivityFragmentCallbacks {
|
||||
public class FolderFragment extends AbsMainActivityFragment implements MainActivity.MainActivityFragmentCallbacks, CabHolder, BreadCrumbLayout.SelectionCallback, SongFileAdapter.Callbacks, AppBarLayout.OnOffsetChangedListener {
|
||||
public static final String TAG = FolderFragment.class.getSimpleName();
|
||||
|
||||
protected static final String PATH = "path";
|
||||
protected static final String CRUMBS = "crumbs";
|
||||
|
||||
@Bind(R.id.container)
|
||||
View container;
|
||||
@Bind(android.R.id.empty)
|
||||
View empty;
|
||||
@Bind(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@Bind(R.id.bread_crumbs)
|
||||
BreadCrumbLayout breadCrumbs;
|
||||
@Bind(R.id.appbar)
|
||||
AppBarLayout appbar;
|
||||
@Bind(R.id.recycler_view)
|
||||
FastScrollRecyclerView recyclerView;
|
||||
|
||||
private SongFileAdapter adapter;
|
||||
private MaterialCab cab;
|
||||
|
||||
public FolderFragment() {
|
||||
}
|
||||
|
||||
public static FolderFragment newInstance() {
|
||||
return newInstance(getDefaultStartFolder());
|
||||
}
|
||||
|
||||
public static FolderFragment newInstance(File directory) {
|
||||
FolderFragment frag = new FolderFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putSerializable(PATH, directory);
|
||||
frag.setArguments(b);
|
||||
return frag;
|
||||
}
|
||||
|
||||
public void setCrumb(BreadCrumbLayout.Crumb crumb, boolean addToHistory) {
|
||||
saveScrollPosition();
|
||||
updateAdapter(crumb.getFile());
|
||||
recyclerView.getLayoutManager().scrollToPosition(crumb.getScrollPosition());
|
||||
breadCrumbs.setActiveOrAdd(crumb, false);
|
||||
if (addToHistory)
|
||||
breadCrumbs.addHistory(crumb);
|
||||
}
|
||||
|
||||
private void saveScrollPosition() {
|
||||
if (breadCrumbs.size() > 0) {
|
||||
BreadCrumbLayout.Crumb crumb = breadCrumbs.getCrumb(breadCrumbs.getActiveIndex());
|
||||
crumb.setScrollPosition(((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(CRUMBS, breadCrumbs.getStateWrapper());
|
||||
}
|
||||
|
||||
private void updateAdapter(File directory) {
|
||||
ArrayList<File> files = loadFiles(directory);
|
||||
if (adapter == null) {
|
||||
adapter = new SongFileAdapter(getMainActivity(), files, R.layout.item_list, this, this);
|
||||
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
checkIsEmpty();
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
checkIsEmpty();
|
||||
} else {
|
||||
adapter.swapDataSet(files);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private ArrayList<File> loadFiles(File directory) {
|
||||
ArrayList<File> fileList = new ArrayList<>();
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
Collections.addAll(fileList, files);
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
|
@ -30,16 +147,249 @@ public class FolderFragment extends AbsMainActivityFragment implements MainActiv
|
|||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
PreferenceUtil.getInstance(getActivity()).setLastPage(-2);
|
||||
|
||||
getMainActivity().setStatusbarColorAuto();
|
||||
getMainActivity().setNavigationbarColorAuto();
|
||||
getMainActivity().setTaskDescriptionColorAuto();
|
||||
|
||||
setUpAppbarColor();
|
||||
setUpToolbar();
|
||||
setUpBreadCrumbs();
|
||||
setUpRecyclerView();
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
setCrumb(new BreadCrumbLayout.Crumb((File) getArguments().getSerializable(PATH)), true);
|
||||
} else {
|
||||
breadCrumbs.restoreFromStateWrapper((BreadCrumbLayout.SavedStateWrapper) savedInstanceState.getParcelable(CRUMBS));
|
||||
setCrumb(breadCrumbs.getCrumb(breadCrumbs.getActiveIndex()), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpAppbarColor() {
|
||||
int primaryColor = ThemeStore.primaryColor(getActivity());
|
||||
appbar.setBackgroundColor(primaryColor);
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
breadCrumbs.setBackgroundColor(primaryColor);
|
||||
breadCrumbs.setActivatedContentColor(ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor));
|
||||
breadCrumbs.setDeactivatedContentColor(ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor));
|
||||
}
|
||||
|
||||
private void setUpToolbar() {
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
getActivity().setTitle(R.string.app_name);
|
||||
getMainActivity().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
private void setUpBreadCrumbs() {
|
||||
breadCrumbs.setCallback(this);
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView, ThemeStore.accentColor(getActivity()));
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
|
||||
appbar.addOnOffsetChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
saveScrollPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
appbar.removeOnOffsetChangedListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
public boolean handleBackPress() {
|
||||
if (cab != null && cab.isActive()) {
|
||||
cab.finish();
|
||||
return true;
|
||||
}
|
||||
if (breadCrumbs.popHistory()) {
|
||||
setCrumb(breadCrumbs.lastHistory(), false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MaterialCab openCab(int menuRes, MaterialCab.Callback callback) {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
|
||||
.setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
|
||||
.setBackgroundColor(PhonographColorUtil.shiftBackgroundColorForLightText(ThemeStore.primaryColor(getActivity())))
|
||||
.start(callback);
|
||||
return cab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_folders, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_go_to_standard_folder:
|
||||
setCrumb(new BreadCrumbLayout.Crumb(getDefaultStartFolder()), true);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCrumbSelection(BreadCrumbLayout.Crumb crumb, int index) {
|
||||
setCrumb(crumb, true);
|
||||
}
|
||||
|
||||
public static File getDefaultStartFolder() {
|
||||
File externalStorageDir = Environment.getExternalStorageDirectory();
|
||||
File musicFolder = new File(externalStorageDir, "Music");
|
||||
File startFolder;
|
||||
if (musicFolder.exists() && musicFolder.isDirectory()) {
|
||||
startFolder = musicFolder;
|
||||
} else if (externalStorageDir.exists() && externalStorageDir.isDirectory()) {
|
||||
startFolder = externalStorageDir;
|
||||
} else {
|
||||
startFolder = new File("/"); // root
|
||||
}
|
||||
return startFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileSelected(File file) {
|
||||
if (file.isDirectory()) {
|
||||
setCrumb(new BreadCrumbLayout.Crumb(file), true);
|
||||
} else {
|
||||
ArrayList<Song> songs = getAllSongs(file.getParentFile(), new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return !pathname.isDirectory();
|
||||
}
|
||||
});
|
||||
|
||||
int startIndex = -1;
|
||||
for (int i = 0; i < songs.size(); i++) {
|
||||
if (file.getPath().equals(songs.get(i).data)) {
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (startIndex > -1) {
|
||||
MusicPlayerRemote.openQueue(songs, startIndex, true);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Could not play selected file.", Toast.LENGTH_SHORT).show(); // TODO replace with proper text.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static SortedCursor makeSongCursor(@NonNull final Context context, @Nullable final List<File> files) {
|
||||
String selection = null;
|
||||
String[] values = null;
|
||||
|
||||
if (files != null && files.size() > 0 && files.size() < 999) { // 999 is the max amount Androids SQL implementation can handle.
|
||||
selection = AudioColumns.DATA + " IN (" + makePlaceholders(files.size()) + ")";
|
||||
|
||||
values = new String[files.size()];
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
values[i] = files.get(i).getPath();
|
||||
}
|
||||
}
|
||||
|
||||
Cursor songCursor = SongLoader.makeSongCursor(context, selection, values);
|
||||
|
||||
return songCursor == null ? null : new SortedCursor(songCursor, values, AudioColumns.DATA);
|
||||
}
|
||||
|
||||
private static String makePlaceholders(int len) {
|
||||
StringBuilder sb = new StringBuilder(len * 2 - 1);
|
||||
sb.append("?");
|
||||
for (int i = 1; i < len; i++) {
|
||||
sb.append(",?");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileMenuClicked(File file) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddToPlaylist(ArrayList<File> files) {
|
||||
AddToPlaylistDialog.create(getAllSongs(files, null)).show(getFragmentManager(), "ADD_PLAYLIST");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddToCurrentPlaying(ArrayList<File> files) {
|
||||
MusicPlayerRemote.enqueue(getAllSongs(files, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteFromDevice(ArrayList<File> files) {
|
||||
DeleteSongsDialog.create(getAllSongs(files, null)).show(getFragmentManager(), "DELETE_SONGS");
|
||||
}
|
||||
|
||||
private ArrayList<Song> getAllSongs(File dir, @Nullable FileFilter fileFilter) {
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
File[] fileArray = dir.listFiles(fileFilter);
|
||||
if (fileArray != null) Collections.addAll(files, fileArray);
|
||||
Iterator<File> iterator = files.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
File file = iterator.next();
|
||||
if (file.isDirectory()) {
|
||||
songs.addAll(getAllSongs(file, fileFilter));
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
SortedCursor cursor = makeSongCursor(getActivity(), files);
|
||||
songs.addAll(SongLoader.getSongs(cursor));
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
private ArrayList<Song> getAllSongs(List<File> files, @Nullable FileFilter fileFilter) {
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
|
||||
Iterator<File> iterator = files.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
File file = iterator.next();
|
||||
if (fileFilter != null && !fileFilter.accept(file)) {
|
||||
iterator.remove();
|
||||
} else if (file.isDirectory()) {
|
||||
iterator.remove();
|
||||
songs.addAll(getAllSongs(file, fileFilter));
|
||||
}
|
||||
}
|
||||
|
||||
SortedCursor cursor = makeSongCursor(getActivity(), files);
|
||||
songs.addAll(SongLoader.getSongs(cursor));
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
|
||||
container.setPadding(container.getPaddingLeft(), container.getPaddingTop(), container.getPaddingRight(), appbar.getTotalScrollRange() + verticalOffset);
|
||||
}
|
||||
|
||||
private void checkIsEmpty() {
|
||||
if (empty != null) {
|
||||
empty.setVisibility(adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ import com.kabouzeid.gramophone.interfaces.CabHolder;
|
|||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||
import com.kabouzeid.gramophone.ui.activities.SearchActivity;
|
||||
import com.kabouzeid.gramophone.ui.fragments.libraryfragments.AbsLibraryRecyclerViewCustomGridSizePagerFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.libraryfragments.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
|
@ -55,6 +55,10 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
private MusicLibraryPagerAdapter pagerAdapter;
|
||||
private MaterialCab cab;
|
||||
|
||||
public static LibraryFragment newInstance() {
|
||||
return new LibraryFragment();
|
||||
}
|
||||
|
||||
public LibraryFragment() {
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +91,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
appbar.setBackgroundColor(primaryColor);
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
getActivity().setTitle(getResources().getString(R.string.app_name));
|
||||
getActivity().setTitle(R.string.app_name);
|
||||
getMainActivity().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
|
|
@ -120,11 +124,12 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
return pager.getCurrentItem() == MusicLibraryPagerAdapter.MusicFragments.PLAYLIST.ordinal();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
||||
public MaterialCab openCab(final int menuRes, final MaterialCab.Callback callback) {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
|
||||
.setMenu(menu)
|
||||
.setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
|
||||
.setBackgroundColor(PhonographColorUtil.shiftBackgroundColorForLightText(ThemeStore.primaryColor(getActivity())))
|
||||
.start(callback);
|
||||
|
|
@ -151,8 +156,8 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
|
||||
}
|
||||
Fragment currentFragment = getCurrentFragment();
|
||||
if (currentFragment instanceof AbsLibraryRecyclerViewCustomGridSizePagerFragment && currentFragment.isAdded()) {
|
||||
AbsLibraryRecyclerViewCustomGridSizePagerFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryRecyclerViewCustomGridSizePagerFragment) currentFragment;
|
||||
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
|
||||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
|
||||
|
||||
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
|
||||
if (Util.isLandscape(getResources())) {
|
||||
|
|
@ -171,8 +176,8 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
Fragment currentFragment = getCurrentFragment();
|
||||
if (currentFragment instanceof AbsLibraryRecyclerViewCustomGridSizePagerFragment) {
|
||||
AbsLibraryRecyclerViewCustomGridSizePagerFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryRecyclerViewCustomGridSizePagerFragment) currentFragment;
|
||||
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) {
|
||||
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
|
||||
if (item.getItemId() == R.id.action_colored_footers) {
|
||||
item.setChecked(!item.isChecked());
|
||||
absLibraryRecyclerViewCustomGridSizeFragment.setAndSaveUsePalette(item.isChecked());
|
||||
|
|
@ -204,7 +209,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void setUpGridSizeMenu(@NonNull AbsLibraryRecyclerViewCustomGridSizePagerFragment fragment, @NonNull SubMenu gridSizeMenu) {
|
||||
private void setUpGridSizeMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu gridSizeMenu) {
|
||||
switch (fragment.getGridSize()) {
|
||||
case 1:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true);
|
||||
|
|
@ -252,7 +257,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
}
|
||||
}
|
||||
|
||||
private boolean handleGridSizeMenuItem(@NonNull AbsLibraryRecyclerViewCustomGridSizePagerFragment fragment, @NonNull MenuItem item) {
|
||||
private boolean handleGridSizeMenuItem(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull MenuItem item) {
|
||||
int gridSize = 0;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_grid_size_1:
|
||||
|
|
@ -290,7 +295,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
public boolean handleBackPress() {
|
||||
if (cab != null && cab.isActive()) {
|
||||
cab.finish();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import com.kabouzeid.gramophone.util.Util;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsLibraryRecyclerViewCustomGridSizePagerFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsLibraryRecyclerViewPagerFragment<A, LM> {
|
||||
public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsLibraryPagerRecyclerViewFragment<A, LM> {
|
||||
private int gridSize;
|
||||
|
||||
private boolean usePaletteInitialized;
|
||||
|
|
@ -14,11 +14,9 @@ import android.view.ViewGroup;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
import com.kabouzeid.appthemehelper.util.ATHUtil;
|
||||
import com.kabouzeid.appthemehelper.util.ColorUtil;
|
||||
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
|
@ -27,9 +25,9 @@ import butterknife.ButterKnife;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsLibraryRecyclerViewPagerFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsLibraryPagerFragment implements OnOffsetChangedListener, MusicServiceEventListener {
|
||||
public abstract class AbsLibraryPagerRecyclerViewFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsLibraryPagerFragment implements OnOffsetChangedListener, MusicServiceEventListener {
|
||||
|
||||
public static final String TAG = AbsLibraryRecyclerViewPagerFragment.class.getSimpleName();
|
||||
public static final String TAG = AbsLibraryPagerRecyclerViewFragment.class.getSimpleName();
|
||||
|
||||
@Bind(R.id.container)
|
||||
View container;
|
||||
|
|
@ -63,11 +61,7 @@ public abstract class AbsLibraryRecyclerViewPagerFragment<A extends RecyclerView
|
|||
|
||||
private void setUpRecyclerView() {
|
||||
if (recyclerView instanceof FastScrollRecyclerView) {
|
||||
int accentColor = ThemeStore.accentColor(getActivity());
|
||||
((FastScrollRecyclerView) recyclerView).setPopupBgColor(accentColor);
|
||||
((FastScrollRecyclerView) recyclerView).setPopupTextColor(MaterialValueHelper.getPrimaryTextColor(getActivity(), ColorUtil.isColorLight(accentColor)));
|
||||
((FastScrollRecyclerView) recyclerView).setThumbColor(accentColor);
|
||||
((FastScrollRecyclerView) recyclerView).setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(getContext(), R.attr.colorControlNormal), 0.12f));
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), ((FastScrollRecyclerView) recyclerView), ThemeStore.accentColor(getActivity()));
|
||||
}
|
||||
invalidateLayoutManager();
|
||||
invalidateAdapter();
|
||||
|
|
@ -11,8 +11,8 @@ import com.kabouzeid.gramophone.util.PreferenceUtil;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumsPagerFragment extends AbsLibraryRecyclerViewCustomGridSizePagerFragment<AlbumAdapter, GridLayoutManager> {
|
||||
public static final String TAG = AlbumsPagerFragment.class.getSimpleName();
|
||||
public class AlbumsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager> {
|
||||
public static final String TAG = AlbumsFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected GridLayoutManager createLayoutManager() {
|
||||
|
|
@ -11,9 +11,9 @@ import com.kabouzeid.gramophone.util.PreferenceUtil;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistsPagerFragment extends AbsLibraryRecyclerViewCustomGridSizePagerFragment<ArtistAdapter, GridLayoutManager> {
|
||||
public class ArtistsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager> {
|
||||
|
||||
public static final String TAG = ArtistsPagerFragment.class.getSimpleName();
|
||||
public static final String TAG = ArtistsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
@ -16,9 +16,9 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaylistsPagerFragment extends AbsLibraryRecyclerViewPagerFragment<PlaylistAdapter, LinearLayoutManager> {
|
||||
public class PlaylistsFragment extends AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager> {
|
||||
|
||||
public static final String TAG = PlaylistsPagerFragment.class.getSimpleName();
|
||||
public static final String TAG = PlaylistsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
@ -15,9 +15,9 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongsPagerFragment extends AbsLibraryRecyclerViewCustomGridSizePagerFragment<SongAdapter, GridLayoutManager> {
|
||||
public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager> {
|
||||
|
||||
public static final String TAG = SongsPagerFragment.class.getSimpleName();
|
||||
public static final String TAG = SongsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
Loading…
Add table
Add a link
Reference in a new issue