Skip to content

Commit 806aaf3

Browse files
committed
Add following changes:
1. Provide option to select columns to be shown on folder item. 2. Render folder columns conditionally based on preferences. 3. Minor change in folder item layout
1 parent 9f5b41d commit 806aaf3

9 files changed

Lines changed: 178 additions & 8 deletions

File tree

app/src/main/kotlin/org/fossify/filemanager/activities/SettingsActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.fossify.commons.helpers.*
1111
import org.fossify.commons.models.RadioItem
1212
import org.fossify.filemanager.R
1313
import org.fossify.filemanager.databinding.ActivitySettingsBinding
14+
import org.fossify.filemanager.dialogs.ManageFolderColumnsDialog
1415
import org.fossify.filemanager.dialogs.ManageVisibleTabsDialog
1516
import org.fossify.filemanager.extensions.config
1617
import org.fossify.filemanager.helpers.RootHelpers
@@ -38,6 +39,7 @@ class SettingsActivity : SimpleActivity() {
3839
setupLanguage()
3940
setupManageFavorites()
4041
setupManageShownTabs()
42+
setupCustomizeFolderOptions()
4143
setupChangeDateTimeFormat()
4244
setupFontSize()
4345
setupShowHidden()
@@ -188,6 +190,12 @@ class SettingsActivity : SimpleActivity() {
188190
}
189191
}
190192

193+
private fun setupCustomizeFolderOptions(){
194+
binding.settingsManageFolderColumnsHolder.setOnClickListener {
195+
ManageFolderColumnsDialog(this)
196+
}
197+
}
198+
191199
private fun setupAppPasswordProtection() {
192200
binding.settingsAppPasswordProtection.isChecked = config.isAppPasswordProtectionOn
193201
binding.settingsAppPasswordProtectionHolder.setOnClickListener {

app/src/main/kotlin/org/fossify/filemanager/adapters/ItemsAdapter.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,19 @@ class ItemsAdapter(
10711071

10721072
if (listItem.isDirectory) {
10731073
itemIcon?.setImageDrawable(folderDrawable)
1074-
itemDetails?.text = getChildrenCnt(listItem)
1075-
itemDate?.beGone()
1074+
val parts = mutableListOf<String>()
1075+
1076+
if (config.showFolderChildrenCount) {
1077+
parts.add(getChildrenCnt(listItem))
1078+
}
1079+
1080+
if (config.showFolderSize) {
1081+
parts.add(listItem.mSize.formatSize())
1082+
loadFolderSize(listItem, getItemKeyPosition(listItem.path.hashCode()))
1083+
}
1084+
1085+
itemDetails?.text = parts.joinToString("")
1086+
setupFolderDate(listItem,itemDate)
10761087
} else {
10771088
itemDetails?.text = listItem.size.formatSize()
10781089
itemDate?.beVisible()
@@ -1101,6 +1112,25 @@ class ItemsAdapter(
11011112
}
11021113
}
11031114

1115+
private fun loadFolderSize(listItem: ListItem, position: Int) {
1116+
ensureBackgroundThread {
1117+
val size = File(listItem.path).getProperSize(config.shouldShowHidden())
1118+
activity.runOnUiThread {
1119+
listItem.mSize = size
1120+
notifyItemChanged(position, Unit)
1121+
}
1122+
}
1123+
}
1124+
1125+
private fun setupFolderDate(listItem : ListItem,dateView: TextView?) {
1126+
if (config.showFolderLastModifiedAt) {
1127+
dateView?.beVisible()
1128+
dateView?.text = listItem.modified.formatDate(activity, dateFormat, timeFormat)
1129+
} else {
1130+
dateView?.beGone()
1131+
}
1132+
}
1133+
11041134
private fun getChildrenCnt(item: FileDirItem): String {
11051135
val children = item.children
11061136
return activity.resources.getQuantityString(R.plurals.items, children, children)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.fossify.filemanager.dialogs
2+
3+
import org.fossify.commons.activities.BaseSimpleActivity
4+
import org.fossify.commons.extensions.getAlertDialogBuilder
5+
import org.fossify.commons.extensions.setupDialogStuff
6+
import org.fossify.commons.views.MyAppCompatCheckbox
7+
import org.fossify.filemanager.databinding.DialogManageFolderColumsBinding
8+
import org.fossify.filemanager.extensions.config
9+
10+
class ManageFolderColumnsDialog(val activity: BaseSimpleActivity) {
11+
private var config = activity.config
12+
private val binding: DialogManageFolderColumsBinding = DialogManageFolderColumsBinding.inflate(activity.layoutInflater)
13+
private var showFolderSize : Boolean = config.showFolderSize
14+
private var showChildrenCount : Boolean = config.showFolderChildrenCount
15+
private var showModifiedAt : Boolean = config.showFolderLastModifiedAt
16+
17+
init {
18+
19+
setupColumnCheckboxSelection()
20+
21+
activity.getAlertDialogBuilder()
22+
.setPositiveButton("OK",{dialog,which -> dialogConfirmed()})
23+
.setNegativeButton("Cancel",null)
24+
.apply {
25+
activity.setupDialogStuff(binding.root, this)
26+
}
27+
}
28+
29+
private fun setupColumnCheckboxSelection(){
30+
setupCheckbox(binding.manageFolderColumnsSize, showFolderSize) { showFolderSize = it }
31+
setupCheckbox(binding.manageFolderColumnsChildrenCount, showChildrenCount) { showChildrenCount = it }
32+
setupCheckbox(binding.manageFolderColumnsModifiedAt, showModifiedAt) { showModifiedAt = it }
33+
}
34+
35+
private fun setupCheckbox(checkbox: MyAppCompatCheckbox, initialState: Boolean, onChanged: (Boolean) -> Unit) {
36+
checkbox.isChecked = initialState
37+
checkbox.setOnClickListener {
38+
onChanged(checkbox.isChecked)
39+
}
40+
}
41+
42+
private fun dialogConfirmed(){
43+
if(config.showFolderSize != showFolderSize){
44+
config.showFolderSize = showFolderSize
45+
}
46+
47+
if(config.showFolderChildrenCount != showChildrenCount){
48+
config.showFolderChildrenCount = showChildrenCount
49+
}
50+
51+
if(config.showFolderLastModifiedAt != showModifiedAt){
52+
config.showFolderLastModifiedAt = showModifiedAt
53+
}
54+
}
55+
}

app/src/main/kotlin/org/fossify/filemanager/helpers/Config.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ class Config(context: Context) : BaseConfig(context) {
121121
var wasStorageAnalysisTabAdded: Boolean
122122
get() = prefs.getBoolean(WAS_STORAGE_ANALYSIS_TAB_ADDED, false)
123123
set(wasStorageAnalysisTabAdded) = prefs.edit().putBoolean(WAS_STORAGE_ANALYSIS_TAB_ADDED, wasStorageAnalysisTabAdded).apply()
124+
125+
var showFolderSize : Boolean
126+
get() = prefs.getBoolean(FOLDER_SHOW_SIZE, false)
127+
set(showFolderSize) = prefs.edit().putBoolean(FOLDER_SHOW_SIZE,showFolderSize).apply()
128+
129+
var showFolderLastModifiedAt : Boolean
130+
get() = prefs.getBoolean(FOLDER_SHOW_LAST_MODIFIED_AT,false)
131+
set(folderShowLastModifiedAt) = prefs.edit().putBoolean(FOLDER_SHOW_LAST_MODIFIED_AT,folderShowLastModifiedAt).apply()
132+
133+
var showFolderChildrenCount : Boolean
134+
get() = prefs.getBoolean(FOLDER_SHOW_CHILDREN_COUNT,true)
135+
set(showFolderChildrenCount) = prefs.edit().putBoolean(FOLDER_SHOW_CHILDREN_COUNT,showFolderChildrenCount).apply()
136+
124137
}

app/src/main/kotlin/org/fossify/filemanager/helpers/Constants.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const val FILE_LANDSCAPE_COLUMN_CNT = "file_landscape_column_cnt"
2222
const val DISPLAY_FILE_NAMES = "display_file_names"
2323
const val SHOW_TABS = "show_tabs"
2424
const val WAS_STORAGE_ANALYSIS_TAB_ADDED = "was_storage_analysis_tab_added"
25+
const val FOLDER_SHOW_SIZE = "show_folder_size"
26+
const val FOLDER_SHOW_LAST_MODIFIED_AT = "show_folder_last_modified_at"
27+
const val FOLDER_SHOW_CHILDREN_COUNT = "show_folder_children_count"
2528

2629
// open as
2730
const val OPEN_AS_DEFAULT = 0

app/src/main/res/layout/activity_settings.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@
143143

144144
</RelativeLayout>
145145

146+
<RelativeLayout
147+
android:id="@+id/settings_manage_folder_columns_holder"
148+
style="@style/SettingsHolderTextViewOneLinerStyle"
149+
android:layout_width="match_parent"
150+
android:layout_height="wrap_content">
151+
152+
<org.fossify.commons.views.MyTextView
153+
android:id="@+id/settings_manage_folder_columns"
154+
style="@style/SettingsTextLabelStyle"
155+
android:layout_width="wrap_content"
156+
android:layout_height="wrap_content"
157+
android:text="@string/manage_folder_columns" />
158+
159+
</RelativeLayout>
160+
146161
<RelativeLayout
147162
android:id="@+id/settings_change_date_time_format_holder"
148163
style="@style/SettingsHolderTextViewOneLinerStyle"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/manage_folder_columns_scroll_view"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content">
6+
7+
<LinearLayout
8+
android:id="@+id/manage_folder_columns_holder"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="vertical"
12+
android:paddingStart="@dimen/activity_margin"
13+
android:paddingTop="@dimen/activity_margin"
14+
android:paddingEnd="@dimen/activity_margin">
15+
16+
<org.fossify.commons.views.MyAppCompatCheckbox
17+
android:id="@+id/manage_folder_columns_size"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:paddingTop="@dimen/activity_margin"
21+
android:paddingBottom="@dimen/activity_margin"
22+
android:text="@string/column_folder_size" />
23+
24+
<org.fossify.commons.views.MyAppCompatCheckbox
25+
android:id="@+id/manage_folder_columns_children_count"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:paddingTop="@dimen/activity_margin"
29+
android:paddingBottom="@dimen/activity_margin"
30+
android:text="@string/column_folder_children_count" />
31+
32+
<org.fossify.commons.views.MyAppCompatCheckbox
33+
android:id="@+id/manage_folder_columns_modified_at"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:paddingTop="@dimen/activity_margin"
37+
android:paddingBottom="@dimen/activity_margin"
38+
android:text="@string/column_folder_last_modified_at" />
39+
40+
</LinearLayout>
41+
</ScrollView>

app/src/main/res/layout/item_file_dir_list.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,24 @@
4949
android:alpha="0.6"
5050
android:paddingStart="@dimen/tiny_margin"
5151
android:textSize="@dimen/smaller_text_size"
52-
app:layout_constraintBottom_toBottomOf="parent"
53-
app:layout_constraintEnd_toStartOf="@+id/item_date"
52+
app:layout_constraintBottom_toTopOf="@+id/item_date"
53+
app:layout_constraintEnd_toEndOf="parent"
5454
app:layout_constraintStart_toEndOf="@id/item_icon"
5555
app:layout_constraintTop_toBottomOf="@+id/item_name"
5656
app:layout_constraintVertical_bias="0.5"
5757
tools:text="1 KB" />
5858

5959
<TextView
6060
android:id="@+id/item_date"
61-
android:layout_width="wrap_content"
61+
android:layout_width="0dp"
6262
android:layout_height="wrap_content"
6363
android:alpha="0.6"
64-
android:gravity="end"
64+
android:paddingStart="@dimen/tiny_margin"
6565
android:textSize="@dimen/smaller_text_size"
66-
app:layout_constraintBottom_toBottomOf="@+id/item_details"
66+
app:layout_constraintBottom_toBottomOf="parent"
6767
app:layout_constraintEnd_toEndOf="parent"
68-
app:layout_constraintTop_toTopOf="@+id/item_details"
68+
app:layout_constraintStart_toEndOf="@id/item_icon"
69+
app:layout_constraintTop_toBottomOf="@+id/item_details"
6970
tools:text="1.1.1970" />
7071

7172
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
<!-- Settings -->
5757
<string name="enable_root_access">Enable root access</string>
5858
<string name="press_back_twice">Require pressing Back twice to leave the app</string>
59+
<string name="manage_folder_columns">Manage folder columns</string>
60+
<string name="column_folder_size">Size</string>
61+
<string name="column_folder_children_count">Children count</string>
62+
<string name="column_folder_last_modified_at">Last modified at</string>
5963
<!--
6064
Haven't found some strings? There's more at
6165
https://github.com/FossifyOrg/Commons/tree/master/commons/src/main/res

0 commit comments

Comments
 (0)