Skip to content

Commit

Permalink
Merge v5 branch changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-vd committed Jan 31, 2023
1 parent 398a1de commit 96bab65
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 83 deletions.
11 changes: 11 additions & 0 deletions opensrp-core/res/layout/fragment_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -343,6 +344,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -369,6 +371,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand Down Expand Up @@ -406,6 +409,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -432,6 +436,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -458,6 +463,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -483,6 +489,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand Down Expand Up @@ -520,6 +527,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -546,6 +554,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -571,6 +580,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand All @@ -596,6 +606,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAlignment="viewStart"
android:textColor="@color/text_black"
android:textSize="18sp" />

Expand Down
2 changes: 1 addition & 1 deletion opensrp-core/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
<string name="build_date">Build Date:</string>
<string name="date">Date:</string>
<string name="user">User:</string>
<string name="synced_vaccine_events">Unynced vaccine events:</string>
<string name="synced_vaccine_events">Unsynced vaccine events:</string>
<string name="unsynced_weight_events">Unsynced weight events:</string>
<string name="unsynced_height_events">Unsynced height events:</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public static class PROPERTY {
public static final String IGNORE_LOCATION_DELETION = "ignore.location.deletion";
public static final String ENABLE_SEARCH_BUTTON = "enable.search.button";
public static final String DISABLE_PROFILE_IMAGES_FEATURE = "feature.profile.images.disabled";
public static final String MONITOR_HEIGHT = "monitor.height";
}

public static class HTTP_REQUEST_HEADERS {
Expand Down
66 changes: 33 additions & 33 deletions opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;

import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.smartregister.AllConstants;
import org.smartregister.CoreLibrary;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.BaseRepository;
import org.smartregister.view.activity.DrishtiApplication;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -54,19 +52,19 @@ public StatsUtils() {
}

public Map<String, String> fetchStatsInfo() {
syncInfoMap.put(SYNCED_EVENTS, "0");
syncInfoMap.put(SYNCED_CLIENTS, "0");
syncInfoMap.put(UNSYNCED_EVENTS, "0");
syncInfoMap.put(UNSYNCED_CLIENTS, "0");
syncInfoMap.put(VALID_EVENTS, "0");
syncInfoMap.put(INVALID_EVENTS, "0");
syncInfoMap.put(VALID_CLIENTS, "0");
syncInfoMap.put(INVALID_CLIENTS, "0");
syncInfoMap.put(TASK_UNPROCESSED_EVENTS, "0");
syncInfoMap.put(NULL_EVENT_SYNC_STATUS, "0");
syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, "0");
syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, "0");
syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, "0");
syncInfoMap.put(SYNCED_EVENTS, "-");
syncInfoMap.put(SYNCED_CLIENTS, "-");
syncInfoMap.put(UNSYNCED_EVENTS, "-");
syncInfoMap.put(UNSYNCED_CLIENTS, "-");
syncInfoMap.put(VALID_EVENTS, "-");
syncInfoMap.put(INVALID_EVENTS, "-");
syncInfoMap.put(VALID_CLIENTS, "-");
syncInfoMap.put(INVALID_CLIENTS, "-");
syncInfoMap.put(TASK_UNPROCESSED_EVENTS, "-");
syncInfoMap.put(NULL_EVENT_SYNC_STATUS, "-");
syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, "-");
syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, "-");
syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, "-");

String eventSyncSql = "select count(*), syncStatus from event group by syncStatus";
String clientSyncSql = "select count(*), syncStatus from client group by syncStatus";
Expand Down Expand Up @@ -112,7 +110,7 @@ public Map<String, String> fetchStatsInfo() {
while (cursor.moveToNext()) {
syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, String.valueOf(cursor.getInt(0)));
}
if (CoreLibrary.getInstance().context().getAppProperties().isTrue(AllConstants.PROPERTY.MONITOR_HEIGHT)) {
if (CoreLibrary.getInstance().context().getAppProperties().isTrue("monitor.height")) { // Constant is defined in growth-monitoring module
cursor = database.rawQuery(unsyncedHeightEventsSQL, new String[]{});
while (cursor.moveToNext()) {
syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, String.valueOf(cursor.getInt(0)));
Expand Down Expand Up @@ -176,9 +174,24 @@ public void populateUserInfo() {


private void populateBuildInfo() {
syncInfoMap.put(APP_VERSION_NAME, getBuildConfigValue("VERSION_NAME"));
syncInfoMap.put(APP_VERSION_CODE, getBuildConfigValue("VERSION_CODE"));
syncInfoMap.put(DB_VERSION, getBuildConfigValue("DATABASE_VERSION"));
try {
syncInfoMap.put(APP_VERSION_NAME, Utils.getVersion(CoreLibrary.getInstance().context().applicationContext()));
} catch (PackageManager.NameNotFoundException e) {
syncInfoMap.put(APP_VERSION_NAME, "-");
Timber.e(e);
}
try {
syncInfoMap.put(APP_VERSION_CODE, String.valueOf(Utils.getVersionCode(CoreLibrary.getInstance().context().applicationContext())));
} catch (PackageManager.NameNotFoundException e) {
syncInfoMap.put(APP_VERSION_CODE, "-");
Timber.e(e);
}
try {
syncInfoMap.put(DB_VERSION, String.valueOf(Utils.getDatabaseVersion()));
} catch (Exception e) {
syncInfoMap.put(DB_VERSION, "-");
Timber.e(e);
}
}

private void populateDeviceInfo() {
Expand All @@ -194,17 +207,4 @@ private void populateDeviceInfo() {
}

}

public String getBuildConfigValue(String fieldName) {
try {
Context context = CoreLibrary.getInstance().context().applicationContext();
Class<?> clazz = Class.forName(context.getPackageName() + ".BuildConfig");
Field field = clazz.getField(fieldName);
return String.valueOf(field.get(null));
} catch (Exception e) {
Timber.e(e);
return "0";
}
}

}
5 changes: 5 additions & 0 deletions opensrp-core/src/main/java/org/smartregister/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.smartregister.domain.jsonmapping.util.TreeNode;
import org.smartregister.receiver.SyncStatusBroadcastReceiver;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.view.activity.DrishtiApplication;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -1038,4 +1039,8 @@ public static String extractTranslatableValue(String value) {
}
return value;
}

public static int getDatabaseVersion() {
return DrishtiApplication.getInstance().getRepository().getReadableDatabase().getVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.smartregister.AllConstants;
import org.smartregister.CoreLibrary;
import org.smartregister.R;
import org.smartregister.view.contract.StatsFragmentContract;
Expand Down Expand Up @@ -126,21 +125,21 @@ private void initializeViews(View view) {
@Override
public void refreshECSyncInfo(Map<String, String> syncInfoMap) {

tvSyncedEvents.setText(syncInfoMap.get(SYNCED_EVENTS) + "");
tvUnSyncedEvents.setText(syncInfoMap.get(UNSYNCED_EVENTS) + "");
tvTaskUnprocessedEvents.setText(syncInfoMap.get(TASK_UNPROCESSED_EVENTS) + "");
tvSyncedEvents.setText(syncInfoMap.get(SYNCED_EVENTS));
tvUnSyncedEvents.setText(syncInfoMap.get(UNSYNCED_EVENTS));
tvTaskUnprocessedEvents.setText(syncInfoMap.get(TASK_UNPROCESSED_EVENTS));

tvSyncedClient.setText(syncInfoMap.get(SYNCED_CLIENTS) + "");
tvUnSyncedClients.setText(syncInfoMap.get(UNSYNCED_CLIENTS) + "");
tvSyncedClient.setText(syncInfoMap.get(SYNCED_CLIENTS));
tvUnSyncedClients.setText(syncInfoMap.get(UNSYNCED_CLIENTS));

tvValidatedEvents.setText(syncInfoMap.get(VALID_EVENTS));
tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS) + "");
tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS));

tvUnsyncedVaccineEvents.setText(syncInfoMap.get(UNSYNCED_VACCINE_EVENTS) + "");
tvUnsyncedWeightEvents.setText(syncInfoMap.get(UNSYNCED_WEIGHT_EVENTS) + "");
tvUnsyncedVaccineEvents.setText(syncInfoMap.get(UNSYNCED_VACCINE_EVENTS));
tvUnsyncedWeightEvents.setText(syncInfoMap.get(UNSYNCED_WEIGHT_EVENTS));
// Only show height stats if they are record height is enabled
if (CoreLibrary.getInstance().context().getAppProperties().isTrue(AllConstants.PROPERTY.MONITOR_HEIGHT))
tvUnsyncedHeightEvents.setText(syncInfoMap.get(UNSYNCED_HEIGHT_EVENTS) + "");
if (CoreLibrary.getInstance().context().getAppProperties().isTrue("monitor.height")) // Constant is defined in growth-monitoring module
tvUnsyncedHeightEvents.setText(syncInfoMap.get(UNSYNCED_HEIGHT_EVENTS));
else {
if (getView() != null) {
getView().findViewById(R.id.height_stats).setVisibility(View.GONE);
Expand Down
3 changes: 1 addition & 2 deletions opensrp-core/src/test/assets/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ DRISHTI_BASE_URL=
PORT=-1
SHOULD_VERIFY_CERTIFICATE=false
SYNC_DOWNLOAD_BATCH_SIZE=10
system.toaster.centered=true
monitor.height=true
system.toaster.centered=true
12 changes: 10 additions & 2 deletions opensrp-core/src/test/java/org/smartregister/TestApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import net.sqlcipher.database.SQLiteDatabase;

/**
* Created by samuelgithengi on 12/30/19.
*/
Expand Down Expand Up @@ -45,8 +48,13 @@ public void logoutCurrentUser() {

@Override
public Repository getRepository() {
if (repository == null)
repository = mock(Repository.class);
if (repository == null) {
Repository mockRepository = mock(Repository.class);
SQLiteDatabase mockSqLiteDatabase = mock(SQLiteDatabase.class);
doReturn(mockSqLiteDatabase).when(mockRepository).getReadableDatabase();
doReturn(1).when(mockSqLiteDatabase).getVersion();
repository = mockRepository;
}
return repository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.MockitoAnnotations;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseUnitTest;
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.interactor.StatsFragmentInteractor;
import org.smartregister.view.presenter.StatsFragmentPresenter;

import java.util.HashMap;
import java.util.Map;

public class StatsFragmentPresenterTest extends BaseUnitTest {

@Spy
StatsFragmentContract.View view;
public class StatsFragmentPresenterTest {

@Mock
private StatsFragmentInteractor interactor;

private StatsFragmentPresenter presenter;

@Mock
StatsFragmentContract.View view;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
presenter = Mockito.mock(StatsFragmentPresenter.class, Mockito.CALLS_REAL_METHODS);
interactor = Mockito.mock(StatsFragmentInteractor.class, Mockito.CALLS_REAL_METHODS);
view = Mockito.spy(view);
interactor = Mockito.spy(interactor);
ReflectionHelpers.setField(presenter, "interactor", interactor);
ReflectionHelpers.setField(presenter, "view", view);
}
Expand Down
Loading

0 comments on commit 96bab65

Please sign in to comment.