@@ -405,48 +405,37 @@ class DialogHelper {
405405 // Trong setWindowBlurBg
406406 fun setWindowBlurBg (window : Window , activity : Activity ) {
407407 val wallpaperMode = activity.window.attributes.flags and WindowManager .LayoutParams .FLAG_SHOW_WALLPAPER != 0
408-
409- if (disableBlurBg) {
410- window.applyDefaultBackground(activity, wallpaperMode)
411- return
412- }
413-
414- FastBlurUtility .getBlurBackgroundAsync(activity) { blurBitmap ->
415- // An toàn: Không làm việc với activity đã đóng
416- if (activity.isFinishing || activity.isDestroyed) {
417- blurBitmap?.recycle()
418- return @getBlurBackgroundAsync
408+ window.run {
409+ val blurBitmap = if (disableBlurBg) {
410+ null
411+ } else {
412+ FastBlurUtility .getBlurBackgroundDrawer(activity)
419413 }
420-
421414 if (blurBitmap != null ) {
422- window. setBackgroundDrawable(BitmapDrawable (activity.resources, blurBitmap ))
415+ setBackgroundDrawable(blurBitmap.toDrawable (activity.resources))
423416 } else {
424- window.applyDefaultBackground(activity, wallpaperMode)
425- }
426- }
427- }
428-
429- // Tách logic nền mặc định ra để tái sử dụng
430- private fun Window.applyDefaultBackground (activity : Activity , wallpaperMode : Boolean ) {
431- try {
432- val bg = getWindowBackground(activity)
433- if (bg == Color .TRANSPARENT ) {
434- if (isFloating) {
435- setBackgroundDrawable(bg.toDrawable())
436- setDimAmount(0.5f )
437- } else {
438- val d = if (wallpaperMode || isNightMode(context)) {
439- Color .argb(255 , 18 , 18 , 18 ).toDrawable()
417+ try {
418+ val bg = getWindowBackground(activity)
419+ if (bg == Color .TRANSPARENT ) {
420+ if (isFloating) {
421+ setBackgroundDrawable(bg.toDrawable())
422+ setDimAmount(0.5f )
423+ return
424+ } else {
425+ val d = if (wallpaperMode || isNightMode(context)) {
426+ Color .argb(255 , 18 , 18 , 18 ).toDrawable()
427+ } else {
428+ Color .argb(255 , 245 , 245 , 245 ).toDrawable()
429+ }
430+ setBackgroundDrawable(d)
431+ }
440432 } else {
441- Color .argb( 255 , 245 , 245 , 245 ) .toDrawable()
433+ setBackgroundDrawable(bg .toDrawable() )
442434 }
443- setBackgroundDrawable(d)
435+ } catch (_: Exception ) {
436+ setBackgroundDrawable(Color .TRANSPARENT .toDrawable())
444437 }
445- } else {
446- setBackgroundDrawable(bg.toDrawable())
447438 }
448- } catch (_: Exception ) {
449- setBackgroundDrawable(Color .TRANSPARENT .toDrawable())
450439 }
451440 }
452441 }
0 commit comments