Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import org.mifos.mobile.feature.qr.qr.QrCodeReaderViewModel
import org.mifos.mobile.feature.qr.qrCodeDisplay.QrCodeDisplayViewModel
import org.mifos.mobile.feature.qr.qrCodeImport.QrCodeImportViewModel

/**
* Koin module for the QR feature.
*
* This module is responsible for providing all the ViewModels used within the QR code
* feature of the application.
*/
val QrModule = module {
viewModelOf(::QrCodeImportViewModel)
viewModelOf(::QrCodeReaderViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ import org.mifos.mobile.feature.qr.qrCodeDisplay.qrDisplayDestination
import org.mifos.mobile.feature.qr.qrCodeImport.navigateToQrImportScreen
import org.mifos.mobile.feature.qr.qrCodeImport.qrImportDestination

/**
* Type-safe navigation route for the entire QR feature's nested navigation graph.
*/
@Serializable
data object QrGraphRoute

/**
* Navigates to the nested QR navigation graph.
*
* @param navOptions Optional navigation options.
*/
fun NavController.navigateToQrGraph(navOptions: NavOptions? = null) {
this.navigate(QrGraphRoute, navOptions)
}

/**
* Builds the nested navigation graph for the QR feature.
*
* @param navController The NavController for the graph.
* @param openBeneficiaryApplication Callback to navigate to the beneficiary application screen.
*/
fun NavGraphBuilder.qrNavGraph(
navController: NavController,
openBeneficiaryApplication: (Beneficiary, BeneficiaryState) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary
import org.mifos.mobile.core.model.enums.BeneficiaryState
import org.mifos.mobile.core.ui.composableWithPushTransitions

/**
* Represents the type-safe navigation route for the QR Code Reader screen.
*/
@Serializable
data object QrCodeReaderRoute

/**
* Navigates to the QR Code Reader screen.
* @param navOptions Optional navigation options.
*/
fun NavController.navigateToQrReaderScreen(navOptions: NavOptions? = null) {
this.navigate(QrCodeReaderRoute, navOptions)
}

/**
* Defines the composable destination for the QR Code Reader screen in the navigation graph.
*
* @param navigateBack Callback to navigate to the previous screen.
* @param navigateToQrImportScreen Callback to navigate to the QR import screen.
* @param openBeneficiaryApplication Callback to open the beneficiary application screen
* with the parsed beneficiary data.
*/
fun NavGraphBuilder.qrReaderDestination(
navigateBack: () -> Unit,
navigateToQrImportScreen: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ import org.mifos.mobile.core.qr.QrScannerWithPermissions
import org.mifos.mobile.core.ui.component.MifosPoweredCard
import org.mifos.mobile.core.ui.utils.EventsEffect

/**
* The main composable for the **QR Code Reader screen**.
* It collects state from the [QrCodeReaderViewModel], handles navigation and events,
* and composes the main UI content and dialogs.
*
* @param navigateBack Callback to navigate to the previous screen.
* @param openBeneficiaryApplication Callback to open the beneficiary application with the parsed [Beneficiary] data and its [BeneficiaryState].
* @param navigateToQrImportScreen Callback to navigate to the screen for importing QR from an image file.
* @param viewModel The [QrCodeReaderViewModel] for managing state and business logic.
*/
@Composable
internal fun QrCodeReaderScreen(
navigateBack: () -> Unit,
Expand Down Expand Up @@ -104,6 +114,12 @@ internal fun QrCodeReaderScreen(
)
}

/**
* Displays dialogs based on the current [QrCodeReaderState].
*
* @param state The current state of the QR reader screen.
* @param onAction Callback for user actions within the dialog.
*/
@Composable
private fun QrCodeReaderDialog(
state: QrCodeReaderState,
Expand All @@ -123,6 +139,10 @@ private fun QrCodeReaderDialog(
}
}

/**
* The main content of the QR Code Reader screen, including the camera preview and UI controls.
* @param onAction Callback for user actions on the screen.
*/
@Composable
private fun QrCodeReaderContent(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -237,6 +257,7 @@ private fun QrCodeReaderContent(
}
}


private fun Modifier.drawQrCorners(): Modifier = drawWithContent {
drawContent()

Expand Down Expand Up @@ -306,6 +327,9 @@ private fun Modifier.drawQrCorners(): Modifier = drawWithContent {
)
}

/**
* A Jetpack Compose Preview for the [QrCodeReaderContent] composable.
*/
@Preview
@Composable
private fun QrCodeReaderScreenPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,30 @@ import androidx.navigation.NavOptions
import kotlinx.serialization.Serializable
import org.mifos.mobile.core.ui.composableWithPushTransitions

/**
* Represents the type-safe navigation route for the QR Code Display screen.
* It can optionally take a `qrString` to display, otherwise it will generate one.
*
* @param qrString The string to be encoded and displayed as a QR code.
*/
@Serializable
data class QrCodeDisplayRoute(val qrString: String = "")

/**
* Navigates to the QR Code Display screen.
*
* @param qrString The string to be encoded into the QR code.
* @param navOptions Optional navigation options.
*/
fun NavController.navigateToQrDisplayScreen(qrString: String, navOptions: NavOptions? = null) {
this.navigate(QrCodeDisplayRoute(qrString), navOptions)
}

/**
* Defines the composable destination for the QR Code Display screen in the navigation graph.
*
* @param navigateBack Callback to navigate to the previous screen.
*/
fun NavGraphBuilder.qrDisplayDestination(
navigateBack: () -> Unit,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ import org.mifos.mobile.core.designsystem.theme.MifosTypography
import org.mifos.mobile.core.ui.component.MifosPoweredCard
import org.mifos.mobile.core.ui.utils.EventsEffect

/**
* The main entry point for the QR Code Display screen. This composable handles state
* from the ViewModel and events.
*
* @param navigateBack Callback to navigate to the previous screen.
* @param viewModel The [QrCodeDisplayViewModel] for this screen.
*/
@Composable
internal fun QrCodeDisplayScreen(
navigateBack: () -> Unit,
Expand All @@ -72,6 +79,13 @@ internal fun QrCodeDisplayScreen(
)
}

/**
* The private, stateless version of the QR Code Display screen.
* This composable is responsible for the UI layout and generating the QR code painter.
*
* @param state The current [QrCodeDisplayState] to render.
* @param onAction Callback for user actions on the screen.
*/
@Suppress("UnusedPrivateProperty")
@Composable
private fun QrCodeDisplayScreen(
Expand Down Expand Up @@ -103,6 +117,12 @@ private fun QrCodeDisplayScreen(
)
}

/**
* The main content of the QR code display screen.
* It lays out the title, instructions, QR code image, and generation date.
*
* @param painter The [Painter] used to draw the QR code.
*/
@Composable
private fun QrCodeDisplayContent(
painter: Painter,
Expand Down Expand Up @@ -163,6 +183,9 @@ private fun QrCodeDisplayContent(
}
}

/**
* A Jetpack Compose Preview for the [QrCodeDisplayScreen] composable.
*/
@Preview
@Composable
private fun QrCodeDisplayScreenPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary
import org.mifos.mobile.core.model.enums.BeneficiaryState
import org.mifos.mobile.core.ui.composableWithPushTransitions

/**
* Represents the type-safe navigation route for the QR Code Import screen.
*/
@Serializable
data object QrCodeImportRoute

/**
* Navigates to the QR Code Import screen.
*
* @param navOptions Optional navigation options.
*/
fun NavController.navigateToQrImportScreen(navOptions: NavOptions? = null) {
this.navigate(QrCodeImportRoute, navOptions)
}

/**
* Defines the composable destination for the QR Code Import screen in the navigation graph.
*
* @param navigateBack Callback to navigate to the previous screen.
* @param openBeneficiaryApplication Callback to open the beneficiary application with the parsed beneficiary data.
*/
fun NavGraphBuilder.qrImportDestination(
navigateBack: () -> Unit,
openBeneficiaryApplication: (Beneficiary, BeneficiaryState) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ import org.mifos.mobile.core.ui.component.MifosPoweredCard
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
import org.mifos.mobile.core.ui.utils.EventsEffect

/**
* The main composable for the QR Code Import screen. It connects the UI to the ViewModel,
* handles state and events, and orchestrates navigation.
*
* @param navigateBack Callback to navigate to the previous screen.
* @param openBeneficiaryApplication Callback to open the beneficiary application with parsed data.
* @param viewModel The [QrCodeImportViewModel] for this screen.
*/
@Composable
internal fun QrCodeImportScreen(
navigateBack: () -> Unit,
Expand Down Expand Up @@ -73,6 +81,13 @@ internal fun QrCodeImportScreen(
)
}

/**
* Displays dialogs based on the current [QrCodeImportState], such as loading indicators
* or error messages.
*
* @param state The current state of the QR import screen.
* @param onAction Callback for user actions within the dialog.
*/
@Composable
private fun QrCodeDialog(
state: QrCodeImportState,
Expand All @@ -92,6 +107,11 @@ private fun QrCodeDialog(
}
}

/**
* The main content layout for the QR Code Import screen, including the scaffold and
* bottom bar.
* @param onAction Callback for user actions on the screen.
*/
@Composable
private fun QrCodeImportScreenContent(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -126,12 +146,25 @@ private fun QrCodeImportScreenContent(
}
}

/**
* Expect composable for a platform-specific image picker UI.
* This allows each platform (Android, iOS) to implement its own native
* image selection logic.
*
* @param onProceed Callback that provides the selected [ImageBitmap] to the caller.
* @param modifier The [Modifier] to be applied to the picker composable.
*/
@Composable
expect fun QrCodeImagePicker(
onProceed: (bitmap: ImageBitmap) -> Unit,
modifier: Modifier = Modifier,
)

/**
* A wrapper composable that hosts the platform-specific [QrCodeImagePicker].
*
* @param proceedClicked Callback invoked when an image is selected and ready to be processed.
*/
@Composable
private fun QrCodeImportContent(
proceedClicked: (bitmap: ImageBitmap) -> Unit,
Expand All @@ -145,6 +178,9 @@ private fun QrCodeImportContent(
)
}

/**
* A Jetpack Compose Preview for the [QrCodeImportScreenContent] composable.
*/
@Preview
@Composable
private fun QrCodeImportPreview() {
Expand Down
Loading