Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class GooglePayActivity : BaseActivity() {
}
binding.amountPresetsFlow.referencedIds = viewIds.toIntArray()
setFilledAmountToText()
setCheckedRecurringDonation()
setButtonHighlighted(filledAmountButton)
}

Expand All @@ -287,6 +288,10 @@ class GooglePayActivity : BaseActivity() {
}
}

private fun setCheckedRecurringDonation() {
binding.checkBoxRecurring.isChecked = viewModel.checkedRecurringDonation
}

private fun setButtonHighlighted(button: View? = null) {
binding.amountPresetsContainer.children.forEach { child ->
if (child is MaterialButton) {
Expand Down Expand Up @@ -315,12 +320,14 @@ class GooglePayActivity : BaseActivity() {
companion object {
private const val CAMPAIGN_ID_APP_MENU = "appmenu"
const val FILLED_AMOUNT = "filledAmount"
const val CHECKED_RECURRING_DONATION = "checkedRecurringDonation"

fun newIntent(context: Context, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f): Intent {
fun newIntent(context: Context, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f, checkedRecurringDonation: Boolean = false): Intent {
return Intent(context, GooglePayActivity::class.java)
.putExtra(DonateDialog.ARG_CAMPAIGN_ID, campaignId)
.putExtra(DonateDialog.ARG_DONATE_URL, donateUrl)
.putExtra(FILLED_AMOUNT, filledAmount)
.putExtra(CHECKED_RECURRING_DONATION, checkedRecurringDonation)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ internal object GooglePayComponent {
return available
}

fun getDonateActivityIntent(activity: Activity, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f): Intent {
return GooglePayActivity.newIntent(activity, campaignId, donateUrl, filledAmount)
fun getDonateActivityIntent(activity: Activity, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f, checkedRecurringDonation: Boolean = false): Intent {
return GooglePayActivity.newIntent(activity, campaignId, donateUrl, filledAmount, checkedRecurringDonation)
}

fun getPaymentDataRequestJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlin.math.abs

class GooglePayViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
val filledAmount = savedStateHandle.get<Float>(GooglePayActivity.FILLED_AMOUNT) ?: 0f
val checkedRecurringDonation = savedStateHandle.get<Boolean>(GooglePayActivity.CHECKED_RECURRING_DONATION) ?: false
val uiState = MutableStateFlow(Resource<DonationConfig>())
private var donationConfig: DonationConfig? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object GooglePayComponent {
return false
}

fun getDonateActivityIntent(activity: Activity, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f): Intent {
fun getDonateActivityIntent(activity: Activity, campaignId: String? = null, donateUrl: String? = null, filledAmount: Float = 0f, checkedRecurringDonation: Boolean = false): Intent {
return Intent()
}
}
49 changes: 41 additions & 8 deletions app/src/main/java/org/wikipedia/donate/DonateDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.wikipedia.donate.donationreminder.DonationReminderHelper
import org.wikipedia.page.ExtendedBottomSheetDialogFragment
import org.wikipedia.settings.Prefs
import org.wikipedia.util.CustomTabsUtil
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.Resource

Expand Down Expand Up @@ -87,7 +88,7 @@ class DonateDialog : ExtendedBottomSheetDialogFragment() {
}
}
if (arguments?.getBoolean(ARG_FROM_DONATION_REMINDER) == true) {
setupDirectGooglePayButton()
setupDirectGooglePayButton(arguments?.getBoolean(ARG_FROM_DONATION_REMINDER_WRAP_UP) ?: false)
}
}
}
Expand All @@ -114,10 +115,14 @@ class DonateDialog : ExtendedBottomSheetDialogFragment() {
}
}

private fun setupDirectGooglePayButton() {
val donateAmount = Prefs.donationReminderConfig.donateAmount
private fun setupDirectGooglePayButton(fromDonationReminderWrapUp: Boolean) {
val donateAmount = if (Prefs.donationReminderConfig.donateAmount <= 0) {
DonationReminderHelper.defaultDonateAmountOptions.first()
} else {
Prefs.donationReminderConfig.donateAmount
}
val donateAmountText =
DonateUtil.currencyFormat.format(Prefs.donationReminderConfig.donateAmount)
DonateUtil.currencyFormat.format(donateAmount)
val donateButtonText = getString(R.string.donation_reminders_gpay_text, donateAmountText)
binding.donateGooglePayButton.text = donateButtonText
binding.donateGooglePayButton.setOnClickListener {
Expand All @@ -127,7 +132,13 @@ class DonateDialog : ExtendedBottomSheetDialogFragment() {
campaignId = DonationReminderHelper.getCampaignId()
)
(requireActivity() as? BaseActivity)?.launchDonateActivity(
GooglePayComponent.getDonateActivityIntent(requireActivity(), filledAmount = donateAmount, campaignId = DonationReminderHelper.getCampaignId()))
GooglePayComponent.getDonateActivityIntent(
activity = requireActivity(),
filledAmount = donateAmount,
checkedRecurringDonation = fromDonationReminderWrapUp,
Comment thread
cooltey marked this conversation as resolved.
campaignId = DonationReminderHelper.getCampaignId()
)
)
}
binding.donateGooglePayDifferentAmountButton.isVisible = true
binding.donateGooglePayDifferentAmountButton.setOnClickListener {
Expand All @@ -137,7 +148,12 @@ class DonateDialog : ExtendedBottomSheetDialogFragment() {
campaignId = DonationReminderHelper.getCampaignId()
)
(requireActivity() as? BaseActivity)?.launchDonateActivity(
GooglePayComponent.getDonateActivityIntent(requireActivity(), campaignId = DonationReminderHelper.getCampaignId()))
GooglePayComponent.getDonateActivityIntent(
activity = requireActivity(),
campaignId = DonationReminderHelper.getCampaignId(),
checkedRecurringDonation = fromDonationReminderWrapUp
)
)
}
binding.donateOtherButton.setOnClickListener {
DonorExperienceEvent.logDonationReminderAction(
Expand All @@ -147,21 +163,38 @@ class DonateDialog : ExtendedBottomSheetDialogFragment() {
)
onDonateClicked()
}
binding.gPayHeaderContainer.isVisible = false
if (fromDonationReminderWrapUp) {
Comment thread
cooltey marked this conversation as resolved.
binding.gPayTitle.text = getString(R.string.donation_reminders_eoe_donate_dialog_title)
(binding.gPayTitle.layoutParams as? ViewGroup.MarginLayoutParams)?.let { params ->
params.bottomMargin = DimenUtil.roundedDpToPx(16.0f)
binding.gPayTitle.layoutParams = params
}
binding.gPayDescription.isVisible = false
} else {
binding.gPayHeaderContainer.isVisible = false
}
}

companion object {
const val ARG_CAMPAIGN_ID = "campaignId"
const val ARG_DONATE_URL = "donateUrl"
const val ARG_FROM_DONATION_REMINDER = "fromDonationReminder"
const val ARG_FROM_DONATION_REMINDER_WRAP_UP = "fromDonationReminderWrapUp"
const val ARG_FROM_YIR = "fromYiR"

fun newInstance(campaignId: String? = null, donateUrl: String? = null, fromDonationReminder: Boolean = false, fromYiR: Boolean = false): DonateDialog {
fun newInstance(
campaignId: String? = null,
donateUrl: String? = null,
fromDonationReminder: Boolean = false,
fromYiR: Boolean = false,
fromDonationReminderWrapUp: Boolean = false
): DonateDialog {
return DonateDialog().apply {
arguments = Bundle().apply {
putString(ARG_CAMPAIGN_ID, campaignId)
putString(ARG_DONATE_URL, donateUrl)
putBoolean(ARG_FROM_DONATION_REMINDER, fromDonationReminder)
putBoolean(ARG_FROM_DONATION_REMINDER_WRAP_UP, fromDonationReminderWrapUp)
putBoolean(ARG_FROM_YIR, fromYiR)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.wikipedia.analytics.eventplatform.DonorExperienceEvent
import org.wikipedia.compose.components.error.WikiErrorClickEvents
import org.wikipedia.compose.theme.BaseTheme
import org.wikipedia.readinglist.recommended.RecommendedReadingListOnboardingActivity.Companion.EXTRA_FROM_SETTINGS
import org.wikipedia.settings.Prefs
import org.wikipedia.util.DeviceUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.UriUtil
Expand Down Expand Up @@ -74,6 +75,7 @@ class DonationReminderActivity : BaseActivity() {
}
}
sendAnalysis()
enableWrapUp()
}

private fun sendAnalysis() {
Expand All @@ -86,6 +88,14 @@ class DonationReminderActivity : BaseActivity() {
}
}

private fun enableWrapUp() {
if (!DonationReminderHelper.isWrapUpEnabled) {
Prefs.donationReminderConfig = Prefs.donationReminderConfig.copy(
wrapUpEnabled = true
)
}
}

companion object {
const val RESULT_OK_FROM_DONATION_REMINDER = 100
fun newIntent(context: Context, isFromSettings: Boolean = false): Intent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.wikipedia.donate.donationreminder
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.core.net.toUri
import androidx.core.view.isVisible
import org.wikipedia.R
import org.wikipedia.databinding.ViewDonationReminderCardBinding
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.StringUtil
import org.wikipedia.util.UriUtil
import org.wikipedia.views.WikiCardView

class DonationReminderCardView(context: Context, attrs: AttributeSet? = null) : WikiCardView(context, attrs) {
Expand All @@ -21,7 +26,7 @@ class DonationReminderCardView(context: Context, attrs: AttributeSet? = null) :
}

fun setMessage(text: String) {
binding.messageTextView.text = text
binding.messageTextView.text = StringUtil.fromHtml(text)
}

fun setPositiveButton(text: String, listener: OnClickListener) {
Expand All @@ -33,4 +38,15 @@ class DonationReminderCardView(context: Context, attrs: AttributeSet? = null) :
binding.negativeButton.text = text
binding.negativeButton.setOnClickListener(listener)
}

fun showWrapUpContainer() {
binding.wrapUpContainer.isVisible = true
binding.learnMoreButton.setOnClickListener {
UriUtil.visitInExternalBrowser(context, context.getString(R.string.donation_reminders_experiment_url).toUri())
}
}
}

enum class DonationReminderType {
GENERAL, WRAP_UP
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,31 @@ object DonationReminderHelper {
private val enabledCountries = listOf(
"NL"
)
private val isInDateRange get() = LocalDate.now() <= LocalDate.of(2026, 11, 9) // TODO: confirm with PM
private val isInDateRange get() = LocalDate.now() <= LocalDate.of(2026, 11, 9)
private val isInWrapUpDateRange get() = LocalDate.now() <= LocalDate.of(2026, 11, 15) &&
LocalDate.now() >= LocalDate.of(2026, 11, 10)
val isInEligibleCountry get() = ReleaseUtil.isDevRelease || enabledCountries.contains(GeoUtil.geoIPCountry.orEmpty())
val defaultReadFrequencyOptions = listOf(5, 10, 20)
val presetsToRemoveFromConfig = listOf(2f, 10f, 15f) // V3 only.
val defaultDonateAmountOptions = listOf(1f, 3f, 5f) // V3 only.

val isEnabled
get() = (ReleaseUtil.isDevRelease || isInEligibleCountry && isInDateRange) && isTestGroupUser
val isWrapUpEnabled
get() = (ReleaseUtil.isDevRelease && Prefs.donationReminderDevWrapUp || isInEligibleCountry && isInWrapUpDateRange) && isTestGroupUser &&
(Prefs.donationReminderConfig.wrapUpEnabled || ReleaseUtil.isDevRelease && Prefs.donationReminderDevWrapUp)
Comment thread
cooltey marked this conversation as resolved.

val hasActiveReminder get() = Prefs.donationReminderConfig.userEnabled && Prefs.donationReminderConfig.isReminderReady && isInEligibleCountry

var shouldShowSettingSnackbar = false

fun getCampaignId(campaignIdOriginal: String = "appmenu"): String {
return if (isInEligibleCountry && isInDateRange) {
return if (isInEligibleCountry && (isInDateRange || isInWrapUpDateRange)) {
campaignIdOriginal + when (DonationReminderAbTest().group) {
GROUP_3 -> "_reminderC"
GROUP_2 -> "_reminderB"
else -> "_reminderA"
} // TODO: confirm with Shay
}
} else {
campaignIdOriginal
}
Expand Down Expand Up @@ -114,9 +119,15 @@ object DonationReminderHelper {

fun dismissReminder() {
val config = Prefs.donationReminderConfig
Prefs.donationReminderConfig = config.copy(
isReminderReady = false
)
if (isWrapUpEnabled) {
Prefs.donationReminderConfig = config.copy(
wrapUpEnabled = false
)
} else {
Prefs.donationReminderConfig = config.copy(
isReminderReady = false
)
}
}
}

Expand All @@ -130,7 +141,8 @@ data class DonationReminderConfig(
val donateAmount: Float = 0f,
val isReminderReady: Boolean = false,
val timesReminderShown: Int = 0,
val goalReachedCount: Int = 0
val goalReachedCount: Int = 0,
val wrapUpEnabled: Boolean = false
) {
val isSetup: Boolean get() = userEnabled && setupTimestamp != 0L && articleFrequency > 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class CampaignDialog internal constructor(private val context: Context, val camp
campaignId = campaignId
)
DonationReminderAbTest().maybeSendExposureEvent()
// Enable wrap up for the user if they are in the eligible country and have seen the campaign.
Prefs.donationReminderConfig = Prefs.donationReminderConfig.copy(
wrapUpEnabled = true
)
}
if (!DonationReminderHelper.isEnabled) {
Prefs.announcementPauseTime = Date().time
Expand Down
Loading