Skip to content

Commit 1693ec7

Browse files
committed
Update
1 parent 9ff6870 commit 1693ec7

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.omarea.common.ui
2+
3+
import android.app.Dialog
4+
import java.lang.ref.WeakReference
5+
6+
/**
7+
* Theo dõi các Dialog đang được hiển thị trong app (đăng ký từ [DialogHelper.customDialog]).
8+
* Dùng để BannerNotificationManager biết cần add banner vào Window của Dialog nào đang mở
9+
* (nếu có), thay vì add vào Activity content — vì Dialog là 1 Window riêng luôn nổi trên
10+
* Window của Activity, add nhầm chỗ sẽ bị Dialog che mất.
11+
*/
12+
object CurrentDialogHolder {
13+
private val dialogs = mutableListOf<WeakReference<Dialog>>()
14+
15+
fun register(dialog: Dialog) {
16+
dialogs.add(WeakReference(dialog))
17+
}
18+
19+
/** Trả về Dialog đang hiển thị được mở gần đây nhất (trên cùng), nếu có. Tự dọn các entry đã chết/đã đóng. */
20+
fun getTopVisible(): Dialog? {
21+
for (i in dialogs.indices.reversed()) {
22+
val d = dialogs[i].get()
23+
if (d == null) {
24+
dialogs.removeAt(i)
25+
continue
26+
}
27+
if (d.isShowing) {
28+
return d
29+
} else {
30+
dialogs.removeAt(i)
31+
}
32+
}
33+
return null
34+
}
35+
}

app/src/main/java/com/omarea/common/ui/DialogHelper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ class DialogHelper {
396396
setBackgroundDrawableResource(android.R.color.transparent)
397397
}
398398
}
399+
CurrentDialogHolder.register(dialog)
399400

400401
return setOutsideTouchDismiss(view, DialogWrap(dialog).setCancelable(cancelable))
401402
}

0 commit comments

Comments
 (0)