Show number of files & folders in current directory

This commit is contained in:
Matéo Duparc 2022-04-10 17:08:13 +02:00
parent 1caabc2554
commit 36ab66fb43
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
3 changed files with 89 additions and 22 deletions

View File

@ -70,6 +70,8 @@ open class BaseExplorerActivity : BaseActivity() {
private lateinit var refresher: SwipeRefreshLayout private lateinit var refresher: SwipeRefreshLayout
private lateinit var textDirEmpty: TextView private lateinit var textDirEmpty: TextView
private lateinit var currentPathText: TextView private lateinit var currentPathText: TextView
private lateinit var numberOfFilesText: TextView
private lateinit var numberOfFoldersText: TextView
private lateinit var totalSizeText: TextView private lateinit var totalSizeText: TextView
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -89,6 +91,8 @@ open class BaseExplorerActivity : BaseActivity() {
refresher = findViewById(R.id.refresher) refresher = findViewById(R.id.refresher)
textDirEmpty = findViewById(R.id.text_dir_empty) textDirEmpty = findViewById(R.id.text_dir_empty)
currentPathText = findViewById(R.id.current_path_text) currentPathText = findViewById(R.id.current_path_text)
numberOfFilesText = findViewById(R.id.number_of_files_text)
numberOfFoldersText = findViewById(R.id.number_of_folders_text)
totalSizeText = findViewById(R.id.total_size_text) totalSizeText = findViewById(R.id.total_size_text)
supportActionBar?.apply { supportActionBar?.apply {
setDisplayShowCustomEnabled(true) setDisplayShowCustomEnabled(true)
@ -140,13 +144,13 @@ open class BaseExplorerActivity : BaseActivity() {
layoutIcon.setImageResource(if (isUsingListLayout) { layoutIcon.setImageResource(if (isUsingListLayout) {
recycler_view_explorer.layoutManager = linearLayoutManager recycler_view_explorer.layoutManager = linearLayoutManager
explorerAdapter.isUsingListLayout = true explorerAdapter.isUsingListLayout = true
R.drawable.icon_view_list R.drawable.icon_view_grid
} else { } else {
val displayMetrics = resources.displayMetrics val displayMetrics = resources.displayMetrics
val columnsNumber = (displayMetrics.widthPixels / displayMetrics.density / 200 + 0.5).toInt() val columnsNumber = (displayMetrics.widthPixels / displayMetrics.density / 200 + 0.5).toInt()
recycler_view_explorer.layoutManager = GridLayoutManager(this, columnsNumber) recycler_view_explorer.layoutManager = GridLayoutManager(this, columnsNumber)
explorerAdapter.isUsingListLayout = false explorerAdapter.isUsingListLayout = false
R.drawable.icon_view_grid R.drawable.icon_view_list
}) })
} }
@ -266,6 +270,21 @@ open class BaseExplorerActivity : BaseActivity() {
} }
} }
private fun displayNumberOfElements(textView: TextView, stringIdSingular: Int, stringIdPlural: Int, count: Int) {
with(textView) {
visibility = if (count == 0) {
View.GONE
} else {
text = if (count == 1) {
getString(stringIdSingular)
} else {
getString(stringIdPlural, count)
}
View.VISIBLE
}
}
}
protected fun setCurrentPath(path: String, onDisplayed: (() -> Unit)? = null) { protected fun setCurrentPath(path: String, onDisplayed: (() -> Unit)? = null) {
synchronized(this) { synchronized(this) {
explorerElements = gocryptfsVolume.listDir(path) explorerElements = gocryptfsVolume.listDir(path)
@ -279,6 +298,8 @@ open class BaseExplorerActivity : BaseActivity() {
textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.GONE textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.GONE
currentDirectoryPath = path currentDirectoryPath = path
currentPathText.text = getString(R.string.location, currentDirectoryPath) currentPathText.text = getString(R.string.location, currentDirectoryPath)
displayNumberOfElements(numberOfFilesText, R.string.one_file, R.string.multiple_files, explorerElements.count { it.isRegularFile })
displayNumberOfElements(numberOfFoldersText, R.string.one_folder, R.string.multiple_folders, explorerElements.count { it.isDirectory })
if (mapFolders) { if (mapFolders) {
Thread { Thread {
var totalSize: Long = 0 var totalSize: Long = 0

View File

@ -1,42 +1,84 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/infoBarBackgroundColor" android:background="?attr/infoBarBackgroundColor"
android:paddingHorizontal="20dp"> android:paddingVertical="5dp">
<TextView <LinearLayout
android:id="@+id/current_path_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/infoBarTextView" android:orientation="vertical"
android:singleLine="true" android:layout_marginStart="10dp"
android:ellipsize="start" android:layout_marginEnd="10dp"
app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0" app:layout_constraintHorizontal_bias="0"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/total_size_text"/> app:layout_constraintEnd_toStartOf="@id/layout_icon">
<TextView <TextView
android:id="@+id/total_size_text" android:id="@+id/current_path_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/infoBarTextView" style="@style/infoBarTextView"
android:text="@string/default_total_size" android:layout_marginBottom="5dp"/>
android:layout_marginHorizontal="20dp"
app:layout_constraintTop_toTopOf="parent" <androidx.constraintlayout.widget.ConstraintLayout
app:layout_constraintBottom_toBottomOf="parent" android:layout_width="wrap_content"
app:layout_constraintStart_toEndOf="@id/current_path_text" android:layout_height="wrap_content">
app:layout_constraintEnd_toStartOf="@id/layout_icon"/>
<TextView
android:id="@+id/number_of_files_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:layout_marginEnd="16sp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0"
app:layout_constrainedWidth="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/number_of_folders_text"/>
<TextView
android:id="@+id/number_of_folders_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:layout_marginEnd="16sp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0"
app:layout_constrainedWidth="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/number_of_files_text"
app:layout_constraintEnd_toStartOf="@id/total_size_text"/>
<TextView
android:id="@+id/total_size_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:text="@string/default_total_size"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/number_of_folders_text"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<ImageButton <ImageButton
android:id="@+id/layout_icon" android:id="@+id/layout_icon"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:src="@drawable/icon_view_grid" android:src="@drawable/icon_view_grid"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/switch_display_layout" android:contentDescription="@string/switch_display_layout"

View File

@ -234,4 +234,8 @@
<string name="new_volume_name">New volume name:</string> <string name="new_volume_name">New volume name:</string>
<string name="volume_rename_failed">Failed to rename volume</string> <string name="volume_rename_failed">Failed to rename volume</string>
<string name="switch_display_layout">Switch display layout</string> <string name="switch_display_layout">Switch display layout</string>
<string name="one_file">1 file</string>
<string name="multiple_files">%d files</string>
<string name="one_folder">1 folder</string>
<string name="multiple_folders">%d folders</string>
</resources> </resources>