|
| 1 | +package one.mixin.android.ui.home.web3.trade |
| 2 | + |
| 3 | +import android.annotation.SuppressLint |
| 4 | +import android.app.Dialog |
| 5 | +import android.os.Bundle |
| 6 | +import android.view.Gravity |
| 7 | +import android.view.View |
| 8 | +import android.view.ViewGroup |
| 9 | +import androidx.compose.runtime.Composable |
| 10 | +import dagger.hilt.android.AndroidEntryPoint |
| 11 | +import one.mixin.android.R |
| 12 | +import one.mixin.android.compose.theme.MixinAppTheme |
| 13 | +import one.mixin.android.extension.booleanFromAttribute |
| 14 | +import one.mixin.android.extension.getSafeAreaInsetsTop |
| 15 | +import one.mixin.android.extension.isNightMode |
| 16 | +import one.mixin.android.extension.screenHeight |
| 17 | +import one.mixin.android.ui.common.MixinComposeBottomSheetDialogFragment |
| 18 | +import one.mixin.android.util.SystemUIManager |
| 19 | + |
| 20 | +@AndroidEntryPoint |
| 21 | +class SpotTradeGuideBottomSheetDialogFragment : MixinComposeBottomSheetDialogFragment() { |
| 22 | + |
| 23 | + companion object { |
| 24 | + const val TAG = "SpotTradeGuideBottomSheetDialogFragment" |
| 25 | + private const val ARGS_INITIAL_TAB = "args_initial_tab" |
| 26 | + |
| 27 | + const val TAB_OVERVIEW = 0 |
| 28 | + const val TAB_SWAP = 1 |
| 29 | + const val TAB_LIMIT = 2 |
| 30 | + |
| 31 | + fun newInstance(initialTab: Int = TAB_OVERVIEW) = SpotTradeGuideBottomSheetDialogFragment().apply { |
| 32 | + arguments = Bundle().apply { |
| 33 | + putInt(ARGS_INITIAL_TAB, initialTab) |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + override fun getTheme() = R.style.AppTheme_Dialog |
| 39 | + |
| 40 | + @SuppressLint("RestrictedApi") |
| 41 | + override fun setupDialog(dialog: Dialog, style: Int) { |
| 42 | + super.setupDialog(dialog, R.style.MixinBottomSheet) |
| 43 | + dialog.window?.let { window -> |
| 44 | + SystemUIManager.lightUI(window, requireContext().isNightMode()) |
| 45 | + } |
| 46 | + dialog.window?.setGravity(Gravity.BOTTOM) |
| 47 | + dialog.window?.setLayout( |
| 48 | + ViewGroup.LayoutParams.MATCH_PARENT, |
| 49 | + ViewGroup.LayoutParams.MATCH_PARENT, |
| 50 | + ) |
| 51 | + } |
| 52 | + |
| 53 | + override fun onStart() { |
| 54 | + super.onStart() |
| 55 | + dialog?.window?.let { window -> |
| 56 | + SystemUIManager.lightUI( |
| 57 | + window, |
| 58 | + !requireContext().booleanFromAttribute(R.attr.flag_night), |
| 59 | + ) |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + @Composable |
| 64 | + override fun ComposeContent() { |
| 65 | + val initialTab = arguments?.getInt(ARGS_INITIAL_TAB, TAB_OVERVIEW) ?: TAB_OVERVIEW |
| 66 | + MixinAppTheme { |
| 67 | + SpotTradeGuidePage( |
| 68 | + initialTab = initialTab, |
| 69 | + pop = { dismiss() } |
| 70 | + ) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + override fun getBottomSheetHeight(view: View): Int { |
| 75 | + return requireContext().screenHeight() - view.getSafeAreaInsetsTop() |
| 76 | + } |
| 77 | + |
| 78 | + override fun showError(error: String) { |
| 79 | + } |
| 80 | +} |
0 commit comments