@@ -108,50 +108,48 @@ object ThemeModeState {
108108 }
109109 }
110110
111- private fun applyWindowFlags (activity : Activity ) {
112- val window = activity.window
111+ private fun applyWindowFlags (activity : Activity ) {
112+ val window = activity.window
113113
114- // 1. Kích hoạt chế độ tràn viền (Edge-to-Edge)
115- androidx.core.view.WindowCompat .setDecorFitsSystemWindows(window, false )
116- window.statusBarColor = android.graphics.Color .TRANSPARENT
117- window.navigationBarColor = android.graphics.Color .TRANSPARENT
118-
119- // 2. Tự động xử lý Padding cho Top và Bottom Bar
120- val rootView = window.decorView.rootView
121- androidx.core.view.ViewCompat .setOnApplyWindowInsetsListener(rootView) { _, insets ->
122- val systemBars = insets.getInsets(androidx.core.view.WindowInsetsCompat .Type .systemBars())
123-
124- // Tìm và đẩy padding cho Top Bar (Status Bar)
125- activity.findViewById<View >(R .id.blur_top_container)?.setPadding(0 , systemBars.top, 0 , 0 )
126- activity.findViewById<View >(R .id.file_selector_list)?.setPadding(0 , systemBars.top, 0 , 0 )
127- activity.findViewById<View >(R .id.main_list)?.setPadding(0 , systemBars.top, 0 , 0 )
114+ // 1. Kích hoạt Edge-to-Edge (Hỗ trợ từ API 21+ thông qua WindowCompat)
115+ androidx.core.view.WindowCompat .setDecorFitsSystemWindows(window, false )
128116
129- // Tìm và đẩy padding cho Bottom Bar (Navigation Bar)
130- activity.findViewById<View >(R .id.blur_bottom_container)?.setPadding(0 , 0 , 0 , systemBars.bottom)
117+ // Đặt màu trong suốt cho thanh hệ thống (API 21+)
118+ window.statusBarColor = android.graphics.Color .TRANSPARENT
119+ window.navigationBarColor = android.graphics.Color .TRANSPARENT
120+
121+ // 2. Xử lý WindowInsets (Cần API 21+ để hoạt động ổn định)
122+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
123+ val rootView = window.decorView.rootView
124+ androidx.core.view.ViewCompat .setOnApplyWindowInsetsListener(rootView) { _, insets ->
125+ val systemBars = insets.getInsets(androidx.core.view.WindowInsetsCompat .Type .systemBars())
126+
127+ activity.findViewById<View >(R .id.blur_top_container)?.setPadding(0 , systemBars.top, 0 , 0 )
128+ activity.findViewById<View >(R .id.file_selector_list)?.setPadding(0 , systemBars.top, 0 , 0 )
129+ activity.findViewById<View >(R .id.main_list)?.setPadding(0 , systemBars.top, 0 , 0 )
130+ activity.findViewById<View >(R .id.blur_bottom_container)?.setPadding(0 , 0 , 0 , systemBars.bottom)
131+
132+ insets
133+ }
134+ }
135+
136+ // 3. Logic xử lý Icon (Light/Dark mode)
137+ val controller = androidx.core.view.WindowInsetsControllerCompat (window, window.decorView)
131138
132- insets
133- }
134-
135- // 3. Logic xử lý Icon sáng/tối hiện tại của bạn
136- if (! themeMode.isDarkMode) {
137- window.run {
138- addFlags(WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS )
139+ if (! themeMode.isDarkMode) {
140+ // Mode Sáng: Cần icon tối màu
139141 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
140- val controller = androidx.core.view.WindowInsetsControllerCompat (this , decorView)
141142 controller.isAppearanceLightStatusBars = true
142- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
143- controller.isAppearanceLightNavigationBars = true
144- }
145143 }
144+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
145+ controller.isAppearanceLightNavigationBars = true
146+ }
147+ } else {
148+ // Mode Tối: Cần icon sáng màu
149+ controller.isAppearanceLightStatusBars = false
150+ controller.isAppearanceLightNavigationBars = false
146151 }
147- } else {
148- // Đảm bảo icon màu trắng khi ở Dark Mode
149- val controller = androidx.core.view.WindowInsetsControllerCompat (window, window.decorView)
150- controller.isAppearanceLightStatusBars = false
151- controller.isAppearanceLightNavigationBars = false
152152 }
153- }
154-
155153
156154 fun getThemeMode (): ThemeMode = themeMode
157155}
0 commit comments