From fb25f6c7ac9ff8e24241e79e94f7ac046f836ad0 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 29 Aug 2018 08:19:15 +0300 Subject: [PATCH] Automatic list layout --- .../fragments/list/BaseListFragment.java | 19 ++++++++++++++----- app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values/settings_keys.xml | 4 +++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index bfa16fb08..21abf40ad 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceManager; @@ -84,8 +85,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem if (updateFlags != 0) { if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) { - final String list_key = getString(R.string.list_view_mode_value); - final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); + final boolean useGrid = isGridLayout(); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); infoListAdapter.setGridItemVariants(useGrid); infoListAdapter.notifyDataSetChanged(); @@ -160,9 +160,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem protected void initViews(View rootView, Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); - final String list_key = getString(R.string.list_view_mode_value); - final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); - + final boolean useGrid = isGridLayout(); itemsList = rootView.findViewById(R.id.items_list); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); @@ -363,4 +361,15 @@ public abstract class BaseListFragment extends BaseStateFragment implem updateFlags |= LIST_MODE_UPDATE_FLAG; } } + + protected boolean isGridLayout() { + final String list_mode = PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), getString(R.string.list_view_mode_value)); + if ("auto".equals(list_mode)) { + final Configuration configuration = getResources().getConfiguration(); + return configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE); + } else { + return "grid".equals(list_mode); + } + } } diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e2198f240..a053cafb3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -501,5 +501,6 @@ Вид списка Список Сетка + Автоматически diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 941f033d8..0c71944c3 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -892,13 +892,15 @@ list_view_mode - list + auto + auto list grid + @string/auto @string/list @string/grid diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f3976c6a4..b63de7dbd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -517,5 +517,6 @@ List view mode List Grid + Auto