From 79b5cc501c8034ba1fcf1e76edb8172af280ad97 Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 9 Feb 2024 10:15:17 +0100 Subject: [PATCH] fix code smells Signed-off-by: Pablo --- app/build.gradle.kts | 1 - .../teiDashboard/TeiDashboardContracts.java | 2 -- .../teiDashboard/TeiDashboardMobileActivity.kt | 8 -------- .../usescases/teiDashboard/TeiDashboardModule.kt | 1 - .../teiDashboard/TeiDashboardPresenter.java | 6 ++---- .../dashboardfragments/teidata/TEIDataContracts.kt | 2 -- .../dashboardfragments/teidata/TEIDataFragment.kt | 6 ------ .../dashboardfragments/teidata/TEIDataPresenter.kt | 8 +++++--- .../teiDashboard/TeiDashboardPresenterTest.kt | 13 ------------- build.gradle.kts | 1 + gradle/libs.versions.toml | 2 +- 11 files changed, 9 insertions(+), 41 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1057264be8..6f9ff04def 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -255,7 +255,6 @@ dependencies { implementation(libs.analytics.customactivityoncrash) implementation(platform(libs.dispatcher.dispatchBOM)) implementation(libs.dispatcher.dispatchCore) - implementation(libs.dhis2.mobile.designsystem) coreLibraryDesugaring(libs.desugar) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java index 645066c482..f15ad4237d 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java @@ -26,8 +26,6 @@ public interface View extends AbstractActivityContracts.View { void showTabsAndEnableSwipe(); - void updateStatus(); - void displayStatusError(StatusChangeResultCode statusCode); } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index da4c7fb462..e2237db418 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -187,11 +187,6 @@ class TeiDashboardMobileActivity : dashboardViewModel.showStatusErrorMessages.observe(this) { displayStatusError(it) } - dashboardViewModel.updateEnrollment.observe(this) { - if (it) { - updateStatus() - } - } dashboardViewModel.dashboardModel.observe(this) { when (it) { is DashboardEnrollmentModel -> setData(it) @@ -618,9 +613,6 @@ class TeiDashboardMobileActivity : ViewCompat.setElevation(binding.toolbar, elevation) } - override fun updateStatus() { - } - override fun displayStatusError(statusCode: StatusChangeResultCode) { when (statusCode) { StatusChangeResultCode.FAILED -> displayMessage(getString(R.string.something_wrong)) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardModule.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardModule.kt index 651c9c7681..386d063420 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardModule.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardModule.kt @@ -42,7 +42,6 @@ class TeiDashboardModule( ): TeiDashboardContracts.Presenter { return TeiDashboardPresenter( view, - teiUid, programUid, dashboardRepository, schedulerProvider, diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java index 76f0f76bb0..080ab925ec 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java @@ -36,7 +36,7 @@ public class TeiDashboardPresenter implements TeiDashboardContracts.Presenter { public TeiDashboardPresenter( TeiDashboardContracts.View view, - String teiUid, String programUid, + String programUid, DashboardRepository dashboardRepository, SchedulerProvider schedulerProvider, AnalyticsHelper analyticsHelper, @@ -176,9 +176,7 @@ public void updateEnrollmentStatus(String enrollmentUid, EnrollmentStatus status .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.ui()) .subscribe(statusCode -> { - if (statusCode == StatusChangeResultCode.CHANGED) { - view.updateStatus(); - } else { + if (statusCode != StatusChangeResultCode.CHANGED) { view.displayStatusError(statusCode); } }, Timber::e) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt index 5a0c408e8c..64ace14afd 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt @@ -11,7 +11,6 @@ import org.dhis2.commons.data.EventViewModel import org.dhis2.commons.data.StageSection import org.dhis2.usescases.general.AbstractActivityContracts import org.hisp.dhis.android.core.enrollment.Enrollment -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus import org.hisp.dhis.android.core.program.Program import org.hisp.dhis.android.core.program.ProgramStage @@ -21,7 +20,6 @@ class TEIDataContracts { fun setEvents(events: List) fun displayGenerateEvent(): Consumer fun areEventsCompleted(): Consumer> - fun enrollmentCompleted(): Consumer fun switchFollowUp(followUp: Boolean) fun displayGenerateEvent(eventUid: String) fun restoreAdapter(programUid: String, teiUid: String, enrollmentUid: String) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index 315a1ba54e..f06e41d02d 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -375,12 +375,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { } } - override fun enrollmentCompleted(): Consumer { - return Consumer { enrollmentStatus -> - if (enrollmentStatus == EnrollmentStatus.COMPLETED) dashboardActivity.updateStatus() - } - } - override fun viewLifecycleOwner(): LifecycleOwner { return this.viewLifecycleOwner } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt index f8e3cc2985..c7eada9f94 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt @@ -7,6 +7,7 @@ import androidx.annotation.VisibleForTesting import androidx.core.app.ActivityOptionsCompat import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Observable import io.reactivex.Single @@ -244,12 +245,13 @@ class TEIDataPresenter( if (hasWriteAccessInProgram) { compositeDisposable.add( - dashboardRepository.completeEnrollment(enrollmentUid) + Completable.fromCallable { + dashboardRepository.completeEnrollment(enrollmentUid).blockingFirst() + } .subscribeOn(schedulerProvider.computation()) .observeOn(schedulerProvider.ui()) - .map { obj -> obj.status() ?: EnrollmentStatus.ACTIVE } .subscribe( - view.enrollmentCompleted(), + {}, Timber.Forest::d, ), ) diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt index 3fb3f0488a..eaee8a1cbf 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt @@ -47,7 +47,6 @@ class TeiDashboardPresenterTest { fun setup() { presenter = TeiDashboardPresenter( view, - teiUid, programUid, repository, schedulers, @@ -182,18 +181,6 @@ class TeiDashboardPresenterTest { verify(repository).getEnrollmentStatus(any()) } - @Test - fun `Should update the status of the enrollment`() { - whenever( - repository.updateEnrollmentStatus("uid", EnrollmentStatus.COMPLETED), - ) doReturn Observable.just(StatusChangeResultCode.CHANGED) - - presenter.updateEnrollmentStatus("uid", EnrollmentStatus.COMPLETED) - - verify(view).updateStatus() - verifyNoMoreInteractions(view) - } - @Test fun `Should show error message when updating the status of the enrollment returns an error`() { whenever( diff --git a/build.gradle.kts b/build.gradle.kts index 05802d5843..b1783fea56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,6 +51,7 @@ val isNonStable: (String) -> Boolean = { version -> allprojects { configurations.all { resolutionStrategy { + cacheDynamicVersionsFor(0, TimeUnit.SECONDS) eachDependency { if (requested.group == "org.jacoco") useVersion("0.8.10") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 06b1bb0691..16219d1544 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ kotlin = '1.9.21' hilt = '2.47' hiltCompiler = '1.0.0' jacoco = '0.8.10' -designSystem = "0.2-20240208.105715-18" +designSystem = "0.2-20240208.162422-19" dhis2sdk = "1.10.0-20240129.132841-8" ruleEngine = "2.1.9" appcompat = "1.6.1"