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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.offline.offlinedashbarod
package com.mifos.core.data.repository

import com.mifos.core.data.CenterPayload
import com.mifos.core.objects.accounts.loan.LoanRepaymentRequest
Expand All @@ -21,4 +21,4 @@ interface OfflineDashboardRepository {
fun databaseLoanRepayments(): Observable<List<LoanRepaymentRequest>>

fun allSavingsAccountTransactions(): Observable<List<SavingsAccountTransactionRequest>>
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.mifosxdroid.offline.offlinedashbarod
package com.mifos.core.data.repository_imp

import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.OfflineDashboardRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.network.datamanager.DataManagerGroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ object MifosIcons {
val upload = Icons.Rounded.FileUpload
val gallery = Icons.Filled.Image
val ArrowDropDown = Icons.Default.ArrowDropDown
val assignmentTurnedIn = Icons.Default.AssignmentTurnedIn
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class SyncGroupPayloadsViewModel @Inject constructor(
) : ViewModel() {

val syncGroupPayloadsUiState get() = _syncGroupPayloadsUiState
private val _syncGroupPayloadsUiState =
MutableStateFlow<SyncGroupPayloadsUiState>(SyncGroupPayloadsUiState.Loading)
private val _syncGroupPayloadsUiState = MutableStateFlow<SyncGroupPayloadsUiState>(SyncGroupPayloadsUiState.Loading)

val groupPayloadsList get() = _groupPayloadsList
private val _groupPayloadsList = MutableStateFlow<List<GroupPayload>>(listOf())
Expand Down
1 change: 1 addition & 0 deletions feature/offline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
14 changes: 14 additions & 0 deletions feature/offline/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
alias(libs.plugins.mifos.android.library.jacoco)
}

android {
namespace = "com.mifos.feature.offline"
}

dependencies {
implementation(projects.core.domain)

}
Empty file.
21 changes: 21 additions & 0 deletions feature/offline/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mifos.feature.offline

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.feature.offline.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/offline/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package com.mifos.feature.offline.dashboard

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AssignmentTurnedIn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.mifos.core.designsystem.component.MifosErrorContent
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.feature.offline.R

/**
* Created by Pronay Sarker on 27/08/2024 (12:09 AM)
*/
@Composable
fun OfflineDashboardRoute(
onBackPressed: () -> Unit,
syncClientPayload: () -> Unit,
syncGroupPayload: () -> Unit,
syncCenterPayload: () -> Unit,
syncLoanRepayment: () -> Unit,
syncSavingsAccountTransactions: () -> Unit
) {
val viewModel: OfflineDashboardViewModel = hiltViewModel()
val uiState by viewModel.offlineDashboardUiState.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
viewModel.loadDatabaseClientPayload()
viewModel.loadDatabaseGroupPayload()
viewModel.loadDatabaseCenterPayload()
viewModel.loadDatabaseLoanRepaymentTransactions()
viewModel.loadDatabaseSavingsAccountTransactions()
}

OfflineDashboardScreen(
uiState = uiState,
onBackPressed = onBackPressed,
syncClientPayload = syncClientPayload,
syncGroupPayload = syncGroupPayload,
syncCenterPayload = syncCenterPayload,
syncSavingsAccountTransactions = syncSavingsAccountTransactions,
syncLoanRepayment = syncLoanRepayment
)
}

@Composable
fun OfflineDashboardScreen(
uiState: OfflineDashboardUiState,
onBackPressed: () -> Unit,
syncClientPayload: () -> Unit,
syncGroupPayload: () -> Unit,
syncCenterPayload: () -> Unit,
syncLoanRepayment: () -> Unit,
syncSavingsAccountTransactions: () -> Unit
) {
val snackBarHostState = remember { SnackbarHostState() }
val context = LocalContext.current
var errorVisibility by rememberSaveable { mutableStateOf(false) }

LaunchedEffect(key1 = uiState) {
if (uiState is OfflineDashboardUiState.SyncUiState) {
var mPayloadIndex = 5

uiState.list.forEach { item ->
if (item.count == 0) {
mPayloadIndex -= 1
if (mPayloadIndex == 0) {
errorVisibility = true
}
} else errorVisibility = false
}
}
}

MifosScaffold(
snackbarHostState = snackBarHostState,
onBackPressed = onBackPressed,
icon = MifosIcons.arrowBack,
title = stringResource(id = R.string.feature_offline_offline_Sync)
) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
if (errorVisibility) {
MifosErrorContent(
message = stringResource(id = R.string.feature_offline_nothing_to_sync),
imageVector = MifosIcons.assignmentTurnedIn
)
} else {
when (uiState) {
is OfflineDashboardUiState.SyncUiState -> {
LazyColumn {
items(uiState.list) { item ->
if (item.count != 0) {
OfflineDashboardItemCard(
paymentItem = item.name,
count = item.count,
onClick = {
when (item.type) {
Type.SYNC_CLIENTS -> syncClientPayload()
Type.SYNC_GROUPS -> syncGroupPayload()
Type.SYNC_CENTERS -> syncCenterPayload()
Type.SYNC_LOAN_REPAYMENTS -> syncLoanRepayment()
Type.SYNC_SAVINGS_ACCOUNT_TRANSACTION -> syncSavingsAccountTransactions()
}
}
)
}

LaunchedEffect(key1 = item.errorMsg) {
if (item.errorMsg != null) {
Toast.makeText(context, item.errorMsg, Toast.LENGTH_SHORT)
.show()
}
}
}
}
}
}
}
}
}
}

@Composable
fun OfflineDashboardItemCard(
paymentItem: Int = -1,
count: Int = 0,
onClick: () -> Unit
) {
OutlinedCard(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
onClick = onClick
) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(id = paymentItem),
style = MaterialTheme.typography.bodyLarge
)

Text(
text = "$count",
style = MaterialTheme.typography.bodyLarge
)
}
}
}

@Composable
@Preview (showSystemUi = true)
fun PreviewOfflineDashboardScreen(modifier: Modifier = Modifier) {
val data = listOf(
SyncStateData(count = 3, name = R.string.feature_offline_sync_clients, type = Type.SYNC_CLIENTS),
SyncStateData(count = 3, name = R.string.feature_offline_sync_groups, type = Type.SYNC_GROUPS),
SyncStateData(count = 2, name = R.string.feature_offline_sync_centers, type = Type.SYNC_CENTERS),
SyncStateData(count = 4, name = R.string.feature_offline_sync_loanRepayments, type = Type.SYNC_LOAN_REPAYMENTS),
SyncStateData(count = 5, name = R.string.feature_offline_sync_savingsAccountTransactions, type = Type.SYNC_SAVINGS_ACCOUNT_TRANSACTION)
)

OfflineDashboardScreen(
uiState = OfflineDashboardUiState.SyncUiState(data),
onBackPressed = { },
syncClientPayload = { },
syncGroupPayload = { },
syncCenterPayload = { },
syncLoanRepayment = { }) {
}
}

enum class Type {
SYNC_CLIENTS,
SYNC_GROUPS,
SYNC_CENTERS,
SYNC_LOAN_REPAYMENTS,
SYNC_SAVINGS_ACCOUNT_TRANSACTION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mifos.feature.offline.dashboard

/**
* Created by Aditya Gupta on 16/08/23.
*/
sealed class OfflineDashboardUiState {
data class SyncUiState(val list : List<SyncStateData>) : OfflineDashboardUiState()
}

data class SyncStateData(
var count: Int = 0,
val name : Int = -1,
val type : Type,
var errorMsg : String? = null
)
Loading