@@ -7,6 +7,7 @@ import android.widget.TextView
77import com.tool.tree.R
88import com.omarea.krscript.executor.ScriptEnvironmen
99import com.omarea.krscript.model.NodeInfoBase
10+ import java.util.regex.Pattern
1011
1112open class ListItemView (private val context : Context ,
1213 layoutId : Int ,
@@ -67,31 +68,39 @@ open class ListItemView(private val context: Context,
6768 return config.index
6869 }
6970
70- // Hàm bổ trợ hỗ trợ cả @string/ và @string:
71- private fun resolveString (value : String ): String {
72- // Kiểm tra xem chuỗi có chứa @string/ hoặc @string: không
73- if (value.contains(" @string/" ) || value.contains(" @string:" )) {
74- // Tách lấy phần tên resource đứng sau dấu / hoặc dấu :
75- val stringName = value.substringAfter(" @string/" ).substringAfter(" @string:" )
71+ // Hàm bổ trợ đã cải tiến bằng Regex để tự dọn rác và cắt chuỗi chính xác tuyệt đối
72+ private fun resolveString (value : String? ): String {
73+ if (value == null ) return " "
74+
75+ // Loại bỏ khoảng trắng hoặc ký tự xuống dòng thừa ở hai đầu
76+ val cleanedValue = value.trim()
77+
78+ // Sử dụng Regex để tìm mẫu @string/tên hoặc @string:tên
79+ // Mẫu này sẽ bắt trích xuất chính xác phần tên resource phía sau
80+ val pattern = Pattern .compile(" @string[/:](\\ w+)" )
81+ val matcher = pattern.matcher(cleanedValue)
82+
83+ if (matcher.find()) {
84+ // matcher.group(1) sẽ là phần tên thuần túy (ví dụ: script_action_check_ext4_image)
85+ val stringName = matcher.group(1 )
7686
77- // Tìm ID của Resource từ tên đã bóc tách
7887 val resId = context.resources.getIdentifier(stringName, " string" , context.packageName)
7988 if (resId != 0 ) {
8089 return context.getString(resId)
8190 }
8291 }
83- return value
92+ return cleanedValue
8493 }
8594
8695 open fun updateViewByShell () {
8796 if (config.descSh.isNotEmpty()) {
8897 config.desc = ScriptEnvironmen .executeResultRoot(context, config.descSh, config)
89- desc = config.desc
98+ desc = resolveString( config.desc)
9099 }
91100
92101 if (config.summarySh.isNotEmpty()) {
93102 config.summary = ScriptEnvironmen .executeResultRoot(context, config.summarySh, config)
94- summary = config.summary
103+ summary = resolveString( config.summary)
95104 }
96105 }
97106
0 commit comments