diff --git a/gradle.properties b/gradle.properties
index 5f0308c43..039164e41 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-VERSION_NAME=5.0.9-SNAPSHOT
+VERSION_NAME=5.1.0-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
diff --git a/opensrp-core/res/layout/fragment_stats.xml b/opensrp-core/res/layout/fragment_stats.xml
index f268f118e..70b1f63bb 100644
--- a/opensrp-core/res/layout/fragment_stats.xml
+++ b/opensrp-core/res/layout/fragment_stats.xml
@@ -1,22 +1,33 @@
-
+ android:layout_height="match_parent"
+ android:fillViewport="true">
+
+
@@ -25,17 +36,18 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
- android:textSize="15sp"
- android:textStyle="bold"
- android:text="@string/synced_events"/>
+ android:text="@string/synced_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -46,21 +58,22 @@
android:weightSum="2">
+ android:text="@string/unsynced_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -71,47 +84,49 @@
android:weightSum="2">
+ android:text="@string/task_unprocessed_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text="@string/synced_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -122,47 +137,49 @@
android:weightSum="2">
+ android:text="@string/unsynced_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text="@string/validated_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -173,34 +190,439 @@
android:weightSum="2">
+ android:text="@string/validated_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
+
\ No newline at end of file
diff --git a/opensrp-core/res/values/strings.xml b/opensrp-core/res/values/strings.xml
index 8b587d131..4a29333b7 100644
--- a/opensrp-core/res/values/strings.xml
+++ b/opensrp-core/res/values/strings.xml
@@ -457,4 +457,24 @@
Return
Other Forms
Write access to the device internal storage is required for database download.
+
+ App Version Name:
+ App Version Code:
+ Database Version:
+ Team:
+ Locality:
+ Sync
+ App Info
+ Device Info
+ Manufacturer:
+ Device:
+ OS Version:
+ Sync Statistics
+ User Info
+ Build Date:
+ Date:
+ User:
+ Unsynced vaccine events:
+ Unsynced weight events:
+ Unsynced height events:
diff --git a/opensrp-core/src/main/java/org/smartregister/AllConstants.java b/opensrp-core/src/main/java/org/smartregister/AllConstants.java
index 56cc33c66..cf8f1e0ee 100644
--- a/opensrp-core/src/main/java/org/smartregister/AllConstants.java
+++ b/opensrp-core/src/main/java/org/smartregister/AllConstants.java
@@ -575,6 +575,7 @@ public interface ClientProcessing {
public interface DatabaseKeys {
String SYNC_STATUS = "syncStatus";
String VALIDATION_STATUS = "validationStatus";
+ String DB_VERSION = "db_version";
}
public interface SyncInfo {
@@ -588,6 +589,21 @@ public interface SyncInfo {
String INVALID_CLIENTS = "INValidClients";
String TASK_UNPROCESSED_EVENTS = "taskUnprocessedEvents";
String NULL_EVENT_SYNC_STATUS = "nullEventSyncStatus";
+ String USER_NAME = "user";
+ String USER_TEAM = "user_team";
+ String USER_LOCALITY = "user_locality";
+ String APP_VERSION_NAME = "app_ver_name";
+ String APP_VERSION_CODE = "app_ver_code";
+ String APP_BUILD_DATE = "app_build_date";
+ String UNSYNCED_VACCINE_EVENTS = "unsynced_vaccine_events";
+ String UNSYNCED_WEIGHT_EVENTS = "unsynced_weight_events";
+ String UNSYNCED_HEIGHT_EVENTS = "unsynced_height_events";
+ }
+
+ public interface DeviceInfo {
+ String MANUFACTURER = "manufacturer";
+ String MODEL = "model";
+ String OS_VERSION = "os_version";
}
public static class EventType {
diff --git a/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java
new file mode 100644
index 000000000..752c604ee
--- /dev/null
+++ b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java
@@ -0,0 +1,210 @@
+package org.smartregister.util;
+
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DatabaseKeys.SYNC_STATUS;
+import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.DeviceInfo.OS_VERSION;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.NULL_EVENT_SYNC_STATUS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
+import android.content.pm.PackageManager;
+import android.os.Build;
+
+import net.sqlcipher.Cursor;
+import net.sqlcipher.database.SQLiteDatabase;
+
+import org.smartregister.CoreLibrary;
+import org.smartregister.repository.AllSharedPreferences;
+import org.smartregister.repository.BaseRepository;
+import org.smartregister.view.activity.DrishtiApplication;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import timber.log.Timber;
+
+public class StatsUtils {
+
+ private final Map syncInfoMap = new HashMap<>();
+ private final SQLiteDatabase database;
+
+ public StatsUtils() {
+ database = DrishtiApplication.getInstance().getRepository().getReadableDatabase();
+ }
+
+ public Map fetchStatsInfo() {
+ 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";
+
+ String validatedEventsSql = "select count(*), validationStatus from event group by validationStatus";
+ String validatedClientsSql = "select count(*), validationStatus from client group by validationStatus";
+
+ String unsyncedVaccineEventsSQL = "SELECT COUNT(*) FROM vaccines WHERE sync_status = 'Unsynced'";
+ String unsyncedWeightEventsSQL = "SELECT COUNT(*) FROM weights WHERE sync_status = 'Unsynced'";
+ String unsyncedHeightEventsSQL = "SELECT COUNT(*) FROM heights WHERE sync_status = 'Unsynced'";
+
+ Cursor cursor;
+
+ cursor = database.rawQuery(eventSyncSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateEventSyncInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(clientSyncSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateClientSyncInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(validatedEventsSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateValidatedEventsInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(validatedClientsSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateValidatedClientsInfo(cursor);
+ }
+
+ cursor = database.rawQuery(unsyncedVaccineEventsSQL, new String[]{});
+ while (cursor.moveToNext()) {
+ syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+
+ cursor = database.rawQuery(unsyncedWeightEventsSQL, new String[]{});
+ while (cursor.moveToNext()) {
+ syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+ 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)));
+ }
+ }
+
+ cursor.close();
+
+ populateUserInfo();
+ populateBuildInfo();
+ populateDeviceInfo();
+ return syncInfoMap;
+ }
+
+ private void populateEventSyncInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
+ if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
+ syncInfoMap.put(SYNCED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
+ syncInfoMap.put(UNSYNCED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Task_Unprocessed.equals(syncStatus)) {
+ syncInfoMap.put(TASK_UNPROCESSED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (syncStatus == null) {
+ syncInfoMap.put(NULL_EVENT_SYNC_STATUS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateClientSyncInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
+ if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
+ syncInfoMap.put(SYNCED_CLIENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
+ syncInfoMap.put(UNSYNCED_CLIENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateValidatedEventsInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
+ if (BaseRepository.TYPE_Valid.equals(syncStatus)) {
+ syncInfoMap.put(VALID_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_InValid.equals(syncStatus)) {
+ syncInfoMap.put(INVALID_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateValidatedClientsInfo(Cursor cursor) {
+ String validationStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
+ if (BaseRepository.TYPE_Valid.equals(validationStatus)) {
+ syncInfoMap.put(VALID_CLIENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_InValid.equals(validationStatus)) {
+ syncInfoMap.put(INVALID_CLIENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ public void populateUserInfo() {
+ AllSharedPreferences sharedPreferences = CoreLibrary.getInstance().context().userService().getAllSharedPreferences();
+ syncInfoMap.put(USER_NAME, sharedPreferences.fetchRegisteredANM());
+ syncInfoMap.put(USER_TEAM, sharedPreferences.fetchDefaultTeam(sharedPreferences.fetchRegisteredANM()));
+ syncInfoMap.put(USER_LOCALITY, sharedPreferences.fetchCurrentLocality());
+ }
+
+
+ private void populateBuildInfo() {
+ 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() {
+ try {
+ syncInfoMap.put(MANUFACTURER, Build.MANUFACTURER);
+ syncInfoMap.put(MODEL, Build.MODEL);
+ syncInfoMap.put(APP_BUILD_DATE, Utils.getBuildDate(true));
+
+ String osName = Build.VERSION_CODES.class.getFields()[android.os.Build.VERSION.SDK_INT].getName();
+ syncInfoMap.put(OS_VERSION, osName);
+ } catch (Exception e) {
+ Timber.e(e);
+ }
+
+ }
+}
diff --git a/opensrp-core/src/main/java/org/smartregister/util/Utils.java b/opensrp-core/src/main/java/org/smartregister/util/Utils.java
index 43980a361..4f3248872 100644
--- a/opensrp-core/src/main/java/org/smartregister/util/Utils.java
+++ b/opensrp-core/src/main/java/org/smartregister/util/Utils.java
@@ -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;
@@ -575,6 +576,10 @@ public static long getVersionCode(Context context) throws PackageManager.NameNot
return packageInfo.versionCode;
}
+ public static int getDatabaseVersion() {
+ return DrishtiApplication.getInstance().getRepository().getReadableDatabase().getVersion();
+ }
+
public static String getBuildDate(Boolean isShortMonth) {
String simpleDateFormat;
if (isShortMonth) {
diff --git a/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java b/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
index 8c51df68c..4353c7d4a 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
@@ -7,7 +7,7 @@
public interface StatsFragmentContract {
interface Presenter {
- void onECSyncInfoFetched(Map syncInfoMap);
+ void onECSyncInfoFetched(Map syncInfoMap);
void fetchSyncInfo();
@@ -16,7 +16,7 @@ interface Presenter {
interface View {
Context getContext();
- void refreshECSyncInfo(Map syncInfoMap);
+ void refreshECSyncInfo(Map syncInfoMap);
}
interface Interactor {
diff --git a/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java b/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
index 04d46464c..b2c2ff011 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
@@ -1,5 +1,26 @@
package org.smartregister.view.fragment;
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.DeviceInfo.OS_VERSION;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -12,20 +33,15 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
+import org.smartregister.CoreLibrary;
import org.smartregister.R;
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.presenter.StatsFragmentPresenter;
+import java.text.DateFormat;
+import java.util.Date;
import java.util.Map;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
-
public class StatsFragment extends Fragment implements StatsFragmentContract.View {
private StatsFragmentPresenter presenter;
@@ -37,6 +53,20 @@ public class StatsFragment extends Fragment implements StatsFragmentContract.Vie
private TextView tvValidatedEvents;
private TextView tvValidatedClients;
private TextView tvTaskUnprocessedEvents;
+ private TextView tvUserName;
+ private TextView tvAppVersionName;
+ private TextView tvAppVersionCode;
+ private TextView tvDBVersion;
+ private TextView tvTeam;
+ private TextView tvLocality;
+ private TextView tvManufacturer;
+ private TextView tvDevice;
+ private TextView tvOS;
+ private TextView tvBuildDate;
+ private TextView tvCurrentDate;
+ private TextView tvUnsyncedVaccineEvents;
+ private TextView tvUnsyncedWeightEvents;
+ private TextView tvUnsyncedHeightEvents;
public static StatsFragment newInstance(Bundle bundle) {
StatsFragment fragment = new StatsFragment();
@@ -70,6 +100,20 @@ private void initializeViews(View view) {
tvValidatedEvents = view.findViewById(R.id.validated_events);
tvValidatedClients = view.findViewById(R.id.validated_clients);
tvTaskUnprocessedEvents = view.findViewById(R.id.task_unprocessed_events);
+ tvUserName = view.findViewById(R.id.user_value);
+ tvAppVersionName = view.findViewById(R.id.app_version_name_value);
+ tvAppVersionCode = view.findViewById(R.id.app_version_code_value);
+ tvDBVersion = view.findViewById(R.id.db_version_value);
+ tvTeam = view.findViewById(R.id.team_value);
+ tvLocality = view.findViewById(R.id.locality_value);
+ tvManufacturer = view.findViewById(R.id.manufacturer_value);
+ tvDevice = view.findViewById(R.id.device_value);
+ tvOS = view.findViewById(R.id.os_value);
+ tvBuildDate = view.findViewById(R.id.build_date_value);
+ tvCurrentDate = view.findViewById(R.id.date_value);
+ tvUnsyncedVaccineEvents = view.findViewById(R.id.synced_vaccine_events);
+ tvUnsyncedHeightEvents = view.findViewById(R.id.synced_height_events);
+ tvUnsyncedWeightEvents = view.findViewById(R.id.synced_weight_events);
Button btnRefreshStats = view.findViewById(R.id.refresh_button);
btnRefreshStats.setOnClickListener(v -> presenter.fetchSyncInfo());
@@ -79,17 +123,41 @@ private void initializeViews(View view) {
@SuppressLint("SetTextI18n")
@Override
- public void refreshECSyncInfo(Map syncInfoMap) {
-
- 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) + "");
-
- tvValidatedEvents.setText(syncInfoMap.get(VALID_EVENTS) + "");
- tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS) + "");
+ public void refreshECSyncInfo(Map syncInfoMap) {
+
+ 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));
+
+ tvValidatedEvents.setText(syncInfoMap.get(VALID_EVENTS));
+ tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS));
+
+ 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("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);
+ }
+ }
+ tvUserName.setText(syncInfoMap.get(USER_NAME));
+ tvAppVersionName.setText(syncInfoMap.get(APP_VERSION_NAME));
+ tvAppVersionCode.setText(syncInfoMap.get(APP_VERSION_CODE));
+ tvDBVersion.setText(syncInfoMap.get(DB_VERSION));
+ tvBuildDate.setText(syncInfoMap.get(APP_BUILD_DATE));
+
+ tvTeam.setText(syncInfoMap.get(USER_TEAM));
+ tvLocality.setText(syncInfoMap.get(USER_LOCALITY));
+
+ tvManufacturer.setText(syncInfoMap.get(MANUFACTURER));
+ tvDevice.setText(syncInfoMap.get(MODEL));
+ tvOS.setText(syncInfoMap.get(OS_VERSION));
+ tvCurrentDate.setText(DateFormat.getDateTimeInstance().format(new Date()));
}
}
diff --git a/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java b/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
index 59ab35bd4..5a0e16e62 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
@@ -1,147 +1,32 @@
package org.smartregister.view.interactor;
-import net.sqlcipher.Cursor;
-import net.sqlcipher.database.SQLiteDatabase;
-
-import org.smartregister.repository.BaseRepository;
import org.smartregister.util.AppExecutors;
-import org.smartregister.view.activity.DrishtiApplication;
+import org.smartregister.util.StatsUtils;
import org.smartregister.view.contract.StatsFragmentContract;
-import java.util.HashMap;
import java.util.Map;
import timber.log.Timber;
-import static org.smartregister.AllConstants.DatabaseKeys.SYNC_STATUS;
-import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
-import static org.smartregister.AllConstants.SyncInfo.INVALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.NULL_EVENT_SYNC_STATUS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
-
public class StatsFragmentInteractor implements StatsFragmentContract.Interactor {
- private AppExecutors appExecutors;
-
- private SQLiteDatabase database;
+ private final AppExecutors appExecutors;
- private StatsFragmentContract.Presenter presenter;
-
- private Map syncInfoMap = new HashMap<>();
+ private final StatsFragmentContract.Presenter presenter;
public StatsFragmentInteractor(StatsFragmentContract.Presenter presenter) {
this.presenter = presenter;
appExecutors = new AppExecutors();
- database = DrishtiApplication.getInstance().getRepository().getReadableDatabase();
}
@Override
public void fetchECSyncInfo() {
- syncInfoMap = new HashMap<>();
- 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);
-
- String eventSyncSql = "select count(*), syncStatus from event group by syncStatus";
- String clientSyncSql = "select count(*), syncStatus from client group by syncStatus";
-
- String validatedEventsSql = "select count(*), validationStatus from event group by validationStatus";
- String validatedClientsSql = "select count(*), validationStatus from client group by validationStatus";
-
- Cursor cursor = null;
-
try {
- cursor = database.rawQuery(eventSyncSql, new String[]{});
- while (cursor.moveToNext()) {
- populateEventSyncInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(clientSyncSql, new String[]{});
- while (cursor.moveToNext()) {
- populateClientSyncInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(validatedEventsSql, new String[]{});
- while (cursor.moveToNext()) {
- populateValidatedEventsInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(validatedClientsSql, new String[]{});
- while (cursor.moveToNext()) {
- populateValidatedClientsInfo(cursor);
- }
-
- cursor.close();
-
- appExecutors.mainThread().execute(new Runnable() {
- @Override
- public void run() {
- presenter.onECSyncInfoFetched(syncInfoMap);
- }
- });
+ Map syncInfoMap = new StatsUtils().fetchStatsInfo();
+ appExecutors.mainThread().execute(() -> presenter.onECSyncInfoFetched(syncInfoMap));
} catch (Exception e) {
Timber.e(e);
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- }
-
- private void populateEventSyncInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
- if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
- syncInfoMap.put(SYNCED_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
- syncInfoMap.put(UNSYNCED_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Task_Unprocessed.equals(syncStatus)) {
- syncInfoMap.put(TASK_UNPROCESSED_EVENTS, cursor.getInt(0));
- } else if (syncStatus == null) {
- syncInfoMap.put(NULL_EVENT_SYNC_STATUS, cursor.getInt(0));
- }
- }
-
- private void populateClientSyncInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
- if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
- syncInfoMap.put(SYNCED_CLIENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
- syncInfoMap.put(UNSYNCED_CLIENTS, cursor.getInt(0));
- }
- }
-
- private void populateValidatedEventsInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
- if (BaseRepository.TYPE_Valid.equals(syncStatus)) {
- syncInfoMap.put(VALID_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_InValid.equals(syncStatus)) {
- syncInfoMap.put(INVALID_EVENTS, cursor.getInt(0));
}
}
- private void populateValidatedClientsInfo(Cursor cursor) {
- String validationStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
- if (BaseRepository.TYPE_Valid.equals(validationStatus)) {
- syncInfoMap.put(VALID_CLIENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_InValid.equals(validationStatus)) {
- syncInfoMap.put(INVALID_CLIENTS, cursor.getInt(0));
- }
- }
}
diff --git a/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java b/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
index 018e94134..6003c5a23 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
@@ -1,5 +1,6 @@
package org.smartregister.view.presenter;
+
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.interactor.StatsFragmentInteractor;
@@ -16,7 +17,7 @@ public StatsFragmentPresenter(StatsFragmentContract.View view) {
}
@Override
- public void onECSyncInfoFetched(Map syncInfoMap) {
+ public void onECSyncInfoFetched(Map syncInfoMap) {
view.refreshECSyncInfo(syncInfoMap);
}
diff --git a/opensrp-core/src/test/assets/app.properties b/opensrp-core/src/test/assets/app.properties
index 809917585..f9c111750 100644
--- a/opensrp-core/src/test/assets/app.properties
+++ b/opensrp-core/src/test/assets/app.properties
@@ -3,4 +3,4 @@ PORT=-1
SHOULD_VERIFY_CERTIFICATE=false
SYNC_DOWNLOAD_BATCH_SIZE=10
system.toaster.centered=false
-allow.offline.login.with.invalid.token=false
+allow.offline.login.with.invalid.token=false
\ No newline at end of file
diff --git a/opensrp-core/src/test/java/org/smartregister/TestApplication.java b/opensrp-core/src/test/java/org/smartregister/TestApplication.java
index 5c006c2d4..11176eaad 100644
--- a/opensrp-core/src/test/java/org/smartregister/TestApplication.java
+++ b/opensrp-core/src/test/java/org/smartregister/TestApplication.java
@@ -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.
*/
@@ -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;
}
diff --git a/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java b/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java
new file mode 100644
index 000000000..a8e03affb
--- /dev/null
+++ b/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java
@@ -0,0 +1,17 @@
+package org.smartregister.clientandeventmodel.populateform;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.smartregister.BaseUnitTest;
+import org.smartregister.clientandeventmodel.populateform.Model;
+
+public class ModelTest extends BaseUnitTest {
+
+
+ @Test
+ public void testConstructorNotNull() {
+ Model model = new Model("","","","");
+ Assert.assertNotNull(model);
+ }
+
+}
diff --git a/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java b/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
index f1a09d3e1..58e44979c 100644
--- a/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
@@ -37,7 +37,7 @@ public void setUp() {
@Test
public void onECSyncInfoFetchedRefreshesECSyncInfo() {
- Map syncInfoMap = new HashMap<>();
+ Map syncInfoMap = new HashMap<>();
presenter.onECSyncInfoFetched(syncInfoMap);
Mockito.verify(view).refreshECSyncInfo(ArgumentMatchers.eq(syncInfoMap));
}
diff --git a/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java
new file mode 100644
index 000000000..97691ef8a
--- /dev/null
+++ b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java
@@ -0,0 +1,148 @@
+package org.smartregister.util;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import net.sqlcipher.Cursor;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.robolectric.util.ReflectionHelpers;
+import org.smartregister.BaseUnitTest;
+import org.smartregister.Context;
+import org.smartregister.CoreLibrary;
+import org.smartregister.repository.AllSharedPreferences;
+import org.smartregister.repository.BaseRepository;
+import org.smartregister.service.UserService;
+
+import java.util.Map;
+
+public class StatsUtilsTest extends BaseUnitTest {
+
+ private StatsUtils statsUtils;
+
+ @Before
+ public void setUp() {
+ statsUtils = new StatsUtils();
+ }
+
+ @Test
+ public void testPopulateUserInfoPopulatesCorrectValues() {
+ CoreLibrary coreLibrary = Mockito.mock(CoreLibrary.class);
+ ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary);
+
+ Context context = Mockito.mock(Context.class);
+ UserService userService = Mockito.mock(UserService.class);
+ AllSharedPreferences sharedPreferences = Mockito.mock(AllSharedPreferences.class);
+
+ Mockito.doReturn(context).when(coreLibrary).context();
+ Mockito.doReturn(userService).when(context).userService();
+ Mockito.doReturn(sharedPreferences).when(userService).getAllSharedPreferences();
+ Mockito.doReturn("user").when(sharedPreferences).fetchRegisteredANM();
+ Mockito.doReturn("team").when(sharedPreferences).fetchDefaultTeam(Mockito.anyString());
+ Mockito.doReturn("locality").when(sharedPreferences).fetchCurrentLocality();
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateUserInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("user", syncInfoMap.get(USER_NAME));
+ Assert.assertEquals("team", syncInfoMap.get(USER_TEAM));
+ Assert.assertEquals("locality", syncInfoMap.get(USER_LOCALITY));
+ }
+
+ @Test
+ public void testPopulateBuildInfoPopulatesCorrectValues() throws PackageManager.NameNotFoundException {
+ CoreLibrary coreLibrary = Mockito.mock(CoreLibrary.class);
+ ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary);
+
+ Context context = Mockito.mock(Context.class);
+ android.content.Context appContext = Mockito.spy(ApplicationProvider.getApplicationContext());
+
+ Mockito.doReturn(context).when(coreLibrary).context();
+ Mockito.doReturn(appContext).when(context).applicationContext();
+
+ PackageManager packageManager = Mockito.mock(PackageManager.class);
+ PackageInfo packageInfo = Mockito.mock(PackageInfo.class);
+ packageInfo.versionName = "v1.0.0";
+ packageInfo.versionCode = 1;
+ Mockito.doReturn(packageManager).when(appContext).getPackageManager();
+ Mockito.doReturn("org.smartregister").when(appContext).getPackageName();
+ Mockito.doReturn(packageInfo).when(packageManager).getPackageInfo(eq("org.smartregister"), eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateBuildInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("v1.0.0", syncInfoMap.get(APP_VERSION_NAME));
+ Assert.assertEquals("1", syncInfoMap.get(APP_VERSION_CODE));
+ Assert.assertEquals("1", syncInfoMap.get(DB_VERSION));
+ }
+
+ @Test
+ public void testPopulateDeviceInfoPopulatesCorrectValues() {
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateDeviceInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("unknown", syncInfoMap.get(MANUFACTURER));
+ Assert.assertEquals("robolectric", syncInfoMap.get(MODEL));
+ Assert.assertEquals("28 Apr 2020", syncInfoMap.get(APP_BUILD_DATE));
+ }
+
+ @Test
+ public void testPopulateValidatedEventsInfoAddValidEventsCountWhenStatusIsValid() {
+ Cursor cursor = Mockito.mock(Cursor.class);
+
+ Mockito.doReturn(1).when(cursor).getColumnIndex(eq(VALIDATION_STATUS));
+ Mockito.doReturn(BaseRepository.TYPE_Valid).when(cursor).getString(eq(1));
+ Mockito.doReturn(10).when(cursor).getInt(eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateValidatedEventsInfo",
+ ReflectionHelpers.ClassParameter.from(Cursor.class, cursor));
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+ Assert.assertEquals("10", syncInfoMap.get(VALID_EVENTS));
+
+ }
+
+ @Test
+ public void testPopulateValidatedEventsInfoAddInvalidEventsCountWhenStatusIsInvalid() {
+ Cursor cursor = Mockito.mock(Cursor.class);
+
+ Mockito.doReturn(1).when(cursor).getColumnIndex(eq(VALIDATION_STATUS));
+ Mockito.doReturn(BaseRepository.TYPE_InValid).when(cursor).getString(eq(1));
+ Mockito.doReturn(10).when(cursor).getInt(eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateValidatedEventsInfo",
+ ReflectionHelpers.ClassParameter.from(Cursor.class, cursor));
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+ Assert.assertEquals("10", syncInfoMap.get(INVALID_EVENTS));
+
+ }
+
+ @After
+ public void destroy() {
+ ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ }
+}
diff --git a/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
index 1a2edab45..ab2db8352 100644
--- a/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
@@ -719,5 +719,15 @@ public void testComposeApiCallParamsStringWithMultipleParamValues() {
apiParams.add(Pair.create("serverVersion", "21"));
assertEquals("&identifier=global_configs&serverVersion=21", Utils.composeApiCallParamsString(apiParams));
}
+
+ @Test
+ public void testTryParseLongShouldParseCorrectly() {
+ assertEquals(123L, (Long) Utils.tryParseLong("123", 0), 0);
+ }
+
+ @Test
+ public void testTryParseLongShouldParseShoouldReturnDefaultValueOnException() {
+ assertEquals(0L, (Long) Utils.tryParseLong("xyz", 0), 0);
+ }
}
diff --git a/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java b/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
index ac7646e4b..34d5afef1 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
@@ -1,11 +1,13 @@
package org.smartregister.view.fragment;
-import static org.mockito.Mockito.doReturn;
import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
@@ -14,6 +16,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.FragmentManager;
@@ -92,19 +95,25 @@ public void onCreateViewInitsViewsAndReturnsCorrectView() {
@Test
public void refreshECSyncInfoUpdatesViews() {
- Map syncInfoMap = new HashMap<>();
- syncInfoMap.put(SYNCED_EVENTS, 2);
- syncInfoMap.put(UNSYNCED_EVENTS, 3);
- syncInfoMap.put(TASK_UNPROCESSED_EVENTS, 4);
- syncInfoMap.put(SYNCED_CLIENTS, 5);
- syncInfoMap.put(UNSYNCED_CLIENTS, 6);
- syncInfoMap.put(VALID_EVENTS, 7);
- syncInfoMap.put(VALID_CLIENTS, 8);
+ Map syncInfoMap = new HashMap<>();
+ syncInfoMap.put(SYNCED_EVENTS, "2");
+ syncInfoMap.put(UNSYNCED_EVENTS, "3");
+ syncInfoMap.put(TASK_UNPROCESSED_EVENTS, "4");
+ syncInfoMap.put(SYNCED_CLIENTS, "5");
+ syncInfoMap.put(UNSYNCED_CLIENTS, "6");
+ syncInfoMap.put(VALID_EVENTS, "7");
+ syncInfoMap.put(VALID_CLIENTS, "8");
+ syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, "1");
+ syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, "1");
+ syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, "1");
View rootView = LayoutInflater.from(RuntimeEnvironment.application).inflate(R.layout.fragment_stats, null);
+ Mockito.doReturn(rootView).when(statsFragment).getView();
TextView tvSyncedEvents = rootView.findViewById(R.id.synced_events);
TextView tvUnSyncedEvents = rootView.findViewById(R.id.unsynced_events);
+ TextView tvUnsyncedHeightEvents = rootView.findViewById(R.id.synced_height_events);
+ LinearLayout layoutUnsyncedHeightEvents = rootView.findViewById(R.id.height_stats);
ReflectionHelpers.setField(statsFragment, "tvSyncedEvents", tvSyncedEvents);
ReflectionHelpers.setField(statsFragment, "tvUnSyncedEvents", tvUnSyncedEvents);
@@ -113,10 +122,25 @@ public void refreshECSyncInfoUpdatesViews() {
ReflectionHelpers.setField(statsFragment, "tvUnSyncedClients", rootView.findViewById(R.id.unsynced_clients));
ReflectionHelpers.setField(statsFragment, "tvValidatedEvents", rootView.findViewById(R.id.validated_events));
ReflectionHelpers.setField(statsFragment, "tvValidatedClients", rootView.findViewById(R.id.validated_clients));
+ ReflectionHelpers.setField(statsFragment, "tvUserName", rootView.findViewById(R.id.user_value));
+ ReflectionHelpers.setField(statsFragment, "tvAppVersionName", rootView.findViewById(R.id.app_version_name_value));
+ ReflectionHelpers.setField(statsFragment, "tvAppVersionCode", rootView.findViewById(R.id.app_version_code_value));
+ ReflectionHelpers.setField(statsFragment, "tvDBVersion", rootView.findViewById(R.id.db_version_value));
+ ReflectionHelpers.setField(statsFragment, "tvTeam", rootView.findViewById(R.id.team_value));
+ ReflectionHelpers.setField(statsFragment, "tvLocality", rootView.findViewById(R.id.locality_value));
+ ReflectionHelpers.setField(statsFragment, "tvManufacturer", rootView.findViewById(R.id.manufacturer_value));
+ ReflectionHelpers.setField(statsFragment, "tvDevice", rootView.findViewById(R.id.device_value));
+ ReflectionHelpers.setField(statsFragment, "tvOS", rootView.findViewById(R.id.os_value));
+ ReflectionHelpers.setField(statsFragment, "tvBuildDate", rootView.findViewById(R.id.build_date_value));
+ ReflectionHelpers.setField(statsFragment, "tvCurrentDate", rootView.findViewById(R.id.date_value));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedVaccineEvents", rootView.findViewById(R.id.synced_vaccine_events));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedWeightEvents", rootView.findViewById(R.id.synced_weight_events));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedHeightEvents", tvUnsyncedHeightEvents);
statsFragment.refreshECSyncInfo(syncInfoMap);
Assert.assertEquals("2", tvSyncedEvents.getText());
Assert.assertEquals("3", tvUnSyncedEvents.getText());
+ Assert.assertEquals(View.GONE, layoutUnsyncedHeightEvents.getVisibility());
}
@Test
@@ -165,7 +189,7 @@ public void assertTestLabelsNotNull() {
@Test
public void testUpdatedLabels() {
View parentLayout = LayoutInflater.from(RuntimeEnvironment.application.getApplicationContext()).inflate(R.layout.fragment_stats, null, false);
- doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false);
+ Mockito.doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false);
TextView tvSyncedEventsLabel = parentLayout.findViewById(R.id.synced_events_label);
TextView tvUnsyncedEventsLabel = parentLayout.findViewById(R.id.unsynced_events_label);