Skip to content

Commit

Permalink
feat: update file activity UI
Browse files Browse the repository at this point in the history
Update the file activity UI with the following changes:

- Enable edge-to-edge display.
- Add a toolbar and set it as the action bar.
- Update the TreeView padding to account for system bars.
- Update the checkable view to be a MaterialCheckBox.
- Simplify onClick to only show a toast with the node name.
- Update onRefresh to not display a toast.
  • Loading branch information
dingyi222666 committed Nov 28, 2024
1 parent e8ead66 commit 2a5d708
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/src/main/kotlin/com/dingyi/treeview/FileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import android.view.ViewGroup
import android.widget.Checkable
import android.widget.Space
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import com.dingyi.treeview.databinding.ActivityMainBinding
import com.dingyi.treeview.databinding.ItemDirBinding
Expand Down Expand Up @@ -49,10 +53,20 @@ class FileActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()

binding = ActivityMainBinding.inflate(layoutInflater)
fileListLoader = FileListLoader()
setContentView(binding.root)

setSupportActionBar(binding.toolbar)

ViewCompat.setOnApplyWindowInsetsListener(binding.treeview) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(bottom = insets.bottom)
windowInsets
}

requestStoragePermission()

if (!hasStoragePermission) {
Expand Down Expand Up @@ -226,7 +240,7 @@ class FileActivity : AppCompatActivity() {
width = node.depth * 22.dp
}

(getCheckableView(node, holder) as MaterialCheckBox).apply {
(getCheckableView(node, holder)).apply {
isVisible = node.selected
isSelected = node.selected
}
Expand Down Expand Up @@ -254,7 +268,7 @@ class FileActivity : AppCompatActivity() {
override fun getCheckableView(
node: TreeNode<File>,
holder: TreeView.ViewHolder
): Checkable {
): MaterialCheckBox {
return if (node.isChild) {
ItemDirBinding.bind(holder.itemView).checkbox
} else {
Expand All @@ -263,12 +277,8 @@ class FileActivity : AppCompatActivity() {
}

override fun onClick(node: TreeNode<File>, holder: TreeView.ViewHolder) {
if (node.isChild) {
applyDir(holder, node)
} else {
Toast.makeText(holder.itemView.context, "Clicked ${node.name}", Toast.LENGTH_LONG)
.show()
}
Toast.makeText(holder.itemView.context, "Clicked ${node.name}", Toast.LENGTH_LONG)
.show()
}

override fun onRefresh(status: Boolean) {
Expand Down

0 comments on commit 2a5d708

Please sign in to comment.