File tree Expand file tree Collapse file tree
app/src/main/java/com/omarea/common/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments