Skip to content

Commit 46efff6

Browse files
committed
Update
1 parent a6928a2 commit 46efff6

4 files changed

Lines changed: 71 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fi
128128
<page icon="'`urlpng utilities`'" config-sh="$ETC/tool-tree.bash Utilities">
129129
<title>'$utilities_text'</title>
130130
<desc>'$home_text_2'</desc>
131+
<option type="default" config-sh="$ETC/tool-tree.bash Project">'$setting_text' - '$setting_text_3'</option>
131132
<option type="checkbox" id="v1" box="glog hide_show" silent="true" reload="true" >'$folder_text' ROM</option>
132133
'$vdbfbfsn'
133134
<option type="default" id="v2" silent="true">'$open_activity_text' ROM</option>
@@ -832,8 +833,8 @@ checktime
832833
<action icon="'`urlpng build_payload`'" >
833834
<title>'$generate_text' Payload</title>
834835
<param name="payload_switch" value-sh="glog payload_switch" label="'$payload_text_3'" type="switch" />
835-
<param name="payload_super_size" required="true" value-sh="glog payload_super_size 11" label="'$sizes_text'" desc="'$default_text': 11GB, '$payload_text_4'" type="number"/>
836-
<param name="payload_super_group" required="true" value-sh="glog payload_super_group qti_dynamic_partitions" label="'$super_text_5'" desc="'$super_text_6', '$payload_text_4'"/>
836+
<param name="payload_super_size" required="true" value-sh="glog payload_super_size 11" label="'$sizes_text'" desc="'$default_text': 11GB, '$payload_text_4'" type="number" depend-on="payload_switch" depend-value="0" depend-mode="hide"/>
837+
<param name="payload_super_group" required="true" value-sh="glog payload_super_group qti_dynamic_partitions" label="'$super_text_5'" desc="'$super_text_6', '$payload_text_4'" depend-on="payload_switch" depend-value="0" depend-mode="hide"/>
837838
<param name="sign_payload" label="'$sign_text'" options-sh="findfile file $ETC/key/2048 .pem | sed '"'s|.pem||'"'" value-sh="glog sign_payload testkey"/>
838839
<param name="IMAGES" desc="'$payload_text_2'" options-sh="findfile 11 $PTSD" required="true" multiple="true"/>
839840
<set>
@@ -945,7 +946,7 @@ checktime
945946
<option value="dat">File.new.dat</option>
946947
<option value="br">File.new.dat.br</option>
947948
</param>
948-
<param name="nen_br" required="true" value-sh="glog nen_br 4" label="'$builds_text_4'" type="seekbar" min="0" max="22" desc="'$convert_text_2'" depend-on="format_img" depend-value="raw,sparse,File.new.dat" depend-mode="hide" depend-logic="priority"/>
949+
<param name="nen_br" required="true" value-sh="glog nen_br 4" label="'$builds_text_4'" type="seekbar" min="0" max="22" desc="'$convert_text_2'" depend-on="format_img" depend-value="raw,sparse,File.new.dat" depend-mode="hide"/>
949950
<param name="build_times" label="'$time_text'" value-sh="glog build_times" type="number" desc="'$build_time_text_1': '$time_riviu'" required="required" depend-on="IMAGES" depend-value="(erofs),(ext),(f2fs)" depend-mode="show" />
950951
<param name="offfscontex" value-sh="glog offfscontex 1" label="'$patch_text_fscontex'" type="switch" depend-on="IMAGES" depend-value="(erofs),(ext),(f2fs)" depend-mode="show"/>
951952
<param name="build_size" label="'$sizes_text'" value-sh="glog build_size 0" type="number" desc="'$builds_text_7'" required="required" depend-on="dinh_dang|dinh_dang|IMAGES" depend-value="EROFS|EXT4,F2FS|(ext),(f2fs)" depend-mode="hide|show|show" depend-logic="priority" depend-default="hide"/>
@@ -1035,7 +1036,7 @@ checktime
10351036
<option value="dat">File.new.dat</option>
10361037
<option value="br">File.new.dat.br</option>
10371038
</param>
1038-
<param name="nen_br" required="true" value-sh="glog nen_br 4" label="'$builds_text_4'" type="seekbar" min="0" max="22" desc="'$convert_text_2'"/>
1039+
<param name="nen_br" required="true" value-sh="glog nen_br 4" label="'$builds_text_4'" type="seekbar" min="0" max="22" desc="'$convert_text_2'" depend-on="format_img" depend-value="raw,sparse,File.new.dat" depend-mode="hide" />
10391040
<param name="IMAGES" desc="'$convert_text_3'" options-sh="findfile 1 $PTSD" multiple="true" required="true"/>
10401041
<set>
10411042
slog format_img "$format_img"

app/src/main/java/com/omarea/krscript/config/PageConfigReader.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ class PageConfigReader {
381381
"depend-onchange", "depend-on-change", "depend-callback" -> {
382382
actionParamInfo.dependOnChangeCallback = attrValue
383383
}
384+
"depend-readonly" -> {
385+
actionParamInfo.dependReadonly = attrValue == "true" || attrValue == "1"
386+
}
384387
}
385388
}
386389
if (actionParamInfo.supported && actionParamInfo.name != null && actionParamInfo.name!!.isNotEmpty()) {

app/src/main/java/com/omarea/krscript/model/ActionParamInfo.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,17 @@ class ActionParamInfo {
126126
// Tên shell script/callback để gọi khi param này thay đổi trạng thái ẩn/hiện
127127
// (chỉ gọi khi trạng thái thực sự thay đổi, từ visible -> hidden hoặc ngược lại)
128128
var dependOnChangeCallback: String? = null
129+
130+
// ========== TÍNH NĂNG MỚI: CHỈ ĐỌC THAY VÌ ẨN (depend-readonly) ==========
131+
// Mặc định, khi điều kiện phụ thuộc đánh giá là "không thỏa" (shouldShow = false),
132+
// param sẽ bị ẨN HOÀN TOÀN (View.GONE) như hành vi cũ.
133+
// Nếu đặt dependReadonly = true, param KHÔNG bị ẩn nữa mà vẫn hiển thị bình thường,
134+
// nhưng sẽ bị làm MỜ (giảm alpha) và VÔ HIỆU HÓA (không thể bấm/nhập/chọn) - tức là
135+
// chuyển sang trạng thái "chỉ đọc" thay vì biến mất khỏi giao diện.
136+
// Khi điều kiện thỏa trở lại (shouldShow = true), param được bật lại bình thường
137+
// (hết mờ, có thể tương tác lại).
138+
// Ví dụ: depend-on="mode" depend-value="advanced" depend-readonly="true"
139+
// -> Khi mode != advanced, param vẫn hiện nhưng bị mờ và khóa tương tác,
140+
// thay vì biến mất như mặc định.
141+
var dependReadonly: Boolean = false
129142
}

app/src/main/java/com/omarea/krscript/ui/ActionParamsLayoutRender.kt

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,21 @@ class ActionParamsLayoutRender(private var linearLayout: LinearLayout, activity:
187187
}
188188
}
189189

190-
// CHỈ set View.visibility tức thời để tránh nhấp nháy lúc mở dialog.
191-
// KHÔNG ghi vào visibilityState ở đây: evaluateDependencies() được gọi ngay sau
192-
// initializeDependencyStates() sẽ tính trạng thái thật (có cascade) và mới là nơi
193-
// ghi visibilityState + quyết định gọi depend-onchange. Nếu ghi ở đây, lần đánh giá
194-
// đầu tiên sẽ hiểu nhầm đây là "thay đổi trạng thái" và gọi nhầm callback ngay khi
195-
// dialog vừa mở.
196-
rowViews[name]?.visibility = if (initialVisibility) View.VISIBLE else View.GONE
190+
// CHỈ set View.visibility (hoặc mờ/khóa với depend-readonly) tức thời để tránh
191+
// nhấp nháy lúc mở dialog. KHÔNG ghi vào visibilityState ở đây: evaluateDependencies()
192+
// được gọi ngay sau initializeDependencyStates() sẽ tính trạng thái thật (có cascade)
193+
// và mới là nơi ghi visibilityState + quyết định gọi depend-onchange. Nếu ghi ở đây,
194+
// lần đánh giá đầu tiên sẽ hiểu nhầm đây là "thay đổi trạng thái" và gọi nhầm
195+
// callback ngay khi dialog vừa mở.
196+
val row = rowViews[name] ?: continue
197+
if (info.dependReadonly) {
198+
// Luôn hiện, chỉ mờ/khóa tương tác theo initialVisibility - không set GONE,
199+
// tránh hàng bị "biến mất" rồi mới hiện lại (nhấp nháy) khi dialog vừa mở.
200+
row.visibility = View.VISIBLE
201+
setRowInteractive(row, initialVisibility)
202+
} else {
203+
row.visibility = if (initialVisibility) View.VISIBLE else View.GONE
204+
}
197205
}
198206
}
199207

@@ -439,20 +447,48 @@ class ActionParamsLayoutRender(private var linearLayout: LinearLayout, activity:
439447
visibilityState[name] = shouldShow
440448

441449
val view = rowViews[name]
442-
view?.visibility = if (shouldShow) View.VISIBLE else View.GONE
450+
val info = currentParamInfos.find { it.name == name }
451+
452+
if (info?.dependReadonly == true) {
453+
// ========== TÍNH NĂNG MỚI: depend-readonly ==========
454+
// Không ẩn (GONE) mà giữ VISIBLE, chỉ làm mờ + khóa tương tác (isEnabled = false)
455+
// khi điều kiện phụ thuộc không thỏa (shouldShow = false).
456+
view?.visibility = View.VISIBLE
457+
view?.let { setRowInteractive(it, shouldShow) }
458+
} else {
459+
view?.visibility = if (shouldShow) View.VISIBLE else View.GONE
460+
}
443461

444462
// Chỉ gọi callback khi ĐÃ TỪNG có trạng thái trước đó (oldState != null) VÀ trạng thái
445463
// thực sự đổi - tránh gọi callback ngay khi dialog vừa mở (lần đầu tiên oldState luôn
446464
// null vì initializeDependencyStates() không ghi vào visibilityState).
447465
if (oldState != null && oldState != shouldShow) {
448-
val info = currentParamInfos.find { it.name == name }
449466
val script = info?.dependOnChangeCallback
450467
if (!script.isNullOrEmpty()) {
451468
executeDependOnChangeCallback(name, shouldShow, script)
452469
}
453470
}
454471
}
455472

473+
// ========== TÍNH NĂNG MỚI: BẬT/TẮT TƯƠNG TÁC + LÀM MỜ CHO depend-readonly ==========
474+
// enabled = true -> hiện bình thường, hết mờ, có thể bấm/nhập/chọn
475+
// enabled = false -> làm mờ cả hàng (alpha) và vô hiệu hóa toàn bộ control con
476+
// (EditText/CheckBox/Switch/SeekBar/Spinner/nút bấm...) để
477+
// người dùng không thể chỉnh sửa giá trị, nhưng vẫn nhìn thấy nó.
478+
private fun setRowInteractive(row: View, enabled: Boolean) {
479+
row.alpha = if (enabled) 1f else 0.4f
480+
setEnabledRecursively(row, enabled)
481+
}
482+
483+
private fun setEnabledRecursively(view: View, enabled: Boolean) {
484+
view.isEnabled = enabled
485+
if (view is ViewGroup) {
486+
for (i in 0 until view.childCount) {
487+
setEnabledRecursively(view.getChildAt(i), enabled)
488+
}
489+
}
490+
}
491+
456492
// ========== TÍNH NĂNG MỚI: THỰC THI depend-onchange ==========
457493
// Chạy script/callback trên luồng nền (KHÔNG được chạy trực tiếp trên UI thread vì lệnh
458494
// shell root có thể mất nhiều thời gian và sẽ làm treo giao diện). Truyền tên param vừa
@@ -584,7 +620,11 @@ class ActionParamsLayoutRender(private var linearLayout: LinearLayout, activity:
584620
}
585621
}
586622

587-
val isHiddenByDepend = rowViews[actionParamInfo.name]?.visibility == View.GONE
623+
// Dùng visibilityState (kết quả logic của evaluateDependencies) thay vì đọc trực
624+
// tiếp View.visibility, vì với depend-readonly=true, view vẫn ở trạng thái
625+
// VISIBLE (chỉ bị mờ + khóa tương tác) dù về mặt logic vẫn được xem là "không
626+
// thỏa điều kiện" (shouldShow = false).
627+
val isHiddenByDepend = visibilityState[actionParamInfo.name] == false
588628

589629
// ========== TÍNH NĂNG MỚI: BỎ QUA PARAM ẨN NẾU KHÔNG CÓ dependIncludeHidden ==========
590630
if (isHiddenByDepend && !actionParamInfo.dependIncludeHidden) {

0 commit comments

Comments
 (0)