Skip to content

Commit

Permalink
fix code smells
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Feb 14, 2024
1 parent a36c75a commit 0f88845
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 41 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public interface View extends AbstractActivityContracts.View {

void showTabsAndEnableSwipe();

void updateStatus();

void displayStatusError(StatusChangeResultCode statusCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,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)
Expand Down Expand Up @@ -629,9 +624,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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class TeiDashboardModule(
): TeiDashboardContracts.Presenter {
return TeiDashboardPresenter(
view,
teiUid,
programUid,
dashboardRepository,
schedulerProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -186,9 +186,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,7 +20,6 @@ class TEIDataContracts {
fun setEvents(events: List<EventViewModel>)
fun displayGenerateEvent(): Consumer<ProgramStage>
fun areEventsCompleted(): Consumer<Single<Boolean>>
fun enrollmentCompleted(): Consumer<EnrollmentStatus>
fun switchFollowUp(followUp: Boolean)
fun displayGenerateEvent(eventUid: String)
fun restoreAdapter(programUid: String, teiUid: String, enrollmentUid: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
}
}

override fun enrollmentCompleted(): Consumer<EnrollmentStatus> {
return Consumer { enrollmentStatus ->
if (enrollmentStatus == EnrollmentStatus.COMPLETED) dashboardActivity.updateStatus()
}
}

override fun viewLifecycleOwner(): LifecycleOwner {
return this.viewLifecycleOwner
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class TeiDashboardPresenterTest {
fun setup() {
presenter = TeiDashboardPresenter(
view,
teiUid,
programUid,
repository,
schedulers,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0f88845

Please sign in to comment.