Skip to content

Commit

Permalink
Merge pull request #61 from OpenSRP/issue60
Browse files Browse the repository at this point in the history
Add support for configurable Numeric Date Picker widget
  • Loading branch information
ndegwamartin authored Feb 6, 2020
2 parents d3a1e38 + 79d5147 commit df7298d
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.1.16-SNAPSHOT
VERSION_NAME=1.1.17-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application
Expand Down
12 changes: 9 additions & 3 deletions opensrp-growth-monitoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:$androidToolsBuildGradle"
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3'
}
}

Expand All @@ -16,7 +16,7 @@ apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'

jacoco {
toolVersion = "0.8.0"
toolVersion = "0.8.5"
}

android {
Expand Down Expand Up @@ -87,10 +87,16 @@ allprojects {
}

dependencies {
implementation('org.smartregister:opensrp-client-core:1.8.16-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:1.8.25-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
}

implementation('org.smartregister:opensrp-client-native-form:1.7.15-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
}

implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.vijay.jsonwizard.utils.NativeFormsProperties;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -61,15 +63,11 @@ public class EditGrowthDialogFragment extends DialogFragment {
private Button cancel;
private LinearLayout heightEntryLayout;
private CustomFontTextView recordHeight;
private boolean hasProperty;
private boolean monitorGrowth = false;
private final boolean monitorGrowth = GrowthMonitoringLibrary.getInstance().getAppProperties().isTrue(AppProperties.KEY.MONITOR_GROWTH);
private boolean isNumericDatePicker = GrowthMonitoringLibrary.getInstance().getAppProperties().isTrue(NativeFormsProperties.KEY.WIDGET_DATEPICKER_IS_NUMERIC);

private EditGrowthDialogFragment(Date dateOfBirth, WeightWrapper weightWrapper, HeightWrapper heightWrapper) {
HeightWrapper heightWrapperTemp;
hasProperty = GrowthMonitoringLibrary.getInstance().getAppProperties().hasProperty(AppProperties.KEY.MONITOR_GROWTH);
if (hasProperty) {
monitorGrowth = GrowthMonitoringLibrary.getInstance().getAppProperties().getPropertyBoolean(AppProperties.KEY.MONITOR_GROWTH);
}

this.dateOfBirth = dateOfBirth;
if (weightWrapper == null) {
Expand All @@ -79,7 +77,7 @@ private EditGrowthDialogFragment(Date dateOfBirth, WeightWrapper weightWrapper,
}

heightWrapperTemp = null;
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
if (heightWrapper == null) {
heightWrapperTemp = new HeightWrapper();
} else {
Expand Down Expand Up @@ -142,7 +140,7 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe

ViewGroup dialogView = setUpViews(inflater, container);

if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
recordHeight.setVisibility(View.VISIBLE);
heightEntryLayout.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -215,7 +213,7 @@ private ViewGroup setUpViews(LayoutInflater inflater, ViewGroup container) {

editWeight = dialogView.findViewById(R.id.edit_weight);
editHeight = dialogView.findViewById(R.id.edit_height);
earlierDatePicker = dialogView.findViewById(R.id.earlier_date_picker);
earlierDatePicker = dialogView.findViewById(isNumericDatePicker ? R.id.earlier_date_picker_numeric :R.id.earlier_date_picker);
nameView = dialogView.findViewById(R.id.child_name);
numberView = dialogView.findViewById(R.id.child_zeir_id);
ageView = dialogView.findViewById(R.id.child_age);
Expand Down Expand Up @@ -251,7 +249,7 @@ public void onClick(View view) {
return;
}
String heightString = null;
if (hasProperty & monitorGrowth) {
if (monitorGrowth) {
heightString = editHeight.getText().toString();
}
dismiss();
Expand All @@ -271,13 +269,13 @@ public void onClick(View view) {
DateTime updateTime = new DateTime(calendar.getTime());
if (currentGrowthDate != null && !org.apache.commons.lang3.time.DateUtils.isSameDay(calendar.getTime(), currentGrowthDate.toDate())) {
weightWrapper.setUpdatedWeightDate(updateTime, false);
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
heightWrapper.setUpdatedHeightDate(updateTime, false);
}
dateChanged = true;
}

if (hasProperty & monitorGrowth && heightString != null && !heightString.isEmpty()) {
if (monitorGrowth && heightString != null && !heightString.isEmpty()) {
updateHeightWrapperForBlankHeightEdit(updateTime);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.VisibleForTesting;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.ViewPager;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void setPersonDetails(CommonPersonObjectClient personDetails) {
this.personDetails = personDetails;
}

@VisibleForTesting
protected void sortWeights() {
HashMap<Long, Weight> weightHashMap = new HashMap<>();
for (Weight curWeight : getWeights()) {
Expand Down Expand Up @@ -111,6 +113,7 @@ protected void sortWeights() {
setWeights(weightList);
}

@VisibleForTesting
protected void sortHeights() {
HashMap<Long, Height> heightHashMap = new HashMap<>();
for (Height curHeight : getHeights()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.vijay.jsonwizard.utils.NativeFormsProperties;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -62,16 +64,10 @@ public class RecordGrowthDialogFragment extends DialogFragment {
private Button set;
private LinearLayout heightEntryLayout;
private CustomFontTextView recordHeight;
private static Boolean hasProperty;
private static Boolean monitorGrowth = false;

public static RecordGrowthDialogFragment newInstance(Date dateOfBirth, WeightWrapper weightWrapper,
HeightWrapper heightWrapper) {
private static final boolean monitorGrowth = GrowthMonitoringLibrary.getInstance().getAppProperties().isTrue(AppProperties.KEY.MONITOR_GROWTH);
private static final boolean isNumericDatePicker = GrowthMonitoringLibrary.getInstance().getAppProperties().isTrue(NativeFormsProperties.KEY.WIDGET_DATEPICKER_IS_NUMERIC);

hasProperty = GrowthMonitoringLibrary.getInstance().getAppProperties().hasProperty(AppProperties.KEY.MONITOR_GROWTH);
if (hasProperty) {
monitorGrowth = GrowthMonitoringLibrary.getInstance().getAppProperties().getPropertyBoolean(AppProperties.KEY.MONITOR_GROWTH);
}
public static RecordGrowthDialogFragment newInstance(Date dateOfBirth, WeightWrapper weightWrapper, HeightWrapper heightWrapper) {

WeightWrapper weightToSend;
if (weightWrapper == null) {
Expand All @@ -81,7 +77,7 @@ public static RecordGrowthDialogFragment newInstance(Date dateOfBirth, WeightWra
}

HeightWrapper heightToSend = null;
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
if (heightWrapper == null) {
heightToSend = new HeightWrapper();
} else {
Expand All @@ -94,7 +90,7 @@ public static RecordGrowthDialogFragment newInstance(Date dateOfBirth, WeightWra
Bundle args = new Bundle();
args.putSerializable(DATE_OF_BIRTH_TAG, dateOfBirth);
args.putSerializable(WEIGHT_WRAPPER_TAG, weightToSend);
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
args.putSerializable(HEIGHT_WRAPPER_TAG, heightToSend);
}
recordGrowthDialogFragment.setArguments(args);
Expand Down Expand Up @@ -185,7 +181,7 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe
}

private void setHeight() {
if (hasProperty && monitorGrowth && heightWrapper.getHeight() != null) {
if (monitorGrowth && heightWrapper.getHeight() != null) {
editHeight.setText(heightWrapper.getHeight().toString());
editHeight.setSelection(editHeight.getText().length());
}
Expand All @@ -199,7 +195,7 @@ private void setWeight() {
}

private void setVisibility() {
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
recordHeight.setVisibility(View.VISIBLE);
heightEntryLayout.setVisibility(View.VISIBLE);
}
Expand All @@ -208,7 +204,7 @@ private void setVisibility() {
private boolean getBundle() {
Bundle bundle = getArguments();
if (getWeightBundle(bundle)) return true;
if (hasProperty && monitorGrowth && getHeightBundle(bundle)) {
if (monitorGrowth && getHeightBundle(bundle)) {
return true;
}

Expand All @@ -223,7 +219,7 @@ private ViewGroup setUpViews(LayoutInflater inflater, ViewGroup container) {
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

editWeight = dialogView.findViewById(R.id.edit_weight);
earlierDatePicker = dialogView.findViewById(R.id.earlier_date_picker);
earlierDatePicker = dialogView.findViewById(isNumericDatePicker ? R.id.earlier_date_picker_numeric : R.id.earlier_date_picker);
nameView = dialogView.findViewById(R.id.child_name);
numberView = dialogView.findViewById(R.id.child_zeir_id);
ageView = dialogView.findViewById(R.id.child_age);
Expand Down Expand Up @@ -287,14 +283,14 @@ private void saveGrowthRecord() {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
weightWrapper.setUpdatedWeightDate(new DateTime(calendar.getTime()), false);
if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
heightWrapper.setUpdatedHeightDate(new DateTime(calendar.getTime()), false);
}

Float weight = Float.valueOf(weightString);
weightWrapper.setWeight(weight);

if (hasProperty && monitorGrowth) {
if (monitorGrowth) {
String heightString = editHeight.getText().toString();
if (!heightString.isEmpty()) {
Float height = Float.valueOf(heightString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.smartregister.growthmonitoring.util;

import java.util.Properties;
import com.vijay.jsonwizard.utils.NativeFormsProperties;

/**
* Created by ndegwamartin on 2019-06-07.
*/
public class AppProperties extends Properties {

public Boolean getPropertyBoolean(String key) {
return Boolean.valueOf(getProperty(key));
}

public Boolean hasProperty(String key) {
return getProperty(key) != null;
}
public class AppProperties extends NativeFormsProperties {

public static class KEY {
public static final String MONITOR_GROWTH = "monitor.height";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,18 @@
android:calendarViewShown="false"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true" />
android:focusableInTouchMode="true"
android:visibility="gone" />

<com.vijay.jsonwizard.customviews.NumericDatePicker
android:id="@+id/earlier_date_picker_numeric"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />

<Button
android:id="@+id/weight_delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@
android:focusableInTouchMode="true"
android:visibility="gone" />

<com.vijay.jsonwizard.customviews.NumericDatePicker
android:id="@+id/earlier_date_picker_numeric"
android:layout_width="wrap_content"
android:layout_height="@dimen/date_picker_height"
android:calendarViewShown="false"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -133,12 +132,25 @@ private List<Weight> getWeights() {
List<Weight> weightArrayList = new ArrayList<>();

Weight weight = new Weight();
weight.setDate(new Date());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 3);
weight.setDate(cal.getTime());
weight.setAnmId("demo");
weight.setBaseEntityId(DUMMY_BASE_ENTITY_ID);
weight.setChildLocationId(TEST_STRING);
weight.setKg(3.4f);

weightArrayList.add(weight);

weight = new Weight();
cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 9);
weight.setDate(cal.getTime());
weight.setAnmId("demo");
weight.setBaseEntityId(DUMMY_BASE_ENTITY_ID);
weight.setChildLocationId(TEST_STRING);
weight.setKg(5.2f);

weightArrayList.add(weight);
return weightArrayList;
}
Expand Down Expand Up @@ -175,4 +187,36 @@ public void testSortHeightsOrdersItemsCorrectly() {
Assert.assertEquals(Float.valueOf("30.4"), sortedHeights.get(2).getCm());
Assert.assertEquals(Float.valueOf("10.0"), sortedHeights.get(3).getCm());
}

@PrepareForTest({GrowthMonitoringLibrary.class})
@Test
public void testSortWeightsOrdersItemsCorrectly() {

PowerMockito.mockStatic(GrowthMonitoringLibrary.class);
PowerMockito.when(GrowthMonitoringLibrary.getInstance()).thenReturn(growthMonitoringLibrary);
PowerMockito.when(growthMonitoringLibrary.getAppProperties()).thenReturn(appProperties);
PowerMockito.when(appProperties.hasProperty(AppProperties.KEY.MONITOR_GROWTH)).thenReturn(true);
PowerMockito.when(appProperties.getPropertyBoolean(AppProperties.KEY.MONITOR_GROWTH)).thenReturn(true);

GrowthDialogFragment growthDialogFragment = GrowthDialogFragment.newInstance(dummydetails(), getWeights(), getHeights());
Assert.assertNotNull(growthDialogFragment);


List<Weight> unsortedWeights = growthDialogFragment.getWeights();

Assert.assertNotNull(unsortedWeights);

//Verify prior order
Assert.assertEquals(Float.valueOf("3.4"), unsortedWeights.get(0).getKg());
Assert.assertEquals(Float.valueOf("5.2"), unsortedWeights.get(1).getKg());

growthDialogFragment.sortWeights();

List<Weight> sortedWeights = growthDialogFragment.getWeights();
Assert.assertNotNull(unsortedWeights);

//Verify sorted order
Assert.assertEquals(Float.valueOf("5.2"), sortedWeights.get(0).getKg());
Assert.assertEquals(Float.valueOf("3.4"), sortedWeights.get(1).getKg());
}
}
Loading

0 comments on commit df7298d

Please sign in to comment.