-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.kt
More file actions
56 lines (46 loc) · 2.18 KB
/
Example.kt
File metadata and controls
56 lines (46 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCleanupBackupBinding.inflate(layoutInflater)
setContentView(binding.root)
// 设置ActionBar
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "清理备份文件"
// 初始化RecyclerView
setupRecyclerView()
// 加载备份文件
loadBackupFiles()
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (actionMode != null) {
actionMode?.finish()
} else {
finish()
}
}
})
}
private fun setupRecyclerView() {
adapter = BackupFileAdapter(mutableListOf(), this::onFileLongClick, this::onFileSelected)
binding.recyclerView.apply {
layoutManager = LinearLayoutManager(this@CleanupBackupActivity)
adapter = this@CleanupBackupActivity.adapter
addItemDecoration(DividerItemDecoration(this@CleanupBackupActivity, DividerItemDecoration.VERTICAL))
val swipeController = SwipeController()
val itemTouchHelper = ItemTouchHelper(swipeController)
itemTouchHelper.attachToRecyclerView(binding.recyclerView)
// 添加触摸事件监听器来处理按钮点击
binding.recyclerView.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
// 仅在非多选模式时处理滑动按钮事件
if (actionMode == null) {
swipeController.handleButtonClick(e, rv)
}
return false
}
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
})
}
// 添加快速滚动条
binding.fastScroller.attachToRecyclerView(binding.recyclerView)
}