Skip to content

Commit

Permalink
refactor: refactor client list screen to compose with clean arch, rea…
Browse files Browse the repository at this point in the history
…lm and paging3
  • Loading branch information
Aditya-gupta99 committed Feb 21, 2024
1 parent 56825eb commit 78bd2be
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.mifos.core.common.utils.Page
import com.mifos.core.model.ClientDb
import io.realm.kotlin.Realm
import io.realm.kotlin.ext.query
import io.realm.kotlin.query.Sort
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
Expand All @@ -15,7 +16,7 @@ import javax.inject.Inject
class DatabaseClientQuery @Inject constructor(private val realm: Realm) {

fun getClientListFromDb(): Flow<Page<ClientDb>> {
return realm.query<ClientDb>().asFlow()
return realm.query<ClientDb>().sort("accountNo", sortOrder = Sort.ASCENDING).asFlow()
.map { Page(totalFilteredRecords = it.list.size, pageItems = it.list) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ClientListPagingSource(private val dataManagerClient: DataManagerClient) :
clientList: List<Client>,
clientDbList: List<ClientDb>
): List<Client> {
if (clientDbList.isEmpty()) {
if (clientDbList.isNotEmpty()) {
clientList.forEach { client ->
clientDbList.forEach { clientDb ->
if (client.id == clientDb._id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import com.mifos.feature.client.R
@Composable
fun ClientListScreen(
createNewClient: () -> Unit,
syncClicked: () -> Unit,
syncClicked: (List<Client>) -> Unit,
onClientSelect: (Client) -> Unit,
) {

Expand Down Expand Up @@ -118,13 +118,16 @@ fun ClientListScreen(
if (isInSelectionMode.value) {
SelectionModeTopAppBar(
selectedItems = selectedItems,
syncClicked = { syncClicked() },
syncClicked = { syncClicked(selectedItems.toList()) },
resetSelectionMode = resetSelectionMode,
)
}
},
floatingActionButton = {
FloatingActionButton(onClick = { createNewClient() }) {
FloatingActionButton(
onClick = { createNewClient() },
containerColor = BlueSecondary
) {
Icon(
imageVector = Icons.Filled.Add,
contentDescription = null
Expand Down
1 change: 1 addition & 0 deletions mifosng-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ dependencies {

implementation(project(":feature:auth"))
implementation(project(":feature:client"))
implementation(project(":core:data"))

// Multidex dependency
implementation("androidx.multidex:multidex:2.0.1")
Expand Down
Loading

0 comments on commit 78bd2be

Please sign in to comment.