Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors to improve Indicator views implementation & Generate ProgressBar Indicator views using configs #117

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8946616
:recycle: Refactor to rename ProgressIndicatorView
allan-on Jan 12, 2021
90cdf18
:fire: Refactor to remove unnecessary model abstraction
allan-on Jan 15, 2021
0275701
:recycle: Remove static imports for readability
allan-on Jan 18, 2021
b016df8
:recycle: User <merge> as root of view layouts
allan-on Jan 18, 2021
b33b5db
:construction: Add ProgressIndicator Factory implementation
allan-on Jan 18, 2021
03ba36a
:construction: Add get progress indicator %
allan-on Jan 19, 2021
635c9e7
:camera_flash: Update reporting snapshot
allan-on Jan 19, 2021
b31d066
:construction: Add setting of title text color
allan-on Jan 22, 2021
f312ffc
:construction: Add setting indicator label & color configs
allan-on Jan 22, 2021
1083cf1
:recycle: Remove progressIndicator calculations
allan-on Jan 22, 2021
e53728d
:camera_flash: Update reporting lib snapshot version
allan-on Jan 26, 2021
166f31c
Merge branch 'master' of github.com:OpenSRP/opensrp-client-reporting …
allan-on Feb 2, 2021
ccfe538
:construction: Fix Annotation import
allan-on Feb 2, 2021
0afe505
:white_check_mark: Fix broken tests
allan-on Feb 4, 2021
cc380c9
:green_heart: Fix codacy issue
allan-on Feb 4, 2021
972e6d9
:white_check_mark: Add Progress indicator factory tests
allan-on Feb 4, 2021
edf37fc
:white_check_mark: Add tests
allan-on Feb 4, 2021
17cb40b
:white_check_mark: Add ProgressIndicatorViewTest
allan-on Feb 4, 2021
4c1e88b
:white_check_mark: Update tests
allan-on Feb 4, 2021
28c17e8
:white_check_mark: Fix codacy issues
allan-on Feb 4, 2021
67bfdd9
:bulb: Update progress indicator documentation
allan-on Feb 8, 2021
f72e248
:bulb: Update progress indicator documentation
allan-on Feb 8, 2021
a7c2e63
:camera_flash: Update snapshot version
allan-on Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());

```
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -78,7 +78,7 @@ using the property **progressDrawable** listed above, you can set the progressDr
**Via XML:**

```
<org.smartregister.reporting.view.ProgressIndicatorView
<org.smartregister.reporting.view.ProgressIndicator
android:id="@+id/progressIndicatorView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -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(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.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.1.1-SNAPSHOT
VERSION_NAME=1.0.0-gs.1-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Reporting Library
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<PieChartSlice> slices;
private PieChartSelectListener listener;

public PieChartIndicatorData(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List<PieChartSlice> slices) {
public PieChartConfig(boolean hasLabels, boolean hasLabelsOutside, boolean hasCenterCircle, List<PieChartSlice> slices) {
this.hasLabels = hasLabels;
this.hasLabelsOutside = hasLabelsOutside;
this.hasCenterCircle = hasCenterCircle;
this.slices = slices;
}

public PieChartIndicatorData() {}
public PieChartConfig() {}

public boolean hasLabels() {
return hasLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.smartregister.reporting.domain;

public class ProgressIndicatorConfig {

private int progressVal;
private String indicatorLabel;
private String progressIndicatorTitle;
private String progressIndicatorSubtitle;
private int progressIndicatorTitleColor;
private int foregroundColor;
private int backgroundColor;

public int getProgressVal() {
return progressVal;
}

public void setProgressVal(int progressVal) {
this.progressVal = progressVal;
}

public String getIndicatorLabel() {
return indicatorLabel;
}

public void setIndicatorLabel(String indicatorLabel) {
this.indicatorLabel = indicatorLabel;
}

public String getProgressIndicatorTitle() {
return progressIndicatorTitle;
}

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() {
return foregroundColor;
}

public void setForegroundColor(int foregroundColor) {
this.foregroundColor = foregroundColor;
}

public int getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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 indicatorLabel;
private String progressIndicatorTitle;
private String progressIndicatorSubtitle;
private int progressIndicatorTitleColor;
private int foregroundColor;
private int backgroundColor;

public ProgressIndicatorBuilder withProgressValue(int value) {
this.progressVal = value;
return this;
}

public ProgressIndicatorBuilder withIndicatorLabel(String indicatorLabel) {
this.indicatorLabel = indicatorLabel;
return this;
}

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;
}

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.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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading