From 7d23a3c04f3413beccf76391dffe6ad0aa36addf Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 6 Aug 2014 17:51:57 +0300 Subject: [PATCH] Updated back functionality to work everywhere --- .../plus/sherpafy/SherpafyStageFragment.java | 15 +++++++--- .../plus/sherpafy/TourViewActivity.java | 28 +++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java index ff197daa96..aa79593a55 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java @@ -41,7 +41,10 @@ public class SherpafyStageFragment extends SherlockFragment { public SherpafyStageFragment() { } - + + public TourInformation getTour(){ + return tour; + } @Override public void onAttach(Activity activity) { @@ -84,7 +87,7 @@ public class SherpafyStageFragment extends SherlockFragment { }); } } - + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -148,8 +151,12 @@ public class SherpafyStageFragment extends SherlockFragment { } } - - /** + public void onBackPressed() { + ((TourViewActivity) getSherlockActivity()).selectMenu(tour); + } + + + /** * This is a helper class that implements the management of tabs and all * details of connecting a ViewPager with associated TabHost. It relies on a * trick. Normally a tab host has a simple API for supplying a View or diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 796742c581..35fda31d0e 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -3,6 +3,8 @@ package net.osmand.plus.sherpafy; import java.util.List; import java.util.WeakHashMap; +import android.view.KeyEvent; +import android.widget.*; import net.osmand.IProgress; import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities.GPXFile; @@ -30,12 +32,7 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; @@ -50,6 +47,7 @@ public class TourViewActivity extends SherlockFragmentActivity { private static final int STATE_SELECT_TOUR = 1; private static final int STATE_TOUR_VIEW = 2; private static final int STATE_STAGE_OVERVIEW = 3; + private static final int STATE_DETAILED_OVERVIEW = 4; private static int state = STATE_LOADING; public static final int APP_EXIT_CODE = 4; @@ -121,12 +119,20 @@ public class TourViewActivity extends SherlockFragmentActivity { @Override public void onBackPressed() { - if (state == STATE_SELECT_TOUR){ + if(state == STATE_SELECT_TOUR) { super.onBackPressed(); - } else if (state == STATE_TOUR_VIEW){ - selectMenu(R.string.sherpafy_tours); + } else if (state == STATE_TOUR_VIEW) { + SherpafyHtmlFragment fragment = (SherpafyHtmlFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(STATE_DETAILED_OVERVIEW)); + if (fragment != null && fragment.isVisible()){ + showSelectedItem(); + } else { + selectMenu(R.string.sherpafy_tours); + } } else if (state == STATE_STAGE_OVERVIEW){ - selectMenu(customization.getSelectedTour()); + SherpafyStageFragment fragment = (SherpafyStageFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(state)); + if (fragment != null){ + fragment.onBackPressed(); + } } } @@ -271,7 +277,7 @@ public class TourViewActivity extends SherlockFragmentActivity { setDrawerIndicatorVisible(false); } if(fragment != null) { - fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); + fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(state)).commit(); } selectedItem = item; if (mDrawerLayout.isDrawerOpen(mDrawerList)) { @@ -343,7 +349,7 @@ public class TourViewActivity extends SherlockFragmentActivity { bl.putString(SherpafyHtmlFragment.HTML, cont); bl.putString(SherpafyHtmlFragment.TITLE, title); fragment.setArguments(bl); - fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); + fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(STATE_DETAILED_OVERVIEW)).commit(); }