From 8946616cb2464a27d0e20de832e258aa399139e5 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 12 Jan 2021 17:37:23 +0300 Subject: [PATCH 01/22] :recycle: Refactor to rename ProgressIndicatorView Renamed to ProgressIndicator since it's the actual Widget --- README.md | 2 +- .../BaseReportIndicatorsModel.java | 5 +++- ...icatorView.java => ProgressIndicator.java} | 10 +++---- .../model/BaseReportIndicatorsModelTest.java | 1 - ...ewTest.java => ProgressIndicatorTest.java} | 26 +++++++++---------- .../sample/presenter/SamplePresenter.java | 2 +- .../sample/view/ResourcesFragment.java | 4 +-- .../main/res/layout/fragment_resources.xml | 4 +-- 8 files changed, 28 insertions(+), 26 deletions(-) rename opensrp-reporting/src/main/java/org/smartregister/reporting/{domain => model}/BaseReportIndicatorsModel.java (83%) rename opensrp-reporting/src/main/java/org/smartregister/reporting/view/{ProgressIndicatorView.java => ProgressIndicator.java} (96%) rename opensrp-reporting/src/test/java/org/smartregister/reporting/view/{ProgressIndicatorViewTest.java => ProgressIndicatorTest.java} (83%) diff --git a/README.md b/README.md index 2f1bcbc6..229935df 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ using the property **progressDrawable** listed above, you can set the progressDr **Via XML:** ``` - - - Date: Fri, 15 Jan 2021 14:26:50 +0300 Subject: [PATCH 02/22] :fire: Refactor to remove unnecessary model abstraction Delete display models offering duplicate display options abstraction and rename classes semantically --- .../NumericIndicatorDisplayOptions.java | 21 +++++++++ .../domain/NumericIndicatorVisualization.java | 29 ------------ ...IndicatorData.java => PieChartConfig.java} | 6 +-- ...a => PieChartIndicatorDisplayOptions.java} | 47 ++++++++----------- ... => ReportingIndicatorDisplayOptions.java} | 8 ++-- .../IndicatorVisualisationFactory.java | 4 +- .../factory/NumericDisplayFactory.java | 15 +++--- .../reporting/factory/PieChartFactory.java | 18 +++---- .../reporting/model/NumericDisplayModel.java | 39 --------------- .../reporting/model/PieChartDisplayModel.java | 45 ------------------ .../reporting/util/ReportingUtil.java | 31 +++++++----- .../reporting/view/NumericIndicatorView.java | 16 ++----- .../reporting/view/PieChartIndicatorView.java | 39 ++++----------- .../PieChartIndicatorVisualizationTest.java | 12 ++--- .../reporting/impl/ReportingUtilTest.java | 7 ++- .../view/NumericDisplayFactoryTest.java | 4 +- .../reporting/view/PieChartFactoryTest.java | 10 ++-- .../sample/view/DashboardFragment.java | 16 +++---- 18 files changed, 122 insertions(+), 245 deletions(-) create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorDisplayOptions.java delete mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorVisualization.java rename opensrp-reporting/src/main/java/org/smartregister/reporting/domain/{PieChartIndicatorData.java => PieChartConfig.java} (87%) rename opensrp-reporting/src/main/java/org/smartregister/reporting/domain/{PieChartIndicatorVisualization.java => PieChartIndicatorDisplayOptions.java} (54%) rename opensrp-reporting/src/main/java/org/smartregister/reporting/domain/{ReportingIndicatorVisualization.java => ReportingIndicatorDisplayOptions.java} (75%) delete mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java delete mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorDisplayOptions.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorDisplayOptions.java new file mode 100644 index 00000000..e8bcdc54 --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorDisplayOptions.java @@ -0,0 +1,21 @@ +package org.smartregister.reporting.domain; + +public class NumericIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions { + private float value; + + public NumericIndicatorDisplayOptions(String label, float value) { + super(label); + this.value = value; + } + + public NumericIndicatorDisplayOptions() { + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorVisualization.java deleted file mode 100644 index d6e65f0f..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/NumericIndicatorVisualization.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.smartregister.reporting.domain; - -/** - * NumericIndicatorVisualization is the base class for indicator visualizations that display - * numeric data e.g. tallies - * The numeric indicator visualization consists the indicator label (text description) and the value (count/amount) to be displayed - * - * @author allan - */ -public class NumericIndicatorVisualization extends ReportingIndicatorVisualization { - private float value; - - public NumericIndicatorVisualization(String indicatorLabel, float value) { - super(indicatorLabel); - this.value = value; - } - - public NumericIndicatorVisualization() { - - } - - public float getValue() { - return value; - } - - public void setValue(float value) { - this.value = value; - } -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorData.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartConfig.java similarity index 87% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorData.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartConfig.java index 45021572..c0dd9333 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorData.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartConfig.java @@ -4,21 +4,21 @@ import java.util.List; -public class PieChartIndicatorData { +public class PieChartConfig { private boolean hasLabels; private boolean hasLabelsOutside; private boolean hasCenterCircle; private List slices; private PieChartSelectListener listener; - public PieChartIndicatorData(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List slices) { + public PieChartConfig(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List slices) { this.hasLabels = hasLabels; this.hasLabelsOutside = hasLabelsOutside; this.hasCenterCircle = hasCenterCircle; this.slices = slices; } - public PieChartIndicatorData() {} + public PieChartConfig() {} public boolean hasLabels() { return hasLabels; diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java similarity index 54% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java index 016fdd40..218787cd 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorVisualization.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/PieChartIndicatorDisplayOptions.java @@ -4,29 +4,20 @@ import java.util.List; -/** - * PieChartIndicatorVisualization is the base class for indicator visualizations that display - * pie chart data - * The pie chart indicator visualization consists the indicator label (text description) and the chart data that - * defines configuration of the chart that is to be displayed - * - * @author allan - */ +public class PieChartIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions { -public class PieChartIndicatorVisualization extends ReportingIndicatorVisualization { + private PieChartConfig pieChartConfig; - private PieChartIndicatorData chartData; - - public PieChartIndicatorVisualization(PieChartIndicatorData chartData) { - this.chartData = chartData; + public PieChartIndicatorDisplayOptions(PieChartConfig pieChartConfig) { + this.pieChartConfig = pieChartConfig; } - public PieChartIndicatorData getChartData() { - return chartData; + public PieChartConfig getPieChartConfig() { + return pieChartConfig; } - public void setChartData(PieChartIndicatorData chartData) { - this.chartData = chartData; + public void setPieChartConfig(PieChartConfig pieChartConfig) { + this.pieChartConfig = pieChartConfig; } public static class PieChartIndicatorVisualizationBuilder { @@ -74,17 +65,17 @@ public PieChartIndicatorVisualizationBuilder chartListener(PieChartSelectListene return this; } - public PieChartIndicatorVisualization build() { - PieChartIndicatorData chartData = new PieChartIndicatorData(); - chartData.setHasLabels(this.hasLabels); - chartData.setHasLabelsOutside(this.hasLabelsOutside); - chartData.setHasCenterCircle(this.hasCenterCircle); - chartData.setSlices(this.slices); - chartData.setListener(this.listener); - PieChartIndicatorVisualization pieChartIndicatorVisualization = new PieChartIndicatorVisualization(chartData); - pieChartIndicatorVisualization.setIndicatorLabel(this.indicatorLabel); - pieChartIndicatorVisualization.setIndicatorNote(this.indicatorNote); - return pieChartIndicatorVisualization; + public PieChartIndicatorDisplayOptions build() { + PieChartConfig chartConfig = new PieChartConfig(); + chartConfig.setHasLabels(this.hasLabels); + chartConfig.setHasLabelsOutside(this.hasLabelsOutside); + chartConfig.setHasCenterCircle(this.hasCenterCircle); + chartConfig.setSlices(this.slices); + chartConfig.setListener(this.listener); + PieChartIndicatorDisplayOptions pieChartIndicatorDisplayOptions = new PieChartIndicatorDisplayOptions(chartConfig); + pieChartIndicatorDisplayOptions.setIndicatorLabel(this.indicatorLabel); + pieChartIndicatorDisplayOptions.setIndicatorNote(this.indicatorNote); + return pieChartIndicatorDisplayOptions; } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java similarity index 75% rename from opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java rename to opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java index 4c08e86d..e6365c1d 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorVisualization.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ReportingIndicatorDisplayOptions.java @@ -1,7 +1,7 @@ package org.smartregister.reporting.domain; /** - * The ReportingIndicatorVisualization base class models reporting indicator visualizations with + * The ReportingIndicatorDisplay base class models reporting indicator visualizations with * common properties. * For instance, the different visualizations will always have a label (description) * of the specific chart. @@ -10,14 +10,14 @@ * @author allan */ -public class ReportingIndicatorVisualization { +public class ReportingIndicatorDisplayOptions { private String indicatorLabel; private String indicatorNote; - public ReportingIndicatorVisualization() { + public ReportingIndicatorDisplayOptions() { } - public ReportingIndicatorVisualization(String indicatorLabel) { + public ReportingIndicatorDisplayOptions(String indicatorLabel) { this.indicatorLabel = indicatorLabel; } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java index 3d64485a..c39ce483 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/IndicatorVisualisationFactory.java @@ -3,8 +3,8 @@ import android.content.Context; import android.view.View; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; public interface IndicatorVisualisationFactory { - View getIndicatorView(ReportingIndicatorVisualization data, Context context); + View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context); } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java index 5e0e8e36..116cd737 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/NumericDisplayFactory.java @@ -6,8 +6,8 @@ import android.widget.TextView; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.util.ReportingUtil; /** @@ -18,18 +18,17 @@ public class NumericDisplayFactory implements IndicatorVisualisationFactory { @Override - public View getIndicatorView(ReportingIndicatorVisualization data, Context context) { - NumericIndicatorVisualization indicatorData = (NumericIndicatorVisualization) data; + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { + NumericIndicatorDisplayOptions numericIndicatorDisplay = (NumericIndicatorDisplayOptions) displayOptions; View rootLayout = LayoutInflater.from(context).inflate(R.layout.numeric_indicator_view, null); TextView chartLabelTextView = rootLayout.findViewById(R.id.numeric_indicator_label); + chartLabelTextView.setText(numericIndicatorDisplay.getIndicatorLabel()); TextView chartValueTextView = rootLayout.findViewById(R.id.numeric_indicator_value); - chartLabelTextView.setText(indicatorData.getIndicatorLabel()); - // Only show the required decimal points - chartValueTextView.setText(ReportingUtil.formatDecimal(indicatorData.getValue())); + chartValueTextView.setText(ReportingUtil.formatDecimal(numericIndicatorDisplay.getValue())); return rootLayout; } -} +} \ No newline at end of file diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java index bb2bb315..f1dae027 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/PieChartFactory.java @@ -7,11 +7,11 @@ import android.widget.TextView; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.PieChartIndicatorData; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartConfig; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.domain.PieSliceValue; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.listener.PieChartSelectListener; import java.util.ArrayList; @@ -30,19 +30,19 @@ public class PieChartFactory implements IndicatorVisualisationFactory { @Override - public View getIndicatorView(ReportingIndicatorVisualization visualization, Context context) { + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.pie_chart_view, null); TextView chartLabelTextView = rootLayout.findViewById(R.id.pie_indicator_label); TextView chartNoteTextView = rootLayout.findViewById(R.id.pie_note_label); TextView numericValueTextView = rootLayout.findViewById(R.id.numeric_indicator_value); - PieChartIndicatorVisualization indicatorVisualization = (PieChartIndicatorVisualization) visualization; - PieChartIndicatorData chartConfiguration = indicatorVisualization.getChartData(); + PieChartIndicatorDisplayOptions pieChartIndicatorDisplayOptions = (PieChartIndicatorDisplayOptions) displayOptions; + PieChartConfig chartConfiguration = pieChartIndicatorDisplayOptions.getPieChartConfig(); - chartLabelTextView.setText(indicatorVisualization.getIndicatorLabel()); - if (indicatorVisualization.getIndicatorNote() != null) { - chartNoteTextView.setText(indicatorVisualization.getIndicatorNote()); + chartLabelTextView.setText(pieChartIndicatorDisplayOptions.getIndicatorLabel()); + if (pieChartIndicatorDisplayOptions.getIndicatorNote() != null) { + chartNoteTextView.setText(pieChartIndicatorDisplayOptions.getIndicatorNote()); } else { // Nothing to show chartNoteTextView.setVisibility(View.GONE); diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java deleted file mode 100644 index 0051f7d3..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/NumericDisplayModel.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.smartregister.reporting.model; - - -import org.smartregister.reporting.contract.ReportContract; - -public class NumericDisplayModel { - - private ReportContract.IndicatorView.CountType countType; - private String indicatorCode; - private int labelStringResource; - private float count; - - public NumericDisplayModel(ReportContract.IndicatorView.CountType countType, String indicatorCode, int labelStringResource, float count) { - this.countType = countType; - this.indicatorCode = indicatorCode; - this.labelStringResource = labelStringResource; - this.count = count; - } - - public ReportContract.IndicatorView.CountType getCountType() { - return countType; - } - - public String getIndicatorCode() { - return indicatorCode; - } - - public int getLabelStringResource() { - return labelStringResource; - } - - public float getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java deleted file mode 100644 index 2d389d15..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/model/PieChartDisplayModel.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.smartregister.reporting.model; - -import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.listener.PieChartSelectListener; - -import java.util.List; - -public class PieChartDisplayModel { - private List pieChartSlices; - private Integer indicatorLabel; - private Integer indicatorNote; - private PieChartSelectListener pieChartSelectListener; - - - public PieChartDisplayModel(List pieChartSlices, Integer indicatorLabel, Integer indicatorNote, PieChartSelectListener pieChartSelectListener) { - this.pieChartSlices = pieChartSlices; - this.indicatorLabel = indicatorLabel; - this.indicatorNote = indicatorNote; - this.pieChartSelectListener = pieChartSelectListener; - } - - public Integer getIndicatorNote() { - return indicatorNote; - } - - public Integer getIndicatorLabel() { - return indicatorLabel; - } - - public List getPieChartSlices() { - return pieChartSlices; - } - - public void setPieChartSlices(List pieChartSlices) { - this.pieChartSlices = pieChartSlices; - } - - public PieChartSelectListener getPieChartSelectListener() { - return pieChartSelectListener; - } - - public void setPieChartSelectListener(PieChartSelectListener pieChartSelectListener) { - this.pieChartSelectListener = pieChartSelectListener; - } -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index 92c7099e..45287452 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -6,12 +6,12 @@ import org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType; import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.domain.ReportingIndicatorVisualization; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.factory.IndicatorVisualisationFactory; import org.smartregister.reporting.listener.PieChartSelectListener; -import org.smartregister.reporting.model.NumericDisplayModel; -import org.smartregister.reporting.model.PieChartDisplayModel; import java.io.InputStream; import java.text.DecimalFormat; @@ -35,14 +35,14 @@ public static float getLatestCountBasedOnDate(List> return getLatestIndicatorCount(indicatorTallies, indicatorKey); } - public static View getIndicatorView(ReportingIndicatorVisualization reportingIndicatorVisualization, + public static View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, IndicatorVisualisationFactory visualisationFactory, Context context) { - return visualisationFactory.getIndicatorView(reportingIndicatorVisualization, context); + return visualisationFactory.getIndicatorView(displayOptions, context); } - public static NumericDisplayModel getIndicatorDisplayModel(CountType countType, String indicatorCode, - int labelResource, List> indicatorTallies) { - return new NumericDisplayModel(countType, indicatorCode, labelResource, getCount(countType, indicatorCode, indicatorTallies)); + public static NumericIndicatorDisplayOptions getNumericIndicatorDisplayOptions(CountType countType, String indicatorCode, + String label, List> indicatorTallies) { + return new NumericIndicatorDisplayOptions(label, getCount(countType, indicatorCode, indicatorTallies)); } private static float getCount(CountType countType, String indicatorCode, List> indicatorTallies) { @@ -55,9 +55,16 @@ private static float getCount(CountType countType, String indicatorCode, List pieChartSlices, - Integer indicatorLabel, Integer indicatorNote, PieChartSelectListener pieChartSelectListener) { - return new PieChartDisplayModel(pieChartSlices, indicatorLabel, indicatorNote, pieChartSelectListener); + public static PieChartIndicatorDisplayOptions getPieChartDisplayOptions(List pieChartSlices, + String indicatorLabel, String indicatorNote, PieChartSelectListener pieChartSelectListener) { + return new PieChartIndicatorDisplayOptions.PieChartIndicatorVisualizationBuilder() + .indicatorLabel(indicatorLabel) + .indicatorNote(indicatorNote) + .chartHasLabels(true) + .chartHasLabelsOutside(true) + .chartHasCenterCircle(false) + .chartSlices(pieChartSlices) + .chartListener(pieChartSelectListener).build(); } public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, @@ -90,7 +97,7 @@ public static AppProperties getProperties(Context context) { } /** - * Formats a double to a maximum of two decimal places or min of an integer representation eg. 2.457, 3.2, 189 + * Formats a double to a maximum of two decimal places or min of an integer representation eg. 2.457, 3.2, 189 */ public static String formatDecimal(double no) { DecimalFormat twoDForm = new DecimalFormat("0.###"); diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java index 1360b2a2..9ba88e7b 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java @@ -4,9 +4,8 @@ import android.view.View; import org.smartregister.reporting.contract.ReportContract; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.factory.NumericDisplayFactory; -import org.smartregister.reporting.model.NumericDisplayModel; import static org.smartregister.reporting.util.ReportingUtil.getIndicatorView; @@ -14,22 +13,17 @@ public class NumericIndicatorView implements ReportContract.IndicatorView { private Context context; - private NumericDisplayModel numericDisplayModel; + private NumericIndicatorDisplayOptions displayOptions; private NumericDisplayFactory numericDisplayFactory; - public NumericIndicatorView(Context context, NumericDisplayModel numericDisplayModel) { + public NumericIndicatorView(Context context, NumericIndicatorDisplayOptions displayOptions) { this.context = context; - this.numericDisplayModel = numericDisplayModel; + this.displayOptions = displayOptions; numericDisplayFactory = new NumericDisplayFactory(); } @Override public View createView() { - return getIndicatorView(getNumericVisualization(), numericDisplayFactory, context); - } - - private NumericIndicatorVisualization getNumericVisualization() { - return new NumericIndicatorVisualization(context.getResources().getString( - numericDisplayModel.getLabelStringResource()), numericDisplayModel.getCount()); + return getIndicatorView(displayOptions, numericDisplayFactory, context); } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java index a884c121..c3d45b14 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java @@ -6,11 +6,10 @@ import org.jetbrains.annotations.Nullable; import org.smartregister.reporting.contract.ReportContract; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.factory.PieChartFactory; import org.smartregister.reporting.listener.PieChartSelectListener; -import org.smartregister.reporting.model.PieChartDisplayModel; import timber.log.Timber; @@ -20,55 +19,35 @@ public class PieChartIndicatorView implements ReportContract.IndicatorView { private Context context; private PieChartFactory pieChartFactory; - private PieChartDisplayModel pieChartDisplayModel; + PieChartIndicatorDisplayOptions displayOptions; - public PieChartIndicatorView(Context context, PieChartDisplayModel pieChartDisplayModel) { + public PieChartIndicatorView(Context context, PieChartIndicatorDisplayOptions displayOptions) { pieChartFactory = new PieChartFactory(); - this.pieChartDisplayModel = pieChartDisplayModel; + this.displayOptions = displayOptions; this.context = context; } /** * Generating a pie chart is memory intensive in lower end devices. * Allow @java.lang.OutOfMemoryError is recorded in some devices + * * @return view */ @Override @Nullable public View createView() { try { - PieChartIndicatorVisualization pieChartIndicatorVisualization = getPieChartVisualization(); - - if (pieChartDisplayModel.getIndicatorLabel() != null) { - pieChartIndicatorVisualization.setIndicatorLabel(context.getResources().getString(pieChartDisplayModel.getIndicatorLabel())); - } - - if (pieChartDisplayModel.getIndicatorNote() != null) { - pieChartIndicatorVisualization.setIndicatorNote(context.getResources().getString(pieChartDisplayModel.getIndicatorNote())); + if (displayOptions.getPieChartConfig().getListener() == null) { + displayOptions.getPieChartConfig().setListener(new ChartListener()); } - return getIndicatorView(pieChartIndicatorVisualization, pieChartFactory, context); - }catch (OutOfMemoryError e){ + return getIndicatorView(displayOptions, pieChartFactory, context); + } catch (OutOfMemoryError e) { Timber.e(e); } return null; } - private PieChartIndicatorVisualization getPieChartVisualization() { - // Build the chart - String pieChartLabel = "No label provided"; //to avoid crash when string resource not provide - if (pieChartDisplayModel.getIndicatorLabel() != null) { - pieChartLabel = context.getResources().getString(pieChartDisplayModel.getIndicatorLabel()); - } - return new PieChartIndicatorVisualization.PieChartIndicatorVisualizationBuilder() - .indicatorLabel(pieChartLabel) - .chartHasLabels(true) - .chartHasLabelsOutside(true) - .chartHasCenterCircle(false) - .chartSlices(pieChartDisplayModel.getPieChartSlices()) - .chartListener(pieChartDisplayModel.getPieChartSelectListener() == null ? new ChartListener() : pieChartDisplayModel.getPieChartSelectListener()).build(); - } - public class ChartListener implements PieChartSelectListener { @Override public void handleOnSelectEvent(PieChartSlice slice) { diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java index 1dff4fa6..97f96c19 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/domain/PieChartIndicatorVisualizationTest.java @@ -46,7 +46,7 @@ public void pieChartIndicatorVisualizationBuilderInitsVisualization() { chartSlices.add(noSlice); // Build the chart - PieChartIndicatorVisualization pieChartIndicatorVisualization = new PieChartIndicatorVisualization.PieChartIndicatorVisualizationBuilder() + PieChartIndicatorDisplayOptions pieChartIndicatorVisualization = new PieChartIndicatorDisplayOptions.PieChartIndicatorVisualizationBuilder() .indicatorLabel(indicatorLabel) .chartHasLabels(true) .indicatorNote("Note") @@ -56,11 +56,11 @@ public void pieChartIndicatorVisualizationBuilderInitsVisualization() { .chartListener(null).build(); Assert.assertEquals(indicatorLabel, pieChartIndicatorVisualization.getIndicatorLabel()); - Assert.assertTrue(pieChartIndicatorVisualization.getChartData().hasLabels()); - Assert.assertTrue(pieChartIndicatorVisualization.getChartData().hasLabelsOutside()); - Assert.assertFalse(pieChartIndicatorVisualization.getChartData().hasCenterCircle()); - Assert.assertEquals(indicatorValue1, pieChartIndicatorVisualization.getChartData().getSlices().get(0).getValue(), 0.0001); - Assert.assertEquals(indicatorValue2, pieChartIndicatorVisualization.getChartData().getSlices().get(1).getValue(), 0.0001); + Assert.assertTrue(pieChartIndicatorVisualization.getPieChartConfig().hasLabels()); + Assert.assertTrue(pieChartIndicatorVisualization.getPieChartConfig().hasLabelsOutside()); + Assert.assertFalse(pieChartIndicatorVisualization.getPieChartConfig().hasCenterCircle()); + Assert.assertEquals(indicatorValue1, pieChartIndicatorVisualization.getPieChartConfig().getSlices().get(0).getValue(), 0.0001); + Assert.assertEquals(indicatorValue2, pieChartIndicatorVisualization.getPieChartConfig().getSlices().get(1).getValue(), 0.0001); } } diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index dfa3e857..b05ab270 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -7,7 +7,6 @@ import org.mockito.junit.MockitoJUnitRunner; import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; -import org.smartregister.reporting.model.NumericDisplayModel; import org.smartregister.reporting.util.ReportingUtil; import java.util.Arrays; @@ -19,7 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.smartregister.reporting.BaseUnitTest.getDateTime; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorDisplayModel; +import static org.smartregister.reporting.util.ReportingUtil.getNumericIndicatorDisplay; @RunWith(MockitoJUnitRunner.class) public class ReportingUtilTest { @@ -70,14 +69,14 @@ public void testGetIndicatorDisplayModelTotalAndLatestCount() { List indicatorTallies = Collections.unmodifiableList(Collections.unmodifiableList(Arrays.asList(tally1, tally2, tally3, tally4))); //Test get model with total count - NumericDisplayModel NumericDisplayModel = getIndicatorDisplayModel(ReportContract.IndicatorView.CountType.TOTAL_COUNT, "indicator1", 182998, indicatorTallies); + NumericDisplayModel NumericDisplayModel = getNumericIndicatorDisplay(ReportContract.IndicatorView.CountType.TOTAL_COUNT, "indicator1", 182998, indicatorTallies); assertNotNull(NumericDisplayModel); assertEquals(12, NumericDisplayModel.getCount(), 0); assertEquals("indicator1", NumericDisplayModel.getIndicatorCode()); assertEquals(182998, NumericDisplayModel.getLabelStringResource()); //Test get model with total count - NumericDisplayModel NumericDisplayModel2 = getIndicatorDisplayModel(ReportContract.IndicatorView.CountType.LATEST_COUNT, "indicator2", 182999, indicatorTallies); + NumericDisplayModel NumericDisplayModel2 = getNumericIndicatorDisplay(ReportContract.IndicatorView.CountType.LATEST_COUNT, "indicator2", 182999, indicatorTallies); assertNotNull(NumericDisplayModel2); assertEquals(13, NumericDisplayModel2.getCount(), 0); assertEquals("indicator2", NumericDisplayModel2.getIndicatorCode()); diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java index c220cc1d..bbf12cef 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/NumericDisplayFactoryTest.java @@ -19,7 +19,7 @@ import org.powermock.modules.junit4.rule.PowerMockRule; import org.smartregister.reporting.BaseUnitTest; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.NumericIndicatorVisualization; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.factory.NumericDisplayFactory; @PrepareForTest(LayoutInflater.class) @@ -29,7 +29,7 @@ public class NumericDisplayFactoryTest extends BaseUnitTest { public PowerMockRule rule = new PowerMockRule(); @Mock - private NumericIndicatorVisualization visualization; + private NumericIndicatorDisplayOptions visualization; @Mock private Context context; diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java index 0ad4eeb1..4d18952e 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/PieChartFactoryTest.java @@ -19,8 +19,8 @@ import org.powermock.modules.junit4.rule.PowerMockRule; import org.smartregister.reporting.BaseUnitTest; import org.smartregister.reporting.R; -import org.smartregister.reporting.domain.PieChartIndicatorData; -import org.smartregister.reporting.domain.PieChartIndicatorVisualization; +import org.smartregister.reporting.domain.PieChartConfig; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.factory.PieChartFactory; import lecho.lib.hellocharts.view.PieChartView; @@ -32,7 +32,7 @@ public class PieChartFactoryTest extends BaseUnitTest { public PowerMockRule rule = new PowerMockRule(); @Mock - private PieChartIndicatorVisualization visualization; + private PieChartIndicatorDisplayOptions visualization; @Mock private Context context; @@ -56,7 +56,7 @@ public class PieChartFactoryTest extends BaseUnitTest { private LinearLayout rootLayout; @Mock - private PieChartIndicatorData chartConfiguration; + private PieChartConfig chartConfiguration; @InjectMocks private PieChartFactory pieChartFactory; @@ -76,7 +76,7 @@ public void getPieChartIndicatorViewReturnsCorrectView() { Mockito.doReturn(chartNoteTextView).when(rootLayout).findViewById(R.id.pie_note_label); Mockito.doReturn(numericValueTextView).when(rootLayout).findViewById(R.id.numeric_indicator_value); Mockito.doReturn(pieChartView).when(rootLayout).findViewById(R.id.pie_chart); - Mockito.doReturn(chartConfiguration).when(visualization).getChartData(); + Mockito.doReturn(chartConfiguration).when(visualization).getPieChartConfig(); View view = pieChartFactorySpy.getIndicatorView(visualization, context); Assert.assertNotNull(view); Assert.assertTrue(view instanceof LinearLayout); diff --git a/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java b/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java index 236f5396..c9a57905 100644 --- a/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java +++ b/sample/src/main/java/org/smartregister/sample/view/DashboardFragment.java @@ -14,8 +14,8 @@ import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.model.NumericDisplayModel; import org.smartregister.reporting.view.NumericIndicatorView; import org.smartregister.reporting.view.PieChartIndicatorView; import org.smartregister.sample.R; @@ -28,8 +28,8 @@ import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.LATEST_COUNT; import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.TOTAL_COUNT; import static org.smartregister.reporting.util.ReportingUtil.addPieChartSlices; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorDisplayModel; -import static org.smartregister.reporting.util.ReportingUtil.getPieChartDisplayModel; +import static org.smartregister.reporting.util.ReportingUtil.getNumericIndicatorDisplayOptions; +import static org.smartregister.reporting.util.ReportingUtil.getPieChartDisplayOptions; import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; public class DashboardFragment extends Fragment implements ReportContract.View, LoaderManager.LoaderCallbacks>> { @@ -103,15 +103,15 @@ public void setIndicatorTallies(List> indicatorTalli } private void createSampleReportViews(ViewGroup mainLayout) { - NumericDisplayModel indicator1 = getIndicatorDisplayModel(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); - mainLayout.addView(new NumericIndicatorView(getContext(), indicator1).createView()); + NumericIndicatorDisplayOptions intDisplay = getNumericIndicatorDisplayOptions(TOTAL_COUNT, ChartUtil.numericIndicatorKey, getString(R.string.total_under_5_count), indicatorTallies); + mainLayout.addView(new NumericIndicatorView(getContext(), intDisplay).createView()); PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartYesIndicatorKey, getResources().getString(R.string.yes_slice_label), getResources().getColor(R.color.colorPieChartGreen), indicatorTallies); PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartNoIndicatorKey, getResources().getString(R.string.no_button_label), getResources().getColor(R.color.colorPieChartRed), indicatorTallies); - mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayModel(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note, null)).createView()); + mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayOptions(addPieChartSlices(indicator2_1, indicator2_2), getString(R.string.num_of_lieterate_children_0_60_label), getString(R.string.sample_note), null)).createView()); - NumericDisplayModel floatIndicatorCount = getIndicatorDisplayModel(TOTAL_COUNT, "S_IND_005", R.string.float_count, indicatorTallies); - mainLayout.addView(new NumericIndicatorView(getContext(), floatIndicatorCount).createView()); + NumericIndicatorDisplayOptions floatDisplay = getNumericIndicatorDisplayOptions(TOTAL_COUNT, "S_IND_005", getContext().getString(R.string.float_count), indicatorTallies); + mainLayout.addView(new NumericIndicatorView(getContext(), floatDisplay).createView()); } @NonNull From 02757018d314be91e992bc93e6f00267d2cabaf6 Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 18 Jan 2021 15:07:58 +0300 Subject: [PATCH 03/22] :recycle: Remove static imports for readability --- .../smartregister/reporting/view/NumericIndicatorView.java | 5 ++--- .../smartregister/reporting/view/PieChartIndicatorView.java | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java index 9ba88e7b..272afe07 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/NumericIndicatorView.java @@ -6,8 +6,7 @@ import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.factory.NumericDisplayFactory; - -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorView; +import org.smartregister.reporting.util.ReportingUtil; public class NumericIndicatorView implements ReportContract.IndicatorView { @@ -24,6 +23,6 @@ public NumericIndicatorView(Context context, NumericIndicatorDisplayOptions disp @Override public View createView() { - return getIndicatorView(displayOptions, numericDisplayFactory, context); + return ReportingUtil.getIndicatorView(displayOptions, numericDisplayFactory, context); } } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java index c3d45b14..a512f120 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java @@ -10,10 +10,10 @@ import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.factory.PieChartFactory; import org.smartregister.reporting.listener.PieChartSelectListener; +import org.smartregister.reporting.util.ReportingUtil; import timber.log.Timber; -import static org.smartregister.reporting.util.ReportingUtil.getIndicatorView; public class PieChartIndicatorView implements ReportContract.IndicatorView { @@ -40,7 +40,7 @@ public View createView() { if (displayOptions.getPieChartConfig().getListener() == null) { displayOptions.getPieChartConfig().setListener(new ChartListener()); } - return getIndicatorView(displayOptions, pieChartFactory, context); + return ReportingUtil.getIndicatorView(displayOptions, pieChartFactory, context); } catch (OutOfMemoryError e) { Timber.e(e); } From b016df8e0fdb408d022b679c84304081ada8b362 Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 18 Jan 2021 16:45:06 +0300 Subject: [PATCH 04/22] :recycle: User as root of view layouts --- .../src/main/res/layout/numeric_indicator_view.xml | 4 ++-- opensrp-reporting/src/main/res/layout/pie_chart_view.xml | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml b/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml index 7fd51df6..84649268 100644 --- a/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml +++ b/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml @@ -1,5 +1,5 @@ - @@ -38,4 +38,4 @@ android:layout_marginTop="24dp" android:background="@color/indicatorSplitLine" /> - \ No newline at end of file + \ No newline at end of file diff --git a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml index e314abdd..3f320c15 100644 --- a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml +++ b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml @@ -1,5 +1,5 @@ - @@ -45,8 +45,7 @@ + android:layout_height="250dp" /> - \ No newline at end of file + \ No newline at end of file From b33b5db01d0ad205973882a24248b889e9fbc03e Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 18 Jan 2021 16:50:20 +0300 Subject: [PATCH 05/22] :construction: Add ProgressIndicator Factory implementation To allow building a progress indicator and getting the view to include --- .../domain/ProgressIndicatorConfig.java | 53 ++++++++++++++++ .../ProgressIndicatorDisplayOptions.java | 63 +++++++++++++++++++ .../ProgressIndicatorVisualization.java | 5 ++ .../factory/ProgressIndicatorFactory.java | 29 +++++++++ .../reporting/view/ProgressIndicatorView.java | 31 +++++++++ .../main/res/layout/progress_indicator.xml | 12 ++++ 6 files changed, 193 insertions(+) create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java create mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java create mode 100644 opensrp-reporting/src/main/res/layout/progress_indicator.xml diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java new file mode 100644 index 00000000..b90c3e35 --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java @@ -0,0 +1,53 @@ +package org.smartregister.reporting.domain; + +public class ProgressIndicatorConfig { + + private int progressVal; + private String title; + private String subtitle; + private int foregroundColor; + private int backgroundColor; + + public ProgressIndicatorConfig() { + } + + public int getProgressVal() { + return progressVal; + } + + public void setProgressVal(int progressVal) { + this.progressVal = progressVal; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSubtitle() { + return subtitle; + } + + public void setSubtitle(String subtitle) { + this.subtitle = subtitle; + } + + public int getForegroundColor() { + return foregroundColor; + } + + public void setForegroundColor(int foregroundColor) { + this.foregroundColor = foregroundColor; + } + + public int getBackgroundColor() { + return backgroundColor; + } + + public void setBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java new file mode 100644 index 00000000..01ab08a1 --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java @@ -0,0 +1,63 @@ +package org.smartregister.reporting.domain; + + +public class ProgressIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions{ + + private ProgressIndicatorConfig config; + + + public ProgressIndicatorDisplayOptions(ProgressIndicatorConfig progressIndicatorConfig) { + this.config = progressIndicatorConfig; + } + + public ProgressIndicatorConfig getConfig() { + return config; + } + + public void setConfig(ProgressIndicatorConfig config) { + this.config = config; + } + + public static class ProgressIndicatorBuilder { + private int progressVal; + private String title; + private String subtitle; + private int foregroundColor; + private int backgroundColor; + + public ProgressIndicatorBuilder withProgressValue(int value) { + this.progressVal = value; + return this; + } + + public ProgressIndicatorBuilder withTitle(String title) { + this.title = title; + return this; + } + + public ProgressIndicatorBuilder withSubtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + public ProgressIndicatorBuilder withForegroundColor(int foregroundColor) { + this.foregroundColor = foregroundColor; + return this; + } + + public ProgressIndicatorBuilder withBackgroundColor(int backgroundColor) { + this.backgroundColor = backgroundColor; + return this; + } + + public ProgressIndicatorDisplayOptions build() { + ProgressIndicatorConfig config = new ProgressIndicatorConfig(); + config.setProgressVal(this.progressVal); + config.setTitle(this.title); + config.setSubtitle(this.subtitle); + config.setForegroundColor(this.foregroundColor); + config.setBackgroundColor(this.backgroundColor); + return new ProgressIndicatorDisplayOptions(config); + } + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java new file mode 100644 index 00000000..d0e1957b --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java @@ -0,0 +1,5 @@ +package org.smartregister.reporting.domain; + +public class ProgressIndicatorVisualization extends ReportingIndicatorDisplayOptions { + +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java new file mode 100644 index 00000000..9d7cf60a --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java @@ -0,0 +1,29 @@ +package org.smartregister.reporting.factory; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.smartregister.reporting.R; +import org.smartregister.reporting.domain.ProgressIndicatorConfig; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; +import org.smartregister.reporting.view.ProgressIndicator; + +public class ProgressIndicatorFactory implements IndicatorVisualisationFactory { + @Override + public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { + ProgressIndicatorConfig config = ((ProgressIndicatorDisplayOptions) displayOptions).getConfig(); + LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.progress_indicator, null); + ProgressIndicator progressWidget = rootLayout.findViewById(R.id.progressIndicatorView); + progressWidget.setTitle(config.getTitle()); + progressWidget.setSubTitle(config.getSubtitle()); + progressWidget.setProgress(config.getProgressVal()); + progressWidget.setProgressBarForegroundColor(config.getForegroundColor()); + progressWidget.setProgressBarBackgroundColor(config.getBackgroundColor()); + + return rootLayout; + } +} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java new file mode 100644 index 00000000..91d33c9a --- /dev/null +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicatorView.java @@ -0,0 +1,31 @@ +package org.smartregister.reporting.view; + +import android.content.Context; +import android.view.View; + +import org.jetbrains.annotations.Nullable; +import org.smartregister.reporting.contract.ReportContract; +import org.smartregister.reporting.factory.ProgressIndicatorFactory; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.util.ReportingUtil; + +public class ProgressIndicatorView implements ReportContract.IndicatorView { + + private Context context; + private ProgressIndicatorDisplayOptions displayOptions; + private ProgressIndicatorFactory progressIndicatorFactory; + + + public ProgressIndicatorView(Context context, ProgressIndicatorDisplayOptions displayOptions) { + this.progressIndicatorFactory = new ProgressIndicatorFactory(); + this.context = context; + this.displayOptions = displayOptions; + } + + @Nullable + @Override + public View createView() { + return ReportingUtil.getIndicatorView(displayOptions, progressIndicatorFactory, context); + } + +} diff --git a/opensrp-reporting/src/main/res/layout/progress_indicator.xml b/opensrp-reporting/src/main/res/layout/progress_indicator.xml new file mode 100644 index 00000000..b3f6747e --- /dev/null +++ b/opensrp-reporting/src/main/res/layout/progress_indicator.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file From 03ba36a9b13e675baa5bbf1cacf39583f11dea6f Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 19 Jan 2021 18:30:37 +0300 Subject: [PATCH 06/22] :construction: Add get progress indicator % --- .../reporting/domain/ProgressIndicatorVisualization.java | 5 ----- .../org/smartregister/reporting/util/ReportingUtil.java | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) delete mode 100644 opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java deleted file mode 100644 index d0e1957b..00000000 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorVisualization.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.smartregister.reporting.domain; - -public class ProgressIndicatorVisualization extends ReportingIndicatorDisplayOptions { - -} diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index 45287452..6d8ab1e0 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -9,6 +9,7 @@ import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.factory.IndicatorVisualisationFactory; import org.smartregister.reporting.listener.PieChartSelectListener; @@ -67,6 +68,12 @@ public static PieChartIndicatorDisplayOptions getPieChartDisplayOptions(List> indicatorTallies) { + float count = getCount(countType, indicatorCode, indicatorTallies); + return (count / target) * 100; + } + public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, List> indicatorTallies, String key) { return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, key); From 635c9e70b929d13519c5237e356cffcb9a1b38cf Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 19 Jan 2021 18:31:00 +0300 Subject: [PATCH 07/22] :camera_flash: Update reporting snapshot --- gradle.properties | 2 +- .../src/main/res/layout/numeric_indicator_view.xml | 4 ++-- opensrp-reporting/src/main/res/layout/pie_chart_view.xml | 4 ++-- opensrp-reporting/src/main/res/layout/progress_indicator.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 589468fe..38aebb7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.0.22-SNAPSHOT +VERSION_NAME=0.1.0-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library diff --git a/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml b/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml index 84649268..7fd51df6 100644 --- a/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml +++ b/opensrp-reporting/src/main/res/layout/numeric_indicator_view.xml @@ -1,5 +1,5 @@ - @@ -38,4 +38,4 @@ android:layout_marginTop="24dp" android:background="@color/indicatorSplitLine" /> - \ No newline at end of file + \ No newline at end of file diff --git a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml index 3f320c15..76340e0e 100644 --- a/opensrp-reporting/src/main/res/layout/pie_chart_view.xml +++ b/opensrp-reporting/src/main/res/layout/pie_chart_view.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/opensrp-reporting/src/main/res/layout/progress_indicator.xml b/opensrp-reporting/src/main/res/layout/progress_indicator.xml index b3f6747e..bcc7eaab 100644 --- a/opensrp-reporting/src/main/res/layout/progress_indicator.xml +++ b/opensrp-reporting/src/main/res/layout/progress_indicator.xml @@ -1,5 +1,5 @@ - @@ -9,4 +9,4 @@ android:layout_height="wrap_content" android:layout_weight="1" /> - \ No newline at end of file + \ No newline at end of file From b31d06636dc04777b05b08d9b0b3ffe0c70b4f5c Mon Sep 17 00:00:00 2001 From: Allan O Date: Fri, 22 Jan 2021 13:16:08 +0300 Subject: [PATCH 08/22] :construction: Add setting of title text color --- .../reporting/view/ProgressIndicator.java | 26 +++++++++++++++++-- ... => progress_indicator_factory_layout.xml} | 6 +++-- .../values/attrs_progress_indicator_view.xml | 1 + .../src/main/res/values/testStyles.xml | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) rename opensrp-reporting/src/main/res/layout/{progress_indicator.xml => progress_indicator_factory_layout.xml} (68%) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java index 6df0cb07..7adeac2a 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java @@ -32,6 +32,7 @@ public class ProgressIndicator extends LinearLayout { private int progressBarBackgroundColor; private int progressBarForegroundColor; + private int progressBarTitleColor; private int progressDrawable; private String title; private String subTitle; @@ -42,6 +43,7 @@ public class ProgressIndicator extends LinearLayout { private static final String PROGRESSBAR_FOREGROUND_COLOR = "progressbar_foreground_color"; private static final String PROGRESSBAR_BACKGROUND_COLOR = "progressbar_background_color"; private static final String PROGRESSBAR_TITLE = "progressbar_title"; + private static final String PROGRESSBAR_TITLE_COLOR = "progressbar_title_color"; private static final String PROGRESSBAR_SUB_TITLE = "progressbar_sub_title"; private static final String PROGRESSBAR_PROGRESS = "progressbar_progress"; private static final String PROGRESSBAR_INSTANCE_STATE = "progressbar_instance_state"; @@ -123,19 +125,20 @@ private void resetLayoutParams(TypedArray typedArray) { setResourceValues(typedArray); - processProgressBarLayoutReset(progress, progressBarForegroundColor, progressBarBackgroundColor, progressDrawable); + processProgressBarLayoutReset(progress, progressBarTitleColor, progressBarForegroundColor, progressBarBackgroundColor, progressDrawable); } private void setResourceValues(TypedArray typedArray) { + progressBarTitleColor = progressBarTitleColor != 0 ? progressBarTitleColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarTitleColor, 0); progressBarForegroundColor = progressBarForegroundColor != 0 ? progressBarForegroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarForegroundColor, 0); progressBarBackgroundColor = progressBarBackgroundColor != 0 ? progressBarBackgroundColor : typedArray.getColor(R.styleable.ProgressIndicatorView_progressBarBackgroundColor, 0); progressDrawable = progressDrawable != 0 ? progressDrawable : typedArray.getResourceId(R.styleable.ProgressIndicatorView_progressDrawable, 0); } - private void processProgressBarLayoutReset(int progress, int progressBarForegroundColor, int progressBarBackgroundColor, int progressDrawable) { + private void processProgressBarLayoutReset(int progress, int progressBarTitleColor, int progressBarForegroundColor, int progressBarBackgroundColor, int progressDrawable) { ProgressBar progressBarView = findViewById(R.id.progressbar_view); progressBarView.setProgressDrawable(progressDrawable > 0 ? getContext().getResources().getDrawable(progressDrawable) : progressBarView.getProgressDrawable()); @@ -143,6 +146,15 @@ private void processProgressBarLayoutReset(int progress, int progressBarForegrou programmaticallyResetProgressBarBackgroundDrawable(progressBarView, progressBarForegroundColor, progressBarBackgroundColor); + resetProgressBarTitleColor(progressBarTitleColor); + + } + + protected void resetProgressBarTitleColor(int progressBarTitleColor) { + if (progressBarTitleColor != 0) { + TextView titleTextView = findViewById(R.id.title_textview); + titleTextView.setTextColor(progressBarTitleColor); + } } @TargetApi(Build.VERSION_CODES.M) @@ -194,6 +206,7 @@ public void onRestoreInstanceState(Parcelable state) { Bundle bundle = (Bundle) state; // Load back our custom view state + this.progressBarTitleColor = bundle.getInt(PROGRESSBAR_TITLE_COLOR); this.progressBarForegroundColor = bundle.getInt(PROGRESSBAR_FOREGROUND_COLOR); this.progressBarBackgroundColor = bundle.getInt(PROGRESSBAR_BACKGROUND_COLOR); this.title = bundle.getString(PROGRESSBAR_TITLE); @@ -226,6 +239,15 @@ private void refreshLayout() { } } + public int getProgressBarTitleColor() { + return progressBarTitleColor; + } + + public void setProgressBarTitleColor(int progressBarTitleColor) { + this.progressBarTitleColor = progressBarTitleColor; + refreshLayout(); + } + public int getProgressBarBackgroundColor() { return progressBarBackgroundColor; } diff --git a/opensrp-reporting/src/main/res/layout/progress_indicator.xml b/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml similarity index 68% rename from opensrp-reporting/src/main/res/layout/progress_indicator.xml rename to opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml index bcc7eaab..b198849e 100644 --- a/opensrp-reporting/src/main/res/layout/progress_indicator.xml +++ b/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml @@ -1,11 +1,13 @@ + android:layout_height="wrap_content" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp"> diff --git a/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml b/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml index 538a0718..bff880af 100644 --- a/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml +++ b/opensrp-reporting/src/main/res/values/attrs_progress_indicator_view.xml @@ -3,6 +3,7 @@ + diff --git a/opensrp-reporting/src/main/res/values/testStyles.xml b/opensrp-reporting/src/main/res/values/testStyles.xml index 8740525e..b3d253c8 100644 --- a/opensrp-reporting/src/main/res/values/testStyles.xml +++ b/opensrp-reporting/src/main/res/values/testStyles.xml @@ -5,6 +5,7 @@ Sub Title 25 @drawable/progress_indicator_bg + @color/colorReportingIndicatorLabel @color/colorPastelGreen @color/colorSecondaryGreen From f312ffc7b2c4f234e0562475f70c6fd4950dff97 Mon Sep 17 00:00:00 2001 From: Allan O Date: Fri, 22 Jan 2021 15:04:30 +0300 Subject: [PATCH 09/22] :construction: Add setting indicator label & color configs --- .../domain/ProgressIndicatorConfig.java | 38 ++++++++++++++----- .../ProgressIndicatorDisplayOptions.java | 32 +++++++++++----- .../factory/ProgressIndicatorFactory.java | 13 +++++-- .../progress_indicator_factory_layout.xml | 25 ++++++++++-- .../src/main/res/values/colors.xml | 2 + 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java index b90c3e35..76bf9aac 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java @@ -3,8 +3,10 @@ public class ProgressIndicatorConfig { private int progressVal; - private String title; - private String subtitle; + private String indicatorLabel; + private String progressIndicatorTitle; + private String progressIndicatorSubtitle; + private int progressIndicatorTitleColor; private int foregroundColor; private int backgroundColor; @@ -19,20 +21,36 @@ public void setProgressVal(int progressVal) { this.progressVal = progressVal; } - public String getTitle() { - return title; + public String getIndicatorLabel() { + return indicatorLabel; } - public void setTitle(String title) { - this.title = title; + public void setIndicatorLabel(String indicatorLabel) { + this.indicatorLabel = indicatorLabel; } - public String getSubtitle() { - return subtitle; + public String getProgressIndicatorTitle() { + return progressIndicatorTitle; } - public void setSubtitle(String subtitle) { - this.subtitle = subtitle; + public void setProgressIndicatorTitle(String progressIndicatorTitle) { + this.progressIndicatorTitle = progressIndicatorTitle; + } + + public String getProgressIndicatorSubtitle() { + return progressIndicatorSubtitle; + } + + public void setProgressIndicatorSubtitle(String progressIndicatorSubtitle) { + this.progressIndicatorSubtitle = progressIndicatorSubtitle; + } + + public int getProgressIndicatorTitleColor() { + return progressIndicatorTitleColor; + } + + public void setProgressIndicatorTitleColor(int progressIndicatorTitleColor) { + this.progressIndicatorTitleColor = progressIndicatorTitleColor; } public int getForegroundColor() { diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java index 01ab08a1..f27f0fc1 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorDisplayOptions.java @@ -1,7 +1,7 @@ package org.smartregister.reporting.domain; -public class ProgressIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions{ +public class ProgressIndicatorDisplayOptions extends ReportingIndicatorDisplayOptions { private ProgressIndicatorConfig config; @@ -20,8 +20,10 @@ public void setConfig(ProgressIndicatorConfig config) { public static class ProgressIndicatorBuilder { private int progressVal; - private String title; - private String subtitle; + private String indicatorLabel; + private String progressIndicatorTitle; + private String progressIndicatorSubtitle; + private int progressIndicatorTitleColor; private int foregroundColor; private int backgroundColor; @@ -30,13 +32,23 @@ public ProgressIndicatorBuilder withProgressValue(int value) { return this; } - public ProgressIndicatorBuilder withTitle(String title) { - this.title = title; + public ProgressIndicatorBuilder withIndicatorLabel(String indicatorLabel) { + this.indicatorLabel = indicatorLabel; return this; } - public ProgressIndicatorBuilder withSubtitle(String subtitle) { - this.subtitle = subtitle; + public ProgressIndicatorBuilder withProgressIndicatorTitle(String title) { + this.progressIndicatorTitle = title; + return this; + } + + public ProgressIndicatorBuilder withProgressIndicatorSubtitle(String subtitle) { + this.progressIndicatorSubtitle = subtitle; + return this; + } + + public ProgressIndicatorBuilder withProgressIndicatorTitleColor(int titleColor) { + this.progressIndicatorTitleColor = titleColor; return this; } @@ -53,8 +65,10 @@ public ProgressIndicatorBuilder withBackgroundColor(int backgroundColor) { public ProgressIndicatorDisplayOptions build() { ProgressIndicatorConfig config = new ProgressIndicatorConfig(); config.setProgressVal(this.progressVal); - config.setTitle(this.title); - config.setSubtitle(this.subtitle); + config.setIndicatorLabel(this.indicatorLabel); + config.setProgressIndicatorTitle(this.progressIndicatorTitle); + config.setProgressIndicatorTitleColor(this.progressIndicatorTitleColor); + config.setProgressIndicatorSubtitle(this.progressIndicatorSubtitle); config.setForegroundColor(this.foregroundColor); config.setBackgroundColor(this.backgroundColor); return new ProgressIndicatorDisplayOptions(config); diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java index 9d7cf60a..b439fbb2 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/factory/ProgressIndicatorFactory.java @@ -6,6 +6,7 @@ import android.widget.LinearLayout; import android.widget.TextView; +import org.apache.commons.lang3.StringUtils; import org.smartregister.reporting.R; import org.smartregister.reporting.domain.ProgressIndicatorConfig; import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; @@ -16,10 +17,16 @@ public class ProgressIndicatorFactory implements IndicatorVisualisationFactory { @Override public View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, Context context) { ProgressIndicatorConfig config = ((ProgressIndicatorDisplayOptions) displayOptions).getConfig(); - LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.progress_indicator, null); + LinearLayout rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.progress_indicator_factory_layout, null); + + TextView indicatorLabel = rootLayout.findViewById(R.id.tv_indicator_label); + String label = StringUtils.isNotBlank(config.getIndicatorLabel()) ? config.getIndicatorLabel() : ""; + indicatorLabel.setText(label); + ProgressIndicator progressWidget = rootLayout.findViewById(R.id.progressIndicatorView); - progressWidget.setTitle(config.getTitle()); - progressWidget.setSubTitle(config.getSubtitle()); + progressWidget.setTitle(config.getProgressIndicatorTitle()); + progressWidget.setProgressBarTitleColor(config.getProgressIndicatorTitleColor()); + progressWidget.setSubTitle(config.getProgressIndicatorSubtitle()); progressWidget.setProgress(config.getProgressVal()); progressWidget.setProgressBarForegroundColor(config.getForegroundColor()); progressWidget.setProgressBarBackgroundColor(config.getBackgroundColor()); diff --git a/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml b/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml index b198849e..1c1db309 100644 --- a/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml +++ b/opensrp-reporting/src/main/res/layout/progress_indicator_factory_layout.xml @@ -2,13 +2,32 @@ + android:orientation="vertical"> + + + + \ No newline at end of file diff --git a/opensrp-reporting/src/main/res/values/colors.xml b/opensrp-reporting/src/main/res/values/colors.xml index b1e608b3..15e8b256 100644 --- a/opensrp-reporting/src/main/res/values/colors.xml +++ b/opensrp-reporting/src/main/res/values/colors.xml @@ -8,4 +8,6 @@ #DEDEDE #00b253 #b2f395 + #ecf1f7 + From 1083cf1b3ec03a8c60e7221a3407ce2eec88554a Mon Sep 17 00:00:00 2001 From: Allan O Date: Fri, 22 Jan 2021 15:16:41 +0300 Subject: [PATCH 10/22] :recycle: Remove progressIndicator calculations --- .../org/smartregister/reporting/util/ReportingUtil.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index 6d8ab1e0..cc3c6df4 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -46,7 +46,7 @@ public static NumericIndicatorDisplayOptions getNumericIndicatorDisplayOptions(C return new NumericIndicatorDisplayOptions(label, getCount(countType, indicatorCode, indicatorTallies)); } - private static float getCount(CountType countType, String indicatorCode, List> indicatorTallies) { + public static float getCount(CountType countType, String indicatorCode, List> indicatorTallies) { float count = 0; if (countType == CountType.TOTAL_COUNT) { count = getTotalCount(indicatorTallies, indicatorCode); @@ -68,12 +68,6 @@ public static PieChartIndicatorDisplayOptions getPieChartDisplayOptions(List> indicatorTallies) { - float count = getCount(countType, indicatorCode, indicatorTallies); - return (count / target) * 100; - } - public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, List> indicatorTallies, String key) { return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, key); From e53728dcd14d77f5095f3dab6a9fedf3bc8a2b7c Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 26 Jan 2021 16:21:49 +0300 Subject: [PATCH 11/22] :camera_flash: Update reporting lib snapshot version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 38aebb7b..88fb747e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.1.0-SNAPSHOT +VERSION_NAME=0.1.0-PREVIEW-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library From ccfe538d549202f7345b3be2b0d639522396d4e5 Mon Sep 17 00:00:00 2001 From: Allan O Date: Tue, 2 Feb 2021 15:44:06 +0300 Subject: [PATCH 12/22] :construction: Fix Annotation import --- .../org/smartregister/reporting/view/ProgressIndicator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java index 7adeac2a..2a4588aa 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/ProgressIndicator.java @@ -12,7 +12,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Parcelable; -import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.AttributeSet; import android.view.Gravity; @@ -21,6 +20,8 @@ import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.Nullable; + import org.smartregister.reporting.R; import timber.log.Timber; From 0afe505d2980575992d021ac58ff1dc1c9578f99 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 15:23:40 +0300 Subject: [PATCH 13/22] :white_check_mark: Fix broken tests --- .../domain/ProgressIndicatorConfig.java | 3 --- .../reporting/util/ReportingUtil.java | 1 - .../reporting/impl/ReportingUtilTest.java | 26 ++++++++++--------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java index 76bf9aac..8467a06c 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/domain/ProgressIndicatorConfig.java @@ -10,9 +10,6 @@ public class ProgressIndicatorConfig { private int foregroundColor; private int backgroundColor; - public ProgressIndicatorConfig() { - } - public int getProgressVal() { return progressVal; } diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index cc3c6df4..ee752957 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -9,7 +9,6 @@ import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; import org.smartregister.reporting.domain.PieChartSlice; -import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; import org.smartregister.reporting.factory.IndicatorVisualisationFactory; import org.smartregister.reporting.listener.PieChartSelectListener; diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index b05ab270..400d3143 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -7,6 +7,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; +import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; import org.smartregister.reporting.util.ReportingUtil; import java.util.Arrays; @@ -18,7 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.smartregister.reporting.BaseUnitTest.getDateTime; -import static org.smartregister.reporting.util.ReportingUtil.getNumericIndicatorDisplay; @RunWith(MockitoJUnitRunner.class) public class ReportingUtilTest { @@ -69,17 +69,19 @@ public void testGetIndicatorDisplayModelTotalAndLatestCount() { List indicatorTallies = Collections.unmodifiableList(Collections.unmodifiableList(Arrays.asList(tally1, tally2, tally3, tally4))); //Test get model with total count - NumericDisplayModel NumericDisplayModel = getNumericIndicatorDisplay(ReportContract.IndicatorView.CountType.TOTAL_COUNT, "indicator1", 182998, indicatorTallies); - assertNotNull(NumericDisplayModel); - assertEquals(12, NumericDisplayModel.getCount(), 0); - assertEquals("indicator1", NumericDisplayModel.getIndicatorCode()); - assertEquals(182998, NumericDisplayModel.getLabelStringResource()); + NumericIndicatorDisplayOptions displayOptions1 = ReportingUtil.getNumericIndicatorDisplayOptions(ReportContract.IndicatorView.CountType.TOTAL_COUNT, + "indicator1", + "first indicator", indicatorTallies); + assertNotNull(displayOptions1); + assertEquals(12, displayOptions1.getValue(), 0); + assertEquals("first indicator", displayOptions1.getIndicatorLabel()); - //Test get model with total count - NumericDisplayModel NumericDisplayModel2 = getNumericIndicatorDisplay(ReportContract.IndicatorView.CountType.LATEST_COUNT, "indicator2", 182999, indicatorTallies); - assertNotNull(NumericDisplayModel2); - assertEquals(13, NumericDisplayModel2.getCount(), 0); - assertEquals("indicator2", NumericDisplayModel2.getIndicatorCode()); - assertEquals(182999, NumericDisplayModel2.getLabelStringResource()); + //Test get model with latest count + NumericIndicatorDisplayOptions displayOptions2 = ReportingUtil.getNumericIndicatorDisplayOptions(ReportContract.IndicatorView.CountType.LATEST_COUNT, + "indicator2", + "second indicator", indicatorTallies); + assertNotNull(displayOptions2); + assertEquals(13, displayOptions2.getValue(), 0); + assertEquals("second indicator", displayOptions2.getIndicatorLabel()); } } From cc380c9f2d30a00e5677dcdbaeaadadbb7acaa09 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 15:32:35 +0300 Subject: [PATCH 14/22] :green_heart: Fix codacy issue --- .../org/smartregister/reporting/view/PieChartIndicatorView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java index a512f120..413e3a75 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/view/PieChartIndicatorView.java @@ -19,7 +19,7 @@ public class PieChartIndicatorView implements ReportContract.IndicatorView { private Context context; private PieChartFactory pieChartFactory; - PieChartIndicatorDisplayOptions displayOptions; + private PieChartIndicatorDisplayOptions displayOptions; public PieChartIndicatorView(Context context, PieChartIndicatorDisplayOptions displayOptions) { pieChartFactory = new PieChartFactory(); From 972e6d90544619cd358e7173a141cb79f548e3bf Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 16:32:51 +0300 Subject: [PATCH 15/22] :white_check_mark: Add Progress indicator factory tests --- .../reporting/util/ReportingUtil.java | 4 +- .../view/ProgressIndicatorFactoryTest.java | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java diff --git a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java index ee752957..743c89a7 100644 --- a/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java +++ b/opensrp-reporting/src/main/java/org/smartregister/reporting/util/ReportingUtil.java @@ -69,12 +69,12 @@ public static PieChartIndicatorDisplayOptions getPieChartDisplayOptions(List> indicatorTallies, String key) { - return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, key); + return new PieChartSlice(getCount(countType, indicatorCode, indicatorTallies), label, color, key); } public static PieChartSlice getPieChartSlice(CountType countType, String indicatorCode, String label, int color, List> indicatorTallies) { - return new PieChartSlice((float) getCount(countType, indicatorCode, indicatorTallies), label, color, indicatorCode); + return new PieChartSlice(getCount(countType, indicatorCode, indicatorTallies), label, color, indicatorCode); } public static List addPieChartSlices(PieChartSlice... chartSlices) { diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java new file mode 100644 index 00000000..78ca998b --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorFactoryTest.java @@ -0,0 +1,77 @@ +package org.smartregister.reporting.view; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.rule.PowerMockRule; +import org.smartregister.reporting.BaseUnitTest; +import org.smartregister.reporting.R; +import org.smartregister.reporting.domain.ProgressIndicatorConfig; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.factory.ProgressIndicatorFactory; + +@PrepareForTest(LayoutInflater.class) +public class ProgressIndicatorFactoryTest extends BaseUnitTest { + + @Rule + public PowerMockRule rule = new PowerMockRule(); + + @Mock + ProgressIndicatorDisplayOptions displayOptions; + + @Mock + private Context context; + + @Mock + private TextView indicatorLabel; + + @Mock + private LinearLayout rootLayout; + + @Mock + private LayoutInflater layoutInflater; + + @Mock + private ProgressIndicator progressWidget; + + @Mock + private ProgressIndicatorConfig config; + + @InjectMocks + private ProgressIndicatorFactory progressIndicatorFactory; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + + @Test + public void getProgressIndicatorViewReturnsCorrectView() { + ProgressIndicatorFactory factorySpy = Mockito.spy(progressIndicatorFactory); + PowerMockito.mockStatic(LayoutInflater.class); + PowerMockito.when(LayoutInflater.from(context)).thenReturn(layoutInflater); + Mockito.doReturn(rootLayout).when(layoutInflater).inflate(R.layout.progress_indicator_factory_layout, null); + Mockito.doReturn(indicatorLabel).when(rootLayout).findViewById(R.id.tv_indicator_label); + Mockito.doReturn(config).when(displayOptions).getConfig(); + Mockito.doReturn(progressWidget).when(rootLayout).findViewById(R.id.progressIndicatorView); + + View view = factorySpy.getIndicatorView(displayOptions, context); + Assert.assertNotNull(view); + Assert.assertTrue(view instanceof LinearLayout); + } + +} From edf37fc5c6eef7d5cf2b471fede260c98058d9fc Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 16:58:09 +0300 Subject: [PATCH 16/22] :white_check_mark: Add tests --- .../reporting/impl/ReportingUtilTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index 400d3143..c8b86570 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -1,5 +1,6 @@ package org.smartregister.reporting.impl; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -8,8 +9,11 @@ import org.smartregister.reporting.contract.ReportContract; import org.smartregister.reporting.domain.IndicatorTally; import org.smartregister.reporting.domain.NumericIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartIndicatorDisplayOptions; +import org.smartregister.reporting.domain.PieChartSlice; import org.smartregister.reporting.util.ReportingUtil; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -19,6 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.smartregister.reporting.BaseUnitTest.getDateTime; +import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.LATEST_COUNT; +import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; @RunWith(MockitoJUnitRunner.class) public class ReportingUtilTest { @@ -84,4 +90,28 @@ public void testGetIndicatorDisplayModelTotalAndLatestCount() { assertEquals(13, displayOptions2.getValue(), 0); assertEquals("second indicator", displayOptions2.getIndicatorLabel()); } + + @Test + public void getPieChartDisplayOptionsReturnsCorrectOptions() { + PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, "IND-1", "slice 1", 0, null); + PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, "IND-2", "slice 2", 0, null); + List slices = new ArrayList<>(); + slices.add(indicator2_1); + slices.add(indicator2_2); + PieChartIndicatorDisplayOptions options = ReportingUtil.getPieChartDisplayOptions(slices, "Test Chart", "", null); + + Assert.assertEquals("Test Chart", options.getIndicatorLabel()); + Assert.assertNotNull(options.getPieChartConfig().getSlices()); + Assert.assertEquals("slice 2", options.getPieChartConfig().getSlices().get(1).getLabel()); + Assert.assertTrue(options.getPieChartConfig().hasLabels()); + Assert.assertFalse(options.getPieChartConfig().hasCenterCircle()); + } + + @Test + public void canFormatDecimals() { + Assert.assertEquals("12.301", ReportingUtil.formatDecimal(12.30123)); + Assert.assertEquals("12.301", ReportingUtil.formatDecimal(12.301)); + Assert.assertEquals("12.3", ReportingUtil.formatDecimal(12.3001)); + Assert.assertEquals("12", ReportingUtil.formatDecimal(12.0)); + } } From 17cb40b7c69f2bca7edaf7859e494dafb5855afd Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 18:06:09 +0300 Subject: [PATCH 17/22] :white_check_mark: Add ProgressIndicatorViewTest --- .../view/ProgressIndicatorViewTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java new file mode 100644 index 00000000..075d6489 --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java @@ -0,0 +1,49 @@ +package org.smartregister.reporting.view; + +import android.content.Context; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.internal.verification.VerificationModeFactory; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.robolectric.annotation.Config; +import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; +import org.smartregister.reporting.factory.ProgressIndicatorFactory; +import org.smartregister.reporting.util.ReportingUtil; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(ReportingUtil.class) +@Config(sdk = 22) +public class ProgressIndicatorViewTest { + + @Mock + Context context; + + @Mock + ProgressIndicatorDisplayOptions displayOptions; + + @Before + public void setUp() { + PowerMockito.mockStatic(ReportingUtil.class); + MockitoAnnotations.initMocks(this); + } + + @Test + public void createViewGetsIndicatorView() { + ProgressIndicatorView view = new ProgressIndicatorView(context, displayOptions); + ProgressIndicatorView viewSpy = Mockito.spy(view); + viewSpy.createView(); + PowerMockito.verifyStatic(ReportingUtil.class, VerificationModeFactory.times(1)); + ReportingUtil.getIndicatorView(ArgumentMatchers.any(ProgressIndicatorDisplayOptions.class), + ArgumentMatchers.any(ProgressIndicatorFactory.class), + ArgumentMatchers.any(Context.class)); + + } +} From 4c1e88bd888d81942e54a9831ee43ced63df1223 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 18:34:12 +0300 Subject: [PATCH 18/22] :white_check_mark: Update tests --- .../reporting/impl/ReportingUtilTest.java | 20 ++++---- .../shadow/ReportUtilShadowHelper.java | 23 ++++++++++ .../view/ProgressIndicatorViewTest.java | 46 +++++++------------ 3 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index c8b86570..78ad2f93 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -21,7 +21,9 @@ import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.smartregister.reporting.BaseUnitTest.getDateTime; import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.LATEST_COUNT; import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; @@ -100,18 +102,18 @@ public void getPieChartDisplayOptionsReturnsCorrectOptions() { slices.add(indicator2_2); PieChartIndicatorDisplayOptions options = ReportingUtil.getPieChartDisplayOptions(slices, "Test Chart", "", null); - Assert.assertEquals("Test Chart", options.getIndicatorLabel()); - Assert.assertNotNull(options.getPieChartConfig().getSlices()); - Assert.assertEquals("slice 2", options.getPieChartConfig().getSlices().get(1).getLabel()); - Assert.assertTrue(options.getPieChartConfig().hasLabels()); - Assert.assertFalse(options.getPieChartConfig().hasCenterCircle()); + assertEquals("Test Chart", options.getIndicatorLabel()); + assertNotNull(options.getPieChartConfig().getSlices()); + assertEquals("slice 2", options.getPieChartConfig().getSlices().get(1).getLabel()); + assertTrue(options.getPieChartConfig().hasLabels()); + assertFalse(options.getPieChartConfig().hasCenterCircle()); } @Test public void canFormatDecimals() { - Assert.assertEquals("12.301", ReportingUtil.formatDecimal(12.30123)); - Assert.assertEquals("12.301", ReportingUtil.formatDecimal(12.301)); - Assert.assertEquals("12.3", ReportingUtil.formatDecimal(12.3001)); - Assert.assertEquals("12", ReportingUtil.formatDecimal(12.0)); + assertEquals("12.301", ReportingUtil.formatDecimal(12.30123)); + assertEquals("12.301", ReportingUtil.formatDecimal(12.301)); + assertEquals("12.3", ReportingUtil.formatDecimal(12.3001)); + assertEquals("12", ReportingUtil.formatDecimal(12.0)); } } diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java new file mode 100644 index 00000000..b25e1f7c --- /dev/null +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/shadow/ReportUtilShadowHelper.java @@ -0,0 +1,23 @@ +package org.smartregister.reporting.shadow; + +import android.content.Context; +import android.view.View; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; +import org.smartregister.reporting.domain.ReportingIndicatorDisplayOptions; +import org.smartregister.reporting.factory.IndicatorVisualisationFactory; +import org.smartregister.reporting.util.ReportingUtil; + +@Implements(ReportingUtil.class) +public class ReportUtilShadowHelper { + + + + @Implementation + public static View getIndicatorView(ReportingIndicatorDisplayOptions displayOptions, + IndicatorVisualisationFactory visualisationFactory, Context context) { + return visualisationFactory.getIndicatorView(displayOptions, context); + } + +} diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java index 075d6489..aabe8517 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/view/ProgressIndicatorViewTest.java @@ -1,49 +1,35 @@ package org.smartregister.reporting.view; -import android.content.Context; +import android.view.View; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.internal.verification.VerificationModeFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.robolectric.annotation.Config; +import org.robolectric.RuntimeEnvironment; +import org.smartregister.reporting.BaseUnitTest; import org.smartregister.reporting.domain.ProgressIndicatorDisplayOptions; -import org.smartregister.reporting.factory.ProgressIndicatorFactory; -import org.smartregister.reporting.util.ReportingUtil; -@RunWith(PowerMockRunner.class) -@PrepareForTest(ReportingUtil.class) -@Config(sdk = 22) -public class ProgressIndicatorViewTest { - @Mock - Context context; - - @Mock - ProgressIndicatorDisplayOptions displayOptions; +public class ProgressIndicatorViewTest extends BaseUnitTest { @Before public void setUp() { - PowerMockito.mockStatic(ReportingUtil.class); MockitoAnnotations.initMocks(this); } @Test public void createViewGetsIndicatorView() { - ProgressIndicatorView view = new ProgressIndicatorView(context, displayOptions); - ProgressIndicatorView viewSpy = Mockito.spy(view); - viewSpy.createView(); - PowerMockito.verifyStatic(ReportingUtil.class, VerificationModeFactory.times(1)); - ReportingUtil.getIndicatorView(ArgumentMatchers.any(ProgressIndicatorDisplayOptions.class), - ArgumentMatchers.any(ProgressIndicatorFactory.class), - ArgumentMatchers.any(Context.class)); - + ProgressIndicatorDisplayOptions displayOptions = new ProgressIndicatorDisplayOptions.ProgressIndicatorBuilder() + .withIndicatorLabel("Number of tasks") + .withProgressValue(80) + .withProgressIndicatorTitle("50%") + .withProgressIndicatorTitleColor(0) + .withForegroundColor(1) + .withBackgroundColor(2) + .build(); + ProgressIndicatorView progressIndicatorView = new ProgressIndicatorView(RuntimeEnvironment.application, displayOptions); + View returnedView = progressIndicatorView.createView(); + Assert.assertNotNull(returnedView); } } From 28c17e8e287afe2d9e470f97311541926a038c23 Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 4 Feb 2021 18:40:10 +0300 Subject: [PATCH 19/22] :white_check_mark: Fix codacy issues --- .../org/smartregister/reporting/impl/ReportingUtilTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java index 78ad2f93..eab4394b 100644 --- a/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java +++ b/opensrp-reporting/src/test/java/org/smartregister/reporting/impl/ReportingUtilTest.java @@ -1,6 +1,5 @@ package org.smartregister.reporting.impl; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,7 +24,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.smartregister.reporting.BaseUnitTest.getDateTime; -import static org.smartregister.reporting.contract.ReportContract.IndicatorView.CountType.LATEST_COUNT; import static org.smartregister.reporting.util.ReportingUtil.getPieChartSlice; @RunWith(MockitoJUnitRunner.class) @@ -95,8 +93,8 @@ public void testGetIndicatorDisplayModelTotalAndLatestCount() { @Test public void getPieChartDisplayOptionsReturnsCorrectOptions() { - PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, "IND-1", "slice 1", 0, null); - PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, "IND-2", "slice 2", 0, null); + PieChartSlice indicator2_1 = getPieChartSlice(ReportContract.IndicatorView.CountType.LATEST_COUNT, "IND-1", "slice 1", 0, null); + PieChartSlice indicator2_2 = getPieChartSlice(ReportContract.IndicatorView.CountType.LATEST_COUNT, "IND-2", "slice 2", 0, null); List slices = new ArrayList<>(); slices.add(indicator2_1); slices.add(indicator2_2); From 67bfdd966916f06e0a53400dab0c9cbdf3d21811 Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 8 Feb 2021 11:01:31 +0300 Subject: [PATCH 20/22] :bulb: Update progress indicator documentation --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57fbb1d6..18ed8e6f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The **mainLayout** is the root view you want the visualizations to be shown. To display a numeric value use the code snippet below. ```Java - NumericDisplayModel indicator1 = getIndicatorDisplayModel(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); + NumericIndicatorDisplayOptions indicator1 = getNumericIndicatorDisplayOptions(TOTAL_COUNT, ChartUtil.numericIndicatorKey, R.string.total_under_5_count, indicatorTallies); mainLayout.addView(new NumericIndicatorView(getContext(), indicator1).createView()); ``` @@ -43,7 +43,7 @@ For pie charts display. You can use the following code snippet. ```Java PieChartSlice indicator2_1 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartYesIndicatorKey, getResources().getString(R.string.yes_slice_label), getResources().getColor(R.color.colorPieChartGreen), indicatorTallies); PieChartSlice indicator2_2 = getPieChartSlice(LATEST_COUNT, ChartUtil.pieChartNoIndicatorKey, getResources().getString(R.string.no_button_label), getResources().getColor(R.color.colorPieChartRed), indicatorTallies); - mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayModel(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note)).createView()); + mainLayout.addView(new PieChartIndicatorView(getContext(), getPieChartDisplayOptions(addPieChartSlices(indicator2_1, indicator2_2), R.string.num_of_lieterate_children_0_60_label, R.string.sample_note, null)).createView()); ``` ### Progress indicator This indicator widget basically has a progressbar, main title(Label) and a sub title. @@ -67,7 +67,7 @@ using the property **progressDrawable** listed above, you can set the progressDr **Programmatically:** ``` - ProgressIndicatorView progressWidget = getActivity().findViewById(R.id.progressIndicatorView); + ProgressIndicator progressWidget = getActivity().findViewById(R.id.progressIndicatorView); progressWidget.setProgress(42); progressWidget.setTitle("Users registered - 42%"); progressWidget.setProgressDrawable(R.drawable.progress_indicator_bg); @@ -89,6 +89,24 @@ using the property **progressDrawable** listed above, you can set the progressDr app:progressDrawable="@drawable/custom_progress_indicator_bg" ``` +**Adding a progress indicator view to a layout using the ProgressIndicatorDisplayOptions:** + +```java + + ProgressIndicatorDisplayOptions displayOptions = new ProgressIndicatorDisplayOptions.ProgressIndicatorBuilder() + .withIndicatorLabel(label) + .withProgressIndicatorTitle(titleString) + .withProgressIndicatorTitleColor(progressColor) + .withProgressValue(percentage) + .withProgressIndicatorSubtitle("") + .withBackgroundColor(defaultBackgroundColor) + .withForegroundColor(progressColor) + .build(); + + mainLayout.addView(new ProgressIndicatorView(mainLayout.getContext(), displayOptions).createView()); + +``` + ### Table View This table widget basically has a header with column head values and rows to display data in a tabular format. From f72e2481003661c93b5291391577526b66b21963 Mon Sep 17 00:00:00 2001 From: Allan O Date: Mon, 8 Feb 2021 11:07:30 +0300 Subject: [PATCH 21/22] :bulb: Update progress indicator documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18ed8e6f..26c923fc 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ using the property **progressDrawable** listed above, you can set the progressDr .withForegroundColor(progressColor) .build(); - mainLayout.addView(new ProgressIndicatorView(mainLayout.getContext(), displayOptions).createView()); + mainLayout.addView(new ProgressIndicatorView(getContext(), displayOptions).createView()); ``` From a7c2e630fe496d26e07954774e33ce2e72c8a0fb Mon Sep 17 00:00:00 2001 From: Allan O Date: Thu, 11 Mar 2021 17:21:04 +0300 Subject: [PATCH 22/22] :camera_flash: Update snapshot version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 748fc5b2..2951e5ba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.1.2-PREVIEW-SNAPSHOT +VERSION_NAME=1.0.0-gs.1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library