Skip to content

Commit

Permalink
Merge pull request #388 from OpenSRP/dashboard-update-button-377
Browse files Browse the repository at this point in the history
Implement manual update/refresh indicators button in Dashboard
  • Loading branch information
allan-on authored Jun 11, 2019
2 parents 2cb2c3a + efd4b89 commit 0a54ffd
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import org.smartregister.chw.BuildConfig;
import org.smartregister.chw.R;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.fragment.JobAidsDashboardFragment;
import org.smartregister.chw.fragment.JobAidsGuideBooksFragment;
import org.smartregister.chw.job.ChwIndicatorGeneratingJob;
import org.smartregister.chw.listener.JobsAidsBottomNavigationListener;
import org.smartregister.helper.BottomNavigationHelper;

public class JobAidsActivity extends FamilyRegisterActivity {

private static final String REPORT_LAST_PROCESSED_DATE = "REPORT_LAST_PROCESSED_DATE";
private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -27,32 +33,6 @@ protected void onCreate(Bundle savedInstanceState) {
registerBottomNavigation();
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return JobAidsDashboardFragment.newInstance();
case 1:
return JobAidsGuideBooksFragment.newInstance();
default:
return JobAidsDashboardFragment.newInstance();
}

}

@Override
public int getCount() {
// Show 3 total pages.
return 2;
}
}

private void setUpView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Expand All @@ -63,7 +43,7 @@ private void setUpView() {
// primary sections of the activity.
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
Expand All @@ -72,6 +52,23 @@ private void setUpView() {
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.job_aids_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_refresh_indicators:
refreshIndicatorData();
return true;
default:
return super.onOptionsItemSelected(menuItem);
}
}

@Override
protected void registerBottomNavigation() {

Expand Down Expand Up @@ -101,4 +98,51 @@ protected void registerBottomNavigation() {
bottomNavigationView.getMenu().removeItem(org.smartregister.family.R.id.action_scan_qr);
}
}

/**
* Refresh the indicator data by clearing the view and scheduling the IndicatorGeneratingJob immediately
* then triggering the reloading of the Fragment
*/
public void refreshIndicatorData() {
// Compute everything afresh. LPD is set to null to avoid messing with the processing timeline
ChwApplication.getInstance().getContext().allSharedPreferences().savePreference(REPORT_LAST_PROCESSED_DATE, null);
ChwIndicatorGeneratingJob.scheduleJobImmediately(ChwIndicatorGeneratingJob.TAG);
if (mViewPager != null) {
mViewPager.getAdapter().notifyDataSetChanged();
}
Log.d(TAG, "Refreshing indicators...");
}

public class SectionsPagerAdapter extends android.support.v4.app.FragmentStatePagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return JobAidsDashboardFragment.newInstance();
case 1:
return JobAidsGuideBooksFragment.newInstance();
default:
return JobAidsDashboardFragment.newInstance();
}
}

@Override
public int getCount() {
// Show 3 total pages.
return 2;
}

@Override
public int getItemPosition(Object object) {
if (object instanceof JobAidsDashboardFragment) {
((JobAidsDashboardFragment) object).loadIndicatorTallies();
}
return super.getItemPosition(object);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public static JobAidsDashboardFragment newInstance() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fetch Indicator data
presenter = new JobAidsDashboardFragmentPresenter(this);
getLoaderManager().initLoader(0, null, this).forceLoad();
loadIndicatorTallies();
}

@Override
Expand Down Expand Up @@ -86,6 +85,10 @@ public void onDetach() {
super.onDetach();
}

public void loadIndicatorTallies() {
getLoaderManager().initLoader(0, null, this).forceLoad();
}

private void buildVisualisations() {
if (indicatorTallies == null || indicatorTallies.isEmpty()) {
return;
Expand Down Expand Up @@ -204,6 +207,7 @@ private void buildVisualisations() {

View children_0_24_months_up_to_date_vaccinations = getIndicatorView(pieChartIndicatorVisualizationData, pieChartFactory);

visualizationsViewGroup.removeAllViews();
visualizationsViewGroup.addView(childrenU5View);
visualizationsViewGroup.addView(deceased_0_11_View);
visualizationsViewGroup.addView(deceased_12_59_View);
Expand Down
4 changes: 2 additions & 2 deletions opensrp-chw/src/main/res/layout/activity_job_aids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@color/customAppThemeBlue"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/FamilyTheme.PopupOverlay">

<org.smartregister.view.customcontrols.CustomFontTextView
Expand Down Expand Up @@ -70,8 +70,8 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="?attr/actionBarSize"
android:layout_marginBottom="?attr/actionBarSize"
android:paddingBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />


Expand Down
10 changes: 10 additions & 0 deletions opensrp-chw/src/main/res/menu/job_aids_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_refresh_indicators"
android:enabled="true"
android:title="@string/refresh_indicators"
android:icon="@mipmap/sidemenu_sync"
app:showAsAction="always" />
</menu>
1 change: 1 addition & 0 deletions opensrp-chw/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<string name="anc_registration">ANC Registration</string>
<string name="log_out_as">Log out as</string>
<string name="job_aids">Job Aids</string>
<string name="refresh_indicators">Refresh indicators</string>
<string name="total_under_5_children_label">Total U5 children</string>
<string name="deceased_children_0_11_months">Children (0&#8211;11 months) who died in the last year</string>
<string name="deceased_children_12_59_months">Children (12&#8211;59 months) who died in the last year</string>
Expand Down

0 comments on commit 0a54ffd

Please sign in to comment.