From 7ed11ba1df17128b8f43d13fbbdc3ccaf85ea31b Mon Sep 17 00:00:00 2001 From: Michael Prommersberger Date: Tue, 2 Jul 2024 14:00:06 +0200 Subject: [PATCH] feat: add option for denser layout of FileList --- .../android/files/filelist/FileListAdapter.kt | 14 +++++++++++++- .../android/files/filelist/FileListFragment.kt | 14 ++++++++++++-- .../me/zhanghai/android/files/settings/Settings.kt | 7 ++++++- app/src/main/res/values/dimens.xml | 3 ++- app/src/main/res/values/donottranslate_prefs.xml | 4 +++- app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/settings.xml | 7 ++++++- 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/me/zhanghai/android/files/filelist/FileListAdapter.kt b/app/src/main/java/me/zhanghai/android/files/filelist/FileListAdapter.kt index 0d300aed3..2faa22e78 100644 --- a/app/src/main/java/me/zhanghai/android/files/filelist/FileListAdapter.kt +++ b/app/src/main/java/me/zhanghai/android/files/filelist/FileListAdapter.kt @@ -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() @@ -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 @@ -484,4 +496,4 @@ class FileListAdapter( fun createShortcut(file: FileItem) fun showPropertiesDialog(file: FileItem) } -} +} \ No newline at end of file diff --git a/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt b/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt index 5c02a1c79..0b06ccfb4 100644 --- a/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt +++ b/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt @@ -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) } @@ -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 ) } } } @@ -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()) { @@ -1736,4 +1746,4 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter. } } } -} +} \ No newline at end of file diff --git a/app/src/main/java/me/zhanghai/android/files/settings/Settings.kt b/app/src/main/java/me/zhanghai/android/files/settings/Settings.kt index d2a8e2035..cc3ec587b 100644 --- a/app/src/main/java/me/zhanghai/android/files/settings/Settings.kt +++ b/app/src/main/java/me/zhanghai/android/files/settings/Settings.kt @@ -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 = + BooleanSettingLiveData( + R.string.pref_key_file_list_dense_layout, R.bool.pref_default_value_file_list_dense_layout + ) + val FILE_NAME_ELLIPSIZE: SettingLiveData = EnumSettingLiveData( R.string.pref_key_file_name_ellipsize, R.string.pref_default_value_file_name_ellipsize, @@ -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 ) -} +} \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 34799c16a..8f3a5165d 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -33,6 +33,7 @@ 40dp 56dp 72dp + 48dp 16dp 1dp 18dp @@ -50,4 +51,4 @@ 24dp - + \ No newline at end of file diff --git a/app/src/main/res/values/donottranslate_prefs.xml b/app/src/main/res/values/donottranslate_prefs.xml index 5edcd3425..3b4f68d94 100644 --- a/app/src/main/res/values/donottranslate_prefs.xml +++ b/app/src/main/res/values/donottranslate_prefs.xml @@ -51,6 +51,8 @@ false key_file_list_animation true + key_file_list_dense_layout + false key_file_name_ellipsize 1 @@ -82,4 +84,4 @@ true key_read_remote_files_for_thumbnail true - + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 964179529..954aeea85 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -748,6 +748,7 @@ Black night mode File list animation + File list dense layout Display long file name Ellipsize the beginning @@ -800,4 +801,4 @@ @string/navigation_standard_directory_downloads @string/ftp_server_title - + \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 8cdac819a..148a49cc8 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -46,6 +46,11 @@ android:title="@string/settings_file_list_animation_title" android:defaultValue="@bool/pref_default_value_file_list_animation" /> + + - + \ No newline at end of file