From beece85c88083f17e1b0a60c5edcc34b377b966e Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 19 Aug 2023 00:02:38 +0530 Subject: [PATCH] Updated PrefManger --- .../main/java/com/mifos/api/BaseApiManager.kt | 4 +- .../java/com/mifos/api/MifosInterceptor.kt | 8 +- .../mifos/api/datamanager/DataManagerAuth.kt | 7 +- .../api/datamanager/DataManagerCenter.kt | 18 +- .../api/datamanager/DataManagerCharge.kt | 6 +- .../api/datamanager/DataManagerClient.kt | 34 +-- .../api/datamanager/DataManagerGroups.kt | 30 +-- .../mifos/api/datamanager/DataManagerLoan.kt | 18 +- .../api/datamanager/DataManagerOffices.kt | 9 +- .../api/datamanager/DataManagerSavings.kt | 22 +- .../mifos/api/datamanager/DataManagerStaff.kt | 9 +- .../api/datamanager/DataManagerSurveys.kt | 8 +- .../com/mifos/mifosxdroid/HomeActivity.kt | 2 +- .../com/mifos/mifosxdroid/SettingsFragment.kt | 11 +- .../mifos/mifosxdroid/SplashScreenActivity.kt | 4 +- .../pathtracking/PathTrackingActivity.kt | 21 +- .../pathtracking/PathTrackingService.kt | 9 +- .../mifosxdroid/core/MifosBaseActivity.kt | 4 +- .../injection/module/ApplicationModule.kt | 14 +- .../SyncCenterPayloadsFragment.kt | 5 +- .../SyncClientPayloadsFragment.kt | 5 +- .../SyncGroupPayloadsFragment.kt | 5 +- .../SyncLoanRepaymentTransactionFragment.kt | 5 +- .../SyncSavingsAccountTransactionFragment.kt | 5 +- .../offlinejobs/OfflineSyncCenter.kt | 2 +- .../offlinejobs/OfflineSyncClient.kt | 2 +- .../offlinejobs/OfflineSyncGroup.kt | 2 +- .../offlinejobs/OfflineSyncLoanRepayment.kt | 2 +- .../offlinejobs/OfflineSyncSavingsAccount.kt | 2 +- .../online/SurveyQuestionActivity.kt | 2 +- .../com/mifos/ui/activities/LoginActivity.kt | 28 +-- .../utils/CheckSelfPermissionAndRequest.kt | 8 +- .../main/java/com/mifos/utils/Constants.kt | 4 +- .../java/com/mifos/utils/ImageLoaderUtils.kt | 9 +- .../com/mifos/utils/MifosResponseHandler.kt | 5 +- .../main/java/com/mifos/utils/PrefManager.kt | 205 +++--------------- .../com/mifos/viewmodels/LoginViewModel.kt | 2 + .../mifos/viewmodels/SurveyListViewModel.kt | 2 +- 38 files changed, 159 insertions(+), 379 deletions(-) diff --git a/mifosng-android/src/main/java/com/mifos/api/BaseApiManager.kt b/mifosng-android/src/main/java/com/mifos/api/BaseApiManager.kt index 27326c0e2c3..fa83717609f 100644 --- a/mifosng-android/src/main/java/com/mifos/api/BaseApiManager.kt +++ b/mifosng-android/src/main/java/com/mifos/api/BaseApiManager.kt @@ -23,7 +23,7 @@ import com.mifos.api.services.SearchService import com.mifos.api.services.StaffService import com.mifos.api.services.SurveyService import com.mifos.utils.JsonDateSerializer -import com.mifos.utils.PrefManager.instanceUrl +import com.mifos.utils.PrefManager import retrofit2.Retrofit import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory import retrofit2.converter.gson.GsonConverterFactory @@ -155,7 +155,7 @@ class BaseApiManager { val gson = GsonBuilder() .registerTypeAdapter(Date::class.java, JsonDateSerializer()).create() mRetrofit = Retrofit.Builder() - .baseUrl(instanceUrl) + .baseUrl(PrefManager.getInstanceUrl()) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) diff --git a/mifosng-android/src/main/java/com/mifos/api/MifosInterceptor.kt b/mifosng-android/src/main/java/com/mifos/api/MifosInterceptor.kt index 3d43567caf1..c408a58d6d7 100644 --- a/mifosng-android/src/main/java/com/mifos/api/MifosInterceptor.kt +++ b/mifosng-android/src/main/java/com/mifos/api/MifosInterceptor.kt @@ -4,9 +4,7 @@ */ package com.mifos.api -import com.mifos.utils.PrefManager.isAuthenticated -import com.mifos.utils.PrefManager.tenant -import com.mifos.utils.PrefManager.token +import com.mifos.utils.PrefManager import okhttp3.Interceptor import okhttp3.Response import java.io.IOException @@ -19,8 +17,8 @@ class MifosInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val chianrequest = chain.request() val builder = chianrequest.newBuilder() - .header(HEADER_TENANT, tenant) - if (isAuthenticated) builder.header(HEADER_AUTH, token) + .header(HEADER_TENANT, PrefManager.getTenant()) + if (PrefManager.isAuthenticated()) builder.header(HEADER_AUTH, PrefManager.getToken()) val request = builder.build() return chain.proceed(request) } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerAuth.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerAuth.kt index ab94e8b202a..aaecdb9363b 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerAuth.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerAuth.kt @@ -18,9 +18,10 @@ class DataManagerAuth @Inject constructor(private val baseApiManager: BaseApiMan * @return Basic OAuth */ fun login(username: String, password: String): Observable { - val body = PostAuthenticationRequest() - body.username = username - body.password = password + val body = PostAuthenticationRequest().apply { + this.username = username + this.password = password + } return baseApiManager.getAuthApi().authenticate(body, true) } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCenter.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCenter.kt index 736269f1232..fd07bae59db 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCenter.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCenter.kt @@ -45,8 +45,8 @@ class DataManagerCenter @Inject constructor( */ fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> { return when (userStatus) { - 0 -> mBaseApiManager.centerApi.getCenters(paged, offset, limit) - 1 -> { + false -> mBaseApiManager.centerApi.getCenters(paged, offset, limit) + true -> { /** * Return All Centers List from DatabaseHelperCenter only one time. * If offset is zero this means this is first request and @@ -54,8 +54,6 @@ class DataManagerCenter @Inject constructor( */ if (offset == 0) mDatabaseHelperCenter.readAllCenters() else Observable.just(Page()) } - - else -> Observable.just(Page()) } } @@ -102,14 +100,12 @@ class DataManagerCenter @Inject constructor( fun createCenter(centerPayload: CenterPayload): Observable { return when (userStatus) { - 0 -> mBaseApiManager.centerApi.createCenter(centerPayload) - 1 -> + false -> mBaseApiManager.centerApi.createCenter(centerPayload) + true -> /** * Save CenterPayload in Database table. */ mDatabaseHelperCenter.saveCenterPayload(centerPayload) - - else -> Observable.just(SaveResponse()) } } @@ -120,14 +116,12 @@ class DataManagerCenter @Inject constructor( */ fun getCenterWithAssociations(centerId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.centerApi.getAllGroupsForCenter(centerId) - 1 -> + false -> mBaseApiManager.centerApi.getAllGroupsForCenter(centerId) + true -> /** * Return Groups from DatabaseHelperGroups. */ mDatabaseHelperCenter.getCenterAssociateGroups(centerId) - - else -> Observable.just(CenterWithAssociations()) } } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCharge.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCharge.kt index 44e2909d1a6..c7a41e26fc8 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCharge.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCharge.kt @@ -35,13 +35,13 @@ class DataManagerCharge @Inject constructor( */ fun getClientCharges(clientId: Int, offset: Int, limit: Int): Observable> { return when (userStatus) { - 0 -> mBaseApiManager.chargeApi.getListOfCharges(clientId, offset, limit) + false -> mBaseApiManager.chargeApi.getListOfCharges(clientId, offset, limit) .concatMap { chargesPage -> mDatabaseHelperCharge.saveClientCharges(chargesPage, clientId) Observable.just(chargesPage) } - 1 -> { + true -> { /** * Return Client Charges from DatabaseHelperClient only one time. */ @@ -49,8 +49,6 @@ class DataManagerCharge @Inject constructor( Page() ) } - - else -> Observable.just(Page()) } } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerClient.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerClient.kt index 87cfc6ae42e..713563d69b4 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerClient.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerClient.kt @@ -19,7 +19,6 @@ import com.mifos.utils.PrefManager.userStatus import okhttp3.MultipartBody import okhttp3.ResponseBody import rx.Observable -import rx.functions.Func1 import javax.inject.Inject import javax.inject.Singleton @@ -31,7 +30,8 @@ import javax.inject.Singleton @Singleton class DataManagerClient @Inject constructor( val mBaseApiManager: BaseApiManager, - val mDatabaseHelperClient: DatabaseHelperClient + val mDatabaseHelperClient: DatabaseHelperClient, + private val baseApiManager: org.mifos.core.apimanager.BaseApiManager ) { /** * This Method sending the Request to REST API if UserStatus is 0 and @@ -51,10 +51,10 @@ class DataManagerClient @Inject constructor( */ fun getAllClients(paged: Boolean, offset: Int, limit: Int): Observable> { return when (userStatus) { - 0 -> mBaseApiManager.clientsApi.getAllClients(paged, offset, limit) + false -> mBaseApiManager.clientsApi.getAllClients(paged, offset, limit) .concatMap { clientPage -> Observable.just(clientPage) } - 1 -> { + true -> { /** * Return All Clients List from DatabaseHelperClient only one time. * If offset is zero this means this is first request and @@ -62,8 +62,6 @@ class DataManagerClient @Inject constructor( */ if (offset == 0) mDatabaseHelperClient.readAllClients() else Observable.just(Page()) } - - else -> Observable.just(Page()) } } @@ -84,16 +82,14 @@ class DataManagerClient @Inject constructor( */ fun getClient(clientId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.clientsApi.getClient(clientId) + false -> mBaseApiManager.clientsApi.getClient(clientId) .concatMap { client -> Observable.just(client) } - 1 -> + true -> /** * Return Clients from DatabaseHelperClient only one time. */ mDatabaseHelperClient.getClient(clientId) - - else -> Observable.just(Client()) } } @@ -114,14 +110,12 @@ class DataManagerClient @Inject constructor( */ fun getClientAccounts(clientId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.clientsApi.getClientAccounts(clientId) - 1 -> + false -> mBaseApiManager.clientsApi.getClientAccounts(clientId) + true -> /** * Return Clients from DatabaseHelperClient only one time. */ mDatabaseHelperClient.realClientAccounts(clientId) - - else -> Observable.just(ClientAccounts()) } } @@ -181,14 +175,14 @@ class DataManagerClient @Inject constructor( */ val clientTemplate: Observable get() = when (userStatus) { - 0 -> mBaseApiManager.clientsApi.clientTemplate + false -> mBaseApiManager.clientsApi.clientTemplate .concatMap { clientsTemplate -> mDatabaseHelperClient.saveClientTemplate( clientsTemplate ) } - 1 -> + true -> /** * Return Clients from DatabaseHelperClient only one time. */ @@ -196,8 +190,6 @@ class DataManagerClient @Inject constructor( * Return Clients from DatabaseHelperClient only one time. */ mDatabaseHelperClient.readClientTemplate() - - else -> Observable.just(ClientsTemplate()) } /** @@ -210,17 +202,15 @@ class DataManagerClient @Inject constructor( */ fun createClient(clientPayload: ClientPayload): Observable { return when (userStatus) { - 0 -> mBaseApiManager.clientsApi.createClient(clientPayload) + false -> mBaseApiManager.clientsApi.createClient(clientPayload) .concatMap { client -> Observable.just(client) } - 1 -> + true -> /** * If user is in offline mode and he is making client. client payload will be saved * in Database for future synchronization to sever. */ mDatabaseHelperClient.saveClientPayloadToDB(clientPayload) - - else -> Observable.just(Client()) } } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerGroups.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerGroups.kt index f46be37e2b8..e9c8aab3c78 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerGroups.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerGroups.kt @@ -46,8 +46,8 @@ class DataManagerGroups @Inject constructor( */ fun getGroups(paged: Boolean, offset: Int, limit: Int): Observable> { return when (userStatus) { - 0 -> mBaseApiManager.groupApi.getGroups(paged, offset, limit) - 1 -> { + false -> mBaseApiManager.groupApi.getGroups(paged, offset, limit) + true -> { /** * offset : is the value from which position we want to fetch the list, It means * if offset is 0 and User is in the Offline Mode So fetch all groups @@ -59,8 +59,6 @@ class DataManagerGroups @Inject constructor( Page() ) } - - else -> Observable.just(Page()) } } @@ -82,14 +80,12 @@ class DataManagerGroups @Inject constructor( */ fun getGroup(groupId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.groupApi.getGroup(groupId) - 1 -> + false -> mBaseApiManager.groupApi.getGroup(groupId) + true -> /** * Return Groups from DatabaseHelperGroups. */ mDatabaseHelperGroups.getGroup(groupId) - - else -> Observable.just(Group()) } } @@ -110,14 +106,12 @@ class DataManagerGroups @Inject constructor( */ fun getGroupWithAssociations(groupId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.groupApi.getGroupWithAssociations(groupId) - 1 -> + false -> mBaseApiManager.groupApi.getGroupWithAssociations(groupId) + true -> /** * Return Groups from DatabaseHelperGroups. */ mDatabaseHelperClient.getGroupAssociateClients(groupId) - - else -> Observable.just(GroupWithAssociations()) } } @@ -130,14 +124,12 @@ class DataManagerGroups @Inject constructor( */ fun getGroupAccounts(groupId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.groupApi.getGroupAccounts(groupId) - 1 -> + false -> mBaseApiManager.groupApi.getGroupAccounts(groupId) + true -> /** * Return Groups from DatabaseHelperGroups. */ mDatabaseHelperGroups.readGroupAccounts(groupId) - - else -> Observable.just(GroupAccounts()) } } @@ -167,14 +159,12 @@ class DataManagerGroups @Inject constructor( */ fun createGroup(groupPayload: GroupPayload): Observable { return when (userStatus) { - 0 -> mBaseApiManager.groupApi.createGroup(groupPayload) - 1 -> + false -> mBaseApiManager.groupApi.createGroup(groupPayload) + true -> /** * Save GroupPayload in Database table. */ mDatabaseHelperGroups.saveGroupPayload(groupPayload) - - else -> Observable.just(SaveResponse()) } } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerLoan.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerLoan.kt index 1a3857a3d35..afdf89bcdb8 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerLoan.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerLoan.kt @@ -43,14 +43,12 @@ class DataManagerLoan @Inject constructor( */ fun getLoanById(loanId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.loanApi.getLoanByIdWithAllAssociations(loanId) - 1 -> + false -> mBaseApiManager.loanApi.getLoanByIdWithAllAssociations(loanId) + true -> /** * Return LoanWithAssociation from DatabaseHelperLoan. */ mDatabaseHelperLoan.getLoanById(loanId) - - else -> Observable.just(LoanWithAssociations()) } } @@ -105,14 +103,12 @@ class DataManagerLoan @Inject constructor( */ fun getLoanRepayTemplate(loanId: Int): Observable { return when (userStatus) { - 0 -> mBaseApiManager.loanApi.getLoanRepaymentTemplate(loanId) - 1 -> + false -> mBaseApiManager.loanApi.getLoanRepaymentTemplate(loanId) + true -> /** * Return LoanRepaymentTemplate from DatabaseHelperLoan. */ mDatabaseHelperLoan.getLoanRepayTemplate(loanId) - - else -> Observable.just(LoanRepaymentTemplate()) } } @@ -158,16 +154,14 @@ class DataManagerLoan @Inject constructor( request: LoanRepaymentRequest ): Observable { return when (userStatus) { - 0 -> mBaseApiManager.loanApi.submitPayment(loanId, request) + false -> mBaseApiManager.loanApi.submitPayment(loanId, request) .concatMap { loanRepaymentResponse -> Observable.just(loanRepaymentResponse) } - 1 -> + true -> /** * Return LoanRepaymentResponse from DatabaseHelperLoan. */ mDatabaseHelperLoan.saveLoanRepaymentTransaction(loanId, request) - - else -> Observable.just(LoanRepaymentResponse()) } } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerOffices.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerOffices.kt index c0e40012f6c..38464534afa 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerOffices.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerOffices.kt @@ -25,13 +25,13 @@ class DataManagerOffices @Inject constructor( */ val offices: Observable> get() = when (userStatus) { - 0 -> mBaseApiManager.officeApi.allOffices + false -> mBaseApiManager.officeApi.allOffices .concatMap { offices -> mDatabaseHelperOffices.saveAllOffices(offices) Observable.just(offices) } - 1 -> + true -> /** * return all List of Offices from DatabaseHelperOffices */ @@ -39,10 +39,5 @@ class DataManagerOffices @Inject constructor( * return all List of Offices from DatabaseHelperOffices */ mDatabaseHelperOffices.readAllOffices() - - else -> { - val offices: List = ArrayList() - Observable.just(offices) - } } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSavings.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSavings.kt index 7d0d4c90205..e74d0acfa5d 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSavings.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSavings.kt @@ -45,17 +45,15 @@ class DataManagerSavings @Inject constructor( type: String?, savingsAccountId: Int, association: String? ): Observable { return when (userStatus) { - 0 -> mBaseApiManager.savingsApi.getSavingsAccountWithAssociations( + false -> mBaseApiManager.savingsApi.getSavingsAccountWithAssociations( type, savingsAccountId, association ) - 1 -> + true -> /** * Return SavingsAccountWithAssociations from DatabaseHelperSavings. */ mDatabaseHelperSavings.readSavingsAccount(savingsAccountId) - - else -> Observable.just(SavingsAccountWithAssociations()) } } @@ -115,20 +113,16 @@ class DataManagerSavings @Inject constructor( type: String?, savingsAccountId: Int, transactionType: String? ): Observable { return when (userStatus) { - 0 -> mBaseApiManager.savingsApi.getSavingsAccountTransactionTemplate( + false -> mBaseApiManager.savingsApi.getSavingsAccountTransactionTemplate( type, savingsAccountId, transactionType ) - 1 -> + true -> /** * Return SavingsAccountTransactionTemplate from DatabaseHelperSavings. */ mDatabaseHelperSavings.readSavingsAccountTransactionTemplate(savingsAccountId) - - else -> Observable.just( - SavingsAccountTransactionTemplate() - ) } } @@ -177,12 +171,12 @@ class DataManagerSavings @Inject constructor( request: SavingsAccountTransactionRequest ): Observable { return when (userStatus) { - 0 -> mBaseApiManager.savingsApi.processTransaction( + false -> mBaseApiManager.savingsApi.processTransaction( savingsAccountType, savingsAccountId, transactionType, request ) - 1 -> + true -> /** * Return SavingsAccountTransactionResponse from DatabaseHelperSavings. */ @@ -191,10 +185,6 @@ class DataManagerSavings @Inject constructor( savingsAccountType, savingsAccountId, transactionType, request ) - - else -> Observable.just( - SavingsAccountTransactionResponse() - ) } } diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerStaff.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerStaff.kt index 0941b5211fd..0551eb5aa56 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerStaff.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerStaff.kt @@ -23,22 +23,17 @@ class DataManagerStaff @Inject constructor( */ fun getStaffInOffice(officeId: Int): Observable> { return when (userStatus) { - 0 -> mBaseApiManager.staffApi.getStaffForOffice(officeId) + false -> mBaseApiManager.staffApi.getStaffForOffice(officeId) .concatMap { staffs -> mDatabaseHelperStaff.saveAllStaffOfOffices(staffs) Observable.just(staffs) } - 1 -> + true -> /** * return all List of Staffs of Office from DatabaseHelperOffices */ mDatabaseHelperStaff.readAllStaffOffices(officeId) - - else -> { - val staffs: List = ArrayList() - Observable.just(staffs) - } } } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSurveys.kt b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSurveys.kt index 9cb3f36eb46..2b8b568dec7 100644 --- a/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSurveys.kt +++ b/mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerSurveys.kt @@ -31,12 +31,8 @@ class DataManagerSurveys @Inject constructor( */ val allSurvey: Observable> get() = when (userStatus) { - 0 -> mBaseApiManager.surveyApi.allSurveys - 1 -> mDatabaseHelperSurveys.readAllSurveys() - else -> { - val defaultSurveyList: List = ArrayList() - Observable.just(defaultSurveyList) - } + false -> mBaseApiManager.surveyApi.allSurveys + true -> mDatabaseHelperSurveys.readAllSurveys() } /** diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeActivity.kt index 61e748f35cd..1f8e230775a 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeActivity.kt @@ -149,7 +149,7 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe */ private fun loadClientDetails() { // download logged in user - val loggedInUser = PrefManager.user + val loggedInUser = PrefManager.getUser() navHeaderBinding.tvUserName.text = loggedInUser.username navHeaderBinding.ivUserPicture.setImageResource(R.drawable.ic_dp_placeholder) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt index 2c2d51dc10b..9f0d3bebe3f 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SettingsFragment.kt @@ -4,7 +4,6 @@ package com.mifos.mifosxdroid import android.content.Intent import android.content.SharedPreferences -import android.os.Build import android.os.Bundle import androidx.preference.* import androidx.preference.Preference.OnPreferenceChangeListener @@ -60,7 +59,7 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP mInstanceUrlPref = (findPreference( requireContext().getString(R.string.hint_instance_url) ) as EditTextPreference?)!! - val instanceUrl = PrefManager.instanceUrl + val instanceUrl = PrefManager.getInstanceUrl() mInstanceUrlPref.text = instanceUrl mInstanceUrlPref.isSelectable = true mInstanceUrlPref.dialogTitle = "Edit Instance Url" @@ -69,14 +68,10 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP OnPreferenceChangeListener { _, o -> val newUrl = o.toString() if (newUrl != instanceUrl) { - PrefManager.instanceUrl = newUrl + PrefManager.setInstanceUrl(newUrl) Toast.makeText(activity, newUrl, Toast.LENGTH_SHORT).show() startActivity(Intent(activity, DashboardActivity::class.java)) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - activity?.finishAffinity() - } else { - activity?.finish() - } + activity?.finishAffinity() } true } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SplashScreenActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SplashScreenActivity.kt index a8efd3dacc1..c5d3c856c6f 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/SplashScreenActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/SplashScreenActivity.kt @@ -22,8 +22,8 @@ class SplashScreenActivity : MifosBaseActivity() { val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) splashScreen.setKeepOnScreenCondition { true } - if (!PrefManager.isAuthenticated) { - PrefManager.instanceUrl = (BaseUrl.PROTOCOL_HTTPS + if (!PrefManager.isAuthenticated()) { + PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS + BaseUrl.API_ENDPOINT + BaseUrl.API_PATH) startActivity(Intent(this@SplashScreenActivity, LoginActivity::class.java)) } else { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.kt index 1d62099e829..b463c929ef0 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.kt @@ -31,12 +31,9 @@ import com.mifos.objects.user.UserLocation import com.mifos.states.PathTrackingUiState import com.mifos.utils.CheckSelfPermissionAndRequest import com.mifos.utils.Constants -import com.mifos.utils.PrefManager.getBoolean -import com.mifos.utils.PrefManager.putBoolean -import com.mifos.utils.PrefManager.userId +import com.mifos.utils.PrefManager import com.mifos.viewmodels.PathTrackingViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject /** * @author fomenkoo @@ -62,7 +59,7 @@ class PathTrackingActivity : MifosBaseActivity(), OnRefreshListener { intentLocationService = Intent(this, PathTrackingService::class.java) createNotificationReceiver() showUserInterface() - viewModel.loadPathTracking(userId) + viewModel.loadPathTracking(PrefManager.getUserId()) binding.layoutError.findViewById