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

Optimize growth chart #92

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=3.0.0-SNAPSHOT
VERSION_NAME=3.0.1-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application
Expand Down
4 changes: 4 additions & 0 deletions opensrp-growth-monitoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ android {
includeAndroidResources = true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

tasks.withType(Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import android.graphics.DashPathEffect;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
Expand Down Expand Up @@ -49,6 +54,9 @@ public class HeightMonitoringFragment extends Fragment {
private boolean isExpanded = false;
private String dobString;
private Gender gender;
private LinearLayout progressBar;
private ConstraintLayout chartLayout;
private ConstraintLayout tableLayout;

public static HeightMonitoringFragment createInstance(String dobString, Gender gender, List<Height> heights) {
HeightMonitoringFragment heightMonitoringFragment = new HeightMonitoringFragment();
Expand All @@ -60,23 +68,51 @@ public static HeightMonitoringFragment createInstance(String dobString, Gender g

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final ViewGroup heightTabView = (ViewGroup) inflater.inflate(R.layout.growth_monitoring_fragment, container, false);
heightTabView.setFilterTouchesWhenObscured(true);
final ImageButton scrollButton = heightTabView.findViewById(R.id.scroll_button);
CustomFontTextView textMetricLabel = heightTabView.findViewById(R.id.metric_label);
textMetricLabel.setText(getActivity().getString(R.string.height));

Date dob = getDate();
scrollButtonClickAction(heightTabView, scrollButton);

try {
refreshGrowthChart(heightTabView, getGender(), dob);
refreshPreviousHeightsTable(heightTabView, getGender(), dob);
} catch (Exception e) {
Timber.e(e);
}
return inflater.inflate(R.layout.growth_monitoring_fragment, container, false);
}

@Override
public void onViewCreated(@NonNull View heightTabView, @androidx.annotation.Nullable Bundle savedInstanceState) {
super.onViewCreated(heightTabView, savedInstanceState);
initViews(heightTabView);
showLoader();
new Thread(() -> {
try {
heightTabView.setFilterTouchesWhenObscured(true);
final ImageButton scrollButton = heightTabView.findViewById(R.id.scroll_button);
CustomFontTextView textMetricLabel = heightTabView.findViewById(R.id.metric_label);
textMetricLabel.setText(requireActivity().getString(R.string.height));

Date dob = getDate();
scrollButtonClickAction((ViewGroup) heightTabView, scrollButton);

refreshGrowthChart(heightTabView, getGender(), dob);
refreshPreviousHeightsTable(heightTabView, getGender(), dob);
} catch (Exception e) {
Timber.e(Log.getStackTraceString(e));
}
if (isVisible())
requireActivity().runOnUiThread(this::hideLoader);
}).start();

return heightTabView;
}

private void initViews(View view) {
progressBar = view.findViewById(R.id.progress_chart);
chartLayout = view.findViewById(R.id.growth_chart_layout);
tableLayout = view.findViewById(R.id.growth_dialog_table_layout);
}

private void hideLoader() {
progressBar.setVisibility(View.GONE);
chartLayout.setVisibility(View.VISIBLE);
tableLayout.setVisibility(View.VISIBLE);
}

private void showLoader() {
progressBar.setVisibility(View.VISIBLE);
chartLayout.setVisibility(View.GONE);
tableLayout.setVisibility(View.GONE);
}

@Nullable
Expand Down Expand Up @@ -197,8 +233,6 @@ private void refreshPreviousHeightsTable(final View heightTabView, Gender gender
params.span = 3;
divider.setLayoutParams(params);
divider.setBackgroundColor(getResources().getColor(R.color.client_list_header_dark_grey));
dividerRow.addView(divider);
tableLayout.addView(dividerRow);

TableRow curRow = new TableRow(heightTabView.getContext());

Expand All @@ -209,7 +243,6 @@ private void refreshPreviousHeightsTable(final View heightTabView, Gender gender
ageTextView.setText(DateUtil.getDuration(height.getDate().getTime() - dob.getTime()));
ageTextView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
ageTextView.setTextColor(getResources().getColor(R.color.client_list_grey));
curRow.addView(ageTextView);

TextView heightTextView = new TextView(heightTabView.getContext());
heightTextView.setHeight(getResources().getDimensionPixelSize(R.dimen.table_contents_text_height));
Expand All @@ -218,7 +251,6 @@ private void refreshPreviousHeightsTable(final View heightTabView, Gender gender
heightTextView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
heightTextView.setText(String.format("%s %s", String.valueOf(height.getCm()), getString(R.string.cm)));
heightTextView.setTextColor(getResources().getColor(R.color.client_list_grey));
curRow.addView(heightTextView);

TextView zScoreTextView = new TextView(heightTabView.getContext());
zScoreTextView.setHeight(getResources().getDimensionPixelSize(R.dimen.table_contents_text_height));
Expand All @@ -233,8 +265,16 @@ private void refreshPreviousHeightsTable(final View heightTabView, Gender gender
zScoreTextView.setTextColor(getResources().getColor(HeightZScore.getZScoreColor(zScore)));
zScoreTextView.setText(String.valueOf(zScore));
}
curRow.addView(zScoreTextView);
tableLayout.addView(curRow);

requireActivity().runOnUiThread(() -> {
dividerRow.addView(divider);
tableLayout.addView(dividerRow);
curRow.addView(ageTextView);
curRow.addView(heightTextView);

curRow.addView(zScoreTextView);
tableLayout.addView(curRow);
});
}

//Now set the expand button if items are too many
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import android.graphics.DashPathEffect;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
Expand Down Expand Up @@ -53,6 +59,9 @@ public class WeightForHeightMonitoringFragment extends Fragment {
private Date dob;
private List<WeightHeight> weightHeights;
private Height currentHeight;
private LinearLayout progressBar;
private ConstraintLayout chartLayout;
private ConstraintLayout tableLayout;

public static WeightForHeightMonitoringFragment createInstance(Gender gender, String dobString, List<Weight> weights, List<Height> heights) {
WeightForHeightMonitoringFragment weightMonitoringFragment = new WeightForHeightMonitoringFragment();
Expand Down Expand Up @@ -80,23 +89,52 @@ private void setDob(String dobString) {

@Override
public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View weightHeightTableView = inflater.inflate(R.layout.growth_monitoring_fragment, container, false);
weightHeightTableView.setFilterTouchesWhenObscured(true);
if (getActivity() != null) {
final ImageButton scrollButton = weightHeightTableView.findViewById(R.id.scroll_button);
CustomFontTextView weightMetric = weightHeightTableView.findViewById(R.id.column_one_metric);
weightMetric.setText(getActivity().getString(R.string.weight));
CustomFontTextView heightMetric = weightHeightTableView.findViewById(R.id.metric_label);
heightMetric.setText(getActivity().getString(R.string.height));
scrollButtonClickAction(weightHeightTableView, scrollButton);
return inflater.inflate(R.layout.growth_monitoring_fragment, container, false);
}

@Override
public void onViewCreated(@NonNull View weightHeightTableView, @Nullable Bundle savedInstanceState) {
super.onViewCreated(weightHeightTableView, savedInstanceState);
initViews(weightHeightTableView);
showLoader();
new Thread(() -> {
try {
weightHeightTableView.setFilterTouchesWhenObscured(true);
final ImageButton scrollButton = weightHeightTableView.findViewById(R.id.scroll_button);
scrollButtonClickAction(weightHeightTableView, scrollButton);

refreshGrowthChart(weightHeightTableView);
refreshPreviousWeightHeightsTable(weightHeightTableView);

} catch (Exception e) {
Timber.e(e);
}
}
return weightHeightTableView;
if (isVisible())
requireActivity().runOnUiThread(this::hideLoader);
}).start();
}

private void initViews(View view) {
progressBar = view.findViewById(R.id.progress_chart);
chartLayout = view.findViewById(R.id.growth_chart_layout);
tableLayout = view.findViewById(R.id.growth_dialog_table_layout);

CustomFontTextView weightMetric = view.findViewById(R.id.column_one_metric);
weightMetric.setText(requireActivity().getString(R.string.weight));
CustomFontTextView heightMetric = view.findViewById(R.id.metric_label);
heightMetric.setText(requireActivity().getString(R.string.height));
}

private void hideLoader() {
progressBar.setVisibility(View.GONE);
chartLayout.setVisibility(View.VISIBLE);
tableLayout.setVisibility(View.VISIBLE);
}

private void showLoader() {
progressBar.setVisibility(View.VISIBLE);
chartLayout.setVisibility(View.GONE);
tableLayout.setVisibility(View.GONE);
}

private void refreshPreviousWeightHeightsTable(View weightHeightTableView) {
Expand All @@ -113,8 +151,6 @@ private void refreshPreviousWeightHeightsTable(View weightHeightTableView) {
params.span = 3;
divider.setLayoutParams(params);
divider.setBackgroundColor(getResources().getColor(R.color.client_list_header_dark_grey));
dividerRow.addView(divider);
tableLayout.addView(dividerRow);

TableRow curRow = new TableRow(weightHeightTableView.getContext());

Expand All @@ -125,7 +161,6 @@ private void refreshPreviousWeightHeightsTable(View weightHeightTableView) {
weightTextView.setText(String.format("%s %s", String.valueOf(weightHeight.getWeight().getKg()), getString(R.string.kg)));
weightTextView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
weightTextView.setTextColor(getResources().getColor(R.color.client_list_grey));
curRow.addView(weightTextView);

TextView heightTextView = new TextView(weightHeightTableView.getContext());
heightTextView.setHeight(getResources().getDimensionPixelSize(R.dimen.table_contents_text_height));
Expand All @@ -134,7 +169,6 @@ private void refreshPreviousWeightHeightsTable(View weightHeightTableView) {
heightTextView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
heightTextView.setText(String.format("%s %s", String.valueOf(weightHeight.getHeight().getCm()), getString(R.string.cm)));
heightTextView.setTextColor(getResources().getColor(R.color.client_list_grey));
curRow.addView(heightTextView);

TextView zScoreTextView = new TextView(weightHeightTableView.getContext());
zScoreTextView.setHeight(getResources().getDimensionPixelSize(R.dimen.table_contents_text_height));
Expand All @@ -146,8 +180,15 @@ private void refreshPreviousWeightHeightsTable(View weightHeightTableView) {
zScoreTextView.setTextColor(getResources().getColor(HeightZScore.getZScoreColor(zScore)));
zScoreTextView.setText(String.valueOf(zScore));

curRow.addView(zScoreTextView);
tableLayout.addView(curRow);
requireActivity().runOnUiThread(() -> {
dividerRow.addView(divider);
tableLayout.addView(dividerRow);
curRow.addView(weightTextView);
curRow.addView(heightTextView);

curRow.addView(zScoreTextView);
tableLayout.addView(curRow);
});
}

//Now set the expand button if items are too many
Expand Down
Loading