Skip to content

Commit f515c4f

Browse files
committed
Upload file
1 parent 8d726bd commit f515c4f

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

common/src/main/java/com/omarea/common/ui/DialogFullScreen.kt

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.view.LayoutInflater
77
import android.view.View
88
import android.view.ViewGroup
99
import com.omarea.common.R
10-
import androidx.fragment.app.DialogFragment
10+
1111

1212
/*
1313
继承使用示例:
@@ -29,41 +29,50 @@ class DialogAppChooser(private val darkMode: Boolean): DialogFullScreen(R.layout
2929
}
3030
*/
3131

32-
open class DialogFullScreen(
33-
private val layout: Int,
34-
darkMode: Boolean
35-
) : DialogFragment() {
36-
37-
init {
38-
setStyle(
39-
STYLE_NORMAL,
40-
if (darkMode)
41-
R.style.dialog_full_screen_dark
42-
else
43-
R.style.dialog_full_screen_light
44-
)
32+
open class DialogFullScreen(private val layout: Int, darkMode: Boolean) : androidx.fragment.app.DialogFragment() {
33+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
34+
currentView = inflater.inflate(layout, container)
35+
return currentView
4536
}
4637

47-
override fun onCreateView(
48-
inflater: LayoutInflater,
49-
container: ViewGroup?,
50-
savedInstanceState: Bundle?
51-
): View {
52-
return inflater.inflate(layout, container, false)
38+
private var themeResId: Int = 0
39+
private lateinit var currentView: View
40+
41+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
42+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
43+
Dialog(activity!!, if (themeResId != 0) themeResId else R.style.dialog_full_screen_light)
44+
} else {
45+
Dialog(activity!!, -1)
46+
}
5347
}
5448

5549
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
5650
super.onViewCreated(view, savedInstanceState)
5751

58-
dialog?.window?.let { window ->
59-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
60-
window.setWindowAnimations(android.R.style.Animation_Translucent)
52+
val activity = this.activity
53+
if (activity != null) {
54+
dialog?.window?.run {
55+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
56+
setWindowAnimations(android.R.style.Animation_Translucent)
57+
}
58+
59+
DialogHelper.setWindowBlurBg(this, activity)
6160
}
62-
DialogHelper.setWindowBlurBg(window, requireActivity())
6361
}
6462
}
6563

64+
override fun onActivityCreated(savedInstanceState: Bundle?) {
65+
super.onActivityCreated(savedInstanceState)
66+
}
67+
6668
fun closeView() {
67-
dismissAllowingStateLoss()
69+
try {
70+
dismiss()
71+
} catch (ex: java.lang.Exception) {
72+
}
73+
}
74+
75+
init {
76+
themeResId = if (darkMode) R.style.dialog_full_screen_dark else R.style.dialog_full_screen_light
6877
}
6978
}

krscript/src/main/java/com/omarea/krscript/ui/ParamsMultipleSelect.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import com.omarea.common.model.SelectItem
88
import com.omarea.common.ui.DialogItemChooser
99
import com.omarea.krscript.R
1010
import com.omarea.krscript.model.ActionParamInfo
11+
import android.content.res.Configuration
1112

1213
class ParamsMultipleSelect(private val actionParamInfo: ActionParamInfo, private val context: FragmentActivity) {
1314
private var options: ArrayList<SelectItem>? = null
1415
private var status = booleanArrayOf()
1516
private var labels: Array<String?> = arrayOf()
1617
private var values: Array<String?> = arrayOf()
18+
private val uiMode = context.resources.configuration.uiMode
19+
// Kiểm tra chế độ tối sử dụng UI_MODE_NIGHT_YES
20+
private var darkMode: Boolean = (uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
1721

1822
fun render(): View {
1923
options = actionParamInfo.optionsFromShell
@@ -72,7 +76,7 @@ class ParamsMultipleSelect(private val actionParamInfo: ActionParamInfo, private
7276
})
7377
}
7478
// TODO:深色模式、浅色模式
75-
DialogItemChooser(true, ArrayList(items), true, object : DialogItemChooser.Callback {
79+
DialogItemChooser(darkMode, ArrayList(items), true, object : DialogItemChooser.Callback {
7680
override fun onConfirm(selected: List<SelectItem>, result: BooleanArray) {
7781
result.forEachIndexed { index, value ->
7882
status[index] = value

0 commit comments

Comments
 (0)