Skip to content
Merged
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
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ dependencies {
implementation(projects.feature.home)
implementation(projects.feature.article)
implementation(projects.feature.paywalls)
implementation(projects.feature.account)
implementation(projects.feature.subscriptions)

// RevenueCat
implementation(libs.revenuecat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import androidx.compose.animation.SharedTransitionScope
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.revenuecat.articles.paywall.core.navigation.CatArticlesScreen
import com.revenuecat.articles.paywall.feature.account.AccountScreen
import com.revenuecat.articles.paywall.feature.article.CatArticlesDetail
import com.revenuecat.articles.paywall.feature.home.CatArticlesHome
import com.revenuecat.articles.paywall.feature.subscriptions.SubscriptionManagementScreen
import com.revenuecat.articles.paywall.paywalls.CatCustomPaywalls

fun NavGraphBuilder.catArticlesNavigation(sharedTransitionScope: SharedTransitionScope) {
Expand All @@ -38,5 +40,13 @@ fun NavGraphBuilder.catArticlesNavigation(sharedTransitionScope: SharedTransitio
composable<CatArticlesScreen.Paywalls> {
CatCustomPaywalls()
}

composable<CatArticlesScreen.Account> {
AccountScreen()
}

composable<CatArticlesScreen.SubscriptionManagement> {
SubscriptionManagementScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface PaywallsRepository {

fun fetchOffering(): Flow<ApiResponse<Offering>>

fun fetchCustomerInfo(): Flow<CustomerInfo?>
fun fetchCustomerInfo(): Flow<ApiResponse<CustomerInfo?>>

fun awaitPurchases(
activity: Activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ internal class PaywallsRepositoryImpl @Inject constructor(
}
}.flowOn(ioDispatcher)

override fun fetchCustomerInfo(): Flow<CustomerInfo?> = flow {
override fun fetchCustomerInfo(): Flow<ApiResponse<CustomerInfo?>> = flow {
try {
val customerInfo = Purchases.sharedInstance.awaitCustomerInfo()
emit(customerInfo)
emit(ApiResponse.of { customerInfo })
} catch (e: PurchasesException) {
emit(null)
emit(ApiResponse.exception(e))
}
}
}.flowOn(ioDispatcher)

override fun awaitPurchases(activity: Activity, availablePackage: Package) = flow {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun CatArticlesAppBar(
modifier: Modifier = Modifier,
title: String = stringResource(id = R.string.app_name),
navigationIcon: @Composable () -> Unit = {},
actions: @Composable () -> Unit = {},
) {
TopAppBar(
modifier = modifier,
Expand All @@ -46,6 +47,7 @@ fun CatArticlesAppBar(
)
},
navigationIcon = navigationIcon,
actions = { actions() },
colors = TopAppBarDefaults.topAppBarColors().copy(
containerColor = Color.Transparent,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ sealed interface CatArticlesScreen {
val typeMap = mapOf(typeOf<Article>() to CatArticlesType)
}
}

@Serializable
data object Account : CatArticlesScreen

@Serializable
data object SubscriptionManagement : CatArticlesScreen
}
1 change: 1 addition & 0 deletions feature/account/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions feature/account/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2025 RevenueCat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("revenuecat.android.library")
id("revenuecat.android.library.compose")
id("revenuecat.android.feature")
id("revenuecat.android.hilt")
id("revenuecat.spotless")
}

android {
namespace = "com.revenuecat.articles.paywall.compose.feature.account"
}

dependencies {
// RevenueCat Purchases
implementation(libs.revenuecat)
implementation(libs.revenuecat.ui)

// Compose
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.runtime)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2025 RevenueCat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.revenuecat.articles.paywall.feature.account

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import com.revenuecat.purchases.ui.revenuecatui.customercenter.CustomerCenter

@Composable
fun AccountScreen(
viewModel: AccountViewModel = hiltViewModel(),
) {
Box(modifier = Modifier.fillMaxSize()) {
CustomerCenter(
modifier = Modifier.fillMaxSize(),
onDismiss = { viewModel.navigateUp() },
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 RevenueCat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.revenuecat.articles.paywall.feature.account

import androidx.lifecycle.ViewModel
import com.revenuecat.articles.paywall.core.navigation.AppComposeNavigator
import com.revenuecat.articles.paywall.core.navigation.CatArticlesScreen
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class AccountViewModel @Inject constructor(
private val navigator: AppComposeNavigator<CatArticlesScreen>,
) : ViewModel() {

fun navigateUp() {
navigator.navigateUp()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import com.revenuecat.articles.paywall.core.model.Article
import com.revenuecat.articles.paywall.core.navigation.AppComposeNavigator
import com.revenuecat.articles.paywall.core.navigation.CatArticlesScreen
import com.revenuecat.articles.paywall.coredata.repository.PaywallsRepository
import com.skydoves.sandwich.fold
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

Expand All @@ -35,11 +37,18 @@ class CatArticlesDetailViewModel @Inject constructor(
) : ViewModel() {

val article = savedStateHandle.getStateFlow<Article?>("article", null)
val customerInfo = repository.fetchCustomerInfo().stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = null,
)
val customerInfo = repository.fetchCustomerInfo()
.map { response ->
response.fold(
onSuccess = { it },
onFailure = { null },
)
}
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = null,
)

fun navigateToCustomPaywalls() {
navigator.navigate(CatArticlesScreen.Paywalls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -72,7 +76,18 @@ fun SharedTransitionScope.CatArticlesHome(
val uiState by catArticlesViewModel.uiState.collectAsStateWithLifecycle()

Column(modifier = Modifier.fillMaxSize()) {
CatArticlesAppBar(modifier = Modifier.background(CatArticlesTheme.colors.primary))
CatArticlesAppBar(
modifier = Modifier.background(CatArticlesTheme.colors.primary),
actions = {
IconButton(onClick = { catArticlesViewModel.navigateToAccount() }) {
Icon(
imageVector = Icons.Default.AccountCircle,
contentDescription = "Account",
tint = Color.White,
)
}
},
)

HomeContent(
uiState = uiState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class CatArticlesViewModel @Inject constructor(
fun navigateToDetails(article: Article) {
navigator.navigate(CatArticlesScreen.CatArticle(article))
}

fun navigateToAccount() {
navigator.navigate(CatArticlesScreen.Account)
}
}

@Stable
Expand Down
1 change: 1 addition & 0 deletions feature/subscriptions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions feature/subscriptions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2025 RevenueCat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("revenuecat.android.library")
id("revenuecat.android.library.compose")
id("revenuecat.android.feature")
id("revenuecat.android.hilt")
id("revenuecat.spotless")
}

android {
namespace = "com.revenuecat.articles.paywall.compose.feature.subscriptions"
}

dependencies {
// RevenueCat Purchases
implementation(libs.revenuecat)

// Compose
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.runtime)
}
Loading
Loading