Skip to content

Commit

Permalink
Merge pull request #129 from opensrp/translation-fix
Browse files Browse the repository at this point in the history
Translation fix
  • Loading branch information
hamza-vd authored Jun 29, 2021
2 parents f017442 + 1188d30 commit 53dd9bf
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
20 changes: 19 additions & 1 deletion opensrp-unicef-tunisia/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,14 @@ dependencies {
implementation "androidx.cardview:cardview:1.0.0"

// implementation(project(':opensrp-child')) {
implementation('org.smartregister:opensrp-client-child:0.7.0-ALPHA4-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-child:0.7.0-ALPHA5-SNAPSHOT@aar') {
transitive = true
exclude group: 'id.zelory', module: 'compressor'
exclude group: 'org.smartregister', module: 'opensrp-client-growth-monitoring'
exclude group: 'org.smartregister', module: 'opensrp-client-immunization'
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'org.smartregister', module: 'opensrp-client-reporting'
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'io.ona.rdt-capture', module: 'lib'
Expand All @@ -261,6 +262,7 @@ dependencies {
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'com.ibm.fhir', module: 'fhir-model'
exclude group: 'com.ibm.fhir', module: 'fhir-path'
}
Expand All @@ -271,6 +273,7 @@ dependencies {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'support-media-compat'
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'com.android.support', module: 'cardview-v7'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.ibm.fhir', module: 'fhir-model'
Expand All @@ -296,11 +299,26 @@ dependencies {
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.github.lecho', module: 'hellocharts-library'
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.ibm.fhir', module: 'fhir-model'
exclude group: 'com.ibm.fhir', module: 'fhir-path'
}

implementation('org.smartregister:opensrp-client-native-form:2.1.0-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'cardview-v7'
exclude group: 'io.ona.rdt-capture', module: 'lib'
exclude group: 'com.google.android.gms', module: 'play-services-vision'
exclude group: 'com.google.code.gson', module: 'gson'
exclude group: 'com.simprints', module: 'libsimprints'
exclude group: 'com.ibm.fhir', module: 'fhir-model'
}

implementation('com.google.android.material:material:1.2.1') {
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'cardview-v7'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package org.smartregister.uniceftunisia.application;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatDelegate;

import com.evernote.android.job.JobManager;
import com.google.firebase.crashlytics.FirebaseCrashlytics;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.smartregister.Context;
import org.smartregister.CoreLibrary;
import org.smartregister.child.ChildLibrary;
Expand Down Expand Up @@ -69,7 +75,7 @@

import timber.log.Timber;

public class UnicefTunisiaApplication extends DrishtiApplication implements TimeChangedBroadcastReceiver.OnTimeChangedListener {
public class UnicefTunisiaApplication extends DrishtiApplication implements TimeChangedBroadcastReceiver.OnTimeChangedListener, Application.ActivityLifecycleCallbacks {

private static List<VaccineGroup> vaccineGroups;
private static CommonFtsObject commonFtsObject;
Expand Down Expand Up @@ -212,6 +218,7 @@ public void onCreate() {
super.onCreate();
mInstance = this;
context = Context.getInstance();
registerActivityLifecycleCallbacks(this);

context.updateApplicationContext(getApplicationContext());
context.updateCommonFtsObject(createCommonFtsObject(context.applicationContext()));
Expand Down Expand Up @@ -439,5 +446,53 @@ public ChildAlertUpdatedRepository alertUpdatedRepository() {
}
return this.childAlertUpdatedRepository;
}

private Activity currentActivity;

@Override
public void onActivityCreated(@NonNull @NotNull Activity activity, @Nullable @org.jetbrains.annotations.Nullable Bundle bundle) {

}

@Override
public void onActivityStarted(@NonNull @NotNull Activity activity) {

}

@Override
public void onActivityResumed(Activity activity){
this.currentActivity = activity;
}

@Override
public void onActivityPaused(Activity activity){
if(this.currentActivity == activity)
this.currentActivity = null;
}

@Override
public void onActivityStopped(@NonNull @NotNull Activity activity) {

}

@Override
public void onActivitySaveInstanceState(@NonNull @NotNull Activity activity, @NonNull @NotNull Bundle bundle) {

}

@Override
public void onActivityDestroyed(@NonNull @NotNull Activity activity) {

}


public Activity getCurrentActivity(){
return this.currentActivity;
}

@TestOnly
public void setCurrentActivity(Activity activity) {
this.currentActivity = activity;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ class AnnualReportRepository : BaseRepository() {
vaccineTarget: String, year: Int): MutableList<VaccineCoverage> {
val vaccineCoverages = mutableListOf<VaccineCoverage>()
vaccineSet.forEach {
val vaccine = VaccinatorUtils.getTranslatedVaccineName(context, it)
val vaccine = VaccinatorUtils.getTranslatedVaccineName(UnicefTunisiaApplication.getInstance().currentActivity, it)
val translatedVaccineName =
if (vaccine == it) context.getString(it.getResourceId(context)) else vaccine
val errorNoTarget = context.getString(R.string.error_no_target)
val targetEmpty = vaccineTarget.isEmpty()
var vaccinated = "0"
var coverage = if (targetEmpty) errorNoTarget else 0.toString().plus("%")
var coverage = if (targetEmpty) errorNoTarget else (context.getString(R.string.percentage_sign, 0.toString()))

if (vaccineCountsMap.containsKey(it)) {
val vaccineCount = vaccineCountsMap.getValue(it)
vaccinated = vaccineCount.count.toString()
coverage = if (targetEmpty) errorNoTarget
else ((vaccineCount.count / vaccineTarget.toDouble()) * 100).toWholeNumber().toString().plus("%")
else context.getString(R.string.percentage_sign, ((vaccineCount.count / vaccineTarget.toDouble()) * 100).toWholeNumber().toString())
}

val vaccineCoverage = VaccineCoverage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:layout_marginBottom="16dp"
android:layout_weight="1.2"
android:text="@string/vaccine"
android:textAlignment="textStart"
android:textAlignment="viewStart"
android:textColor="@color/black_text_color"
android:textSize="@dimen/report_item_text_size" />

Expand Down
1 change: 1 addition & 0 deletions opensrp-unicef-tunisia/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,5 @@
<string name="generating_daily_tallies_completed">Generating daily tallies completed</string>
<!-- Card support strings -->
<string name="opensrp_id">IDV NUMBER</string>
<string name="percentage_sign">%1$s\%%</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.smartregister.uniceftunisia.reporting.annual.coverage.repository

import io.mockk.every
import io.mockk.mockkObject
import io.mockk.spyk
import io.mockk.unmockkAll
import io.mockk.*
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
Expand All @@ -13,6 +10,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.smartregister.uniceftunisia.TestUnicefTunisiaApplication
import org.smartregister.uniceftunisia.application.UnicefTunisiaApplication
import org.smartregister.uniceftunisia.reporting.ReportsDao
import org.smartregister.uniceftunisia.reporting.annual.coverage.domain.CoverageTarget
import org.smartregister.uniceftunisia.reporting.annual.coverage.domain.CoverageTargetType
Expand All @@ -36,6 +34,7 @@ class AnnualReportRepositoryTest {

@Test
fun `Should return the right vaccine coverages`() {
UnicefTunisiaApplication.getInstance().currentActivity = mockk(relaxed = true)
every { ReportsDao.getCoverageTarget(2020) } returns
listOf(
CoverageTarget(CoverageTargetType.UNDER_ONE_TARGET, 2020, 20),
Expand All @@ -59,6 +58,7 @@ class AnnualReportRepositoryTest {
assertEquals( "20%", opv2.coverage )
assertEquals( "2020", opv2.year )
assertEquals( "10", opv2.vaccinated )
UnicefTunisiaApplication.getInstance().currentActivity = null
}

@Test
Expand Down

0 comments on commit 53dd9bf

Please sign in to comment.