|
|
@@ -2,14 +2,10 @@ package io.legado.app.ui.replace.edit
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
-import android.graphics.Rect
|
|
|
import android.os.Bundle
|
|
|
-import android.view.Gravity
|
|
|
import android.view.Menu
|
|
|
import android.view.MenuItem
|
|
|
-import android.view.ViewTreeObserver
|
|
|
import android.widget.EditText
|
|
|
-import android.widget.PopupWindow
|
|
|
import androidx.activity.viewModels
|
|
|
import io.legado.app.R
|
|
|
import io.legado.app.base.VMBaseActivity
|
|
|
@@ -21,15 +17,12 @@ import io.legado.app.ui.widget.dialog.TextDialog
|
|
|
import io.legado.app.utils.showDialogFragment
|
|
|
import io.legado.app.utils.toastOnUi
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|
|
-import io.legado.app.utils.windowSize
|
|
|
-import kotlin.math.abs
|
|
|
|
|
|
/**
|
|
|
* 编辑替换规则
|
|
|
*/
|
|
|
class ReplaceEditActivity :
|
|
|
VMBaseActivity<ActivityReplaceEditBinding, ReplaceEditViewModel>(false),
|
|
|
- ViewTreeObserver.OnGlobalLayoutListener,
|
|
|
KeyboardToolPop.CallBack {
|
|
|
|
|
|
companion object {
|
|
|
@@ -54,13 +47,12 @@ class ReplaceEditActivity :
|
|
|
override val binding by viewBinding(ActivityReplaceEditBinding::inflate)
|
|
|
override val viewModel by viewModels<ReplaceEditViewModel>()
|
|
|
|
|
|
- private val mSoftKeyboardTool: PopupWindow by lazy {
|
|
|
- KeyboardToolPop(this, this, this)
|
|
|
+ private val softKeyboardTool by lazy {
|
|
|
+ KeyboardToolPop(this, this, binding.root, this)
|
|
|
}
|
|
|
- private var mIsSoftKeyBoardShowing = false
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
- window.decorView.viewTreeObserver.addOnGlobalLayoutListener(this)
|
|
|
+ window.decorView.viewTreeObserver.addOnGlobalLayoutListener(softKeyboardTool)
|
|
|
viewModel.initData(intent) {
|
|
|
upReplaceView(it)
|
|
|
}
|
|
|
@@ -91,6 +83,11 @@ class ReplaceEditActivity :
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ override fun onDestroy() {
|
|
|
+ super.onDestroy()
|
|
|
+ softKeyboardTool.dismiss()
|
|
|
+ }
|
|
|
+
|
|
|
private fun upReplaceView(replaceRule: ReplaceRule) = binding.run {
|
|
|
etName.setText(replaceRule.name)
|
|
|
etGroup.setText(replaceRule.group)
|
|
|
@@ -146,37 +143,4 @@ class ReplaceEditActivity :
|
|
|
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
|
|
}
|
|
|
|
|
|
- private fun showKeyboardTopPopupWindow() {
|
|
|
- mSoftKeyboardTool.let {
|
|
|
- if (it.isShowing) return
|
|
|
- if (!isFinishing) {
|
|
|
- it.showAtLocation(binding.llContent, Gravity.BOTTOM, 0, 0)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun closePopupWindow() {
|
|
|
- mSoftKeyboardTool.dismiss()
|
|
|
- }
|
|
|
-
|
|
|
- override fun onGlobalLayout() {
|
|
|
- val rect = Rect()
|
|
|
- // 获取当前页面窗口的显示范围
|
|
|
- window.decorView.getWindowVisibleDisplayFrame(rect)
|
|
|
- val screenHeight = this.windowSize.heightPixels
|
|
|
- val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
|
|
|
- val preShowing = mIsSoftKeyBoardShowing
|
|
|
- if (abs(keyboardHeight) > screenHeight / 5) {
|
|
|
- mIsSoftKeyBoardShowing = true // 超过屏幕五分之一则表示弹出了输入法
|
|
|
- binding.rootView.setPadding(0, 0, 0, 100)
|
|
|
- showKeyboardTopPopupWindow()
|
|
|
- } else {
|
|
|
- mIsSoftKeyBoardShowing = false
|
|
|
- binding.rootView.setPadding(0, 0, 0, 0)
|
|
|
- if (preShowing) {
|
|
|
- closePopupWindow()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|