Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option for denser layout of FileList #1264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class FileListAdapter(
notifyItemRangeChanged(0, itemCount, PAYLOAD_STATE_CHANGED)
}

private var _denseLayout: Boolean = false
var denseLayout: Boolean
get() = _denseLayout
set(value) {
_denseLayout = value
}

fun replaceSelectedFiles(files: FileItemSet) {
val changedFiles = fileItemSetOf()
val iterator = selectedFiles.iterator()
Expand Down Expand Up @@ -191,6 +198,11 @@ class FileListAdapter(
} else {
CheckableItemBackground.create(0f, 0f, context)
}
if (viewType == FileViewType.LIST && denseLayout) {
layoutParams = layoutParams.apply {
height = context.resources.getDimensionPixelSize(R.dimen.dense_two_line_list_item_height)
}
}
}
thumbnailOutlineView?.apply {
val context = context
Expand Down Expand Up @@ -484,4 +496,4 @@ class FileListAdapter(
fun createShortcut(file: FileItem)
fun showPropertiesDialog(file: FileItem)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
}
viewModel.pickOptionsLiveData.observe(viewLifecycleOwner) { onPickOptionsChanged(it) }
viewModel.selectedFilesLiveData.observe(viewLifecycleOwner) { onSelectedFilesChanged(it) }
Settings.FILE_LIST_DENSE_LAYOUT.observe(viewLifecycleOwner) { onDenseLayoutChanged(it) }
viewModel.pasteStateLiveData.observe(viewLifecycleOwner) { onPasteStateChanged(it) }
Settings.FILE_NAME_ELLIPSIZE.observe(viewLifecycleOwner) { onFileNameEllipsizeChanged(it) }
viewModel.fileListLiveData.observe(viewLifecycleOwner) { onFileListChanged(it) }
Expand Down Expand Up @@ -663,7 +664,7 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
persistentDrawerLayout.isDrawerOpen(GravityCompat.START)) {
widthDp -= getDimensionDp(R.dimen.navigation_max_width).roundToInt()
}
(widthDp / 180).coerceAtLeast(2)
(widthDp / 180).coerceAtLeast(if (adapter.denseLayout) 3 else 2 )
}
}
}
Expand Down Expand Up @@ -846,6 +847,15 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
adapter.replaceSelectedFiles(files)
}

private fun onDenseLayoutChanged(denseLayout: Boolean) {
adapter.denseLayout = denseLayout
updateSpanCount()
// re-set adapter to prevent RecyclerView from recycling views and reusing old padding
// values on refresh. Neither notifyDataSetChanged() / notifyItemRangeChanged
// nor adapter.refresh() does work here.
binding.recyclerView.adapter = adapter
}

private fun updateOverlayToolbar() {
val files = viewModel.selectedFiles
if (files.isEmpty()) {
Expand Down Expand Up @@ -1736,4 +1746,4 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ object Settings {
R.string.pref_key_file_list_animation, R.bool.pref_default_value_file_list_animation
)

val FILE_LIST_DENSE_LAYOUT: SettingLiveData<Boolean> =
BooleanSettingLiveData(
R.string.pref_key_file_list_dense_layout, R.bool.pref_default_value_file_list_dense_layout
)

val FILE_NAME_ELLIPSIZE: SettingLiveData<TextUtils.TruncateAt> =
EnumSettingLiveData(
R.string.pref_key_file_name_ellipsize, R.string.pref_default_value_file_name_ellipsize,
Expand Down Expand Up @@ -181,4 +186,4 @@ object Settings {
R.string.pref_key_read_remote_files_for_thumbnail,
R.bool.pref_default_value_read_remote_files_for_thumbnail
)
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<dimen name="dense_single_line_list_item_height">40dp</dimen>
<dimen name="single_line_list_item_height">56dp</dimen>
<dimen name="two_line_list_item_height">72dp</dimen>
<dimen name="dense_two_line_list_item_height">48dp</dimen>
<dimen name="list_item_vertical_padding">16dp</dimen>
<dimen name="horizontal_divider_height">1dp</dimen>
<dimen name="small_icon_size">18dp</dimen>
Expand All @@ -50,4 +51,4 @@

<!-- Reduce fast scroll thumb touch target size because we have the popup menu beside it. -->
<dimen name="afs_min_touch_target_size">24dp</dimen>
</resources>
</resources>
4 changes: 3 additions & 1 deletion app/src/main/res/values/donottranslate_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<bool name="pref_default_value_black_night_mode">false</bool>
<string name="pref_key_file_list_animation">key_file_list_animation</string>
<bool name="pref_default_value_file_list_animation">true</bool>
<string name="pref_key_file_list_dense_layout">key_file_list_dense_layout</string>
<bool name="pref_default_value_file_list_dense_layout">false</bool>
<string name="pref_key_file_name_ellipsize">key_file_name_ellipsize</string>
<string name="pref_default_value_file_name_ellipsize">1</string>
<string-array name="pref_entry_values_file_name_ellipsize">
Expand Down Expand Up @@ -82,4 +84,4 @@
<bool name="pref_visible_show_pdf_thumbnail_pre_28">true</bool>
<string name="pref_key_read_remote_files_for_thumbnail">key_read_remote_files_for_thumbnail</string>
<bool name="pref_default_value_read_remote_files_for_thumbnail">true</bool>
</resources>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@
</string-array>
<string name="settings_black_night_mode">Black night mode</string>
<string name="settings_file_list_animation_title">File list animation</string>
<string name="settings_file_list_dense_layout_title">File list dense layout</string>
<string name="settings_file_name_ellipsize_title">Display long file name</string>
<string-array name="settings_file_name_ellipsize_entries">
<item>Ellipsize the beginning</item>
Expand Down Expand Up @@ -800,4 +801,4 @@

<string name="shortcut_downloads_title" translatable="false">@string/navigation_standard_directory_downloads</string>
<string name="shortcut_ftp_server_title" translatable="false">@string/ftp_server_title</string>
</resources>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
android:title="@string/settings_file_list_animation_title"
android:defaultValue="@bool/pref_default_value_file_list_animation" />

<SwitchPreferenceCompat
android:key="@string/pref_key_file_list_dense_layout"
android:title="@string/settings_file_list_dense_layout_title"
android:defaultValue="@bool/pref_default_value_file_list_dense_layout" />

<rikka.preference.SimpleMenuPreference
android:key="@string/pref_key_file_name_ellipsize"
android:title="@string/settings_file_name_ellipsize_title"
Expand Down Expand Up @@ -108,4 +113,4 @@
android:title="@string/settings_read_remote_files_for_thumbnail_title"
android:defaultValue="@bool/pref_default_value_read_remote_files_for_thumbnail" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>