Skip to content

Commit f4bee87

Browse files
committed
Update
1 parent 20c4467 commit f4bee87

2 files changed

Lines changed: 50 additions & 51 deletions

File tree

app/src/main/assets/home/etc/tool-tree.bash

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,6 @@ fi
5959
</action>'
6060
}
6161

62-
showaddon(){
63-
local dirvad="$1"
64-
gprop(){
65-
cat "$dirvad/addon.prop" 2>/dev/null | awk -F= -v k="$1" '$1==k{print $2; exit}';
66-
}
67-
echo '<group>
68-
<page id="patch_rom" icon="'`urladd icon`'" config-sh="'$dirvad'/index.bash home">
69-
<title>'$(gprop name)'</title>
70-
<option type="checkbox" box="glog auto_trans_text_patch_rom" id="v1" auto-off="true" reload="true" interruptible="false">'$google_translate_text'</option>
71-
<option type="refresh">'$refresh_text'</option>
72-
<option type="default" auto-finish="true" id="123">'$update_text' add-on</option>
73-
<handler>
74-
if [ "$menu_id" == "v1" ]; then
75-
[ "$(glog auto_trans_text_patch_rom)" == 1 ] && slog auto_trans_text_patch_rom 0 || slog auto_trans_text_patch_rom 1
76-
elif [ "$menu_id" == "123" ]; then
77-
'$dirvad'/index.bash update_addon
78-
fi
79-
</handler>
80-
</page>
81-
</group>'
82-
}
83-
8462
# Tạo ngôn ngữ tự động
8563
if [ "$(glog language_kkts)" == 'auto' ]; then
8664
[ -f $ETC/lang/$LANGUAGE.bash ] && texgg="$LANGUAGE.bash" || texgg=vi.bash
@@ -123,7 +101,9 @@ Vip_text_infor="$(eval echo "${text_id_1}${text_id_3}${text_id_2}")"
123101

124102
# Văn bản
125103
Home(){
104+
126105
[ -z "$Vip_text_infor" ] || echo '<group><text summary="'"$Vip_text_infor"'"/></group>'
106+
[ -f "$AON/patch_rom/addon.prop" ] && vdbfbfsn='<option type="checkbox" id="v4" box="glog hide_show_patch_rom" silent="true" reload="true">Patch ROM</option>'
127107

128108
echo '<group>
129109
<page icon="'`urlpng settings`'" config-sh="$ETC/tool-tree.bash Info">
@@ -148,8 +128,8 @@ fi
148128
<page icon="'`urlpng utilities`'" config-sh="$ETC/tool-tree.bash Utilities">
149129
<title>'$utilities_text'</title>
150130
<desc>'$home_text_2'</desc>
131+
'$vdbfbfsn'
151132
<option type="checkbox" id="v1" box="glog hide_show" silent="true" reload="true" >'$folder_text' ROM</option>
152-
<option type="checkbox" id="v4" box="glog hide_show_patch_rom" silent="true" reload="true">Patch ROM</option>
153133
<option type="default" id="v2" silent="true">'$open_activity_text' ROM</option>
154134
<option type="default" id="v3" silent="true">'$open_activity_text' (data-root)</option>
155135
<handler>
@@ -1071,8 +1051,23 @@ checktime
10711051
</action>
10721052
</group>'
10731053

1074-
if [ "$(glog hide_show_patch_rom 1)" == 1 ]; then
1075-
[ -f "$AON/patch_rom/addon.prop" ] && showaddon "$AON/patch_rom"
1054+
if [ "$(glog hide_show_patch_rom 1)" == 1 ] && [ -f "$AON/patch_rom/addon.prop" ]; then
1055+
dirvad="$AON/patch_rom"
1056+
echo '<group>
1057+
<page id="patch_rom" icon="'`urladd icon`'" config-sh="'$dirvad'/index.bash home">
1058+
<title>Patch ROM</title>
1059+
<option type="checkbox" box="glog auto_trans_text_patch_rom" id="v1" auto-off="true" reload="true" interruptible="false">'$google_translate_text'</option>
1060+
<option type="refresh">'$refresh_text'</option>
1061+
<option type="default" auto-finish="true" id="123">'$update_text' add-on</option>
1062+
<handler>
1063+
if [ "$menu_id" == "v1" ]; then
1064+
[ "$(glog auto_trans_text_patch_rom)" == 1 ] && slog auto_trans_text_patch_rom 0 || slog auto_trans_text_patch_rom 1
1065+
elif [ "$menu_id" == "123" ]; then
1066+
'$dirvad'/index.bash update_addon
1067+
fi
1068+
</handler>
1069+
</page>
1070+
</group>'
10761071
fi
10771072
}
10781073

app/src/main/java/com/tool/tree/ActionPage.kt

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ActionPage : AppCompatActivity() {
4343
private lateinit var binding: ActivityActionPageBinding
4444
private var openedSubPage = false
4545

46-
// Lưu danh sách các itemId (index) vừa mới được click để tạm chặn việc script ghi đè sai trạng thái
47-
private val justClickedItems = HashSet<Int>()
46+
// Sử dụng HashCode của String ID để khóa trạng thái tạm thời, không sợ lệch index
47+
private val justClickedItemIds = HashSet<Int>()
4848

4949
override fun onCreate(savedInstanceState: Bundle?) {
5050
super.onCreate(savedInstanceState)
@@ -162,11 +162,13 @@ class ActionPage : AppCompatActivity() {
162162

163163
menu?.clear()
164164

165-
menuOptions?.forEachIndexed { index, option ->
165+
menuOptions?.forEach { option ->
166166
if (option.isFab) {
167167
addFab(option)
168168
} else {
169-
val menuItem = menu?.add(Menu.NONE, index, index, option.title)
169+
// ĐỔI: Sử dụng hashCode của chuỗi ID duy nhất (option.key hoặc option.id) làm itemId cho Menu
170+
val uniqueItemId = option.key.hashCode()
171+
val menuItem = menu?.add(Menu.NONE, uniqueItemId, Menu.NONE, option.title)
170172
if (option.type == "checkbox") {
171173
menuItem?.isCheckable = true
172174
}
@@ -176,9 +178,11 @@ class ActionPage : AppCompatActivity() {
176178
}
177179

178180
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
179-
menuOptions?.forEachIndexed { index, option ->
181+
// Tìm và gán chính xác trạng thái checkbox theo uniqueId
182+
menuOptions?.forEach { option ->
180183
if (!option.isFab && option.type == "checkbox") {
181-
val menuItem = menu.findItem(index)
184+
val uniqueItemId = option.key.hashCode()
185+
val menuItem = menu.findItem(uniqueItemId)
182186
menuItem?.isChecked = option.checked
183187
}
184188
}
@@ -189,28 +193,29 @@ class ActionPage : AppCompatActivity() {
189193
private fun refreshCheckboxMenuStates() {
190194
val config = currentPageConfig ?: return
191195

192-
val checkboxOptionsWithIndex = menuOptions?.mapIndexed { index, option -> index to option }
193-
?.filter { (index, option) ->
194-
// SỬA: Nếu checkbox này vừa mới được click và đang đợi script chạy, TẠM THỜI bỏ qua không quét từ hệ thống nữa
195-
option.type == "checkbox" && option.checkedSh.isNotEmpty() && !justClickedItems.contains(index)
196-
}
196+
// Lọc danh sách checkbox dựa trên ID duy nhất
197+
val checkboxOptions = menuOptions?.filter { option ->
198+
val uniqueItemId = option.key.hashCode()
199+
option.type == "checkbox" && option.checkedSh.isNotEmpty() && !justClickedItemIds.contains(uniqueItemId)
200+
}
197201

198-
if (checkboxOptionsWithIndex.isNullOrEmpty() || menuCheckboxRefreshing) return
202+
if (checkboxOptions.isNullOrEmpty() || menuCheckboxRefreshing) return
199203
menuCheckboxRefreshing = true
200204

201205
lifecycleScope.launch(Dispatchers.IO) {
202-
val results = checkboxOptionsWithIndex.map { (originalIndex, option) ->
206+
val results = checkboxOptions.map { option ->
203207
val result = ScriptEnvironmen.executeResultRoot(this@ActionPage, option.checkedSh, config)?.trim()
204-
Triple(originalIndex, option, result)
208+
option to result
205209
}
206210

207211
withContext(Dispatchers.Main) {
208212
menuCheckboxRefreshing = false
209213
var changed = false
210214

211-
results.forEach { (originalIndex, option, result) ->
212-
// Kiểm tra lại một lần nữa trước khi ghi đè dữ liệu lên option nhằm tránh xung đột chạy song song
213-
if (!justClickedItems.contains(originalIndex)) {
215+
results.forEach { (option, result) ->
216+
val uniqueItemId = option.key.hashCode()
217+
// Khớp chính xác ID để tránh đè dữ liệu cũ trong khi lệnh shell click đang thực thi
218+
if (!justClickedItemIds.contains(uniqueItemId)) {
214219
val newChecked = result == "1" || result?.lowercase() == "true"
215220
if (option.checked != newChecked) changed = true
216221
option.checked = newChecked
@@ -238,21 +243,20 @@ class ActionPage : AppCompatActivity() {
238243

239244
override fun onOptionsItemSelected(item: MenuItem): Boolean {
240245
val options = menuOptions ?: return false
241-
val index = item.itemId
246+
val targetItemId = item.itemId // Đây chính là hashCode của checkbox vừa click
242247

243-
if (index in options.indices) {
244-
val option = options[index]
245-
248+
// ĐỔI: Tìm option khớp với hashCode của ID thay vì dùng vị trí mảng index
249+
val option = options.find { it.key.hashCode() == targetItemId }
250+
251+
if (option != null) {
246252
if (option.type == "checkbox") {
247253
option.checked = !option.checked
248254
item.isChecked = option.checked
249255

250-
// Đánh dấu ô này vừa click xong để lock (khóa) trạng thái, tránh bị hàm check đồng bộ đè dữ liệu cũ lên
251-
justClickedItems.add(index)
252-
253-
// Mở khóa sau 1.5 giây - khoảng thời gian dư dả để lệnh Shell cũ thực thi xong hoàn toàn
256+
// Khóa đồng bộ theo ID cụ thể
257+
justClickedItemIds.add(targetItemId)
254258
handler.postDelayed({
255-
justClickedItems.remove(index)
259+
justClickedItemIds.remove(targetItemId)
256260
}, 1500)
257261
}
258262

0 commit comments

Comments
 (0)