1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-17 15:24:55 +00:00

Automatic list layout

This commit is contained in:
Vasily 2018-08-29 08:19:15 +03:00
parent fbd983217d
commit fb25f6c7ac
4 changed files with 19 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -84,8 +85,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
if (updateFlags != 0) { if (updateFlags != 0) {
if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) { if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) {
final String list_key = getString(R.string.list_view_mode_value); final boolean useGrid = isGridLayout();
final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key));
itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager());
infoListAdapter.setGridItemVariants(useGrid); infoListAdapter.setGridItemVariants(useGrid);
infoListAdapter.notifyDataSetChanged(); infoListAdapter.notifyDataSetChanged();
@ -160,9 +160,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
protected void initViews(View rootView, Bundle savedInstanceState) { protected void initViews(View rootView, Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState); super.initViews(rootView, savedInstanceState);
final String list_key = getString(R.string.list_view_mode_value); final boolean useGrid = isGridLayout();
final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key));
itemsList = rootView.findViewById(R.id.items_list); itemsList = rootView.findViewById(R.id.items_list);
itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager());
@ -363,4 +361,15 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
updateFlags |= LIST_MODE_UPDATE_FLAG; 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);
}
}
} }

View File

@ -501,5 +501,6 @@
<string name="list_view_mode">Вид списка</string> <string name="list_view_mode">Вид списка</string>
<string name="list">Список</string> <string name="list">Список</string>
<string name="grid">Сетка</string> <string name="grid">Сетка</string>
<string name="auto">Автоматически</string>
</resources> </resources>

View File

@ -892,13 +892,15 @@
</string-array> </string-array>
<string name="list_view_mode_key" translatable="false">list_view_mode</string> <string name="list_view_mode_key" translatable="false">list_view_mode</string>
<string name="list_view_mode_value" translatable="false">list</string> <string name="list_view_mode_value" translatable="false">auto</string>
<string-array name="list_view_mode_values" translatable="false"> <string-array name="list_view_mode_values" translatable="false">
<item>auto</item>
<item>list</item> <item>list</item>
<item>grid</item> <item>grid</item>
</string-array> </string-array>
<string-array name="list_view_mode_description" translatable="false"> <string-array name="list_view_mode_description" translatable="false">
<item>@string/auto</item>
<item>@string/list</item> <item>@string/list</item>
<item>@string/grid</item> <item>@string/grid</item>
</string-array> </string-array>

View File

@ -517,5 +517,6 @@
<string name="list_view_mode">List view mode</string> <string name="list_view_mode">List view mode</string>
<string name="list">List</string> <string name="list">List</string>
<string name="grid">Grid</string> <string name="grid">Grid</string>
<string name="auto">Auto</string>
</resources> </resources>