Merge pull request #229 from TouchInstinct/show_listener_utils

moved the method to extension
This commit is contained in:
rinstance 2021-10-07 18:12:46 +03:00 committed by GitHub
commit 111bb58463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package ru.touchin.roboswag.mvi_arch.core
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
@ -16,10 +15,9 @@ import androidx.core.os.bundleOf
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import ru.touchin.mvi_arch.R
import ru.touchin.roboswag.components.utils.setResizableListener
import ru.touchin.roboswag.mvi_arch.di.ViewModelAssistedFactory
import ru.touchin.roboswag.mvi_arch.di.ViewModelFactory
import ru.touchin.roboswag.mvi_arch.marker.ViewAction
@ -54,17 +52,6 @@ abstract class FullscreenBottomSheetDialog<NavArgs, State, Action, VM>(
).get(ViewModel::class.java)
}
private val onShowListener by lazy {
DialogInterface.OnShowListener { dialog ->
(dialog as BottomSheetDialog).findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
?.let { BottomSheetBehavior.from(it) }
?.apply {
state = BottomSheetBehavior.STATE_EXPANDED
skipCollapsed = true
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.RoundedCornersBottomSheetDialogTheme)
@ -102,7 +89,7 @@ abstract class FullscreenBottomSheetDialog<NavArgs, State, Action, VM>(
}
override fun setupDialog(dialog: Dialog, style: Int) {
dialog.setOnShowListener(onShowListener)
dialog.setResizableListener()
}
override fun onSaveInstanceState(outState: Bundle) {

View File

@ -4,6 +4,7 @@ dependencies {
implementation project(':kotlin-extensions')
implementation "androidx.core:core"
implementation "androidx.annotation:annotation"
implementation "com.google.android.material:material"
constraints {
implementation("androidx.core:core") {
@ -17,5 +18,11 @@ dependencies {
require '1.1.0'
}
}
implementation("com.google.android.material:material") {
version {
require '1.2.0-rc01'
}
}
}
}

View File

@ -1,10 +1,16 @@
package ru.touchin.roboswag.components.utils
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.content.res.Resources
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
/**
* Returns string representation of [View]'s ID.
@ -46,3 +52,17 @@ fun View.showSoftInput() {
val inputManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
/**
* Returns listener for BottomSheetDialogFragment so that dialog is shifted when the keyboard is opened
*/
fun Dialog.setResizableListener() {
setOnShowListener { dialog ->
(dialog as BottomSheetDialog).findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
?.let { BottomSheetBehavior.from(it) }
?.apply {
state = BottomSheetBehavior.STATE_EXPANDED
skipCollapsed = true
}
}
}