forked from openMF/android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cec92e8
commit 4822876
Showing
22 changed files
with
495 additions
and
33 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
core/common/src/main/java/com/mifos/core/common/utils/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mifos.core.common.utils | ||
|
||
object Constants { | ||
|
||
const val SERVICE_STATUS = "service_status" | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
core/common/src/main/java/com/mifos/core/common/utils/Page.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* This project is licensed under the open source MPL V2. | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.common.utils | ||
|
||
/** | ||
* Created by ishankhanna on 09/02/14. | ||
*/ | ||
data class Page<T>( | ||
var totalFilteredRecords: Int = 0, | ||
|
||
var pageItems: List<T> = ArrayList() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/datastore/src/main/java/com/mifos/core/database/DatabaseHelperClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mifos.core.database | ||
|
||
import com.mifos.core.common.utils.Page | ||
import com.mifos.core.data.model.client.Client | ||
import com.raizlabs.android.dbflow.sql.language.SQLite | ||
import rx.Observable | ||
|
||
class DatabaseHelperClient { | ||
|
||
|
||
/** | ||
* Reading All Clients from table of Client and return the ClientList | ||
* | ||
* @return List Of Client | ||
*/ | ||
//TODO Implement Observable Transaction to load Client List | ||
fun readAllClients(): Observable<Page<Client>> { | ||
return Observable.create { subscriber -> | ||
val clientPage = Page<Client>() | ||
clientPage.pageItems = SQLite.select() | ||
.from(Client::class.java) | ||
.queryList() | ||
subscriber.onNext(clientPage) | ||
subscriber.onCompleted() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...esignsystem/src/main/java/com/mifos/core/designsystem/component/MifosProgressIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.mifos.core.designsystem.component | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun MifosPagingAppendProgress() { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.wrapContentHeight(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
CircularProgressIndicator( | ||
modifier = Modifier | ||
.width(40.dp) | ||
.height(40.dp) | ||
.padding(8.dp), | ||
strokeWidth = 4.dp | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
core/network/src/main/java/com/mifos/core/network/datamanger/DataManagerClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.mifos.core.network.datamanger | ||
|
||
import com.mifos.core.common.utils.Page | ||
import com.mifos.core.data.model.client.Client | ||
import com.mifos.core.database.DatabaseHelperClient | ||
import com.mifos.core.datastore.PrefManager | ||
import com.mifos.core.network.di.BaseApiManagerQualifier | ||
import com.mifos.core.network.mappers.clients.GetClientResponseMapper | ||
import org.mifos.core.apimanager.BaseApiManager | ||
import rx.Observable | ||
import javax.inject.Inject | ||
|
||
class DataManagerClient @Inject constructor( | ||
@BaseApiManagerQualifier private val baseApiManager: BaseApiManager, | ||
private val prefManager: PrefManager, | ||
private val databaseHelperClient: DatabaseHelperClient | ||
) { | ||
|
||
/** | ||
* This Method sending the Request to REST API if UserStatus is 0 and | ||
* get list of the clients. The response is pass to the DatabaseHelperClient | ||
* that save the response in Database different thread and next pass the response to | ||
* Presenter to show in the view | ||
* | ||
* | ||
* If the offset is zero and UserStatus is 1 then fetch all clients list and show on the view. | ||
* else if offset is not zero and UserStatus is 1 then return default empty response to | ||
* presenter | ||
* | ||
* @param paged True Enable the Pagination of the client list REST API | ||
* @param offset Value give from which position Fetch ClientList | ||
* @param limit Maximum Number of clients will come in response | ||
* @return Client List from offset to max Limit | ||
*/ | ||
|
||
fun getAllClients(offset: Int, limit: Int): Observable<Page<Client>> { | ||
return when (prefManager.userStatus) { | ||
false -> baseApiManager.getClientsApi().retrieveAll21( | ||
null, null, null, | ||
null, null, null, | ||
null, null, offset, | ||
limit, null, null, null | ||
).map(GetClientResponseMapper::mapFromEntity) | ||
|
||
true -> { | ||
/** | ||
* Return All Clients List from DatabaseHelperClient only one time. | ||
* If offset is zero this means this is first request and | ||
* return all clients from DatabaseHelperClient | ||
*/ | ||
if (offset == 0) databaseHelperClient.readAllClients() else Observable.just(Page()) | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This Method Request to the DatabaseHelperClient and DatabaseHelperClient Read the All | ||
* clients from Client_Table and give the response Page of List of Client | ||
* | ||
* @return Page of Client List | ||
*/ | ||
val allDatabaseClients: Observable<Page<Client>> | ||
get() = databaseHelperClient.readAllClients() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/network/src/main/java/com/mifos/core/network/mappers/clients/ClientMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.mifos.core.network.mappers.clients | ||
|
||
import com.mifos.core.data.model.client.Client | ||
import com.mifos.core.data.model.client.Status | ||
import org.apache.fineract.client.models.GetClientStatus | ||
import org.apache.fineract.client.models.GetClientsPageItemsResponse | ||
import org.mifos.core.data.AbstractMapper | ||
|
||
object ClientMapper : AbstractMapper<GetClientsPageItemsResponse, Client>() { | ||
|
||
override fun mapFromEntity(entity: GetClientsPageItemsResponse): Client { | ||
return Client().apply { | ||
id = entity.id!! | ||
accountNo = entity.accountNo | ||
fullname = entity.fullname | ||
firstname = entity.displayName!!.split(" ")[0] | ||
lastname = | ||
if (entity.displayName!!.split(" ").size >= 2) entity.displayName!!.split(" ")[1] else "" | ||
displayName = entity.displayName | ||
officeId = entity.officeId!! | ||
officeName = entity.officeName | ||
active = entity.active!! | ||
status = Status().apply { | ||
id = entity.status?.id!! | ||
code = entity.status?.code | ||
value = entity.status?.description | ||
} | ||
} | ||
} | ||
|
||
override fun mapToEntity(domainModel: Client): GetClientsPageItemsResponse { | ||
return GetClientsPageItemsResponse().apply { | ||
id = domainModel.id | ||
accountNo = domainModel.accountNo | ||
fullname = domainModel.fullname | ||
displayName = domainModel.displayName | ||
officeId = domainModel.officeId | ||
officeName = domainModel.officeName | ||
active = domainModel.active | ||
status = GetClientStatus().apply { | ||
id = domainModel.status?.id | ||
code = domainModel.status?.code | ||
description = domainModel.status?.value | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientResponseMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mifos.core.network.mappers.clients | ||
|
||
import com.mifos.core.common.utils.Page | ||
import com.mifos.core.data.model.client.Client | ||
import org.apache.fineract.client.models.GetClientsResponse | ||
import org.mifos.core.data.AbstractMapper | ||
|
||
object GetClientResponseMapper : AbstractMapper<GetClientsResponse, Page<Client>>() { | ||
|
||
override fun mapFromEntity(entity: GetClientsResponse): Page<Client> { | ||
return Page<Client>().apply { | ||
totalFilteredRecords = entity.totalFilteredRecords!! | ||
pageItems = ClientMapper.mapFromEntityList(entity.pageItems!!) | ||
} | ||
} | ||
|
||
override fun mapToEntity(domainModel: Page<Client>): GetClientsResponse { | ||
return GetClientsResponse().apply { | ||
totalFilteredRecords = domainModel.totalFilteredRecords | ||
pageItems = ClientMapper.mapToEntityList(domainModel.pageItems) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...in/java/com/mifos/feature/client/clientList/data/repositoryImp/ClientListRepositoryImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.mifos.feature.client.clientList.data.repositoryImp | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import androidx.paging.PagingData | ||
import com.mifos.core.common.utils.Page | ||
import com.mifos.core.data.model.client.Client | ||
import com.mifos.core.network.datamanger.DataManagerClient | ||
import com.mifos.feature.client.clientList.domain.repository.ClientListRepository | ||
import com.mifos.feature.client.clientList.paging.ClientListPagingSource | ||
import kotlinx.coroutines.flow.Flow | ||
import rx.Observable | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Created by Aditya Gupta on 08/08/23. | ||
*/ | ||
class ClientListRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) : | ||
ClientListRepository { | ||
|
||
override fun getAllClients(): Flow<PagingData<Client>> { | ||
return Pager( | ||
config = PagingConfig( | ||
pageSize = 10 | ||
), pagingSourceFactory = { | ||
ClientListPagingSource(dataManagerClient) | ||
} | ||
).flow | ||
} | ||
|
||
override fun allDatabaseClients(): Observable<Page<Client>> { | ||
return dataManagerClient.allDatabaseClients | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
feature/client/src/main/java/com/mifos/feature/client/clientList/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mifos.feature.client.clientList.di | ||
|
||
import com.mifos.core.network.datamanger.DataManagerClient | ||
import com.mifos.feature.client.clientList.data.repositoryImp.ClientListRepositoryImp | ||
import com.mifos.feature.client.clientList.domain.repository.ClientListRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object RepositoryModule { | ||
|
||
@Singleton | ||
@Provides | ||
fun provideClientListRepository(dataManagerClient: DataManagerClient): ClientListRepository = | ||
ClientListRepositoryImp(dataManagerClient) | ||
|
||
} |
Oops, something went wrong.