From 2a5d708c677a505af7659c9f050c1773acef94e0 Mon Sep 17 00:00:00 2001 From: dingyi Date: Thu, 28 Nov 2024 19:04:06 +0800 Subject: [PATCH] feat: update file activity UI 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. --- .../com/dingyi/treeview/FileActivity.kt | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/dingyi/treeview/FileActivity.kt b/app/src/main/kotlin/com/dingyi/treeview/FileActivity.kt index 35c5b74..301b9e5 100644 --- a/app/src/main/kotlin/com/dingyi/treeview/FileActivity.kt +++ b/app/src/main/kotlin/com/dingyi/treeview/FileActivity.kt @@ -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 @@ -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) { @@ -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 } @@ -254,7 +268,7 @@ class FileActivity : AppCompatActivity() { override fun getCheckableView( node: TreeNode, holder: TreeView.ViewHolder - ): Checkable { + ): MaterialCheckBox { return if (node.isChild) { ItemDirBinding.bind(holder.itemView).checkbox } else { @@ -263,12 +277,8 @@ class FileActivity : AppCompatActivity() { } override fun onClick(node: TreeNode, 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) {