Add child count to folders

Fixes #559

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-11-04 18:20:49 +05:30
parent 159e8967b6
commit a21353cb06
No known key found for this signature in database
GPG key ID: C2E74282C2133D62
2 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.utils.PasswordItem import com.zeapo.pwdstore.utils.PasswordItem
import com.zeapo.pwdstore.widget.MultiselectableLinearLayout import com.zeapo.pwdstore.widget.MultiselectableLinearLayout
import java.io.File
import java.util.ArrayList import java.util.ArrayList
import java.util.TreeSet import java.util.TreeSet
@ -81,11 +82,17 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList<P
holder.type.visibility = View.GONE holder.type.visibility = View.GONE
holder.typeImage.setImageResource(R.drawable.ic_folder_tinted_24dp) holder.typeImage.setImageResource(R.drawable.ic_folder_tinted_24dp)
holder.folderIndicator.visibility = View.VISIBLE holder.folderIndicator.visibility = View.VISIBLE
val childCount = (pass.file.list { current, name -> File(current, name).isFile } ?: emptyArray<File>()).size
if (childCount > 0) {
holder.childCount.visibility = View.VISIBLE
holder.childCount.text = "$childCount"
}
} else { } else {
holder.typeImage.setImageResource(R.drawable.ic_action_secure) holder.typeImage.setImageResource(R.drawable.ic_action_secure)
holder.name.text = pass.toString() holder.name.text = pass.toString()
holder.type.visibility = View.VISIBLE holder.type.visibility = View.VISIBLE
holder.type.text = pass.fullPathToParent.replace("(^/)|(/$)".toRegex(), "") holder.type.text = pass.fullPathToParent.replace("(^/)|(/$)".toRegex(), "")
holder.childCount.visibility = View.GONE
holder.folderIndicator.visibility = View.GONE holder.folderIndicator.visibility = View.GONE
} }
@ -122,6 +129,7 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList<P
val name: AppCompatTextView = view.findViewById(R.id.label) val name: AppCompatTextView = view.findViewById(R.id.label)
val type: AppCompatTextView = view.findViewById(R.id.type) val type: AppCompatTextView = view.findViewById(R.id.type)
val typeImage: AppCompatImageView = view.findViewById(R.id.type_image) val typeImage: AppCompatImageView = view.findViewById(R.id.type_image)
val childCount: AppCompatTextView = view.findViewById(R.id.child_count)
val folderIndicator: AppCompatImageView = view.findViewById(R.id.folder_indicator) val folderIndicator: AppCompatImageView = view.findViewById(R.id.folder_indicator)
} }
} }

View file

@ -47,6 +47,17 @@
app:layout_constraintTop_toBottomOf="@id/type" app:layout_constraintTop_toBottomOf="@id/type"
tools:text="FILE_NAME" /> tools:text="FILE_NAME" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/child_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/folder_indicator"
android:layout_marginEnd="12dp"
tools:text="12" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/folder_indicator" android:id="@+id/folder_indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"