Skip to content

Commit 2faad8d

Browse files
committed
Add a grid density setting
The grid cell size could only be changed by pinching the file list, which is easy to miss and awkward to land on a particular size. Add a density setting that writes the same stored value the pinch gesture uses, so the two stay in step and neither overrides the other. The options set how large the cells are rather than a fixed column count, because a column count that suits a tablet leaves a phone with cells too narrow to read. The file list only read that value while creating its view, so a density picked in the settings did not reach a list that was already open, and the list then wrote its stale value back when it saved its state. Read the value again on resume so the change takes effect on the way back. Signed-off-by: David Sandquist <sandquist@gmail.com>
1 parent a379a2c commit 2faad8d

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.os.Bundle;
2828
import android.os.Handler;
2929
import android.os.Looper;
30+
import android.preference.ListPreference;
3031
import android.preference.Preference;
3132
import android.preference.PreferenceActivity;
3233
import android.preference.PreferenceCategory;
@@ -966,6 +967,30 @@ private void setupGeneralCategory() {
966967
return true;
967968
});
968969
}
970+
971+
setupGridDensityPreference();
972+
}
973+
974+
/**
975+
* The grid density shares its stored value with the pinch to zoom gesture in the file list,
976+
* so picking a density here and pinching the grid are two ways of setting the same thing.
977+
*/
978+
private void setupGridDensityPreference() {
979+
if (!(findPreference("grid_density") instanceof ListPreference densityPref)) {
980+
return;
981+
}
982+
983+
densityPref.setValue(String.valueOf(Math.round(preferences.getGridColumns())));
984+
985+
densityPref.setOnPreferenceChangeListener((preference, newValue) -> {
986+
try {
987+
preferences.setGridColumns(Float.parseFloat(newValue.toString()));
988+
} catch (NumberFormatException e) {
989+
Log_OC.w(TAG, "Ignoring unusable grid density value: " + newValue);
990+
return false;
991+
}
992+
return true;
993+
});
969994
}
970995

971996
private void updateThemePreferenceSummary(String themeValue) {

app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,21 @@ open class ExtendedListFragment :
418418
scrollToPosition(referencePosition)
419419
}
420420

421+
@SuppressLint("NotifyDataSetChanged")
422+
override fun onResume() {
423+
super.onResume()
424+
425+
// The density may have been changed in the settings while this list was in the
426+
// background, and the stored value is only read when the view is created.
427+
val stored = preferences.getGridColumns()
428+
if (stored != mScale) {
429+
mScale = stored
430+
// The layout manager reads the target column width again on its next layout.
431+
recyclerView?.requestLayout()
432+
recyclerView?.adapter?.notifyDataSetChanged()
433+
}
434+
}
435+
421436
override fun onSaveInstanceState(savedInstanceState: Bundle) {
422437
super.onSaveInstanceState(savedInstanceState)
423438
Log_OC.d(TAG, "onSaveInstanceState()")

app/src/main/res/values/strings.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,4 +1549,15 @@
15491549
<string name="governance_permission_denied">You do not have permission to change this label</string>
15501550
<string name="file_info_governance_section_title">Governance</string>
15511551
<string name="file_info_image_details_section_title">Image details</string>
1552+
<string name="prefs_grid_density_title">Grid density</string>
1553+
<string-array name="prefs_grid_density_entries">
1554+
<item>Spacious</item>
1555+
<item>Default</item>
1556+
<item>Compact</item>
1557+
</string-array>
1558+
<string-array name="prefs_grid_density_values" translatable="false">
1559+
<item>2</item>
1560+
<item>3</item>
1561+
<item>4</item>
1562+
</string-array>
15521563
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
android:defaultValue="true"
4949
android:title="@string/sort_favorites_first"
5050
android:key="sort_favorites_first" />
51+
<ListPreference
52+
android:title="@string/prefs_grid_density_title"
53+
android:key="grid_density"
54+
android:entries="@array/prefs_grid_density_entries"
55+
android:entryValues="@array/prefs_grid_density_values"
56+
android:summary="%s" />
5157
</PreferenceCategory>
5258

5359
<PreferenceCategory android:title="@string/prefs_category_details" android:key="details">

0 commit comments

Comments
 (0)