From d0d6b87b562d350cfcac0296d973c6bb969d0c7a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 14 Nov 2015 11:32:37 -0800 Subject: Show lager grid for landscape tablets with only one fragment visible --- .../daneren2005/dsub/activity/SubsonicActivity.java | 5 +++++ .../daneren2005/dsub/fragments/SearchFragment.java | 4 ++-- .../dsub/fragments/SelectPodcastsFragment.java | 4 ++-- .../dsub/fragments/SelectRecyclerFragment.java | 15 +++++++++++++-- .../daneren2005/dsub/fragments/SubsonicFragment.java | 16 ++++++++++++---- app/src/main/res/values-large-land/integers.xml | 4 ++++ app/src/main/res/values-xlarge-land/integers.xml | 4 ++++ app/src/main/res/values/integers.xml | 1 + 8 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/values-large-land/integers.xml create mode 100644 app/src/main/res/values-xlarge-land/integers.xml (limited to 'app') diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java index e055983e..e190e4c1 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -745,6 +745,9 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte // Commit it all trans.commit(); + + oldFragment.setIsOnlyVisible(false); + currentFragment.setIsOnlyVisible(false); } recreateSpinner(); } @@ -791,6 +794,8 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte } else { secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right)); secondaryContainer.setVisibility(View.GONE); + + currentFragment.setIsOnlyVisible(true); } trans.commit(); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java index 4e1fbdca..b19ededa 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java @@ -90,13 +90,13 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O } @Override - public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int columns) { + public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() { return new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { int viewType = adapter.getItemViewType(position); if(viewType == EntryGridAdapter.VIEW_TYPE_SONG || viewType == EntryGridAdapter.VIEW_TYPE_HEADER || viewType == ArtistAdapter.VIEW_TYPE_ARTIST) { - return columns; + return getRecyclerColumnCount(); } else { return 1; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index bdb1e550..3f8f7844 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -251,7 +251,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment } @Override - public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int columns) { + public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() { return new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { @@ -259,7 +259,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment if(adapter != null) { int viewType = getCurrentAdapter().getItemViewType(position); if (viewType == SectionAdapter.VIEW_TYPE_HEADER || viewType == PodcastChannelAdapter.VIEW_TYPE_PODCAST_EPISODE || viewType == PodcastChannelAdapter.VIEW_TYPE_PODCAST_LEGACY) { - return columns; + return getRecyclerColumnCount(); } else { return 1; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java index 84011480..7ae7fff8 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java @@ -17,6 +17,7 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; @@ -48,7 +49,6 @@ public abstract class SelectRecyclerFragment extends SubsonicFragment impleme protected List objects; protected boolean serialize = true; protected boolean largeAlbums = false; - protected int columns; protected boolean pullToRefresh = true; protected boolean backgroundUpdate = true; @@ -59,7 +59,6 @@ public abstract class SelectRecyclerFragment extends SubsonicFragment impleme if(bundle != null && serialize) { objects = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); } - columns = context.getResources().getInteger(R.integer.Grid_Columns); } @Override @@ -110,6 +109,18 @@ public abstract class SelectRecyclerFragment extends SubsonicFragment impleme return super.onOptionsItemSelected(item); } + @Override + public void setIsOnlyVisible(boolean isOnlyVisible) { + boolean update = this.isOnlyVisible != isOnlyVisible; + super.setIsOnlyVisible(isOnlyVisible); + if(update && adapter != null) { + RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); + if(layoutManager instanceof GridLayoutManager) { + ((GridLayoutManager) layoutManager).setSpanCount(getRecyclerColumnCount()); + } + } + } + @Override protected void refresh(final boolean refresh) { int titleRes = getTitleResource(); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index e7685ed4..956597a4 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -113,6 +113,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected View rootView; protected boolean primaryFragment = false; protected boolean secondaryFragment = false; + protected boolean isOnlyVisible = true; protected boolean invalidated = false; protected static Random random = new Random(); protected GestureDetector gestureScanner; @@ -476,6 +477,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public void setSecondaryFragment(boolean secondary) { secondaryFragment = secondary; } + public void setIsOnlyVisible(boolean isOnlyVisible) { + this.isOnlyVisible = isOnlyVisible; + } public void invalidate() { if(primaryFragment) { @@ -632,7 +636,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR final int columns = getRecyclerColumnCount(); GridLayoutManager gridLayoutManager = new GridLayoutManager(context, columns); - GridLayoutManager.SpanSizeLookup spanSizeLookup = getSpanSizeLookup(columns); + GridLayoutManager.SpanSizeLookup spanSizeLookup = getSpanSizeLookup(); if(spanSizeLookup != null) { gridLayoutManager.setSpanSizeLookup(spanSizeLookup); } @@ -647,7 +651,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR layoutManager.setOrientation(LinearLayoutManager.VERTICAL); return layoutManager; } - public GridLayoutManager.SpanSizeLookup getSpanSizeLookup(final int columns) { + public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() { return new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { @@ -655,7 +659,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR if(adapter != null) { int viewType = getCurrentAdapter().getItemViewType(position); if (viewType == SectionAdapter.VIEW_TYPE_HEADER) { - return columns; + return getRecyclerColumnCount(); } else { return 1; } @@ -669,7 +673,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return new GridSpacingDecoration(); } public int getRecyclerColumnCount() { - return context.getResources().getInteger(R.integer.Grid_Columns); + if(isOnlyVisible) { + return context.getResources().getInteger(R.integer.Grid_FullScreen_Columns); + } else { + return context.getResources().getInteger(R.integer.Grid_Columns); + } } protected void warnIfStorageUnavailable() { diff --git a/app/src/main/res/values-large-land/integers.xml b/app/src/main/res/values-large-land/integers.xml new file mode 100644 index 00000000..b9736063 --- /dev/null +++ b/app/src/main/res/values-large-land/integers.xml @@ -0,0 +1,4 @@ + + + 4 + \ No newline at end of file diff --git a/app/src/main/res/values-xlarge-land/integers.xml b/app/src/main/res/values-xlarge-land/integers.xml new file mode 100644 index 00000000..acfc72ff --- /dev/null +++ b/app/src/main/res/values-xlarge-land/integers.xml @@ -0,0 +1,4 @@ + + + 5 + \ No newline at end of file diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml index 57371a11..05bcdb28 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -1,5 +1,6 @@ 2 + @integer/Grid.Columns 5 \ No newline at end of file -- cgit v1.2.3