That fuck shit the fascists are using
1package org.tm.archive.components
2
3import android.app.Dialog
4import android.os.Bundle
5import android.view.LayoutInflater
6import android.view.View
7import android.view.ViewGroup
8import android.view.WindowManager
9import androidx.annotation.LayoutRes
10import androidx.fragment.app.DialogFragment
11import org.tm.archive.R
12
13/**
14 * Fullscreen Dialog Fragment which will dismiss itself when the keyboard is closed
15 */
16abstract class KeyboardEntryDialogFragment(@LayoutRes contentLayoutId: Int) :
17 DialogFragment(contentLayoutId),
18 KeyboardAwareLinearLayout.OnKeyboardShownListener,
19 KeyboardAwareLinearLayout.OnKeyboardHiddenListener {
20
21 private var hasShown = false
22
23 protected open val withDim: Boolean = false
24
25 protected open val themeResId: Int = R.style.Theme_Signal_RoundedBottomSheet
26
27 override fun onCreate(savedInstanceState: Bundle?) {
28 setStyle(STYLE_NORMAL, themeResId)
29 super.onCreate(savedInstanceState)
30 }
31
32 @Suppress("DEPRECATION")
33 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
34 val dialog = super.onCreateDialog(savedInstanceState)
35
36 if (!withDim) {
37 dialog.window?.setDimAmount(0f)
38 }
39
40 dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE or WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
41
42 return dialog
43 }
44
45 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
46 hasShown = false
47
48 val view = super.onCreateView(inflater, container, savedInstanceState)
49 return if (view is KeyboardAwareLinearLayout) {
50 view.addOnKeyboardShownListener(this)
51 view.addOnKeyboardHiddenListener(this)
52 view
53 } else {
54 throw IllegalStateException("Expected parent of view hierarchy to be keyboard aware.")
55 }
56 }
57
58 override fun onPause() {
59 super.onPause()
60 hasShown = false
61 }
62
63 override fun onKeyboardShown() {
64 hasShown = true
65 }
66
67 override fun onKeyboardHidden() {
68 if (hasShown) {
69 dismissAllowingStateLoss()
70 }
71 }
72}