Skip to content

Commit 02f1543

Browse files
committed
Update
1 parent 52df474 commit 02f1543

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.net.Uri
99
import android.os.Bundle
1010
import android.os.Handler
1111
import android.os.Looper
12+
import android.view.MenuItem
1213
import android.view.View
1314
import android.webkit.*
1415
import android.widget.Toast
@@ -34,28 +35,48 @@ class ActionPageOnline : AppCompatActivity() {
3435
private var progressPolling: Timer? = null
3536
private var fileSelectedInterface: ParamsFileChooserRender.FileSelectedInterface? = null
3637
private val ACTION_FILE_PATH_CHOOSER = 65400
38+
39+
// ID định danh cho mục menu mới
40+
private val MENU_OPEN_BROWSER = 1001
3741

3842
override fun onCreate(savedInstanceState: Bundle?) {
3943
super.onCreate(savedInstanceState)
4044

41-
// Sử dụng ThemeModeState để quản lý giao diện đồng nhất (Status Bar, Navigation Bar)
4245
themeMode = ThemeModeState.switchTheme(this)
4346

4447
binding = ActivityActionPageOnlineBinding.inflate(layoutInflater)
4548
setContentView(binding.root)
4649

47-
val toolbar = findViewById<View>(R.id.toolbar) as Toolbar
50+
// Lấy toolbar từ layout được include (webappbar)
51+
val toolbar = binding.webappbar.toolbar
4852
setSupportActionBar(toolbar)
4953
setTitle(R.string.app_name)
5054

51-
// Hiển thị nút quay lại
5255
supportActionBar?.setDisplayHomeAsUpEnabled(true)
5356
supportActionBar?.setHomeButtonEnabled(true)
57+
5458
toolbar.setNavigationOnClickListener {
5559
finish()
5660
}
5761

58-
// Xử lý nút back chuẩn Android 13+
62+
// --- THÊM MENU 3 CHẤM BẰNG CODE ---
63+
// Thêm mục "Mở bằng trình duyệt" vào menu
64+
toolbar.menu.add(0, MENU_OPEN_BROWSER, 0, "Mở bằng trình duyệt").apply {
65+
setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
66+
}
67+
68+
// Xử lý sự kiện khi click vào menu
69+
toolbar.setOnMenuItemClickListener { item ->
70+
when (item.itemId) {
71+
MENU_OPEN_BROWSER -> {
72+
openInDefaultBrowser()
73+
true
74+
}
75+
else -> false
76+
}
77+
}
78+
// ----------------------------------
79+
5980
onBackPressedDispatcher.addCallback(this) {
6081
if (binding.krOnlineWebview.canGoBack()) {
6182
binding.krOnlineWebview.goBack()
@@ -67,6 +88,21 @@ class ActionPageOnline : AppCompatActivity() {
6788
loadIntentData()
6889
}
6990

91+
// Hàm thực hiện mở URL hiện tại bằng trình duyệt mặc định của máy
92+
private fun openInDefaultBrowser() {
93+
val currentUrl = binding.krOnlineWebview.url
94+
if (!currentUrl.isNullOrEmpty()) {
95+
try {
96+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(currentUrl))
97+
startActivity(intent)
98+
} catch (e: Exception) {
99+
Toast.makeText(this, "Không tìm thấy trình duyệt phù hợp", Toast.LENGTH_SHORT).show()
100+
}
101+
} else {
102+
Toast.makeText(this, "Trang web hiện không có URL hợp lệ", Toast.LENGTH_SHORT).show()
103+
}
104+
}
105+
70106
private fun loadIntentData() {
71107
val intent = this.intent
72108
val extras = intent.extras
@@ -75,13 +111,11 @@ class ActionPageOnline : AppCompatActivity() {
75111
title = extras.getString("title")
76112
}
77113

78-
// Load URL vào Webview
79114
when {
80115
extras.containsKey("config") -> initWebview(extras.getString("config"))
81116
extras.containsKey("url") -> initWebview(extras.getString("url"))
82117
}
83118

84-
// Xử lý download nếu có
85119
if (extras.containsKey("downloadUrl")) {
86120
val downloader = Downloader(this)
87121
val url = extras.getString("downloadUrl")!!

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<color name="status_bg_dark">#222222</color>
66
<color name="status_bg_light">@android:color/white</color>
77
<color name="cardBgDark">#222222</color>
8-
<color name="cardBgDarkTransparent">#9A222222</color>
8+
<color name="cardBgDarkTransparent">#9A111111</color>
99
<color name="cardBgLight">#CCFFFFFF</color>
1010
<color name="cardBgLightTransparent">#B3FFFFFF</color>
1111

0 commit comments

Comments
 (0)