diff --git a/app/src/androidTest/java/com/objectivetruth/uoitlibrarybooking/test/DrawerInstrumentationTests.java b/app/src/androidTest/java/com/objectivetruth/uoitlibrarybooking/test/DrawerInstrumentationTests.java index 36868ce..a5d79f7 100644 --- a/app/src/androidTest/java/com/objectivetruth/uoitlibrarybooking/test/DrawerInstrumentationTests.java +++ b/app/src/androidTest/java/com/objectivetruth/uoitlibrarybooking/test/DrawerInstrumentationTests.java @@ -18,6 +18,7 @@ import com.objectivetruth.uoitlibrarybooking.app.UOITLibraryBookingApp; import com.objectivetruth.uoitlibrarybooking.app.networking.MockHttpStack; import com.objectivetruth.uoitlibrarybooking.data.DataModule; +import com.squareup.spoon.Spoon; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -67,38 +68,38 @@ protected RequestQueue providesRequestQueue() { @Test public void testDrawerGoesToCorrectScreens() { - //Spoon.screenshot(mActivity, "initial_screen"); + Spoon.screenshot(mActivity, "initial_screen"); - //onView(withId(android.R.id.button1)).perform(click()); - //Spoon.screenshot(mActivity, "after_dismiss_dialog"); + onView(withId(android.R.id.button1)).perform(click()); + Spoon.screenshot(mActivity, "after_dismiss_dialog"); onView(withId(R.id.calendar_content_frame)).check(matches((isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); - //Spoon.screenshot(mActivity, "after_open_drawer"); + Spoon.screenshot(mActivity, "after_open_drawer"); onView(withText("Library Booking Policies")).perform(click()); - //Spoon.screenshot(mActivity, "after_open_guidelines_policies"); + Spoon.screenshot(mActivity, "after_open_guidelines_policies"); onView(withText("Booking Guidelines")).check(matches(isDisplayed())); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); - //Spoon.screenshot(mActivity, "after_open_drawer_2"); + Spoon.screenshot(mActivity, "after_open_drawer_2"); onView(withText("About")).perform(click()); - //Spoon.screenshot(mActivity, "after_open_about"); + Spoon.screenshot(mActivity, "after_open_about"); onView(withText(R.string.about_description)).check(matches(isDisplayed())); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); - //Spoon.screenshot(mActivity, "after_open_drawer_3"); + Spoon.screenshot(mActivity, "after_open_drawer_3"); onView(withText("My Account")).perform(click()); - //Spoon.screenshot(mActivity, "after_open_my_account"); + Spoon.screenshot(mActivity, "after_open_my_account"); onView(withText("Login")).check(matches(isDisplayed())); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); - //Spoon.screenshot(mActivity, "after_open_drawer_4"); + Spoon.screenshot(mActivity, "after_open_drawer_4"); onView(withText("Calendar")).perform(click()); - //Spoon.screenshot(mActivity, "after_open_calendar"); + Spoon.screenshot(mActivity, "after_open_calendar"); onView(withId(R.id.calendar_content_frame)).check(matches((isDisplayed()))); } } diff --git a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/about/About.java b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/about/About.java index f82b983..53fff5b 100644 --- a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/about/About.java +++ b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/about/About.java @@ -5,18 +5,23 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.app.ActionBar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.objectivetruth.uoitlibrarybooking.BuildConfig; +import com.objectivetruth.uoitlibrarybooking.MainActivity; import com.objectivetruth.uoitlibrarybooking.R; import mehdi.sakout.aboutpage.AboutPage; import mehdi.sakout.aboutpage.Element; +import timber.log.Timber; import java.util.HashMap; import java.util.Map; public class About extends Fragment{ + private static final String ABOUT_TITLE = "About"; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @@ -69,6 +74,23 @@ public View onCreateView(LayoutInflater inflater, return aboutPage.create(); } + @Override + public void onHiddenChanged(boolean isNowHidden) { + if(isNowHidden) { + Timber.d(getClass().getSimpleName() + " isNowHidden"); + }else { + Timber.d(getClass().getSimpleName() + " isNowVisible"); + _setTitle(ABOUT_TITLE); + } + super.onHiddenChanged(isNowHidden); + } + + private void _setTitle(String title) { + ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar(); + if(actionBar != null) { + actionBar.setTitle(title); + } + } private Element _makeElement(String description) { Element element = new Element(); diff --git a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/calendar/Calendar.java b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/calendar/Calendar.java index c0de20c..0890f12 100644 --- a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/calendar/Calendar.java +++ b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/calendar/Calendar.java @@ -8,6 +8,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.view.*; import android.widget.Toast; @@ -19,6 +20,7 @@ import com.google.gson.Gson; import com.objectivetruth.uoitlibrarybooking.ActivityRoomInteraction; import com.objectivetruth.uoitlibrarybooking.BuildConfig; +import com.objectivetruth.uoitlibrarybooking.MainActivity; import com.objectivetruth.uoitlibrarybooking.R; import com.objectivetruth.uoitlibrarybooking.app.UOITLibraryBookingApp; import com.objectivetruth.uoitlibrarybooking.data.models.CalendarModel; @@ -44,6 +46,7 @@ import static com.objectivetruth.uoitlibrarybooking.common.constants.SHARED_PREFERENCES_KEYS.HAS_LEARNED_HELP; public class Calendar extends Fragment { + private static final String CALENDAR_TITLE = "Calendar"; @Inject CalendarModel calendarModel; @Inject SharedPreferences mDefaultSharedPreferences; @Inject SharedPreferences.Editor mDefaultSharedPreferencesEditor; @@ -84,10 +87,11 @@ public void onStart() { @Override public void onHiddenChanged(boolean isNowHidden) { if(isNowHidden) { - Timber.d("Calendar isNowHidden"); + Timber.d(getClass().getSimpleName() + " isNowHidden"); _teardownViewBindings(_mSwipeLayout); }else { - Timber.d("Calendar isNowVisible"); + Timber.d(getClass().getSimpleName() + "isNowVisible"); + _setTitle(CALENDAR_TITLE); _setupViewBindings(_mSwipeLayout, calendarModel.getCalendarDataRefreshObservable()); } super.onHiddenChanged(isNowHidden); @@ -95,7 +99,7 @@ public void onHiddenChanged(boolean isNowHidden) { @Override public void onStop() { - Timber.d("Calendar Stopped"); + Timber.d(getClass().getSimpleName() + " Stopped"); _teardownViewBindings(_mSwipeLayout); super.onStop(); } @@ -106,6 +110,13 @@ public void onSaveInstanceState(Bundle outState) { outState.putBoolean(HAS_SHOWN_INITIAL_SCREEN_BUNDLE_KEY, _hasShownInitialScreen); } + private void _setTitle(String title) { + ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar(); + if(actionBar != null) { + actionBar.setTitle(title); + } + } + /** * Undoes all the bindings to the view, this is important so events don't get fired when the view is no longer * visible, or "in-view". This function is idempotent diff --git a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/common/ActivityBase.java b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/common/ActivityBase.java index 6c8c73a..cd22ad4 100644 --- a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/common/ActivityBase.java +++ b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/common/ActivityBase.java @@ -36,6 +36,7 @@ public abstract class ActivityBase extends AppCompatActivity { private DrawerLayout _mDrawerLayout; private HashMap stringFragmentHashMap = new HashMap(); private int _lastMenuItemIDRequested; + private boolean _isFirstTimeSelectDrawerItem = true; private NavigationView navigationView; private String LAST_MENU_ITEM_ID_REQUESTED_BUNDLE_KEY = "LAST_MENU_ITEM_ID_REQUESTED"; private String MAIN_FRAGMENT_TAGS_BUNDLE_KEY = "MAIN_FRAGMENT_TAGS_BUNDLE_KEY"; @@ -244,7 +245,7 @@ protected boolean selectDrawerItem(MenuItem menuItem) { } if(fragmentTagIsFoundTriple == null) {return false;} - FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); // If the fragment was already created(isFound), just show it. If not, // Insert the fragment by replacing any existing fragment. // Don't forget to tag it so it can be retrieved later without loading it again @@ -252,24 +253,37 @@ protected boolean selectDrawerItem(MenuItem menuItem) { if(_isFragmentFoundAndVisible(fragmentTagIsFoundTriple)) { Timber.d("Drawer Item: " + menuItem.getTitle() + " already being shown. Not changing screen"); }else if(!_isFragmentFoundAndVisible(fragmentTagIsFoundTriple)) { - _hideAllVisibleFragments(stringFragmentHashMap); - fragmentManager.beginTransaction() + fragmentTransaction = + _addHideAllVisibleFragmentsToFragmentTransaction(stringFragmentHashMap, fragmentTransaction) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) - .show(fragmentTagIsFoundTriple.getLeft()) + .show(fragmentTagIsFoundTriple.getLeft()); + // On the first time opening the drawer there is a special case where the backstack will be empty, so adding + // will cause the user to see a blank screen with nothing if they press back + if(_isFirstTimeSelectDrawerItem) { + _isFirstTimeSelectDrawerItem = false; + }else{ + fragmentTransaction.addToBackStack(null); + } + + fragmentTransaction .commit(); }else { - _hideAllVisibleFragments(stringFragmentHashMap); - fragmentManager.beginTransaction() + // To make sure the backstack works correctly, we split this into 2 separate transactions + // This one JUST adds it to the correct frame, and the 2nd one hides/unhides + getSupportFragmentManager().beginTransaction() .add(R.id.mainactivity_content_frame, fragmentTagIsFoundTriple.getLeft(), fragmentTagIsFoundTriple.getMiddle()) .commit(); + + _addHideAllVisibleFragmentsToFragmentTransaction(stringFragmentHashMap, fragmentTransaction) + .addToBackStack(null) + .commit(); } // Highlight the selected item menuItem.setChecked(true); // Set action bar title - if(getSupportActionBar() != null) {getSupportActionBar().setTitle(menuItem.getTitle());}; _mDrawerLayout.closeDrawers(); return true; } @@ -278,16 +292,16 @@ private boolean _isFragmentFoundAndVisible(Triple fra return fragmentTagIsFoundTriple.getRight() && fragmentTagIsFoundTriple.getLeft().isVisible(); } - private void _hideAllVisibleFragments(HashMap stringFragmentHashMap) { - FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); - + private FragmentTransaction _addHideAllVisibleFragmentsToFragmentTransaction(HashMap + stringFragmentHashMap, + FragmentTransaction fragmentTransaction) { Collection fragmentCollection = stringFragmentHashMap.values(); for(Fragment fragment: fragmentCollection) { if(fragment != null && fragment.isVisible()) { fragmentTransaction = fragmentTransaction.hide(fragment); } } - fragmentTransaction.commit(); + return fragmentTransaction; } protected ActionBarDrawerToggle getActionBarDrawerToggle() { diff --git a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/guidelinespolicies/GuidelinesAndPolicies.java b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/guidelinespolicies/GuidelinesAndPolicies.java index ddc4abc..3fb1f6a 100644 --- a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/guidelinespolicies/GuidelinesAndPolicies.java +++ b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/guidelinespolicies/GuidelinesAndPolicies.java @@ -3,12 +3,16 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.app.ActionBar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.objectivetruth.uoitlibrarybooking.MainActivity; import com.objectivetruth.uoitlibrarybooking.R; +import timber.log.Timber; public class GuidelinesAndPolicies extends Fragment{ + private static final String GUIDELINES_AND_POLICIES_TITLE = "Policies"; @Nullable @Override public View onCreateView(LayoutInflater inflater, @@ -17,6 +21,24 @@ public View onCreateView(LayoutInflater inflater, return inflater.inflate(R.layout.guidelines_policies, container, false); } + @Override + public void onHiddenChanged(boolean isNowHidden) { + if(isNowHidden) { + Timber.d(getClass().getSimpleName() + " isNowHidden"); + }else { + Timber.d(getClass().getSimpleName() + " isNowVisible"); + _setTitle(GUIDELINES_AND_POLICIES_TITLE); + } + super.onHiddenChanged(isNowHidden); + } + + private void _setTitle(String title) { + ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar(); + if(actionBar != null) { + actionBar.setTitle(title); + } + } + public static GuidelinesAndPolicies newInstance() { return new GuidelinesAndPolicies(); } diff --git a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/myaccount/MyAccount.java b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/myaccount/MyAccount.java index d561de0..7e02114 100644 --- a/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/myaccount/MyAccount.java +++ b/app/src/main/java/com/objectivetruth/uoitlibrarybooking/userinterface/myaccount/MyAccount.java @@ -3,9 +3,11 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.app.ActionBar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.objectivetruth.uoitlibrarybooking.MainActivity; import com.objectivetruth.uoitlibrarybooking.R; import com.objectivetruth.uoitlibrarybooking.app.UOITLibraryBookingApp; import com.objectivetruth.uoitlibrarybooking.data.models.UserModel; @@ -23,6 +25,7 @@ public class MyAccount extends Fragment { private Subscription myAccountDataLoginStateObservableSubscription; + private static final String MY_ACCOUNT_TITLE = "My Account"; public @Inject UserModel userModel; @Override @@ -40,7 +43,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onStart() { - Timber.d("MyAccount onStart"); + Timber.d(getClass().getSimpleName() + " onStart"); _setupViewBindings(userModel.getLoginStateObservable()); super.onStart(); } @@ -48,17 +51,19 @@ public void onStart() { @Override public void onHiddenChanged(boolean isNowHidden) { if(isNowHidden) { - Timber.d("MyAccount isNowHidden"); + Timber.d(getClass().getSimpleName() + " isNowHidden"); _teardownViewBindings(); }else { - Timber.d("MyAccount isNowVisible"); + Timber.d(getClass().getSimpleName() + " isNowVisible"); + _setTitle(MY_ACCOUNT_TITLE); _setupViewBindings(userModel.getLoginStateObservable()); } super.onHiddenChanged(isNowHidden); } + @Override public void onStop() { - Timber.d("MyAccount Stopped"); + Timber.d(getClass().getSimpleName() + " Stopped"); _teardownViewBindings(); super.onStop(); } @@ -116,7 +121,6 @@ public void onNext(MyAccountDataLoginState myAccountDataLoginState) { private void _showFullscreenLoading() { getChildFragmentManager().beginTransaction() .replace(R.id.my_account_content_frame, Loading.newInstance()) - .addToBackStack(null) .commit(); } @@ -126,6 +130,13 @@ private boolean _isMyAccountLoadedShowing() { return currentFragmentInContentFrame instanceof MyAccountLoaded && currentFragmentInContentFrame.isVisible(); } + private void _setTitle(String title) { + ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar(); + if(actionBar != null) { + actionBar.setTitle(title); + } + } + private boolean _isMyAccountLoadedNOTShowing() { return !_isMyAccountLoadedShowing(); } @@ -144,7 +155,6 @@ private void _showMyAccountLoadedFragment(MyAccountDataLoginState myAccountDataL //getActivity().invalidateOptionsMenu(); getChildFragmentManager().beginTransaction() .replace(R.id.my_account_content_frame, myAccountLoadedFragment, MY_ACCOUNT_LOADED_FRAGMENT_TAG) - .addToBackStack(null) .commit(); } @@ -163,7 +173,6 @@ private void _showLoginFragment(MyAccountDataLoginState myAccountDataLoginState) getChildFragmentManager().beginTransaction() .replace(R.id.my_account_content_frame, myAccountLoginFragment, MY_ACCOUNT_LOGIN_FRAGMENT_TAG) - .addToBackStack(null) .commit(); }