Re added the adjustable grid size feature. Transition between two grid sizes are not working yet. Fixes kabouzeid/phonograph-issue-tracker#43
This commit is contained in:
parent
fe3a70c395
commit
d1b06b79f8
17 changed files with 398 additions and 200 deletions
|
|
@ -10,10 +10,10 @@ import android.util.SparseArray;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AlbumViewFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.ArtistViewFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.PlaylistViewFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.SongViewFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AlbumsFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.ArtistsFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.PlaylistsFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.SongsFragment;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -107,10 +107,10 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
|||
}
|
||||
|
||||
public enum MusicFragments {
|
||||
SONG(SongViewFragment.class),
|
||||
ALBUM(AlbumViewFragment.class),
|
||||
ARTIST(ArtistViewFragment.class),
|
||||
PLAYLIST(PlaylistViewFragment.class);
|
||||
SONG(SongsFragment.class),
|
||||
ALBUM(AlbumsFragment.class),
|
||||
ARTIST(ArtistsFragment.class),
|
||||
PLAYLIST(PlaylistsFragment.class);
|
||||
|
||||
private final Class<? extends Fragment> mFragmentClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ import com.kabouzeid.gramophone.model.Song;
|
|||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AbsMainActivityFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AbsMainActivityRecyclerViewLayoutModeFragment;
|
||||
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AbsMainActivityRecyclerViewCustomGridSizeFragment;
|
||||
import com.kabouzeid.gramophone.util.ColorUtil;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
|
|
@ -324,10 +324,20 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
|
||||
}
|
||||
Fragment currentFragment = getCurrentFragment();
|
||||
if (currentFragment instanceof AbsMainActivityRecyclerViewLayoutModeFragment) {
|
||||
setUpLayoutModeMenu((AbsMainActivityRecyclerViewLayoutModeFragment) currentFragment, menu);
|
||||
if (currentFragment instanceof AbsMainActivityRecyclerViewCustomGridSizeFragment) {
|
||||
AbsMainActivityRecyclerViewCustomGridSizeFragment absMainActivityRecyclerViewCustomGridSizeFragment = (AbsMainActivityRecyclerViewCustomGridSizeFragment) currentFragment;
|
||||
|
||||
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
|
||||
if (Util.isLandscape(this)) {
|
||||
gridSizeItem.setTitle(R.string.action_grid_size_land);
|
||||
}
|
||||
setUpGridSizeMenu(absMainActivityRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());
|
||||
|
||||
menu.findItem(R.id.action_colored_footers).setChecked(absMainActivityRecyclerViewCustomGridSizeFragment.usePalette());
|
||||
menu.findItem(R.id.action_colored_footers).setEnabled(absMainActivityRecyclerViewCustomGridSizeFragment.canUsePalette());
|
||||
} else {
|
||||
menu.removeItem(R.id.action_view_as);
|
||||
menu.removeItem(R.id.action_grid_size);
|
||||
menu.removeItem(R.id.action_colored_footers);
|
||||
}
|
||||
ViewUtil.setToolbarContentColorForBackground(this, toolbar, getThemeColorPrimary());
|
||||
return true;
|
||||
|
|
@ -353,9 +363,16 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
ViewUtil.invalidateToolbarPopupMenuTint(toolbar);
|
||||
|
||||
Fragment currentFragment = getCurrentFragment();
|
||||
if (currentFragment instanceof AbsMainActivityRecyclerViewLayoutModeFragment) {
|
||||
if (handleLayoutModeMenuItem((AbsMainActivityRecyclerViewLayoutModeFragment) currentFragment, item))
|
||||
if (currentFragment instanceof AbsMainActivityRecyclerViewCustomGridSizeFragment) {
|
||||
AbsMainActivityRecyclerViewCustomGridSizeFragment absMainActivityRecyclerViewCustomGridSizeFragment = (AbsMainActivityRecyclerViewCustomGridSizeFragment) currentFragment;
|
||||
if (item.getItemId() == R.id.action_colored_footers) {
|
||||
item.setChecked(!item.isChecked());
|
||||
absMainActivityRecyclerViewCustomGridSizeFragment.setAndSaveUsePalette(item.isChecked());
|
||||
return true;
|
||||
}
|
||||
if (handleGridSizeMenuItem(absMainActivityRecyclerViewCustomGridSizeFragment, item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
|
|
@ -379,41 +396,68 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void setUpLayoutModeMenu(@NonNull AbsMainActivityRecyclerViewLayoutModeFragment fragment, @NonNull Menu menu) {
|
||||
SubMenu layoutModeMenu = menu.findItem(R.id.action_view_as).getSubMenu();
|
||||
|
||||
switch (fragment.getLayoutMode()) {
|
||||
case PreferenceUtil.LAYOUT_MODE_LIST:
|
||||
layoutModeMenu.findItem(R.id.action_layout_mode_list).setChecked(true);
|
||||
layoutModeMenu.findItem(R.id.action_colored_footers).setEnabled(false);
|
||||
private void setUpGridSizeMenu(@NonNull AbsMainActivityRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu gridSizeMenu) {
|
||||
switch (fragment.getGridSize()) {
|
||||
case 1:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true);
|
||||
break;
|
||||
case PreferenceUtil.LAYOUT_MODE_GRID:
|
||||
layoutModeMenu.findItem(R.id.action_layout_mode_grid).setChecked(true);
|
||||
layoutModeMenu.findItem(R.id.action_colored_footers).setEnabled(true);
|
||||
case 2:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_2).setChecked(true);
|
||||
break;
|
||||
case 3:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_3).setChecked(true);
|
||||
break;
|
||||
case 4:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_4).setChecked(true);
|
||||
break;
|
||||
case 5:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_5).setChecked(true);
|
||||
break;
|
||||
case 6:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_6).setChecked(true);
|
||||
break;
|
||||
case 7:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_7).setChecked(true);
|
||||
break;
|
||||
case 8:
|
||||
gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
layoutModeMenu.findItem(R.id.action_colored_footers).setChecked(fragment.loadUsePalette());
|
||||
}
|
||||
|
||||
private boolean handleLayoutModeMenuItem(AbsMainActivityRecyclerViewLayoutModeFragment fragment, @NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_colored_footers) {
|
||||
item.setChecked(!item.isChecked());
|
||||
fragment.setUsePaletteAndSaveValue(item.isChecked());
|
||||
private boolean handleGridSizeMenuItem(@NonNull AbsMainActivityRecyclerViewCustomGridSizeFragment fragment, @NonNull MenuItem item) {
|
||||
int gridSize = 0;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_grid_size_1:
|
||||
gridSize = 1;
|
||||
break;
|
||||
case R.id.action_grid_size_2:
|
||||
gridSize = 2;
|
||||
break;
|
||||
case R.id.action_grid_size_3:
|
||||
gridSize = 3;
|
||||
break;
|
||||
case R.id.action_grid_size_4:
|
||||
gridSize = 4;
|
||||
break;
|
||||
case R.id.action_grid_size_5:
|
||||
gridSize = 5;
|
||||
break;
|
||||
case R.id.action_grid_size_6:
|
||||
gridSize = 6;
|
||||
break;
|
||||
case R.id.action_grid_size_7:
|
||||
gridSize = 7;
|
||||
break;
|
||||
case R.id.action_grid_size_8:
|
||||
gridSize = 8;
|
||||
break;
|
||||
}
|
||||
if (gridSize > 0) {
|
||||
item.setChecked(true);
|
||||
fragment.setAndSaveGridSize(gridSize);
|
||||
toolbar.getMenu().findItem(R.id.action_colored_footers).setEnabled(fragment.canUsePalette());
|
||||
return true;
|
||||
} else {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_layout_mode_list:
|
||||
item.setChecked(true);
|
||||
fragment.setLayoutModeAndSaveValue(PreferenceUtil.LAYOUT_MODE_LIST);
|
||||
toolbar.getMenu().findItem(R.id.action_colored_footers).setEnabled(false);
|
||||
return true;
|
||||
case R.id.action_layout_mode_grid:
|
||||
item.setChecked(true);
|
||||
fragment.setLayoutModeAndSaveValue(PreferenceUtil.LAYOUT_MODE_GRID);
|
||||
toolbar.getMenu().findItem(R.id.action_colored_footers).setEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -505,32 +549,32 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
// return pager.getCurrentItem() == PagerAdapter.MusicFragments.ARTIST.ordinal();
|
||||
// }
|
||||
//
|
||||
// public ArtistViewFragment getArtistFragment() {
|
||||
// return (ArtistViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ARTIST.ordinal());
|
||||
// public ArtistsFragment getArtistFragment() {
|
||||
// return (ArtistsFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ARTIST.ordinal());
|
||||
// }
|
||||
//
|
||||
// private boolean isAlbumPage() {
|
||||
// return pager.getCurrentItem() == PagerAdapter.MusicFragments.ALBUM.ordinal();
|
||||
// }
|
||||
//
|
||||
// public AlbumViewFragment getAlbumFragment() {
|
||||
// return (AlbumViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ALBUM.ordinal());
|
||||
// public AlbumsFragment getAlbumFragment() {
|
||||
// return (AlbumsFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.ALBUM.ordinal());
|
||||
// }
|
||||
//
|
||||
// private boolean isSongPage() {
|
||||
// return pager.getCurrentItem() == PagerAdapter.MusicFragments.SONG.ordinal();
|
||||
// }
|
||||
//
|
||||
// public SongViewFragment getSongFragment() {
|
||||
// return (SongViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.SONG.ordinal());
|
||||
// public SongsFragment getSongFragment() {
|
||||
// return (SongsFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.SONG.ordinal());
|
||||
// }
|
||||
|
||||
private boolean isPlaylistPage() {
|
||||
return pager.getCurrentItem() == PagerAdapter.MusicFragments.PLAYLIST.ordinal();
|
||||
}
|
||||
|
||||
// public PlaylistViewFragment getPlaylistFragment() {
|
||||
// return (PlaylistViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.PLAYLIST.ordinal());
|
||||
// public PlaylistsFragment getPlaylistFragment() {
|
||||
// return (PlaylistsFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.PLAYLIST.ordinal());
|
||||
// }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsMainActivityRecyclerViewCustomGridSizeFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsMainActivityRecyclerViewFragment<A, LM> {
|
||||
private int gridSize;
|
||||
|
||||
private boolean usePaletteInitialized;
|
||||
private boolean usePalette;
|
||||
|
||||
public final int getGridSize() {
|
||||
if (gridSize == 0) {
|
||||
if (isLandscape()) {
|
||||
gridSize = loadGridSizeLand();
|
||||
} else {
|
||||
gridSize = loadGridSize();
|
||||
}
|
||||
}
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the palette should be used at all or not
|
||||
*/
|
||||
public final boolean usePalette() {
|
||||
if (!usePaletteInitialized) {
|
||||
usePalette = loadUsePalette();
|
||||
usePaletteInitialized = true;
|
||||
}
|
||||
return usePalette;
|
||||
}
|
||||
|
||||
public void setAndSaveGridSize(final int gridSize) {
|
||||
int oldLayoutRes = getItemLayoutRes();
|
||||
this.gridSize = gridSize;
|
||||
if (isLandscape()) {
|
||||
saveGridSizeLand(gridSize);
|
||||
} else {
|
||||
saveGridSize(gridSize);
|
||||
}
|
||||
// only recreate the adapter and layout manager if the layout res has changed
|
||||
if (oldLayoutRes != getItemLayoutRes()) {
|
||||
invalidateLayoutManager();
|
||||
invalidateAdapter();
|
||||
} else {
|
||||
setGridSize(gridSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAndSaveUsePalette(final boolean usePalette) {
|
||||
this.usePalette = usePalette;
|
||||
saveUsePalette(usePalette);
|
||||
setUsePalette(usePalette);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the palette option should be available for the current item layout or not
|
||||
*/
|
||||
public boolean canUsePalette() {
|
||||
return getItemLayoutRes() == R.layout.item_grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to customize which item layout res should be used. You might also want to override {@link #canUsePalette()} then.
|
||||
*
|
||||
* @see #getGridSize()
|
||||
*/
|
||||
@LayoutRes
|
||||
protected int getItemLayoutRes() {
|
||||
if (getGridSize() > getMaxGridSizeForList()) {
|
||||
return R.layout.item_grid;
|
||||
}
|
||||
return R.layout.item_list;
|
||||
}
|
||||
|
||||
protected abstract int loadGridSize();
|
||||
|
||||
protected abstract void saveGridSize(int gridColumns);
|
||||
|
||||
protected abstract int loadGridSizeLand();
|
||||
|
||||
protected abstract void saveGridSizeLand(int gridColumns);
|
||||
|
||||
protected abstract void saveUsePalette(boolean usePalette);
|
||||
|
||||
protected abstract boolean loadUsePalette();
|
||||
|
||||
protected abstract void setUsePalette(boolean usePalette);
|
||||
|
||||
protected abstract void setGridSize(int gridSize);
|
||||
|
||||
protected int getMaxGridSizeForList() {
|
||||
if (isLandscape()) {
|
||||
return getActivity().getResources().getInteger(R.integer.default_list_columns_land);
|
||||
}
|
||||
return getActivity().getResources().getInteger(R.integer.default_list_columns);
|
||||
}
|
||||
|
||||
protected final boolean isLandscape() {
|
||||
return Util.isLandscape(getActivity());
|
||||
}
|
||||
}
|
||||
|
|
@ -177,12 +177,4 @@ public abstract class AbsMainActivityRecyclerViewFragment<A extends RecyclerView
|
|||
getMainActivity().removeMusicServiceEventListener(this);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
protected int getDefaultGridColumnCount() {
|
||||
return getActivity().getResources().getInteger(R.integer.grid_num_columns);
|
||||
}
|
||||
|
||||
protected int getDefaultListColumnCount() {
|
||||
return getActivity().getResources().getInteger(R.integer.list_num_columns);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsMainActivityRecyclerViewLayoutModeFragment<A extends RecyclerView.Adapter, LM extends RecyclerView.LayoutManager> extends AbsMainActivityRecyclerViewFragment<A, LM> {
|
||||
public static final int NO_LAYOUT_MODE = -1;
|
||||
|
||||
private int layoutMode = NO_LAYOUT_MODE;
|
||||
|
||||
public int getLayoutMode() {
|
||||
if (layoutMode == NO_LAYOUT_MODE) {
|
||||
layoutMode = loadLayoutMode();
|
||||
}
|
||||
return layoutMode;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
protected int getItemLayoutRes() {
|
||||
switch (getLayoutMode()) {
|
||||
case PreferenceUtil.LAYOUT_MODE_LIST:
|
||||
return R.layout.item_list;
|
||||
case PreferenceUtil.LAYOUT_MODE_GRID:
|
||||
return R.layout.item_grid;
|
||||
default:
|
||||
return R.layout.item_list;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getColumnCount() {
|
||||
switch (getLayoutMode()) {
|
||||
case PreferenceUtil.LAYOUT_MODE_LIST:
|
||||
return getDefaultListColumnCount();
|
||||
case PreferenceUtil.LAYOUT_MODE_GRID:
|
||||
return getDefaultGridColumnCount();
|
||||
default:
|
||||
return getDefaultListColumnCount();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLayoutModeAndSaveValue(int layoutMode) {
|
||||
this.layoutMode = layoutMode;
|
||||
saveLayoutMode(layoutMode);
|
||||
invalidateLayoutManager();
|
||||
invalidateAdapter();
|
||||
}
|
||||
|
||||
protected abstract int loadLayoutMode();
|
||||
|
||||
protected abstract void saveLayoutMode(int layoutMode);
|
||||
|
||||
public abstract void setUsePaletteAndSaveValue(boolean usePalette);
|
||||
|
||||
public abstract boolean loadUsePalette();
|
||||
}
|
||||
|
|
@ -11,12 +11,12 @@ import com.kabouzeid.gramophone.util.PreferenceUtil;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragment<AlbumAdapter, GridLayoutManager> {
|
||||
public static final String TAG = AlbumViewFragment.class.getSimpleName();
|
||||
public class AlbumsFragment extends AbsMainActivityRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager> {
|
||||
public static final String TAG = AlbumsFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected GridLayoutManager createLayoutManager() {
|
||||
return new GridLayoutManager(getActivity(), getColumnCount());
|
||||
return new GridLayoutManager(getActivity(), getGridSize());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -35,25 +35,45 @@ public class AlbumViewFragment extends AbsMainActivityRecyclerViewLayoutModeFrag
|
|||
return R.string.no_albums;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsePaletteAndSaveValue(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
PreferenceUtil.getInstance(getActivity()).setAlbumColoredFooters(usePalette);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadUsePalette() {
|
||||
return PreferenceUtil.getInstance(getActivity()).albumColoredFooters();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int loadLayoutMode() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getAlbumLayoutMode();
|
||||
protected void setUsePalette(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveLayoutMode(int layoutMode) {
|
||||
PreferenceUtil.getInstance(getActivity()).setAlbumLayoutMode(layoutMode);
|
||||
protected void setGridSize(int gridSize) {
|
||||
getLayoutManager().setSpanCount(gridSize);
|
||||
getLayoutManager().requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int loadGridSize() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getAlbumGridSize(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveGridSize(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setAlbumGridSize(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int loadGridSizeLand() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getAlbumGridSizeLand(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveGridSizeLand(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setAlbumGridSizeLand(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveUsePalette(boolean usePalette) {
|
||||
PreferenceUtil.getInstance(getActivity()).setAlbumColoredFooters(usePalette);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -11,14 +11,14 @@ import com.kabouzeid.gramophone.util.PreferenceUtil;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragment<ArtistAdapter, GridLayoutManager> {
|
||||
public class ArtistsFragment extends AbsMainActivityRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager> {
|
||||
|
||||
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
||||
public static final String TAG = ArtistsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected GridLayoutManager createLayoutManager() {
|
||||
return new GridLayoutManager(getActivity(), getColumnCount());
|
||||
return new GridLayoutManager(getActivity(), getGridSize());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -43,18 +43,27 @@ public class ArtistViewFragment extends AbsMainActivityRecyclerViewLayoutModeFra
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int loadLayoutMode() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getArtistLayoutMode();
|
||||
protected int loadGridSize() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getArtistGridSize(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveLayoutMode(int layoutMode) {
|
||||
PreferenceUtil.getInstance(getActivity()).setArtistLayoutMode(layoutMode);
|
||||
protected void saveGridSize(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setArtistGridSize(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsePaletteAndSaveValue(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
protected int loadGridSizeLand() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getArtistGridSizeLand(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveGridSizeLand(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setArtistGridSizeLand(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveUsePalette(boolean usePalette) {
|
||||
PreferenceUtil.getInstance(getActivity()).setArtistColoredFooters(usePalette);
|
||||
}
|
||||
|
||||
|
|
@ -62,4 +71,15 @@ public class ArtistViewFragment extends AbsMainActivityRecyclerViewLayoutModeFra
|
|||
public boolean loadUsePalette() {
|
||||
return PreferenceUtil.getInstance(getActivity()).artistColoredFooters();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUsePalette(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setGridSize(int gridSize) {
|
||||
getLayoutManager().setSpanCount(gridSize);
|
||||
getLayoutManager().requestLayout();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,9 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaylistViewFragment extends AbsMainActivityRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager> {
|
||||
public class PlaylistsFragment extends AbsMainActivityRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager> {
|
||||
|
||||
public static final String TAG = PlaylistViewFragment.class.getSimpleName();
|
||||
public static final String TAG = PlaylistsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
@ -16,14 +16,14 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragment<SongAdapter, GridLayoutManager> {
|
||||
public class SongsFragment extends AbsMainActivityRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager> {
|
||||
|
||||
public static final String TAG = SongViewFragment.class.getSimpleName();
|
||||
public static final String TAG = SongsFragment.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected GridLayoutManager createLayoutManager() {
|
||||
return new GridLayoutManager(getActivity(), getColumnCount());
|
||||
return new GridLayoutManager(getActivity(), getGridSize());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -34,7 +34,7 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragm
|
|||
int itemLayoutRes = getItemLayoutRes();
|
||||
boolean usePalette = loadUsePalette();
|
||||
|
||||
if (getLayoutMode() == PreferenceUtil.LAYOUT_MODE_LIST) {
|
||||
if (getGridSize() <= getMaxGridSizeForList()) {
|
||||
return new ShuffleButtonSongAdapter(
|
||||
mainActivity,
|
||||
songs,
|
||||
|
|
@ -61,18 +61,27 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragm
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int loadLayoutMode() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getSongLayoutMode();
|
||||
protected int loadGridSize() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getSongGridSize(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveLayoutMode(int layoutMode) {
|
||||
PreferenceUtil.getInstance(getActivity()).setSongLayoutMode(layoutMode);
|
||||
protected void saveGridSize(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setSongGridSize(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsePaletteAndSaveValue(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
protected int loadGridSizeLand() {
|
||||
return PreferenceUtil.getInstance(getActivity()).getSongGridSizeLand(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveGridSizeLand(int gridSize) {
|
||||
PreferenceUtil.getInstance(getActivity()).setSongGridSizeLand(gridSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUsePalette(boolean usePalette) {
|
||||
PreferenceUtil.getInstance(getActivity()).setSongColoredFooters(usePalette);
|
||||
}
|
||||
|
||||
|
|
@ -80,4 +89,15 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragm
|
|||
public boolean loadUsePalette() {
|
||||
return PreferenceUtil.getInstance(getActivity()).songColoredFooters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsePalette(boolean usePalette) {
|
||||
getAdapter().usePalette(usePalette);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setGridSize(int gridSize) {
|
||||
getLayoutManager().setSpanCount(gridSize);
|
||||
getLayoutManager().requestLayout();
|
||||
}
|
||||
}
|
||||
|
|
@ -25,11 +25,17 @@ public final class PreferenceUtil {
|
|||
// don't use "colored_navigation_bar" key here as this causes a class cast exception for users upgrading from older versions
|
||||
public static final String COLORED_NAVIGATION_BAR = "should_color_navigation_bar";
|
||||
|
||||
public static final String ALBUM_LAYOUT_MODE = "album_layout_mode";
|
||||
public static final String ALBUM_GRID_SIZE = "album_grid_size";
|
||||
public static final String ALBUM_GRID_SIZE_LAND = "album_grid_size_land";
|
||||
|
||||
public static final String SONG_GRID_SIZE = "song_grid_size";
|
||||
public static final String SONG_GRID_SIZE_LAND = "song_grid_size_land";
|
||||
|
||||
public static final String ARTIST_GRID_SIZE = "artist_grid_size";
|
||||
public static final String ARTIST_GRID_SIZE_LAND = "artist_grid_size_land";
|
||||
|
||||
public static final String ALBUM_COLORED_FOOTERS = "album_colored_footers";
|
||||
public static final String SONG_LAYOUT_MODE = "song_layout_mode";
|
||||
public static final String SONG_COLORED_FOOTERS = "song_colored_footers";
|
||||
public static final String ARTIST_LAYOUT_MODE = "artist_layout_mode";
|
||||
public static final String ARTIST_COLORED_FOOTERS = "artist_colored_footers";
|
||||
|
||||
public static final String OPAQUE_TOOLBAR_NOW_PLAYING = "opaque_toolbar_now_playing";
|
||||
|
|
@ -257,37 +263,64 @@ public final class PreferenceUtil {
|
|||
editor.apply();
|
||||
}
|
||||
|
||||
public static final int LAYOUT_MODE_LIST = 0;
|
||||
public static final int LAYOUT_MODE_GRID = 1;
|
||||
|
||||
public void setAlbumLayoutMode(final int value) {
|
||||
public void setAlbumGridSize(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(ALBUM_LAYOUT_MODE, value);
|
||||
editor.putInt(ALBUM_GRID_SIZE, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getAlbumLayoutMode() {
|
||||
return mPreferences.getInt(ALBUM_LAYOUT_MODE, LAYOUT_MODE_GRID);
|
||||
public final int getAlbumGridSize(Context context) {
|
||||
return mPreferences.getInt(ALBUM_GRID_SIZE, context.getResources().getInteger(R.integer.default_grid_columns));
|
||||
}
|
||||
|
||||
public void setSongLayoutMode(final int value) {
|
||||
public void setSongGridSize(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(SONG_LAYOUT_MODE, value);
|
||||
editor.putInt(SONG_GRID_SIZE, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getSongLayoutMode() {
|
||||
return mPreferences.getInt(SONG_LAYOUT_MODE, LAYOUT_MODE_LIST);
|
||||
public final int getSongGridSize(Context context) {
|
||||
return mPreferences.getInt(SONG_GRID_SIZE, context.getResources().getInteger(R.integer.default_list_columns));
|
||||
}
|
||||
|
||||
public void setArtistLayoutMode(final int value) {
|
||||
public void setArtistGridSize(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(ARTIST_LAYOUT_MODE, value);
|
||||
editor.putInt(ARTIST_GRID_SIZE, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getArtistLayoutMode() {
|
||||
return mPreferences.getInt(ARTIST_LAYOUT_MODE, LAYOUT_MODE_GRID);
|
||||
public final int getArtistGridSize(Context context) {
|
||||
return mPreferences.getInt(ARTIST_GRID_SIZE, context.getResources().getInteger(R.integer.default_grid_columns));
|
||||
}
|
||||
|
||||
public void setAlbumGridSizeLand(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(ALBUM_GRID_SIZE_LAND, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getAlbumGridSizeLand(Context context) {
|
||||
return mPreferences.getInt(ALBUM_GRID_SIZE_LAND, context.getResources().getInteger(R.integer.default_grid_columns_land));
|
||||
}
|
||||
|
||||
public void setSongGridSizeLand(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(SONG_GRID_SIZE_LAND, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getSongGridSizeLand(Context context) {
|
||||
return mPreferences.getInt(SONG_GRID_SIZE_LAND, context.getResources().getInteger(R.integer.default_list_columns_land));
|
||||
}
|
||||
|
||||
public void setArtistGridSizeLand(final int gridSize) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(ARTIST_GRID_SIZE_LAND, gridSize);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getArtistGridSizeLand(Context context) {
|
||||
return mPreferences.getInt(ARTIST_GRID_SIZE_LAND, context.getResources().getInteger(R.integer.default_grid_columns_land));
|
||||
}
|
||||
|
||||
public void setAlbumColoredFooters(final boolean value) {
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ public class Util {
|
|||
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
||||
}
|
||||
|
||||
public static boolean isInPortraitMode(@NonNull final Context context) {
|
||||
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
||||
public static boolean isLandscape(@NonNull final Context context) {
|
||||
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
public static Drawable resolveDrawable(@NonNull Context context, @AttrRes int drawableAttr) {
|
||||
|
|
|
|||
|
|
@ -15,30 +15,49 @@
|
|||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_view_as"
|
||||
android:title="@string/action_view_as">
|
||||
android:id="@+id/action_grid_size"
|
||||
android:title="@string/action_grid_size">
|
||||
<menu>
|
||||
<group
|
||||
android:id="@+id/group_view_as"
|
||||
android:id="@+id/group_grid_size"
|
||||
android:checkableBehavior="single"
|
||||
tools:ignore="HardcodedText">
|
||||
<item
|
||||
android:id="@+id/action_layout_mode_list"
|
||||
android:title="@string/list" />
|
||||
android:id="@+id/action_grid_size_1"
|
||||
android:title="@string/grid_size_1" />
|
||||
<item
|
||||
android:id="@+id/action_layout_mode_grid"
|
||||
android:title="@string/grid" />
|
||||
android:id="@+id/action_grid_size_2"
|
||||
android:title="@string/grid_size_2" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_3"
|
||||
android:title="@string/grid_size_3" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_4"
|
||||
android:title="@string/grid_size_4" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_5"
|
||||
android:title="@string/grid_size_5" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_6"
|
||||
android:title="@string/grid_size_6" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_7"
|
||||
android:title="@string/grid_size_7" />
|
||||
<item
|
||||
android:id="@+id/action_grid_size_8"
|
||||
android:title="@string/grid_size_8" />
|
||||
</group>
|
||||
<item
|
||||
android:id="@+id/action_colored_footers"
|
||||
android:checkable="true"
|
||||
android:title="@string/colored_footers" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:orderInCategory="98"
|
||||
android:id="@+id/action_colored_footers"
|
||||
android:checkable="true"
|
||||
android:title="@string/colored_footers" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_sleep_timer"
|
||||
android:orderInCategory="98"
|
||||
android:title="@string/action_sleep_timer"
|
||||
app:showAsAction="never" />
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="grid_num_columns">4</integer>
|
||||
<integer name="list_num_columns">2</integer>
|
||||
</resources>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="grid_num_columns">6</integer>
|
||||
<integer name="list_num_columns">3</integer>
|
||||
</resources>
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="grid_num_columns">4</integer>
|
||||
<integer name="list_num_columns">2</integer>
|
||||
<integer name="default_grid_columns">4</integer>
|
||||
<integer name="default_list_columns">2</integer>
|
||||
<integer name="default_grid_columns_land">6</integer>
|
||||
<integer name="default_list_columns_land">3</integer>
|
||||
</resources>
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="grid_num_columns">2</integer>
|
||||
<integer name="list_num_columns">1</integer>
|
||||
<integer name="default_grid_columns">2</integer>
|
||||
<integer name="default_grid_columns_land">4</integer>
|
||||
|
||||
<integer name="default_list_columns">1</integer>
|
||||
<integer name="default_list_columns_land">2</integer>
|
||||
|
||||
<integer name="font_textStyle_medium">1</integer>
|
||||
</resources>
|
||||
|
|
@ -60,7 +60,8 @@
|
|||
<string name="added_title_to_playing_queue">"Added 1 title to the playing queue."</string>
|
||||
<string name="added_x_titles_to_playing_queue">Added %1$d titles to the playing queue.</string>
|
||||
<string name="action_remove_from_playlist">Remove from playlist</string>
|
||||
<string name="action_view_as">View as</string>
|
||||
<string name="action_grid_size">Grid size</string>
|
||||
<string name="action_grid_size_land">Grid size (land)</string>
|
||||
<string name="inserted_x_songs_into_playlist_x">Inserted %1$d songs into the playlist %2$s.</string>
|
||||
<string name="created_playlist_x">Created playlist %1$s.</string>
|
||||
<string name="deleted_playlist_x">Deleted playlist %1$s.</string>
|
||||
|
|
@ -166,8 +167,14 @@
|
|||
<string name="sleep_timer_set">Sleep timer set for %d minutes from now.</string>
|
||||
<string name="action_new_playlist">New playlist…</string>
|
||||
<string name="new_playlist_title">New playlist</string>
|
||||
<string name="grid">Grid</string>
|
||||
<string name="list">List</string>
|
||||
<string name="grid_size_1">1</string>
|
||||
<string name="grid_size_2">2</string>
|
||||
<string name="grid_size_3">3</string>
|
||||
<string name="grid_size_4">4</string>
|
||||
<string name="grid_size_5">5</string>
|
||||
<string name="grid_size_6">6</string>
|
||||
<string name="grid_size_7">7</string>
|
||||
<string name="grid_size_8">8</string>
|
||||
<string name="colored_footers">Colored footers</string>
|
||||
<string name="special_thanks_to">Special thanks to</string>
|
||||
<string name="changelog">Changelog</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue