Skip to content

Commit

Permalink
fix: address PR comments
Browse files Browse the repository at this point in the history
- Code improvements
  • Loading branch information
farhan-arshad-dev committed Jul 1, 2024
1 parent 7bf3226 commit a985f18
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 55 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId appId
minSdk 24
targetSdk 34
versionCode 6
versionName "6.0.0"
versionCode 1
versionName "1.0.0"

resourceConfigurations += ["en", "uk"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class CourseDatesCalendarSync(
val isDeepLinkEnabled: Boolean,
) : Serializable

class IAPConfig(
data class IAPConfig(
val isEnabled: Boolean = false,
val productPrefix: String? = null,
val disableVersions: List<String> = listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class CourseStructure(
val isUpgradeable: Boolean
get() = enrollmentDetails.isAuditMode &&
isStarted &&
courseAccessDetails.coursewareAccess?.hasAccess == true &&
enrollmentDetails.isUpgradeDeadlinePassed.not() &&
productInfo != null
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openedx.core.domain.model.iap

import org.openedx.core.domain.ProductInfo
import org.openedx.core.presentation.iap.IAPFlow

data class PurchaseFlowData(
val screenName: String? = null,
Expand All @@ -10,7 +9,6 @@ data class PurchaseFlowData(
val isSelfPaced: Boolean? = null,
val componentId: String? = null,
val productInfo: ProductInfo? = null,
val flow: String = IAPFlow.USER_INITIATED.value()
) {
var currencyCode: String = ""
var price: Double = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class IAPDialogFragment : DialogFragment() {
}

companion object {
const val TAG = "IAPDialogFragment"

private const val ARG_IAP_FLOW = "iap_flow"
private const val ARG_SCREEN_NAME = "SCREEN_NAME"
private const val ARG_COURSE_ID = "course_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class IAPFlow(val value: String) {
}

enum class IAPAction(val action: String) {
ACTION_USER_INITIATED("user_initiated"),
ACTION_GET_HELP("get_help"),
ACTION_CLOSE("close"),
ACTION_RELOAD_PRICE("reload_price"),
Expand All @@ -37,6 +38,7 @@ enum class IAPAction(val action: String) {
ACTION_UNFULFILLED("Unfulfilled"),
ACTION_RESTORE("restore"),
ACTION_ERROR_CLOSE("error_close"),
ACTION_COMPLETION("completion")
}

enum class IAPRequestType(val request: String) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/openedx/core/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ data class AppShapes(
val MaterialTheme.appShapes: AppShapes
@Composable
@ReadOnlyComposable
get() =LocalShapes.current
get() = LocalShapes.current
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fun CourseDashboard(
productInfo = viewModel.courseStructure?.productInfo!!
).show(
fragmentManager,
IAPDialogFragment::class.simpleName
IAPDialogFragment.TAG
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import coil.compose.AsyncImage
import coil.request.ImageRequest
import org.koin.android.ext.android.inject
Expand Down Expand Up @@ -147,7 +146,6 @@ class DashboardListFragment : Fragment() {
iapUiState = iapUiState,
canLoadMore = canLoadMore,
refreshing = refreshing,
fragmentManager = requireActivity().supportFragmentManager,
hasInternetConnection = viewModel.hasInternetConnection,
onReloadClick = {
viewModel.getCourses()
Expand All @@ -173,8 +171,35 @@ class DashboardListFragment : Fragment() {
AppUpdateState.openPlayMarket(requireContext())
},
),
onIAPAction = { action, iapException ->
onIAPAction = { action, course, iapException ->
when (action) {
IAPAction.ACTION_USER_INITIATED -> {
if (course != null) {
IAPDialogFragment.newInstance(
iapFlow = IAPFlow.USER_INITIATED,
screenName = IAPAnalyticsScreen.COURSE_ENROLLMENT.screenName,
courseId = course.course.id,
courseName = course.course.name,
isSelfPaced = course.course.isSelfPaced,
productInfo = course.productInfo!!
).show(
requireActivity().supportFragmentManager,
IAPDialogFragment.TAG
)
}
}

IAPAction.ACTION_COMPLETION -> {
IAPDialogFragment.newInstance(
IAPFlow.SILENT,
IAPAnalyticsScreen.COURSE_ENROLLMENT.screenName
).show(
requireActivity().supportFragmentManager,
IAPDialogFragment.TAG
)
viewModel.clearIAPState()
}

IAPAction.ACTION_UNFULFILLED -> {
viewModel.detectUnfulfilledPurchase()
}
Expand Down Expand Up @@ -213,13 +238,12 @@ internal fun DashboardListView(
iapUiState: IAPUIState?,
canLoadMore: Boolean,
refreshing: Boolean,
fragmentManager: FragmentManager,
hasInternetConnection: Boolean,
onReloadClick: () -> Unit,
onSwipeRefresh: () -> Unit,
paginationCallback: () -> Unit,
onItemClick: (EnrolledCourse) -> Unit,
onIAPAction: (IAPAction, IAPException?) -> Unit,
onIAPAction: (IAPAction, EnrolledCourse?, IAPException?) -> Unit,
appUpgradeParameters: AppUpdateState.AppUpgradeParameters,
) {
val scaffoldState = rememberScaffoldState()
Expand Down Expand Up @@ -329,16 +353,10 @@ internal fun DashboardListView(
bottom = 16.dp
)
) {
IAPDialogFragment.newInstance(
iapFlow = IAPFlow.USER_INITIATED,
screenName = IAPAnalyticsScreen.COURSE_ENROLLMENT.screenName,
courseId = course.course.id,
courseName = course.course.name,
isSelfPaced = course.course.isSelfPaced,
productInfo = course.productInfo!!
).show(
fragmentManager,
IAPDialogFragment::class.simpleName
onIAPAction(
IAPAction.ACTION_USER_INITIATED,
course,
null
)
}
}
Expand All @@ -364,7 +382,7 @@ internal fun DashboardListView(

LaunchedEffect(state.courses) {
if (state.courses.isNotEmpty()) {
onIAPAction(IAPAction.ACTION_UNFULFILLED, null)
onIAPAction(IAPAction.ACTION_UNFULFILLED, null, null)
}
}
}
Expand Down Expand Up @@ -424,16 +442,9 @@ internal fun DashboardListView(
when (iapUiState) {
is IAPUIState.PurchasesFulfillmentCompleted -> {
PurchasesFulfillmentCompletedDialog(onConfirm = {
onIAPAction(IAPAction.ACTION_CLOSE, null)
IAPDialogFragment.newInstance(
IAPFlow.SILENT,
IAPAnalyticsScreen.COURSE_ENROLLMENT.screenName
).show(
fragmentManager,
IAPDialogFragment::class.simpleName
)
onIAPAction(IAPAction.ACTION_COMPLETION, null, null)
}, onDismiss = {
onIAPAction(IAPAction.ACTION_CLOSE, null)
onIAPAction(IAPAction.ACTION_CLOSE, null, null)
})
}

Expand All @@ -442,11 +453,18 @@ internal fun DashboardListView(
title = stringResource(id = CoreR.string.iap_error_title),
description = stringResource(id = CoreR.string.iap_course_not_fullfilled),
confirmText = stringResource(id = CoreR.string.core_cancel),
onConfirm = { onIAPAction(IAPAction.ACTION_ERROR_CLOSE, null) },
onConfirm = {
onIAPAction(
IAPAction.ACTION_ERROR_CLOSE,
null,
null
)
},
dismissText = stringResource(id = CoreR.string.iap_get_help),
onDismiss = {
onIAPAction(
IAPAction.ACTION_GET_HELP,
null,
iapUiState.iapException
)
}
Expand Down Expand Up @@ -618,8 +636,6 @@ private fun CourseItemPreview() {
}
}

object MockFragmentManager : FragmentManager()

@Preview(uiMode = UI_MODE_NIGHT_NO)
@Preview(uiMode = UI_MODE_NIGHT_YES)
@Composable
Expand All @@ -642,13 +658,12 @@ private fun DashboardListViewPreview() {
iapUiState = null,
canLoadMore = false,
refreshing = false,
fragmentManager = MockFragmentManager,
hasInternetConnection = true,
onReloadClick = {},
onSwipeRefresh = {},
paginationCallback = {},
onItemClick = {},
onIAPAction = { _, _ -> },
onIAPAction = { _, _, _ -> },
appUpgradeParameters = AppUpdateState.AppUpgradeParameters()
)
}
Expand Down Expand Up @@ -676,13 +691,12 @@ private fun DashboardListViewTabletPreview() {
iapUiState = null,
canLoadMore = false,
refreshing = false,
fragmentManager = MockFragmentManager,
hasInternetConnection = true,
onReloadClick = {},
onSwipeRefresh = {},
paginationCallback = {},
onItemClick = {},
onIAPAction = { _, _ -> },
onIAPAction = { _, _, _ -> },
appUpgradeParameters = AppUpdateState.AppUpgradeParameters()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.presentation.IAPAnalyticsScreen
import org.openedx.core.presentation.dialog.IAPDialogFragment
import org.openedx.core.presentation.iap.IAPAction
import org.openedx.core.presentation.iap.IAPFlow
import org.openedx.core.ui.rememberWindowSize
import org.openedx.core.ui.theme.OpenEdXTheme

Expand All @@ -36,7 +39,6 @@ class SettingsFragment : Fragment() {
windowSize = windowSize,
uiState = uiState,
iapUiState = iapUiState,
fragmentManager = requireActivity().supportFragmentManager,
appUpgradeEvent = appUpgradeEvent,
onBackClick = {
requireActivity().supportFragmentManager.popBackStack()
Expand Down Expand Up @@ -127,6 +129,16 @@ class SettingsFragment : Fragment() {
?.let { viewModel.showFeedbackScreen(requireActivity(), it) }
}

IAPAction.ACTION_RESTORE -> {
IAPDialogFragment.newInstance(
IAPFlow.RESTORE,
IAPAnalyticsScreen.PROFILE.screenName
).show(
requireActivity().supportFragmentManager,
IAPDialogFragment.TAG
)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.fragment.app.FragmentManager
import org.openedx.core.R
import org.openedx.core.domain.model.AgreementUrls
import org.openedx.core.exception.iap.IAPException
import org.openedx.core.presentation.IAPAnalyticsScreen
import org.openedx.core.presentation.dialog.IAPDialogFragment
import org.openedx.core.presentation.global.AppData
import org.openedx.core.presentation.iap.IAPAction
import org.openedx.core.presentation.iap.IAPFlow
import org.openedx.core.presentation.iap.IAPLoaderType
import org.openedx.core.presentation.iap.IAPUIState
import org.openedx.core.system.notifier.AppUpgradeEvent
Expand Down Expand Up @@ -87,7 +83,6 @@ internal fun SettingsScreen(
windowSize: WindowSize,
uiState: SettingsUIState,
iapUiState: IAPUIState?,
fragmentManager: FragmentManager,
appUpgradeEvent: AppUpgradeEvent?,
onBackClick: () -> Unit,
onAction: (SettingsScreenAction) -> Unit,
Expand Down Expand Up @@ -241,13 +236,7 @@ internal fun SettingsScreen(
}

iapUiState is IAPUIState.PurchasesFulfillmentCompleted -> {
IAPDialogFragment.newInstance(
IAPFlow.RESTORE,
IAPAnalyticsScreen.PROFILE.screenName
).show(
fragmentManager,
IAPDialogFragment::class.simpleName
)
onIAPAction(IAPAction.ACTION_RESTORE, null)
}

iapUiState is IAPUIState.Error -> {
Expand Down Expand Up @@ -770,8 +759,6 @@ private fun LogoutDialogPreview() {
LogoutDialog({}, {})
}

object MockFragmentManager : FragmentManager()

@Preview
@Composable
private fun SettingsScreenPreview() {
Expand All @@ -784,7 +771,6 @@ private fun SettingsScreenPreview() {
onBackClick = {},
onAction = {},
onIAPAction = { _, _ -> },
fragmentManager = MockFragmentManager,
)
}
}

0 comments on commit a985f18

Please sign in to comment.