Skip to content

Commit 8b03c1b

Browse files
committed
Update
1 parent 27e5851 commit 8b03c1b

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ class PageConfigReader {
444444
val attrValue = parser.getAttributeValue(i)
445445
option.silent = attrValue.isEmpty() || attrValue == "silent" || attrValue == "hidden" || attrValue == "true" || attrValue == "1"
446446
}
447+
// Cho phép menu item mở giống 1 "page" (như 1 dòng bình thường trong danh sách)
448+
// thay vì chạy pageHandlerSh - ưu tiên xử lý giống hệt onPageClick()/OpenPageHelper:
449+
// link > activity > html/config-sh/config
450+
"link", "href" -> option.link = parser.getAttributeValue(i)
451+
"activity", "a", "intent" -> option.activity = parser.getAttributeValue(i)
452+
"html" -> option.onlineHtmlPage = parser.getAttributeValue(i)
453+
"config" -> option.pageConfigPath = parser.getAttributeValue(i)
454+
"config-sh" -> option.pageConfigSh = parser.getAttributeValue(i)
447455
}
448456
}
449457
option.title = resolveStringRes(parser.nextText())
@@ -529,12 +537,12 @@ class PageConfigReader {
529537
"need-input", "needs-input", "require-input" -> clickableNode.needInput = (
530538
attrValue.isEmpty() || attrValue == "need-input" || attrValue == "true" || attrValue == "1")
531539
"reload-page" -> {
532-
if (attrValue == "reload-page" || attrValue == "reload" || attrValue == "page" || attrValue == "true" || attrValue == "1") {
540+
if (attrValue == "reload-page" || attrValue == "true" || attrValue == "1") {
533541
clickableNode.reloadPage = true
534542
}
535543
}
536544
"reload" -> {
537-
if (attrValue == "reload-page" || attrValue == "reload" || attrValue == "page" || attrValue == "true" || attrValue == "1") {
545+
if (attrValue == "reload" || attrValue == "true" || attrValue == "1") {
538546
clickableNode.reloadPage = true
539547
} else if (attrValue.isNotEmpty()) {
540548
clickableNode.updateBlocks = attrValue.split(",").map { it.trim() }.dropLastWhile { it.isEmpty() }.toTypedArray()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ class PageMenuOption(currentConfigXml: String) : RunnableNode(currentConfigXml)
2222
var checked: Boolean = false
2323
// Nếu true: khi click, chạy script ẩn ở nền (không hiện dialog log/không cho người dùng thấy output)
2424
var silent: Boolean = false
25+
// Cho phép menu item mở giống 1 "page" (như 1 dòng bình thường trong danh sách) thay vì chạy
26+
// pageHandlerSh khi click. Thứ tự ưu tiên giống PageNode: link > activity > html/config-sh/config.
27+
var link: String = ""
28+
var activity: String = ""
29+
var onlineHtmlPage: String = ""
30+
var pageConfigPath: String = ""
31+
var pageConfigSh: String = ""
2532
}

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ class ActionPage : AppCompatActivity() {
234234
}
235235

236236
private fun onMenuItemClick(menuOption: PageMenuOption) {
237+
// Nếu menu item được khai báo link/activity/html/config/config-sh -> mở giống 1 page/dòng
238+
// bình thường trong danh sách, bỏ qua hoàn toàn việc chạy pageHandlerSh của menu.
239+
if (menuOption.link.isNotEmpty() || menuOption.activity.isNotEmpty() ||
240+
menuOption.onlineHtmlPage.isNotEmpty() || menuOption.pageConfigSh.isNotEmpty() ||
241+
menuOption.pageConfigPath.isNotEmpty()) {
242+
openMenuOptionAsPage(menuOption)
243+
return
244+
}
245+
237246
when(menuOption.type) {
238247
"refresh", "reload" -> recreate()
239248
"restart" -> restartApp()
@@ -250,6 +259,38 @@ class ActionPage : AppCompatActivity() {
250259
}
251260
}
252261

262+
// Mở menu item giống hệt cách 1 dòng PageNode bình thường được mở (xem onPageClick trong
263+
// ActionListFragment): link -> mở trình duyệt/app ngoài; activity -> mở activity chỉ định;
264+
// còn lại (html/config-sh/config) -> chuyển thành PageNode rồi dùng lại OpenPageHelper.
265+
private fun openMenuOptionAsPage(menuOption: PageMenuOption) {
266+
if (menuOption.link.isNotEmpty()) {
267+
try {
268+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(menuOption.link))
269+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
270+
startActivity(intent)
271+
} catch (ex: Exception) {
272+
Toast.makeText(this, getString(R.string.kr_slice_activity_fail), Toast.LENGTH_SHORT).show()
273+
}
274+
return
275+
}
276+
277+
if (menuOption.activity.isNotEmpty()) {
278+
TryOpenActivity(this, menuOption.activity).tryOpen()
279+
return
280+
}
281+
282+
if (menuOption.onlineHtmlPage.isNotEmpty() || menuOption.pageConfigSh.isNotEmpty() || menuOption.pageConfigPath.isNotEmpty()) {
283+
val parentConfigPath = currentPageConfig?.currentPageConfigPath ?: ""
284+
val page = PageNode(parentConfigPath).apply {
285+
title = menuOption.title
286+
onlineHtmlPage = menuOption.onlineHtmlPage
287+
pageConfigSh = menuOption.pageConfigSh
288+
pageConfigPath = menuOption.pageConfigPath
289+
}
290+
OpenPageHelper(this).openPage(page)
291+
}
292+
}
293+
253294
// Chạy script của menu item ở NỀN (IO thread), không hiện DialogLogFragment/không có output hiển thị.
254295
// Vẫn tôn trọng các cờ auto-finish/reload-page/auto-kill/auto-restart sau khi script chạy xong.
255296
private fun menuItemExecuteSilent(menuOption: PageMenuOption) {

0 commit comments

Comments
 (0)