-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1618: Create alpha screen for pledge redemption (#2079)
- Loading branch information
Showing
11 changed files
with
261 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/kickstarter/features/pledgeredemption/ui/PledgeRedemptionActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/java/com/kickstarter/features/pledgeredemption/viewmodels/PledgeRedemptionViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.