Adjust boost dialog fragment to behave better with keyboard.
This commit is contained in:
parent
35393fc331
commit
f6542440c7
4 changed files with 48 additions and 28 deletions
|
@ -20,7 +20,8 @@ abstract class DSLSettingsBottomSheetFragment(
|
|||
override val peekHeightPercentage: Float = 1f
|
||||
) : FixedRoundedCornerBottomSheetDialogFragment() {
|
||||
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
protected lateinit var recyclerView: RecyclerView
|
||||
private set
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(layoutId, container, false)
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.airbnb.lottie.LottieAnimationView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.signal.core.util.DimensionUnit
|
||||
|
@ -14,6 +15,7 @@ import org.signal.core.util.logging.Log
|
|||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.badges.models.Badge
|
||||
import org.thoughtcrime.securesms.badges.models.BadgePreview
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout
|
||||
import org.thoughtcrime.securesms.components.settings.DSLConfiguration
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsAdapter
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsBottomSheetFragment
|
||||
|
@ -24,6 +26,7 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.DonationE
|
|||
import org.thoughtcrime.securesms.components.settings.app.subscription.models.CurrencySelection
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.models.GooglePayButton
|
||||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
import org.thoughtcrime.securesms.util.BottomSheetUtil.requireCoordinatorLayout
|
||||
import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||
import org.thoughtcrime.securesms.util.Projection
|
||||
import org.thoughtcrime.securesms.util.SpanUtil
|
||||
|
@ -70,6 +73,8 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
|
|||
.setCancelable(false)
|
||||
.create()
|
||||
|
||||
recyclerView.overScrollMode = RecyclerView.OVER_SCROLL_IF_CONTENT_SCROLLS
|
||||
|
||||
boost1AnimationView = requireView().findViewById(R.id.boost1_animation)
|
||||
boost2AnimationView = requireView().findViewById(R.id.boost2_animation)
|
||||
boost3AnimationView = requireView().findViewById(R.id.boost3_animation)
|
||||
|
@ -77,6 +82,18 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
|
|||
boost5AnimationView = requireView().findViewById(R.id.boost5_animation)
|
||||
boost6AnimationView = requireView().findViewById(R.id.boost6_animation)
|
||||
|
||||
KeyboardAwareLinearLayout(requireContext()).apply {
|
||||
addOnKeyboardHiddenListener {
|
||||
recyclerView.post { recyclerView.requestLayout() }
|
||||
}
|
||||
|
||||
addOnKeyboardShownListener {
|
||||
recyclerView.post { recyclerView.scrollToPosition(adapter.itemCount - 1) }
|
||||
}
|
||||
|
||||
requireCoordinatorLayout().addView(this)
|
||||
}
|
||||
|
||||
viewModel.state.observe(viewLifecycleOwner) { state ->
|
||||
adapter.submitList(getConfiguration(state).toMappingModelList())
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
public final class BottomSheetUtil {
|
||||
|
||||
public static final String STANDARD_BOTTOM_SHEET_FRAGMENT_TAG = "BOTTOM";
|
||||
|
||||
private BottomSheetUtil() {}
|
||||
|
||||
/**
|
||||
* Show preventing a possible IllegalStateException.
|
||||
*/
|
||||
public static void show(@NonNull FragmentManager manager,
|
||||
@Nullable String tag,
|
||||
@NonNull BottomSheetDialogFragment dialog)
|
||||
{
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.add(dialog, tag);
|
||||
transaction.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import org.thoughtcrime.securesms.R
|
||||
|
||||
object BottomSheetUtil {
|
||||
const val STANDARD_BOTTOM_SHEET_FRAGMENT_TAG = "BOTTOM"
|
||||
|
||||
/**
|
||||
* Show preventing a possible IllegalStateException.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun show(
|
||||
manager: FragmentManager,
|
||||
tag: String?,
|
||||
dialog: BottomSheetDialogFragment
|
||||
) {
|
||||
manager.beginTransaction().apply {
|
||||
add(dialog, tag)
|
||||
commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
fun BottomSheetDialogFragment.requireCoordinatorLayout(): CoordinatorLayout {
|
||||
return requireDialog().findViewById(R.id.coordinator)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue