Skip to content

Commit

Permalink
MBL-1618: Create alpha screen for pledge redemption (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang authored Jul 23, 2024
1 parent d2b7028 commit 7088247
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity android:name=".ui.activities.ReportProjectActivity" />
<activity
android:name=".features.pledgeredemption.ui.PledgeRedemptionActivity"
android:parentActivityName=".ui.activities.ProjectPageActivity"
android:exported="false"
android:theme="@style/KSTheme" />

<activity android:name=".ui.activities.DeepLinkActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.kickstarter.features.pledgeredemption.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import com.kickstarter.features.pledgeredemption.viewmodels.PledgeRedemptionViewModel
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.isDarkModeEnabled
import com.kickstarter.mock.factories.RewardFactory
import com.kickstarter.models.Reward
import com.kickstarter.models.ShippingRule
import com.kickstarter.ui.activities.compose.projectpage.CheckoutScreen
import com.kickstarter.ui.compose.designsystem.KickstarterApp
import com.kickstarter.ui.data.PledgeReason

class PledgeRedemptionActivity : ComponentActivity() {
private lateinit var viewModelFactory: PledgeRedemptionViewModel.Factory
private val viewModel: PledgeRedemptionViewModel by viewModels { viewModelFactory }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val env = this.getEnvironment()?.let { env ->
viewModelFactory = PledgeRedemptionViewModel.Factory(env, bundle = intent.extras)
env
}
viewModel.start()

setContent {
setContent {

val backing = viewModel.backing
val project = viewModel.project
val lists = mutableListOf<Reward>()
val shippingAmount = backing.shippingAmount().toDouble()
val totalAmount = backing.amount()
val bonus = backing.bonusAmount()

backing.reward()?.let { lists.add(it) }
backing.addOns()?.map { lists.add(it) }

val darModeEnabled = this.isDarkModeEnabled(env = requireNotNull(env))
KickstarterApp(useDarkTheme = darModeEnabled) {
CheckoutScreen(
rewardsList = lists.map { Pair(it.title() ?: "", it.pledgeAmount().toString()) },
environment = env,
shippingAmount = shippingAmount,
selectedReward = RewardFactory.rewardWithShipping(),
currentShippingRule = ShippingRule.builder().build(),
totalAmount = totalAmount,
totalBonusSupport = bonus,
storedCards = emptyList(),
project = project,
email = "[email protected]",
pledgeReason = PledgeReason.PLEDGE,
rewardsHaveShippables = true,
onPledgeCtaClicked = { },
newPaymentMethodClicked = { },
onDisclaimerItemClicked = {},
onAccountabilityLinkClicked = {}
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kickstarter.features.pledgeredemption.viewmodels

import android.os.Bundle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.kickstarter.libs.Environment
import com.kickstarter.models.Backing
import com.kickstarter.models.Project
import com.kickstarter.ui.IntentKey

class PledgeRedemptionViewModel(private val environment: Environment, private val bundle: Bundle? = null) : ViewModel() {

lateinit var backing: Backing
lateinit var project: Project

fun start() {
project = (bundle?.getParcelable(IntentKey.PROJECT) as Project?)?.let {
it
} ?: Project.builder().build()

backing = project.backing() ?: Backing.builder().build()
}

class Factory(private val environment: Environment, private val bundle: Bundle? = null) :
ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return PledgeRedemptionViewModel(environment, bundle = bundle) as T
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/kickstarter/libs/FirebaseAnalyticsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
import com.kickstarter.libs.featureflag.FeatureFlagClientType
import com.kickstarter.libs.featureflag.FlagKey
import com.kickstarter.models.User
import com.kickstarter.ui.SharedPreferenceKey.CONSENT_MANAGEMENT_PREFERENCE

interface FirebaseAnalyticsClientType {
fun isEnabled(): Boolean

fun trackEvent(eventName: String, parameters: Bundle)

fun sendUserId(user: User)
}

open class FirebaseAnalyticsClient(
Expand All @@ -28,4 +31,12 @@ open class FirebaseAnalyticsClient(
}
}
}

override fun sendUserId(user: User) {
firebaseAnalytics?.let {
if (isEnabled()) {
firebaseAnalytics.setUserId(user.id().toString())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ enum class FlagKey(val key: String) {
ANDROID_OAUTH("android_oauth"),
ANDROID_ENCRYPT("android_encrypt_token"),
ANDROID_STRIPE_LINK("android_stripe_link"),
ANDROID_PLEDGED_PROJECTS_OVERVIEW("android_pledged_projects_overview")
ANDROID_PLEDGED_PROJECTS_OVERVIEW("android_pledged_projects_overview"),
ANDROID_PLEDGE_REDEMPTION("android_pledge_redemption")
}

fun FeatureFlagClient.getFetchInterval(): Long =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kickstarter.libs.utils.extensions

import android.content.Context
import android.content.Intent
import com.kickstarter.features.pledgeredemption.ui.PledgeRedemptionActivity
import com.kickstarter.models.Project
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.activities.CommentsActivity
Expand Down Expand Up @@ -43,6 +44,15 @@ fun Intent.getPaymentMethodsIntent(context: Context): Intent {
return this.setClass(context, PaymentMethodsSettingsActivity::class.java)
}

fun Intent.getPledgeRedemptionIntent(
context: Context,
project: Project
): Intent {
this.setClass(context, PledgeRedemptionActivity::class.java)
.putExtra(IntentKey.PROJECT, project)
return this
}

fun Intent.getRootCommentsActivityIntent(
context: Context,
projectData: ProjectData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.kickstarter.libs.utils.extensions.showLatePledgeFlow
import com.kickstarter.libs.utils.extensions.toVisibility
import com.kickstarter.models.Project
import com.kickstarter.models.Reward
import com.kickstarter.models.User
import com.kickstarter.models.chrome.ChromeTabsHelperActivity
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.activities.compose.projectpage.ProjectPledgeButtonAndFragmentContainer
Expand All @@ -80,6 +81,7 @@ import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.showErrorToast
import com.kickstarter.ui.extensions.showSnackbar
import com.kickstarter.ui.extensions.startDisclaimerChromeTab
import com.kickstarter.ui.extensions.startPledgeRedemption
import com.kickstarter.ui.extensions.startRootCommentsActivity
import com.kickstarter.ui.extensions.startUpdatesActivity
import com.kickstarter.ui.extensions.startVideoActivity
Expand Down Expand Up @@ -466,6 +468,22 @@ class ProjectPageActivity :
}
}.addToDisposable(disposables)

var pBacking: Project? = null
var user: User? = null
viewModel.outputs.showPledgeRedemptionScreen()
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
pBacking = it.first
user = it.second
binding.pledgeRedemptionAlpha.visibility = View.VISIBLE
}.addToDisposable(disposables)

binding.pledgeRedemptionAlpha.setOnClickListener {
pBacking?.let {
startPledgeRedemption(it)
}
}

binding.backIcon.setOnClickListener {
if (binding.pledgeContainerLayout.pledgeContainerRoot.visibility == View.GONE) {
onBackPressedDispatcher.onBackPressed()
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.kickstarter.libs.utils.Secrets
import com.kickstarter.libs.utils.TransitionUtils
import com.kickstarter.libs.utils.UrlUtils
import com.kickstarter.libs.utils.extensions.getCreatorBioWebViewActivityIntent
import com.kickstarter.libs.utils.extensions.getPledgeRedemptionIntent
import com.kickstarter.libs.utils.extensions.getPreLaunchProjectActivity
import com.kickstarter.libs.utils.extensions.getProjectUpdatesActivityIntent
import com.kickstarter.libs.utils.extensions.getReportProjectActivityIntent
Expand Down Expand Up @@ -143,6 +144,16 @@ fun Activity.showRatingDialogWidget() {
}
}

fun Activity.startPledgeRedemption(project: Project) {
startActivity(
Intent().getPledgeRedemptionIntent(this, project)
)

this.let {
TransitionUtils.transition(it, TransitionUtils.slideInFromRight())
}
}

/**
* This function starts the RootCommentActivity with Transition animation included
* @param projectData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ interface ProjectPageViewModel {
fun updateVideoCloseSeekPosition(): Observable<Long>

fun showLatePledgeFlow(): Observable<Boolean>

fun showPledgeRedemptionScreen(): Observable<Pair<Project, User>>
}

class ProjectPageViewModel(val environment: Environment) :
Expand Down Expand Up @@ -356,6 +358,7 @@ interface ProjectPageViewModel {
private val onOpenVideoInFullScreen = PublishSubject.create<kotlin.Pair<String, Long>>()
private val updateVideoCloseSeekPosition = BehaviorSubject.create<Long>()
private val showLatePledgeFlow = BehaviorSubject.create<Boolean>()
private val showPledgeRedemptionScreen = BehaviorSubject.create<Pair<Project, User>>()

val inputs: Inputs = this
val outputs: Outputs = this
Expand Down Expand Up @@ -789,9 +792,27 @@ interface ProjectPageViewModel {
val backedProject = currentProject
.filter { it.isBacking() }

val backing = backedProject
val projectBacking = backedProject
.filter { it.backing().isNotNull() }
.map { requireNotNull(it.backing()) }
.map { requireNotNull(it) }

val backing = projectBacking.map { requireNotNull(it.backing()) }

val isAdmin = this.currentUser.observable()
.filter { it.isPresent() }
.map { requireNotNull(it.getValue()) }
.filter { it.isAdmin() && ffClient.getBoolean(FlagKey.ANDROID_PLEDGE_REDEMPTION) }
.map { it }

Observable.combineLatest(projectBacking, isAdmin) { pBacking, adminUser ->
Pair(pBacking, adminUser)
}
.subscribe {
// remove userId tracking when removing feature flag or giving access to all users
this.environment.firebaseAnalyticsClient()?.sendUserId(it.second)
this.showPledgeRedemptionScreen.onNext(it)
}
.addToDisposable(disposables)

// - Update fragments with the backing data
currentProjectData
Expand Down Expand Up @@ -1272,6 +1293,8 @@ interface ProjectPageViewModel {

override fun showLatePledgeFlow(): Observable<Boolean> = this.showLatePledgeFlow

override fun showPledgeRedemptionScreen(): Observable<Pair<Project, User>> = this.showPledgeRedemptionScreen

private fun backingDetailsSubtitle(project: Project): Either<String, Int>? {
return project.backing()?.let { backing ->
return if (backing.status() == Backing.STATUS_ERRORED) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_project_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/reward_fragment_guideline_constraint_end" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/pledge_redemption_alpha"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:src="@drawable/ic_face"
android:contentDescription="@string/A_little_extra_to_help"
android:layout_margin="16dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit 7088247

Please sign in to comment.