diff --git a/app/src/main/java/org/glucosio/android/activity/MainActivity.java b/app/src/main/java/org/glucosio/android/activity/MainActivity.java index 1cfb8094..61204178 100644 --- a/app/src/main/java/org/glucosio/android/activity/MainActivity.java +++ b/app/src/main/java/org/glucosio/android/activity/MainActivity.java @@ -71,6 +71,7 @@ import org.glucosio.android.adapter.HomePagerAdapter; import org.glucosio.android.analytics.Analytics; import org.glucosio.android.db.DatabaseHandler; +import org.glucosio.android.fragment.HistoryFragment; import org.glucosio.android.presenter.ExportPresenter; import org.glucosio.android.presenter.MainPresenter; import org.glucosio.android.tools.LocaleHelper; @@ -166,6 +167,7 @@ public void onPageSelected(int position) { public void onPageScrollStateChanged(int state) { } + }); FloatingActionButton fabAddReading = findViewById(R.id.activity_main_fab_add_reading); @@ -272,6 +274,30 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { analytics.reportScreen("Main Activity"); } + @Override + protected void onResume() { + /* Added this method to ensure that new data is shown after being added by other activities + example - while viewing HbA1c history, use calculator to add reading. The new reading + wasn't being shown on the history until the user navigated away from the history page + and came back, and it should refresh with data IMHO + */ + super.onResume(); + + if (viewPager != null) { + int currentPage = viewPager.getCurrentItem(); + if (currentPage == 1) { // assumption - history tab is always position 1 + if (homePagerAdapter != null) { + HistoryFragment historyFragment = homePagerAdapter.getHistoryFragment(); + if (historyFragment != null) { + historyFragment.reloadFragmentAdapter(); + } + } + } + } + + + } + private void openRemindersActivity() { Intent intent = new Intent(this, RemindersActivity.class); startActivity(intent); @@ -793,4 +819,6 @@ private boolean checkPlayServices() { private void showErrorDialogPlayServices() { Toast.makeText(getApplicationContext(), R.string.activity_main_error_play_services, Toast.LENGTH_SHORT).show(); } + + }