Skip to content

Commit

Permalink
Fixed openMF#2442 :When Recent Transactions is opened without connect…
Browse files Browse the repository at this point in the history
…ion of internet…
  • Loading branch information
kmanikanta335 committed Jan 2, 2024
2 parents dd4aa5a + e6a6d7b commit be769be
Show file tree
Hide file tree
Showing 45 changed files with 1,213 additions and 352 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,7 @@ dependencies {
debugImplementation "androidx.compose.ui:ui-tooling:$rootProject.composeVersion"
implementation "androidx.compose.material3:material3:$rootProject.materialVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$rootProject.lifecycleVersion"
implementation "androidx.compose.material:material-icons-extended:$rootProject.composeVersion"

}
apply plugin: 'com.google.gms.google-services'
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:value="@string/google_maps_key" />

<activity
android:name="org.mifos.mobile.ui.activities.LoginActivity"
android:name="org.mifos.mobile.ui.login.LoginActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize" />
Expand Down Expand Up @@ -67,7 +67,7 @@
android:windowSoftInputMode="adjustResize" />

<activity
android:name="org.mifos.mobile.ui.activities.UserProfileActivity"
android:name="org.mifos.mobile.ui.user_profile.UserProfileActivity"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize" />

Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/org/mifos/mobile/api/DataManager.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mifos.mobile.api

import io.reactivex.Observable
import kotlinx.coroutines.flow.Flow
import okhttp3.ResponseBody
import org.mifos.mobile.api.local.DatabaseHelper
import org.mifos.mobile.api.local.PreferencesHelper
Expand Down Expand Up @@ -74,22 +73,22 @@ class DataManager @Inject constructor(
return baseApiManager.clientsApi.getAccounts(clientId, accountType)
}

suspend fun getRecentTransactions(offset: Int, limit: Int): Response<Page<Transaction?>?>? {
suspend fun getRecentTransactions(offset: Int, limit: Int): Page<Transaction> {
return baseApiManager.recentTransactionsApi
.getRecentTransactionsList(clientId, offset, limit)
}

suspend fun getClientCharges(clientId: Long): Response<Page<Charge?>?>? {
suspend fun getClientCharges(clientId: Long): Page<Charge> {
return baseApiManager.clientChargeApi.getClientChargeList(clientId).apply {
databaseHelper.syncCharges(this?.body())
databaseHelper.syncCharges(this)
}
}

suspend fun getLoanCharges(loanId: Long): Response<List<Charge?>?>? {
suspend fun getLoanCharges(loanId: Long): List<Charge> {
return baseApiManager.clientChargeApi.getLoanAccountChargeList(loanId)
}

suspend fun getSavingsCharges(savingsId: Long): Response<List<Charge?>?>? {
suspend fun getSavingsCharges(savingsId: Long): List<Charge> {
return baseApiManager.clientChargeApi.getSavingsAccountChargeList(savingsId)
}

Expand Down Expand Up @@ -206,7 +205,7 @@ class DataManager @Inject constructor(
return baseApiManager.registrationApi.verifyUser(userVerify)
}

suspend fun clientLocalCharges(): Response<Page<Charge?>?> = databaseHelper.clientCharges()
suspend fun clientLocalCharges(): Page<Charge?> = databaseHelper.clientCharges()

fun notifications(): List<MifosNotification> = databaseHelper.notifications()

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/org/mifos/mobile/api/local/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.mifos.mobile.api.local

import com.raizlabs.android.dbflow.sql.language.SQLite
import io.reactivex.Observable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.mifos.mobile.models.Charge
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.notification.MifosNotification
Expand All @@ -17,21 +19,21 @@ import javax.inject.Singleton
*/
@Singleton
class DatabaseHelper @Inject constructor() {
fun syncCharges(charges: Page<Charge?>?): Response<Page<Charge?>?> {
fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
if (charges != null) {
for (charge in charges.pageItems)
charge?.save()
charge.save()
}
return Response.success(charges)
return charges
}

fun clientCharges(): Response<Page<Charge?>?> {
fun clientCharges(): Page<Charge?> {
val charges = SQLite.select()
.from(Charge::class.java)
.queryList()
val chargePage = Page<Charge?>()
chargePage.pageItems = charges
return Response.success(chargePage)
return chargePage
}

fun notifications(): List<MifosNotification> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import retrofit2.http.Path
interface ClientChargeService {

@GET(ApiEndPoints.CLIENTS + "/{clientId}/charges")
suspend fun getClientChargeList(@Path("clientId") clientId: Long?): Response<Page<Charge?>?>?
suspend fun getClientChargeList(@Path("clientId") clientId: Long?): Page<Charge>

@GET(ApiEndPoints.LOANS + "/{loanId}/charges")
suspend fun getLoanAccountChargeList(@Path("loanId") loanId: Long?): Response<List<Charge?>?>?
suspend fun getLoanAccountChargeList(@Path("loanId") loanId: Long?): List<Charge>

@GET(ApiEndPoints.SAVINGS_ACCOUNTS + "/{savingsId}/charges")
suspend fun getSavingsAccountChargeList(@Path("savingsId") savingsId: Long?): Response<List<Charge?>?>?
suspend fun getSavingsAccountChargeList(@Path("savingsId") savingsId: Long?): List<Charge>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.mifos.mobile.api.services
import org.mifos.mobile.api.ApiEndPoints
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.Transaction
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
Expand All @@ -18,5 +17,5 @@ interface RecentTransactionsService {
@Path("clientId") clientId: Long?,
@Query("offset") offset: Int?,
@Query("limit") limit: Int?,
): Response<Page<Transaction?>?>?
): Page<Transaction>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.mifos.mobile.repositories

import kotlinx.coroutines.flow.Flow
import org.mifos.mobile.models.Charge
import org.mifos.mobile.models.Page
import retrofit2.Response

interface ClientChargeRepository {

suspend fun getClientCharges(clientId: Long): Response<Page<Charge?>?>?
suspend fun getLoanCharges(loanId: Long): Response<List<Charge?>?>?
suspend fun getSavingsCharges(savingsId: Long): Response<List<Charge?>?>?
suspend fun clientLocalCharges(): Response<Page<Charge?>?>
suspend fun getClientCharges(clientId: Long): Flow<Page<Charge>>
suspend fun getLoanCharges(loanId: Long): Flow<List<Charge>>
suspend fun getSavingsCharges(savingsId: Long): Flow<List<Charge>>
suspend fun clientLocalCharges(): Flow<Page<Charge?>>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mifos.mobile.repositories

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.Charge
import org.mifos.mobile.models.Page
Expand All @@ -9,19 +11,27 @@ import javax.inject.Inject
class ClientChargeRepositoryImp @Inject constructor(private val dataManager: DataManager) :
ClientChargeRepository {

override suspend fun getClientCharges(clientId: Long): Response<Page<Charge?>?>? {
return dataManager.getClientCharges(clientId)
override suspend fun getClientCharges(clientId: Long): Flow<Page<Charge>> {
return flow {
emit(dataManager.getClientCharges(clientId))
}
}

override suspend fun getLoanCharges(loanId: Long): Response<List<Charge?>?>? {
return dataManager.getLoanCharges(loanId)
override suspend fun getLoanCharges(loanId: Long): Flow<List<Charge>> {
return flow {
emit(dataManager.getLoanCharges(loanId))
}
}

override suspend fun getSavingsCharges(savingsId: Long): Response<List<Charge?>?>? {
return dataManager.getSavingsCharges(savingsId)
override suspend fun getSavingsCharges(savingsId: Long): Flow<List<Charge>> {
return flow {
emit(dataManager.getSavingsCharges(savingsId))
}
}

override suspend fun clientLocalCharges(): Response<Page<Charge?>?> {
return dataManager.clientLocalCharges()
override suspend fun clientLocalCharges(): Flow<Page<Charge?>> {
return flow {
emit(dataManager.clientLocalCharges())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.mifos.mobile.repositories


import kotlinx.coroutines.flow.Flow
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.Transaction
import retrofit2.Response

interface RecentTransactionRepository {

suspend fun recentTransactions(
offset: Int?,
limit: Int?
): Response<Page<Transaction?>?>?
): Flow<Page<Transaction>>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.mifos.mobile.repositories

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.Page
import org.mifos.mobile.models.Transaction
import retrofit2.Response
import javax.inject.Inject

class RecentTransactionRepositoryImp @Inject constructor(private val dataManager: DataManager) :
Expand All @@ -12,7 +13,10 @@ class RecentTransactionRepositoryImp @Inject constructor(private val dataManager
override suspend fun recentTransactions(
offset: Int?,
limit: Int?
): Response<Page<Transaction?>?>? {
return limit?.let { offset?.let { it1 -> dataManager.getRecentTransactions(it1, it) } }
): Flow<Page<Transaction>> {
return flow {
offset?.let { limit?.let { it1 -> dataManager.getRecentTransactions(it, it1) } }
?.let { emit(it) }
}
}
}
11 changes: 8 additions & 3 deletions app/src/main/java/org/mifos/mobile/ui/about/AboutUsFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mifos.mobile.ui.about

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -30,6 +31,7 @@ class AboutUsFragment : BaseFragment() {

private val viewModel: AboutUsViewModel by viewModels()

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -39,9 +41,7 @@ class AboutUsFragment : BaseFragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MifosMobileTheme {
Scaffold {
AboutUsScreen(viewModel)
}
AboutUsScreen(viewModel)
}
}
}
Expand All @@ -54,18 +54,23 @@ class AboutUsFragment : BaseFragment() {
AboutUsListItemId.OFFICE_WEBSITE -> {
startActivity(WEBSITE_LINK)
}

AboutUsListItemId.LICENSES -> {
startActivity(LICENSE_LINK)
}

AboutUsListItemId.PRIVACY_POLICY -> {
startActivity(PrivacyPolicyActivity::class.java)
}

AboutUsListItemId.SOURCE_CODE -> {
startActivity(SOURCE_CODE_LINK)
}

AboutUsListItemId.LICENSES_STRING_WITH_VALUE -> {
startActivity(OssLicensesMenuActivity::class.java)
}

else -> {}
}
}
Expand Down
73 changes: 39 additions & 34 deletions app/src/main/java/org/mifos/mobile/ui/about/AboutUsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,57 @@ import org.mifos.mobile.core.ui.component.MifosItemCard
import org.mifos.mobile.ui.enums.AboutUsListItemId
import java.util.*

@SuppressWarnings("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun AboutUsScreen(viewModel: AboutUsViewModel) {
Column(
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
) {
Spacer(modifier = Modifier.height(48.dp))
AboutUsHeader()
LazyColumn {
items(viewModel.aboutUsItems) { item ->
MifosItemCard(
modifier = Modifier.padding(bottom = 8.dp),
onClick = {
when (item.itemId) {
AboutUsListItemId.OFFICE_WEBSITE -> {
viewModel.navigateToItem(AboutUsListItemId.OFFICE_WEBSITE)
}
AboutUsListItemId.LICENSES -> {
viewModel.navigateToItem(AboutUsListItemId.LICENSES)
}
AboutUsListItemId.PRIVACY_POLICY -> {
viewModel.navigateToItem(AboutUsListItemId.PRIVACY_POLICY)
}
AboutUsListItemId.SOURCE_CODE -> {
viewModel.navigateToItem(AboutUsListItemId.SOURCE_CODE)
}
AboutUsListItemId.LICENSES_STRING_WITH_VALUE -> {
viewModel.navigateToItem(AboutUsListItemId.LICENSES_STRING_WITH_VALUE)
}
else -> {}
item {
Spacer(modifier = Modifier.height(48.dp))
AboutUsHeader()
}
items(viewModel.aboutUsItems) { item ->
MifosItemCard(
modifier = Modifier.padding(bottom = 8.dp),
onClick = {
when (item.itemId) {
AboutUsListItemId.OFFICE_WEBSITE -> {
viewModel.navigateToItem(AboutUsListItemId.OFFICE_WEBSITE)
}

AboutUsListItemId.LICENSES -> {
viewModel.navigateToItem(AboutUsListItemId.LICENSES)
}

AboutUsListItemId.PRIVACY_POLICY -> {
viewModel.navigateToItem(AboutUsListItemId.PRIVACY_POLICY)
}

AboutUsListItemId.SOURCE_CODE -> {
viewModel.navigateToItem(AboutUsListItemId.SOURCE_CODE)
}

AboutUsListItemId.LICENSES_STRING_WITH_VALUE -> {
viewModel.navigateToItem(AboutUsListItemId.LICENSES_STRING_WITH_VALUE)
}

else -> {}
}
) {
item.title?.let {
AboutUsItemCard(
title = it,
subtitle = item.subtitle,
iconUrl = item.iconUrl
)
}
}
) {
item.title?.let {
AboutUsItemCard(
title = it,
subtitle = item.subtitle,
iconUrl = item.iconUrl
)
}
}
}
}

}

@Composable
Expand Down
Loading

0 comments on commit be769be

Please sign in to comment.