Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Implement DonateScreen.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jun 11, 2022
1 parent f9b7d54 commit bed2401
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class IvyBilling(

private const val LIFETIME_V1 = "ivy_wallet_lifetime_v1"

const val DONATE_2 = "donate_2"
const val DONATE_5 = "donate_5"
const val DONATE_10 = "donate_10"
const val DONATE_15 = "donate_15"
const val DONATE_25 = "donate_25"
const val DONATE_50 = "donate_50"
const val DONATE_100 = "donate_100"

val SUBSCRIPTIONS = listOf(
MONTHLY_V1,
Expand All @@ -29,11 +31,13 @@ class IvyBilling(
)

val ONE_TIME_PLANS = listOf(
DONATE_2,
DONATE_5,
DONATE_10,
DONATE_15,
DONATE_25,
DONATE_50
DONATE_50,
DONATE_100
)
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/RootActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.ivy.wallet.ui.budget.BudgetScreen
import com.ivy.wallet.ui.category.CategoriesScreen
import com.ivy.wallet.ui.charts.ChartsScreen
import com.ivy.wallet.ui.csvimport.ImportCSVScreen
import com.ivy.wallet.ui.donate.DonateScreen
import com.ivy.wallet.ui.edit.EditTransactionScreen
import com.ivy.wallet.ui.experiment.images.ImagesScreen
import com.ivy.wallet.ui.loan.LoansScreen
Expand Down Expand Up @@ -212,6 +213,7 @@ class RootActivity : AppCompatActivity() {
is IvyWebView -> WebViewScreen(screen = screen)
is ImagesScreen -> ImagesScreen(screen = screen)
is ExperimentalScreen -> ExperimentalScreen(screen = screen)
is DonateScreen -> DonateScreen(screen = screen)
null -> {
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/donate/DonateEvent.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.ivy.wallet.ui.donate

import com.ivy.wallet.android.billing.Plan
import com.ivy.wallet.ui.RootActivity
import com.ivy.wallet.ui.donate.data.DonateOption

sealed class DonateEvent {
data class Load(val activity: RootActivity) : DonateEvent()

data class Buy(val plan: Plan) : DonateEvent()
data class Donate(
val activity: RootActivity,
val option: DonateOption
) : DonateEvent()
}
289 changes: 289 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/donate/DonateScreen.kt
Original file line number Diff line number Diff line change
@@ -1,2 +1,291 @@
package com.ivy.wallet.ui.donate

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.accompanist.insets.navigationBarsPadding
import com.ivy.design.l0_system.Black
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.White
import com.ivy.design.l0_system.style
import com.ivy.design.l1_buildingBlocks.ColumnRoot
import com.ivy.design.l1_buildingBlocks.IvyText
import com.ivy.design.l1_buildingBlocks.SpacerHor
import com.ivy.design.l1_buildingBlocks.SpacerVer
import com.ivy.design.l1_buildingBlocks.data.Background
import com.ivy.design.l2_components.IconButton
import com.ivy.design.utils.padding
import com.ivy.frp.view.FRP
import com.ivy.frp.view.navigation.Screen
import com.ivy.frp.view.navigation.navigation
import com.ivy.wallet.R
import com.ivy.wallet.ui.IvyWalletPreview
import com.ivy.wallet.ui.RootActivity
import com.ivy.wallet.ui.donate.data.DonateOption
import com.ivy.wallet.ui.rootActivity
import com.ivy.wallet.ui.theme.Gradient
import com.ivy.wallet.ui.theme.components.IvyButton

object DonateScreen : Screen

@Composable
fun BoxWithConstraintsScope.DonateScreen(screen: DonateScreen) {
FRP<DonateState, DonateEvent, DonateViewModel>(
initialEvent = DonateEvent.Load(rootActivity())
) { state, onEvent ->
UI(state, onEvent)
}
}

@Composable
private fun BoxWithConstraintsScope.UI(
state: DonateState,
onEvent: (DonateEvent) -> Unit
) {
var donateOption by remember {
mutableStateOf(DonateOption.DONATE_5)
}

Column {
Image(
modifier = Modifier.fillMaxWidth(),
painter = painterResource(id = R.drawable.donate_illustration),
contentDescription = "rocket illustration",
contentScale = ContentScale.FillWidth
)

ScreenContent()
}

ColumnRoot {
SpacerVer(height = 16.dp)

val nav = navigation()
IconButton(
modifier = Modifier.padding(start = 16.dp),
icon = R.drawable.ic_back_android,
background = Background.Outlined(
width = 2.dp,
color = White,
shape = CircleShape,
padding = padding(all = 12.dp)
)
) {
nav.back()
}

SpacerVer(height = 16.dp)

IvyText(
modifier = Modifier.padding(start = 24.dp),
text = "Donate",
typo = UI.typo.h2.style(
fontWeight = FontWeight.Bold,
color = White
)
)

SpacerVer(height = 4.dp)

DonateOptionPicker(option = donateOption) {
donateOption = it
}
}

val context = LocalView.current.context
DonateButton {
onEvent(DonateEvent.Donate(context as RootActivity, donateOption))
}
}

@Composable
private fun DonateOptionPicker(
option: DonateOption,
onSelect: (DonateOption) -> Unit
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
SpacerHor(width = 16.dp)

if (option != DonateOption.DONATE_2)
OptionPickerButton(
icon = R.drawable.ic_donate_minus,
contentDescription = "btn_minus"
) {
val newOption = when (option) {
DonateOption.DONATE_2 -> DonateOption.DONATE_2
DonateOption.DONATE_5 -> DonateOption.DONATE_2
DonateOption.DONATE_10 -> DonateOption.DONATE_5
DonateOption.DONATE_15 -> DonateOption.DONATE_10
DonateOption.DONATE_25 -> DonateOption.DONATE_15
DonateOption.DONATE_50 -> DonateOption.DONATE_25
DonateOption.DONATE_100 -> DonateOption.DONATE_50
}
onSelect(newOption)
}

SpacerHor(width = 12.dp)

IvyText(
text = "$${
when (option) {
DonateOption.DONATE_2 -> 2
DonateOption.DONATE_5 -> 5
DonateOption.DONATE_10 -> 10
DonateOption.DONATE_15 -> 15
DonateOption.DONATE_25 -> 25
DonateOption.DONATE_50 -> 50
DonateOption.DONATE_100 -> 100
}
}",
typo = UI.typo.nH1.style(
fontWeight = FontWeight.Bold,
color = White
)
)

SpacerHor(width = 12.dp)

if (option != DonateOption.DONATE_100)
OptionPickerButton(
icon = R.drawable.ic_donate_plus,
contentDescription = "btn_plus"
) {
val newOption = when (option) {
DonateOption.DONATE_2 -> DonateOption.DONATE_5
DonateOption.DONATE_5 -> DonateOption.DONATE_10
DonateOption.DONATE_10 -> DonateOption.DONATE_15
DonateOption.DONATE_15 -> DonateOption.DONATE_25
DonateOption.DONATE_25 -> DonateOption.DONATE_50
DonateOption.DONATE_50 -> DonateOption.DONATE_100
DonateOption.DONATE_100 -> DonateOption.DONATE_100
}
onSelect(newOption)
}
}
}

@Composable
private fun OptionPickerButton(
@DrawableRes icon: Int,
contentDescription: String,
onClick: () -> Unit
) {
Image(
modifier = Modifier
.clip(UI.shapes.r4)
.background(Black)
.clickable { onClick() }
.padding(horizontal = 8.dp, vertical = 4.dp),
painter = painterResource(icon),
contentDescription = contentDescription,
)
}

@Composable
private fun ScreenContent() {
LazyColumn {
item {
SpacerVer(height = 32.dp)

IvyText(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp),
text = "It seems like you enjoy free and open-source software. We too!",
typo = UI.typo.b1.style(
color = UI.colors.pureInverse,
fontWeight = FontWeight.Bold
)
)
}

item {
SpacerVer(height = 12.dp)

IvyText(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp),
text = "BIG THANKS to all Ivy contributors who made Ivy Wallet possible! That's why we opened a donations channel to sustain and improve our small project.",
typo = UI.typo.b2.style(
color = UI.colors.gray,
fontWeight = FontWeight.Medium
)
)
}

item {
SpacerVer(height = 24.dp)

Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp)
.background(UI.colors.medium, UI.shapes.r4)
.padding(horizontal = 24.dp, vertical = 16.dp),
text = "If you want to support us feel free to donate whatever amount you're comfortable with - it all helps! (local taxes may apply)".uppercase(),
style = UI.typo.c.style(
fontWeight = FontWeight.Bold,
color = UI.colors.red1Inverse
)
)
}

item {
SpacerVer(height = 120.dp) //scroll hack
}
}
}

@Composable
private fun BoxWithConstraintsScope.DonateButton(
onClick: () -> Unit
) {
IvyButton(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.navigationBarsPadding(
bottom = true, start = false, end = false
)
.padding(horizontal = 20.dp)
.padding(bottom = 16.dp),
iconStart = R.drawable.ic_donate_crown,
wrapContentMode = false,
iconTint = UI.colors.pure,
iconEdgePadding = 16.dp,
text = "Donate",
backgroundGradient = Gradient.solid(UI.colors.pureInverse),
textStyle = UI.typo.b1.style(
fontWeight = FontWeight.Bold,
color = UI.colors.pure
)
) {
onClick()
}
}

@Preview
@Composable
private fun Preview() {
IvyWalletPreview {
UI(state = DonateState.Success, onEvent = {})
}
}
10 changes: 1 addition & 9 deletions app/src/main/java/com/ivy/wallet/ui/donate/DonateState.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package com.ivy.wallet.ui.donate

import com.ivy.wallet.android.billing.Plan

sealed class DonateState {
object Loading : DonateState()

data class Success(
val donate5: Pair<String, Plan>,
val donate10: Pair<String, Plan>,
val donate15: Pair<String, Plan>,
val donate25: Pair<String, Plan>,
val donate50: Pair<String, Plan>
)
object Success : DonateState()

data class Error(
val errMsg: String
Expand Down
Loading

0 comments on commit bed2401

Please sign in to comment.