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 untrusted user: 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 textDirEmpty: TextView
private lateinit var currentPathText: TextView
private lateinit var numberOfFilesText: TextView
private lateinit var numberOfFoldersText: TextView
private lateinit var totalSizeText: TextView
override fun onCreate(savedInstanceState: Bundle?) {
@ -89,6 +91,8 @@ open class BaseExplorerActivity : BaseActivity() {
refresher = findViewById(R.id.refresher)
textDirEmpty = findViewById(R.id.text_dir_empty)
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)
supportActionBar?.apply {
setDisplayShowCustomEnabled(true)
@ -140,13 +144,13 @@ open class BaseExplorerActivity : BaseActivity() {
layoutIcon.setImageResource(if (isUsingListLayout) {
recycler_view_explorer.layoutManager = linearLayoutManager
explorerAdapter.isUsingListLayout = true
R.drawable.icon_view_list
R.drawable.icon_view_grid
} else {
val displayMetrics = resources.displayMetrics
val columnsNumber = (displayMetrics.widthPixels / displayMetrics.density / 200 + 0.5).toInt()
recycler_view_explorer.layoutManager = GridLayoutManager(this, columnsNumber)
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) {
synchronized(this) {
explorerElements = gocryptfsVolume.listDir(path)
@ -279,6 +298,8 @@ open class BaseExplorerActivity : BaseActivity() {
textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.GONE
currentDirectoryPath = path
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) {
Thread {
var totalSize: Long = 0

View File

@ -1,24 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/infoBarBackgroundColor"
android:paddingHorizontal="20dp">
android:paddingVertical="5dp">
<TextView
android:id="@+id/current_path_text"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:singleLine="true"
android:ellipsize="start"
android:orientation="vertical"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
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/layout_icon">
<TextView
android:id="@+id/current_path_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:layout_marginBottom="5dp"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<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
@ -27,16 +65,20 @@
android:layout_height="wrap_content"
style="@style/infoBarTextView"
android:text="@string/default_total_size"
android:layout_marginHorizontal="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/current_path_text"
app:layout_constraintEnd_toStartOf="@id/layout_icon"/>
app:layout_constraintStart_toEndOf="@id/number_of_folders_text"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<ImageButton
android:id="@+id/layout_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:src="@drawable/icon_view_grid"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/switch_display_layout"

View File

@ -234,4 +234,8 @@
<string name="new_volume_name">New volume name:</string>
<string name="volume_rename_failed">Failed to rename volume</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>