Skip to content

Commit e972421

Browse files
committed
refactor: enhanced viewModel, state & removed dialogs
1 parent 4e10873 commit e972421

File tree

61 files changed

+3215
-1733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3215
-1733
lines changed

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavigation.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import org.mifos.mobile.feature.accounts.accounts.navigateToAccountsScreen
3333
import org.mifos.mobile.feature.auth.login.navigateToLoginScreen
3434
import org.mifos.mobile.feature.auth.navigation.AuthGraphRoute
3535
import org.mifos.mobile.feature.beneficiary.beneficiaryApplication.navigateToManualBeneficiaryAddScreen
36+
import org.mifos.mobile.feature.beneficiary.beneficiaryApplicationConfirmation.BeneficiaryApplicationConfirmationNavRoute
37+
import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryNavRoute
3638
import org.mifos.mobile.feature.beneficiary.navigation.beneficiaryNavGraph
3739
import org.mifos.mobile.feature.beneficiary.navigation.navigateToBeneficiaryNavGraph
3840
import org.mifos.mobile.feature.charge.charges.navigateToClientChargeScreen
@@ -189,6 +191,10 @@ internal fun NavGraphBuilder.authenticatedGraph(
189191
navController.navigateToAccountFromStatus(Constants.SHARE_ACCOUNTS)
190192
}
191193

194+
StatusNavigationDestination.BENEFICIARY.name -> {
195+
navController.navigateToBeneficiaryFromStatus()
196+
}
197+
192198
StatusNavigationDestination.PREVIOUS_SCREEN.name -> {
193199
navController.popScreens()
194200
}
@@ -451,10 +457,24 @@ fun NavController.navigateToAccountFromStatus(
451457
}
452458
}
453459

460+
fun NavController.navigateToBeneficiaryFromStatus() {
461+
this.navigate(AuthenticatedNavbarRoute) {
462+
popUpTo(StatusNavigationRoute::class) {
463+
inclusive = true
464+
}
465+
launchSingleTop = true
466+
}
467+
468+
this.navigate(BeneficiaryNavRoute) {
469+
launchSingleTop = true
470+
}
471+
}
472+
454473
fun NavController.popScreens(
455474
popRules: Map<String, Int> = mapOf(
456475
ConfirmDetailsRoute::class.qualifiedName.orEmpty() to 2,
457476
TransferProcessRoute::class.qualifiedName.orEmpty() to 2,
477+
BeneficiaryApplicationConfirmationNavRoute::class.qualifiedName.orEmpty() to 2,
458478
),
459479
) {
460480
val lastEntry = previousBackStackEntry?.destination?.route

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/BeneficiaryRepositoryImp.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.flow.Flow
1617
import kotlinx.coroutines.flow.flow
1718
import kotlinx.coroutines.flow.flowOn
1819
import kotlinx.coroutines.withContext
20+
import kotlinx.io.IOException
1921
import org.mifos.mobile.core.common.DataState
2022
import org.mifos.mobile.core.data.repository.BeneficiaryRepository
2123
import org.mifos.mobile.core.data.util.extractErrorMessage
@@ -49,6 +51,10 @@ class BeneficiaryRepositoryImp(
4951
} catch (e: ClientRequestException) {
5052
val errorMessage = extractErrorMessage(e.response)
5153
DataState.Error(Exception(errorMessage), null)
54+
} catch (e: IOException) {
55+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
56+
} catch (e: ServerResponseException) {
57+
DataState.Error(Exception("Server error: ${e.message}"), null)
5258
}
5359
}
5460
}
@@ -64,6 +70,10 @@ class BeneficiaryRepositoryImp(
6470
} catch (e: ClientRequestException) {
6571
val errorMessage = extractErrorMessage(e.response)
6672
DataState.Error(Exception(errorMessage), null)
73+
} catch (e: IOException) {
74+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
75+
} catch (e: ServerResponseException) {
76+
DataState.Error(Exception("Server error: ${e.message}"), null)
6777
}
6878
}
6979
}
@@ -77,6 +87,10 @@ class BeneficiaryRepositoryImp(
7787
} catch (e: ClientRequestException) {
7888
val errorMessage = extractErrorMessage(e.response)
7989
DataState.Error(Exception(errorMessage), null)
90+
} catch (e: IOException) {
91+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
92+
} catch (e: ServerResponseException) {
93+
DataState.Error(Exception("Server error: ${e.message}"), null)
8094
}
8195
}
8296
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/LoanRepositoryImp.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.flow.Flow
1617
import kotlinx.coroutines.flow.flow
1718
import kotlinx.coroutines.flow.flowOn
1819
import kotlinx.coroutines.withContext
20+
import kotlinx.io.IOException
1921
import org.mifos.mobile.core.common.DataState
2022
import org.mifos.mobile.core.common.asDataStateFlow
2123
import org.mifos.mobile.core.data.repository.LoanRepository
@@ -56,6 +58,10 @@ class LoanRepositoryImp(
5658
} catch (e: ClientRequestException) {
5759
val errorMessage = extractErrorMessage(e.response)
5860
DataState.Error(Exception(errorMessage), null)
61+
} catch (e: IOException) {
62+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
63+
} catch (e: ServerResponseException) {
64+
DataState.Error(Exception("Server error: ${e.message}"), null)
5965
}
6066
}
6167
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/ReviewLoanApplicationRepositoryImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import kotlinx.coroutines.CoroutineDispatcher
1415
import kotlinx.coroutines.withContext
16+
import kotlinx.io.IOException
1517
import org.mifos.mobile.core.common.DataState
1618
import org.mifos.mobile.core.data.repository.ReviewLoanApplicationRepository
1719
import org.mifos.mobile.core.data.util.extractErrorMessage
@@ -46,6 +48,10 @@ class ReviewLoanApplicationRepositoryImpl(
4648
} catch (e: ClientRequestException) {
4749
val errorMessage = extractErrorMessage(e.response)
4850
DataState.Error(Exception(errorMessage), null)
51+
} catch (e: IOException) {
52+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
53+
} catch (e: ServerResponseException) {
54+
DataState.Error(Exception("Server error: ${e.message}"), null)
4955
}
5056
}
5157
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/SavingsAccountRepositoryImp.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.flow.Flow
1617
import kotlinx.coroutines.flow.flowOn
1718
import kotlinx.coroutines.withContext
19+
import kotlinx.io.IOException
1820
import org.mifos.mobile.core.common.DataState
1921
import org.mifos.mobile.core.common.asDataStateFlow
2022
import org.mifos.mobile.core.data.repository.SavingsAccountRepository
@@ -70,6 +72,10 @@ class SavingsAccountRepositoryImp(
7072
} catch (e: ClientRequestException) {
7173
val errorMessage = extractErrorMessage(e.response)
7274
DataState.Error(Exception(errorMessage), null)
75+
} catch (e: IOException) {
76+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
77+
} catch (e: ServerResponseException) {
78+
DataState.Error(Exception("Server error: ${e.message}"), null)
7379
}
7480
}
7581
}
@@ -86,6 +92,10 @@ class SavingsAccountRepositoryImp(
8692
} catch (e: ClientRequestException) {
8793
val errorMessage = extractErrorMessage(e.response)
8894
DataState.Error(Exception(errorMessage), null)
95+
} catch (e: IOException) {
96+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
97+
} catch (e: ServerResponseException) {
98+
DataState.Error(Exception("Server error: ${e.message}"), null)
8999
}
90100
}
91101
}
@@ -102,6 +112,10 @@ class SavingsAccountRepositoryImp(
102112
} catch (e: ClientRequestException) {
103113
val errorMessage = extractErrorMessage(e.response)
104114
DataState.Error(Exception(errorMessage), null)
115+
} catch (e: IOException) {
116+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
117+
} catch (e: ServerResponseException) {
118+
DataState.Error(Exception("Server error: ${e.message}"), null)
105119
}
106120
}
107121
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/ShareAccountRepositoryImp.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.flow.Flow
1617
import kotlinx.coroutines.flow.catch
1718
import kotlinx.coroutines.flow.flowOn
1819
import kotlinx.coroutines.flow.map
1920
import kotlinx.coroutines.withContext
21+
import kotlinx.io.IOException
2022
import org.mifos.mobile.core.common.DataState
2123
import org.mifos.mobile.core.common.asDataStateFlow
2224
import org.mifos.mobile.core.data.repository.ShareAccountRepository
@@ -56,6 +58,10 @@ class ShareAccountRepositoryImp(
5658
} catch (e: ClientRequestException) {
5759
val errorMessage = extractErrorMessage(e.response)
5860
DataState.Error(Exception(errorMessage), null)
61+
} catch (e: IOException) {
62+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
63+
} catch (e: ServerResponseException) {
64+
DataState.Error(Exception("Server error: ${e.message}"), null)
5965
}
6066
}
6167
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.withContext
17+
import kotlinx.io.IOException
1618
import kotlinx.serialization.json.Json
1719
import org.mifos.mobile.core.common.DataState
1820
import org.mifos.mobile.core.data.repository.TransferRepository
@@ -42,6 +44,10 @@ class TransferRepositoryImp(
4244
} catch (e: ClientRequestException) {
4345
val errorMessage = extractErrorMessage(e.response)
4446
DataState.Error(Exception(errorMessage), null)
47+
} catch (e: IOException) {
48+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
49+
} catch (e: ServerResponseException) {
50+
DataState.Error(Exception("Server error: ${e.message}"), null)
4551
}
4652
}
4753
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/UserAuthRepositoryImp.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import io.ktor.client.plugins.ClientRequestException
13+
import io.ktor.client.plugins.ServerResponseException
1314
import io.ktor.client.statement.bodyAsText
1415
import kotlinx.coroutines.CoroutineDispatcher
1516
import kotlinx.coroutines.withContext
17+
import kotlinx.io.IOException
1618
import org.mifos.mobile.core.common.DataState
1719
import org.mifos.mobile.core.data.repository.UserAuthRepository
1820
import org.mifos.mobile.core.data.util.extractErrorMessage
@@ -55,6 +57,10 @@ class UserAuthRepositoryImp(
5557
} catch (e: ClientRequestException) {
5658
val errorMessage = extractErrorMessage(e.response)
5759
DataState.Error(Exception(errorMessage), null)
60+
} catch (e: IOException) {
61+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
62+
} catch (e: ServerResponseException) {
63+
DataState.Error(Exception("Server error: ${e.message}"), null)
5864
}
5965
}
6066
}
@@ -76,6 +82,10 @@ class UserAuthRepositoryImp(
7682
} catch (e: ClientRequestException) {
7783
val errorMessage = extractErrorMessage(e.response)
7884
DataState.Error(Exception(errorMessage), null)
85+
} catch (e: IOException) {
86+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
87+
} catch (e: ServerResponseException) {
88+
DataState.Error(Exception("Server error: ${e.message}"), null)
7989
}
8090
}
8191

@@ -94,6 +104,10 @@ class UserAuthRepositoryImp(
94104
} catch (e: ClientRequestException) {
95105
val errorMessage = extractErrorMessage(e.response)
96106
DataState.Error(Exception(errorMessage), null)
107+
} catch (e: IOException) {
108+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
109+
} catch (e: ServerResponseException) {
110+
DataState.Error(Exception("Server error: ${e.message}"), null)
97111
}
98112
}
99113
}
@@ -113,6 +127,10 @@ class UserAuthRepositoryImp(
113127
} catch (e: ClientRequestException) {
114128
val errorMessage = extractErrorMessage(e.response)
115129
DataState.Error(Exception(errorMessage), null)
130+
} catch (e: IOException) {
131+
DataState.Error(Exception("Network error: ${e.message ?: "Please check your connection"}"), null)
132+
} catch (e: ServerResponseException) {
133+
DataState.Error(Exception("Server error: ${e.message}"), null)
116134
}
117135
}
118136
}

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/StatusNavigationDestination.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ enum class StatusNavigationDestination {
2626

2727
SAVINGS_UPDATE,
2828
SAVINGS_WITHDRAW,
29+
30+
BENEFICIARY,
2931
}

core/ui/src/commonMain/kotlin/org/mifos/mobile/core/ui/utils/ScreenUiState.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ sealed interface ScreenUiState {
4343
*/
4444
data class Error(val message: StringResource) : ScreenUiState
4545

46+
/**
47+
* Represents a full-screen error state with a simple string message.
48+
*
49+
* This is useful for handling error messages received directly as a string from an API
50+
* or a library, without needing to map them to a resource ID.
51+
*
52+
* @property message The plain string error message to be displayed.
53+
*/
54+
data class ErrorString(val message: String) : ScreenUiState
55+
4656
/** * Represents a successful state where content can be displayed.
4757
* * This is the final state after a successful data fetch or operation.
4858
* The UI can now display the main content of the screen.

0 commit comments

Comments
 (0)