Skip to content

Commit 94ae601

Browse files
committed
Update
1 parent cfc93a8 commit 94ae601

File tree

4 files changed

+23
-55
lines changed

4 files changed

+23
-55
lines changed

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

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.tool.tree.ui.TabIconHelper
3838
import kotlinx.coroutines.Dispatchers
3939
import kotlinx.coroutines.launch
4040
import kotlinx.coroutines.withContext
41+
import androidx.core.app.NotificationManagerCompat
4142

4243
class MainActivity : AppCompatActivity() {
4344

@@ -80,37 +81,19 @@ class MainActivity : AppCompatActivity() {
8081

8182
private fun checkNotificationPermission() {
8283
val themeConfig = ThemeConfig(this)
83-
// Chỉ xin quyền nếu người dùng đang bật tính năng Thông báo trong cài đặt
8484
if (themeConfig.getAllowNotificationUI()) {
85-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
86-
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
85+
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
86+
WakeLockService.startService(applicationContext)
87+
} else {
88+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
8789
ActivityCompat.requestPermissions(
8890
this,
8991
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
9092
NOTIFICATION_PERMISSION_REQUEST_CODE
9193
)
9294
} else {
93-
WakeLockService.startService(applicationContext)
95+
Toast.makeText(this, "Please enable notifications in your device settings.", Toast.LENGTH_SHORT).show()
9496
}
95-
} else {
96-
WakeLockService.startService(applicationContext)
97-
}
98-
}
99-
}
100-
101-
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
102-
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
103-
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
104-
val themeConfig = ThemeConfig(this)
105-
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
106-
// Người dùng đồng ý cấp quyền
107-
if (themeConfig.getAllowNotificationUI()) {
108-
WakeLockService.startService(applicationContext)
109-
}
110-
} else {
111-
// Người dùng từ chối: Tắt cấu hình thông báo để lần sau không hỏi nữa
112-
themeConfig.setAllowNotificationUI(false)
113-
Toast.makeText(this, "Notifications have been disabled due to lack of permission.", Toast.LENGTH_SHORT).show()
11497
}
11598
}
11699
}
@@ -265,6 +248,7 @@ class MainActivity : AppCompatActivity() {
265248
this.fileSelectedInterface = fileSelectedInterface
266249
true
267250
} catch (e: Exception) {
251+
Toast.makeText(this, "File picker error: ${e.message}", Toast.LENGTH_SHORT).show()
268252
false
269253
}
270254
}
@@ -336,10 +320,6 @@ class MainActivity : AppCompatActivity() {
336320
checkNotification.isChecked = themeConfig.getAllowNotificationUI()
337321
checkNotification.setOnCheckedChangeListener { _, isChecked ->
338322
themeConfig.setAllowNotificationUI(isChecked)
339-
// Nếu người dùng chủ động bật lại, thực hiện xin quyền ngay
340-
if (isChecked) {
341-
checkNotificationPermission()
342-
}
343323
}
344324

345325
// Các liên kết thông tin

app/src/main/res/drawable/ic_settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:height="30dp"
3-
android:width="30dp"
2+
android:height="220dp"
3+
android:width="220dp"
44
android:viewportWidth="128.0"
55
android:viewportHeight="128.0">
66
<path

app/src/main/res/drawable/ic_settings_background.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:height="30dp"
3-
android:width="30dp"
2+
android:height="250dp"
3+
android:width="250dp"
44
android:viewportWidth="128.0"
55
android:viewportHeight="128.0">
66
<path

app/src/main/res/layout/activity_splash.xml

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,54 @@
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
android:fitsSystemWindows="false"
5+
android:fitsSystemWindows="true"
66
android:backgroundTintMode="screen"
7-
android:clipToPadding="true"> <!-- đổi màu nền nếu muốn -->
7+
android:clipToPadding="true">
88

9-
<!-- LinearLayout chính chứa FrameLayout + TextView -->
109
<LinearLayout
1110
android:id="@+id/start_logo"
12-
android:layout_width="match_parent"
11+
android:layout_width="wrap_content"
1312
android:layout_height="wrap_content"
1413
android:orientation="vertical"
1514
android:gravity="center"
16-
android:layout_gravity="center_horizontal"
17-
android:paddingTop="50dp">
15+
android:layout_gravity="center"> <!-- <--- căn cả màn hình -->
1816

19-
<!-- FrameLayout chồng background + logo -->
2017
<FrameLayout
2118
android:layout_width="250dp"
22-
android:layout_height="250dp"
23-
android:layout_gravity="center">
19+
android:layout_height="250dp">
2420

25-
<!-- Background xoay -->
2621
<ImageView
2722
android:id="@+id/start_logo_xml"
2823
android:layout_width="match_parent"
2924
android:layout_height="match_parent"
3025
android:src="@drawable/ic_settings_background"
3126
android:scaleType="centerCrop"/>
3227

33-
<!-- Logo chính -->
3428
<ImageView
3529
android:layout_width="match_parent"
3630
android:layout_height="match_parent"
3731
android:src="@drawable/ic_settings"
3832
android:scaleType="centerInside"/>
3933
</FrameLayout>
4034

41-
<!-- Text hiển thị trạng thái -->
4235
<TextView
4336
android:id="@+id/fullscreen_content"
4437
android:layout_width="wrap_content"
4538
android:layout_height="wrap_content"
46-
android:layout_marginTop="20dp"
47-
android:gravity="center"
48-
android:keepScreenOn="true"
4939
android:text="@string/pio_starting"
5040
android:textSize="35sp"
51-
android:textStyle="bold"/>
41+
android:textStyle="bold"
42+
android:gravity="center"
43+
android:layout_marginTop="20dp"/>
5244

5345
<TextView
5446
android:id="@+id/start_state_text"
55-
android:layout_width="match_parent"
47+
android:layout_width="wrap_content"
5648
android:layout_height="wrap_content"
57-
android:layout_marginTop="10dp"
58-
android:layout_marginStart="20dp"
59-
android:layout_marginEnd="20dp"
60-
android:layout_marginBottom="40dp"
61-
android:minLines="8"
6249
android:text="@string/pop_before_start"
63-
android:textAlignment="center"
64-
android:textSize="14sp"/>
50+
android:textSize="14sp"
51+
android:gravity="center"
52+
android:layout_marginTop="10dp"/>
6553
</LinearLayout>
6654

6755
</FrameLayout>

0 commit comments

Comments
 (0)