From 10d950b514067e93b18ed948d9ac7ae43502fb83 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Tue, 14 Jan 2020 11:14:52 +0300 Subject: [PATCH 1/4] Migrate to latest core Latest core upgrade alters repository implementation for stability --- opensrp-growth-monitoring/build.gradle | 2 +- .../GrowthMonitoringLibrary.java | 10 +++---- .../repository/GrowthRepository.java | 5 ---- .../repository/HeightRepository.java | 28 +++++++---------- .../repository/HeightZScoreRepository.java | 9 ++---- .../repository/WeightRepository.java | 30 ++++++++----------- .../repository/WeightZScoreRepository.java | 10 ++----- sample/build.gradle | 2 +- 8 files changed, 34 insertions(+), 62 deletions(-) diff --git a/opensrp-growth-monitoring/build.gradle b/opensrp-growth-monitoring/build.gradle index dce630f..105e9a5 100644 --- a/opensrp-growth-monitoring/build.gradle +++ b/opensrp-growth-monitoring/build.gradle @@ -87,7 +87,7 @@ allprojects { } dependencies { - implementation('org.smartregister:opensrp-client-core:1.8.6-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:1.8.16-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' } diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java index 9c9a618..0b231e4 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/GrowthMonitoringLibrary.java @@ -61,7 +61,7 @@ public static GrowthMonitoringLibrary getInstance() { public WeightRepository weightRepository() { if (weightRepository == null) { - weightRepository = new WeightRepository(getRepository()); + weightRepository = new WeightRepository(); } return weightRepository; } @@ -72,7 +72,7 @@ public Repository getRepository() { public HeightRepository heightRepository() { if (heightRepository == null) { - heightRepository = new HeightRepository(getRepository()); + heightRepository = new HeightRepository(); } return heightRepository; } @@ -80,7 +80,7 @@ public HeightRepository heightRepository() { public WeightZScoreRepository weightZScoreRepository() { if (weightZScoreRepository == null) { - weightZScoreRepository = new WeightZScoreRepository(getRepository()); + weightZScoreRepository = new WeightZScoreRepository(); } return weightZScoreRepository; @@ -88,7 +88,7 @@ public WeightZScoreRepository weightZScoreRepository() { public HeightZScoreRepository heightZScoreRepository() { if (heightZScoreRepository == null) { - heightZScoreRepository = new HeightZScoreRepository(getRepository()); + heightZScoreRepository = new HeightZScoreRepository(); } return heightZScoreRepository; @@ -96,7 +96,7 @@ public HeightZScoreRepository heightZScoreRepository() { public EventClientRepository eventClientRepository() { if (eventClientRepository == null) { - eventClientRepository = new EventClientRepository(getRepository()); + eventClientRepository = new EventClientRepository(); } return eventClientRepository; diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/GrowthRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/GrowthRepository.java index 0621386..5e07190 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/GrowthRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/GrowthRepository.java @@ -7,7 +7,6 @@ import org.smartregister.location.helper.LocationHelper; import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.BaseRepository; -import org.smartregister.repository.Repository; import timber.log.Timber; @@ -16,10 +15,6 @@ */ public abstract class GrowthRepository extends BaseRepository { - public GrowthRepository(Repository repository) { - super(repository); - } - @Nullable public static String getChildLocationId(@NonNull String defaultLocationId, @NonNull AllSharedPreferences allSharedPreferences) { try { diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java index 75aa1b2..17af913 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightRepository.java @@ -13,7 +13,6 @@ import org.smartregister.growthmonitoring.domain.HeightZScore; import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.EventClientRepository; -import org.smartregister.repository.Repository; import java.text.ParseException; import java.util.ArrayList; @@ -86,11 +85,6 @@ public class HeightRepository extends GrowthRepository { "CREATE INDEX " + HEIGHT_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + HEIGHT_TABLE_NAME + "(" + UPDATED_AT_COLUMN + ");"; - - public HeightRepository(Repository repository) { - super(repository); - } - public static void createTable(SQLiteDatabase database) { database.execSQL(HEIGHT_SQL); database.execSQL(BASE_ENTITY_ID_INDEX); @@ -150,7 +144,7 @@ public void add(Height height) { height.setUpdatedAt(Calendar.getInstance().getTimeInMillis()); } - SQLiteDatabase database = getRepository().getWritableDatabase(); + SQLiteDatabase database = getWritableDatabase(); if (height.getId() == null) { Height sameheight = findUnique(database, height); if (sameheight != null) { @@ -182,7 +176,7 @@ public Height findUnique(SQLiteDatabase db, Height height) { try { SQLiteDatabase database = db; if (database == null) { - database = getRepository().getReadableDatabase(); + database = getReadableDatabase(); } String selection = null; @@ -219,7 +213,7 @@ public void update(SQLiteDatabase database, Height height) { try { SQLiteDatabase db; if (database == null) { - db = getRepository().getWritableDatabase(); + db = getWritableDatabase(); } else { db = database; } @@ -321,7 +315,7 @@ public List findUnSyncedBeforeTime(int hours) { Long time = calendar.getTimeInMillis(); - cursor = getRepository().getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, + cursor = getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, UPDATED_AT_COLUMN + " < ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? " + COLLATE_NOCASE, new String[]{time.toString(), TYPE_Unsynced}, null, null, null, null); heights = readAllHeights(cursor); @@ -340,7 +334,7 @@ public Height findUnSyncedByEntityId(String entityId) { Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, + cursor = getReadableDatabase().query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ", new String[]{entityId, TYPE_Unsynced}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null); List heights = readAllHeights(cursor); @@ -361,7 +355,7 @@ public List findByEntityId(String entityId) { List heights = null; Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE, new String[]{entityId}, null, null, null, null); heights = readAllHeights(cursor); @@ -380,7 +374,7 @@ public List findWithNoZScore() { List result = new ArrayList<>(); Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, Z_SCORE + " = " + DEFAULT_Z_SCORE, null, null, null, null, null); result = readAllHeights(cursor); @@ -399,7 +393,7 @@ public Height find(Long caseId) { Height height = null; Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, ID_COLUMN + " = ?", new String[]{caseId.toString()}, null, null, null, null); List heights = readAllHeights(cursor); @@ -420,7 +414,7 @@ public List findLast5(String entityId) { List heightList = new ArrayList<>(); Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(HEIGHT_TABLE_NAME, HEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE, new String[]{entityId}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null); heightList = readAllHeights(cursor); @@ -436,7 +430,7 @@ public List findLast5(String entityId) { public void delete(String id) { try { - getRepository().getWritableDatabase() + getWritableDatabase() .delete(HEIGHT_TABLE_NAME, ID_COLUMN + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ", new String[]{id, TYPE_Unsynced}); } catch (Exception e) { @@ -448,7 +442,7 @@ public void close(Long caseId) { try { ContentValues values = new ContentValues(); values.put(SYNC_STATUS, TYPE_Synced); - getRepository().getWritableDatabase() + getWritableDatabase() .update(HEIGHT_TABLE_NAME, values, ID_COLUMN + " = ?", new String[]{caseId.toString()}); } catch (Exception e) { Timber.e(Log.getStackTraceString(e)); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightZScoreRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightZScoreRepository.java index e346bdb..41ed34d 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightZScoreRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/HeightZScoreRepository.java @@ -9,7 +9,6 @@ import org.smartregister.growthmonitoring.domain.HeightZScore; import org.smartregister.growthmonitoring.util.GrowthMonitoringConstants; import org.smartregister.repository.BaseRepository; -import org.smartregister.repository.Repository; import java.util.ArrayList; import java.util.List; @@ -49,9 +48,6 @@ public class HeightZScoreRepository extends BaseRepository { "CREATE INDEX " + TABLE_NAME + "_" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + "_index ON " + TABLE_NAME + "(" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + " COLLATE NOCASE);"; - public HeightZScoreRepository(Repository repository) { - super(repository); - } public static void createTable(SQLiteDatabase database) { database.execSQL(CREATE_TABLE_QUERY); @@ -61,12 +57,11 @@ public static void createTable(SQLiteDatabase database) { /** * @param query - * * @return */ public boolean runRawQuery(String query) { try { - getRepository().getWritableDatabase().execSQL(query); + getWritableDatabase().execSQL(query); return true; } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); @@ -79,7 +74,7 @@ public List findByGender(Gender gender) { List result = new ArrayList<>(); Cursor cursor = null; try { - SQLiteDatabase database = getRepository().getReadableDatabase(); + SQLiteDatabase database = getReadableDatabase(); cursor = database.query(TABLE_NAME, null, GrowthMonitoringConstants.ColumnHeaders.COLUMN_SEX + " = ? " + COLLATE_NOCASE, new String[]{gender.name()}, null, null, null, null); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java index 8b8619f..c5d8471 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightRepository.java @@ -13,7 +13,6 @@ import org.smartregister.growthmonitoring.domain.WeightZScore; import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.EventClientRepository; -import org.smartregister.repository.Repository; import java.text.ParseException; import java.util.ArrayList; @@ -85,11 +84,6 @@ public class WeightRepository extends GrowthRepository { "CREATE INDEX " + WEIGHT_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + WEIGHT_TABLE_NAME + "(" + UPDATED_AT_COLUMN + ");"; - - public WeightRepository(Repository repository) { - super(repository); - } - public static void createTable(SQLiteDatabase database) { database.execSQL(WEIGHT_SQL); database.execSQL(BASE_ENTITY_ID_INDEX); @@ -148,7 +142,7 @@ public void add(Weight weight) { weight.setUpdatedAt(Calendar.getInstance().getTimeInMillis()); } - SQLiteDatabase database = getRepository().getWritableDatabase(); + SQLiteDatabase database = getWritableDatabase(); if (weight.getId() == null) { Weight sameWeight = findUnique(database, weight); if (sameWeight != null) { @@ -180,7 +174,7 @@ public Weight findUnique(SQLiteDatabase db, Weight weight) { try { SQLiteDatabase database = db; if (database == null) { - database = getRepository().getReadableDatabase(); + database = getReadableDatabase(); } String selection = null; @@ -218,7 +212,7 @@ public Weight findUniqueByDate(SQLiteDatabase db, String baseEntityId, Date enco SQLiteDatabase database = db; if (database == null) { - database = getRepository().getReadableDatabase(); + database = getReadableDatabase(); } String selection = BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND strftime('%d-%m-%Y', datetime(" + DATE + "/1000, 'unixepoch')) = strftime('%d-%m-%Y', datetime(?/1000, 'unixepoch')) " + COLLATE_NOCASE; @@ -245,7 +239,7 @@ public void update(SQLiteDatabase database, Weight weight) { try { SQLiteDatabase db; if (database == null) { - db = getRepository().getWritableDatabase(); + db = getWritableDatabase(); } else { db = database; } @@ -347,7 +341,7 @@ public List findUnSyncedBeforeTime(int hours) { long time = calendar.getTimeInMillis(); - cursor = getRepository().getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, + cursor = getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, UPDATED_AT_COLUMN + " < ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? " + COLLATE_NOCASE, new String[]{Long.toString(time), TYPE_Unsynced}, null, null, null, null); weights = readAllWeights(cursor); @@ -366,7 +360,7 @@ public Weight findUnSyncedByEntityId(String entityId) { Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, + cursor = getReadableDatabase().query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ", new String[]{entityId, TYPE_Unsynced}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null); List weights = readAllWeights(cursor); @@ -387,7 +381,7 @@ public List findByEntityId(String entityId) { List weights = null; Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE, new String[]{entityId}, null, null, null, null); weights = readAllWeights(cursor); @@ -406,7 +400,7 @@ public List findWithNoZScore() { List result = new ArrayList<>(); Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, Z_SCORE + " = " + DEFAULT_Z_SCORE, null, null, null, null, null); result = readAllWeights(cursor); @@ -425,7 +419,7 @@ public Weight find(Long caseId) { Weight weight = null; Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, ID_COLUMN + " = ?", new String[]{caseId.toString()}, null, null, null, null); List weights = readAllWeights(cursor); @@ -446,7 +440,7 @@ public List findLast5(String entityid) { List weightList = new ArrayList<>(); Cursor cursor = null; try { - cursor = getRepository().getReadableDatabase() + cursor = getReadableDatabase() .query(WEIGHT_TABLE_NAME, WEIGHT_TABLE_COLUMNS, BASE_ENTITY_ID + " = ? " + COLLATE_NOCASE, new String[]{entityid}, null, null, UPDATED_AT_COLUMN + COLLATE_NOCASE + " DESC", null); weightList = readAllWeights(cursor); @@ -462,7 +456,7 @@ public List findLast5(String entityid) { public void delete(String id) { try { - getRepository().getWritableDatabase() + getWritableDatabase() .delete(WEIGHT_TABLE_NAME, ID_COLUMN + " = ? " + COLLATE_NOCASE + " AND " + SYNC_STATUS + " = ? ", new String[]{id, TYPE_Unsynced}); } catch (Exception e) { @@ -474,7 +468,7 @@ public void close(Long caseId) { try { ContentValues values = new ContentValues(); values.put(SYNC_STATUS, TYPE_Synced); - getRepository().getWritableDatabase() + getWritableDatabase() .update(WEIGHT_TABLE_NAME, values, ID_COLUMN + " = ?", new String[]{caseId.toString()}); } catch (Exception e) { Timber.e(Log.getStackTraceString(e)); diff --git a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightZScoreRepository.java b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightZScoreRepository.java index f3b92e2..0732062 100644 --- a/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightZScoreRepository.java +++ b/opensrp-growth-monitoring/src/main/java/org/smartregister/growthmonitoring/repository/WeightZScoreRepository.java @@ -9,7 +9,6 @@ import org.smartregister.growthmonitoring.domain.WeightZScore; import org.smartregister.growthmonitoring.util.GrowthMonitoringConstants; import org.smartregister.repository.BaseRepository; -import org.smartregister.repository.Repository; import java.util.ArrayList; import java.util.List; @@ -48,10 +47,6 @@ public class WeightZScoreRepository extends BaseRepository { "CREATE INDEX " + TABLE_NAME + "_" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + "_index ON " + TABLE_NAME + "(" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_MONTH + " COLLATE NOCASE);"; - public WeightZScoreRepository(Repository repository) { - super(repository); - } - public static void createTable(SQLiteDatabase database) { database.execSQL(CREATE_TABLE_QUERY); database.execSQL(CREATE_INDEX_SEX_QUERY); @@ -60,12 +55,11 @@ public static void createTable(SQLiteDatabase database) { /** * @param query - * * @return */ public boolean runRawQuery(String query) { try { - getRepository().getWritableDatabase().execSQL(query); + getWritableDatabase().execSQL(query); return true; } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); @@ -78,7 +72,7 @@ public List findByGender(Gender gender) { List result = new ArrayList<>(); Cursor cursor = null; try { - SQLiteDatabase database = getRepository().getReadableDatabase(); + SQLiteDatabase database = getReadableDatabase(); cursor = database.query(TABLE_NAME, null, GrowthMonitoringConstants.ColumnHeaders.COLUMN_SEX + " = ? " + COLLATE_NOCASE, new String[]{gender.name()}, null, null, null, null); diff --git a/sample/build.gradle b/sample/build.gradle index c1cd198..857a14c 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -73,7 +73,7 @@ android { } dependencies { - implementation('org.smartregister:opensrp-client-core:1.8.6-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:1.8.16-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' } From 979c59859ea8d143b618c14d9d32ef3296bae38c Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Tue, 14 Jan 2020 11:26:58 +0300 Subject: [PATCH 2/4] Edit weight updates - Change button to say "Delete Weight" instead of "Delete Record" - Remove header "DELETE RECORD - Update Arabic translations --- gradle.properties | 2 +- .../main/res/layout/edit_growth_dialog_view.xml | 15 --------------- .../src/main/res/values-ar/strings.xml | 2 +- .../src/main/res/values/strings.xml | 2 +- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0a1e13d..6181c82 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.1.13-SNAPSHOT +VERSION_NAME=1.1.14-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application diff --git a/opensrp-growth-monitoring/src/main/res/layout/edit_growth_dialog_view.xml b/opensrp-growth-monitoring/src/main/res/layout/edit_growth_dialog_view.xml index f3b80a4..9b54ad1 100644 --- a/opensrp-growth-monitoring/src/main/res/layout/edit_growth_dialog_view.xml +++ b/opensrp-growth-monitoring/src/main/res/layout/edit_growth_dialog_view.xml @@ -221,21 +221,6 @@ android:focusable="true" android:focusableInTouchMode="true" /> - -