kopia lustrzana https://github.com/ryukoposting/Signal-Android
Stick buttons to bottom of subscription page.
rodzic
cb9a219c4b
commit
ef950bdbb5
|
@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.models.Cu
|
||||||
import org.thoughtcrime.securesms.components.settings.app.subscription.models.GooglePayButton
|
import org.thoughtcrime.securesms.components.settings.app.subscription.models.GooglePayButton
|
||||||
import org.thoughtcrime.securesms.components.settings.app.subscription.models.NetworkFailure
|
import org.thoughtcrime.securesms.components.settings.app.subscription.models.NetworkFailure
|
||||||
import org.thoughtcrime.securesms.components.settings.configure
|
import org.thoughtcrime.securesms.components.settings.configure
|
||||||
|
import org.thoughtcrime.securesms.components.settings.models.Button
|
||||||
import org.thoughtcrime.securesms.components.settings.models.Progress
|
import org.thoughtcrime.securesms.components.settings.models.Progress
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||||
import org.thoughtcrime.securesms.payments.FiatMoneyUtil
|
import org.thoughtcrime.securesms.payments.FiatMoneyUtil
|
||||||
|
@ -38,6 +39,7 @@ import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||||
import org.thoughtcrime.securesms.util.SpanUtil
|
import org.thoughtcrime.securesms.util.SpanUtil
|
||||||
import org.thoughtcrime.securesms.util.fragments.requireListener
|
import org.thoughtcrime.securesms.util.fragments.requireListener
|
||||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||||
|
import org.thoughtcrime.securesms.util.visible
|
||||||
import java.util.Currency
|
import java.util.Currency
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@ -63,6 +65,10 @@ class SubscribeFragment : DSLSettingsFragment(
|
||||||
private lateinit var processingDonationPaymentDialog: AlertDialog
|
private lateinit var processingDonationPaymentDialog: AlertDialog
|
||||||
private lateinit var donationPaymentComponent: DonationPaymentComponent
|
private lateinit var donationPaymentComponent: DonationPaymentComponent
|
||||||
|
|
||||||
|
private lateinit var googlePayButtonViewHolder: GooglePayButton.ViewHolder
|
||||||
|
private lateinit var updateSubscriptionButtonViewHolder: Button.ViewHolder<Button.Model.Primary>
|
||||||
|
private lateinit var cancelSubscriptionButtonViewHolder: Button.ViewHolder<Button.Model.SecondaryNoOutline>
|
||||||
|
|
||||||
private var errorDialog: DialogInterface? = null
|
private var errorDialog: DialogInterface? = null
|
||||||
|
|
||||||
private val viewModel: SubscribeViewModel by viewModels(
|
private val viewModel: SubscribeViewModel by viewModels(
|
||||||
|
@ -83,16 +89,20 @@ class SubscribeFragment : DSLSettingsFragment(
|
||||||
BadgePreview.register(adapter)
|
BadgePreview.register(adapter)
|
||||||
CurrencySelection.register(adapter)
|
CurrencySelection.register(adapter)
|
||||||
Subscription.register(adapter)
|
Subscription.register(adapter)
|
||||||
GooglePayButton.register(adapter)
|
|
||||||
Progress.register(adapter)
|
Progress.register(adapter)
|
||||||
NetworkFailure.register(adapter)
|
NetworkFailure.register(adapter)
|
||||||
|
|
||||||
|
googlePayButtonViewHolder = GooglePayButton.ViewHolder(requireView().findViewById(R.id.pay_button_wrapper))
|
||||||
|
updateSubscriptionButtonViewHolder = Button.ViewHolder(requireView().findViewById(R.id.update_button_wrapper))
|
||||||
|
cancelSubscriptionButtonViewHolder = Button.ViewHolder(requireView().findViewById(R.id.cancel_button_wrapper))
|
||||||
|
|
||||||
processingDonationPaymentDialog = MaterialAlertDialogBuilder(requireContext())
|
processingDonationPaymentDialog = MaterialAlertDialogBuilder(requireContext())
|
||||||
.setView(R.layout.processing_payment_dialog)
|
.setView(R.layout.processing_payment_dialog)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.create()
|
.create()
|
||||||
|
|
||||||
viewModel.state.observe(viewLifecycleOwner) { state ->
|
viewModel.state.observe(viewLifecycleOwner) { state ->
|
||||||
|
bindFixedButtons(state)
|
||||||
adapter.submitList(getConfiguration(state).toMappingModelList())
|
adapter.submitList(getConfiguration(state).toMappingModelList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,71 +212,83 @@ class SubscribeFragment : DSLSettingsFragment(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state.activeSubscription?.isActive == true) {
|
private fun bindFixedButtons(state: SubscribeState) {
|
||||||
space(DimensionUnit.DP.toPixels(16f).toInt())
|
val areFieldsEnabled = state.stage == SubscribeState.Stage.READY && !state.hasInProgressSubscriptionTransaction
|
||||||
|
|
||||||
val activeAndSameLevel = state.activeSubscription.isActive &&
|
if (state.activeSubscription?.isActive == true) {
|
||||||
state.selectedSubscription?.level == state.activeSubscription.activeSubscription?.level
|
val activeAndSameLevel = state.activeSubscription.isActive &&
|
||||||
|
state.selectedSubscription?.level == state.activeSubscription.activeSubscription?.level
|
||||||
|
|
||||||
primaryButton(
|
val updateModel = Button.Model.Primary(
|
||||||
text = DSLSettingsText.from(R.string.SubscribeFragment__update_subscription),
|
title = DSLSettingsText.from(R.string.SubscribeFragment__update_subscription),
|
||||||
isEnabled = areFieldsEnabled && (!activeAndSameLevel || state.isSubscriptionExpiring()),
|
icon = null,
|
||||||
onClick = {
|
isEnabled = areFieldsEnabled && (!activeAndSameLevel || state.isSubscriptionExpiring()),
|
||||||
val price = viewModel.getPriceOfSelectedSubscription() ?: return@primaryButton
|
onClick = {
|
||||||
|
val price = viewModel.getPriceOfSelectedSubscription() ?: return@Primary
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.SubscribeFragment__update_subscription_question)
|
.setTitle(R.string.SubscribeFragment__update_subscription_question)
|
||||||
.setMessage(
|
.setMessage(
|
||||||
getString(
|
getString(
|
||||||
R.string.SubscribeFragment__you_will_be_charged_the_full_amount_s_of,
|
R.string.SubscribeFragment__you_will_be_charged_the_full_amount_s_of,
|
||||||
FiatMoneyUtil.format(
|
FiatMoneyUtil.format(
|
||||||
requireContext().resources,
|
requireContext().resources,
|
||||||
price,
|
price,
|
||||||
FiatMoneyUtil.formatOptions().trimZerosAfterDecimal()
|
FiatMoneyUtil.formatOptions().trimZerosAfterDecimal()
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setPositiveButton(R.string.SubscribeFragment__update) { dialog, _ ->
|
)
|
||||||
dialog.dismiss()
|
.setPositiveButton(R.string.SubscribeFragment__update) { dialog, _ ->
|
||||||
viewModel.updateSubscription()
|
dialog.dismiss()
|
||||||
}
|
viewModel.updateSubscription()
|
||||||
.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
}
|
||||||
dialog.dismiss()
|
.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||||
}
|
dialog.dismiss()
|
||||||
.show()
|
}
|
||||||
}
|
.show()
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
|
||||||
secondaryButtonNoOutline(
|
updateSubscriptionButtonViewHolder.bind(updateModel)
|
||||||
text = DSLSettingsText.from(R.string.SubscribeFragment__cancel_subscription),
|
|
||||||
isEnabled = areFieldsEnabled,
|
|
||||||
onClick = {
|
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
|
||||||
.setTitle(R.string.SubscribeFragment__confirm_cancellation)
|
|
||||||
.setMessage(R.string.SubscribeFragment__you_wont_be_charged_again)
|
|
||||||
.setPositiveButton(R.string.SubscribeFragment__confirm) { d, _ ->
|
|
||||||
d.dismiss()
|
|
||||||
viewModel.cancel()
|
|
||||||
}
|
|
||||||
.setNegativeButton(R.string.SubscribeFragment__not_now) { d, _ ->
|
|
||||||
d.dismiss()
|
|
||||||
}
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
space(DimensionUnit.DP.toPixels(16f).toInt())
|
|
||||||
|
|
||||||
customPref(
|
val cancelModel = Button.Model.SecondaryNoOutline(
|
||||||
GooglePayButton.Model(
|
title = DSLSettingsText.from(R.string.SubscribeFragment__cancel_subscription),
|
||||||
onClick = this@SubscribeFragment::onGooglePayButtonClicked,
|
icon = null,
|
||||||
isEnabled = areFieldsEnabled && state.selectedSubscription != null
|
isEnabled = areFieldsEnabled,
|
||||||
)
|
onClick = {
|
||||||
)
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle(R.string.SubscribeFragment__confirm_cancellation)
|
||||||
|
.setMessage(R.string.SubscribeFragment__you_wont_be_charged_again)
|
||||||
|
.setPositiveButton(R.string.SubscribeFragment__confirm) { d, _ ->
|
||||||
|
d.dismiss()
|
||||||
|
viewModel.cancel()
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.SubscribeFragment__not_now) { d, _ ->
|
||||||
|
d.dismiss()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
space(DimensionUnit.DP.toPixels(8f).toInt())
|
cancelSubscriptionButtonViewHolder.bind(cancelModel)
|
||||||
}
|
|
||||||
|
updateSubscriptionButtonViewHolder.itemView.visible = true
|
||||||
|
cancelSubscriptionButtonViewHolder.itemView.visible = true
|
||||||
|
googlePayButtonViewHolder.itemView.visible = false
|
||||||
|
} else {
|
||||||
|
val googlePayModel = GooglePayButton.Model(
|
||||||
|
onClick = this@SubscribeFragment::onGooglePayButtonClicked,
|
||||||
|
isEnabled = areFieldsEnabled && state.selectedSubscription != null
|
||||||
|
)
|
||||||
|
|
||||||
|
googlePayButtonViewHolder.bind(googlePayModel)
|
||||||
|
|
||||||
|
updateSubscriptionButtonViewHolder.itemView.visible = false
|
||||||
|
cancelSubscriptionButtonViewHolder.itemView.visible = false
|
||||||
|
googlePayButtonViewHolder.itemView.visible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,43 @@
|
||||||
android:id="@+id/recycler"
|
android:id="@+id/recycler"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toTopOf="@id/fixed_button_container"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/fixed_button_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/update_button_wrapper"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<include layout="@layout/dsl_button_primary" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/cancel_button_wrapper"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<include layout="@layout/dsl_button_secondary" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/pay_button_wrapper"
|
||||||
|
layout="@layout/google_pay_button_pref" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Ładowanie…
Reference in New Issue