diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 49d0b301cf..a8d9fb89b0 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -2,6 +2,7 @@ @@ -56,7 +57,8 @@ android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:theme="@style/MwmTheme"> + android:theme="@style/MwmTheme" + tools:ignore="UnusedAttribute"> + android:launchMode="singleTask" + android:theme="@style/MwmTheme.Map"> + android:label="@string/download_maps" + android:parentActivityName="com.mapswithme.maps.MWMActivity"> + + + + + android:label="@string/settings_and_more" + android:parentActivityName="com.mapswithme.maps.MWMActivity"> + + + android:label="@string/maps_storage" + android:parentActivityName="com.mapswithme.maps.MWMActivity"> + + + android:label="@string/bookmarks" + android:parentActivityName="com.mapswithme.maps.MWMActivity"> + + + android:label="@string/bookmarks" + android:parentActivityName="com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity"> + + @@ -240,7 +272,6 @@ - diff --git a/android/src/com/mapswithme/country/DownloadActivity.java b/android/src/com/mapswithme/country/DownloadActivity.java index 2a15affe4f..8398c1c1b2 100644 --- a/android/src/com/mapswithme/country/DownloadActivity.java +++ b/android/src/com/mapswithme/country/DownloadActivity.java @@ -15,9 +15,20 @@ public class DownloadActivity extends BaseMwmFragmentActivity { super.onCreate(savedInstanceState); + final String fragmentClassName = DownloadFragment.class.getName(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - DownloadFragment downloadFragment = (DownloadFragment) Fragment.instantiate(this, DownloadFragment.class.getName(), getIntent().getExtras()); - transaction.replace(android.R.id.content, downloadFragment, "fragment"); + DownloadFragment downloadFragment = (DownloadFragment) Fragment.instantiate(this, fragmentClassName, getIntent().getExtras()); + transaction.replace(android.R.id.content, downloadFragment, fragmentClassName); transaction.commit(); } + + @Override + public void onBackPressed() + { + DownloadFragment fragment = (DownloadFragment) getSupportFragmentManager().findFragmentByTag(DownloadFragment.class.getName()); + if (fragment != null && fragment.onBackPressed()) + return; + + super.onBackPressed(); + } } diff --git a/android/src/com/mapswithme/country/DownloadAdapter.java b/android/src/com/mapswithme/country/DownloadAdapter.java index 4a4ad3c09d..685828f124 100644 --- a/android/src/com/mapswithme/country/DownloadAdapter.java +++ b/android/src/com/mapswithme/country/DownloadAdapter.java @@ -43,8 +43,7 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country { CountryTree.showLeafOnMap(position); resetCountryListener(); - mFragment.onBackPressed(); - mFragment.onBackPressed(); + mFragment.navigateUpToParent(); } protected void expandGroup(int position) diff --git a/android/src/com/mapswithme/country/DownloadFragment.java b/android/src/com/mapswithme/country/DownloadFragment.java index 188571c477..29c2244ced 100644 --- a/android/src/com/mapswithme/country/DownloadFragment.java +++ b/android/src/com/mapswithme/country/DownloadFragment.java @@ -1,8 +1,8 @@ package com.mapswithme.country; -import android.content.Intent; import android.database.DataSetObserver; import android.os.Bundle; +import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,11 +10,9 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; -import com.mapswithme.maps.MWMActivity; import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmListFragment; import com.mapswithme.maps.base.OnBackPressListener; -import com.mapswithme.util.UiUtils; public class DownloadFragment extends BaseMwmListFragment implements View.OnClickListener, ActiveCountryTree.ActiveCountryListener, OnBackPressListener { @@ -53,17 +51,9 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic private void initToolbar() { - UiUtils.showHomeUpButton(getToolbar()); - getToolbar().setTitle(getString(R.string.maps)); - getToolbar().setNavigationOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - onBackPressed(); - } - }); - mTvUpdateAll = (TextView) getToolbar().findViewById(R.id.tv__update_all); + final Toolbar toolbar = getToolbar(); + toolbar.setTitle(getString(R.string.maps)); + mTvUpdateAll = (TextView) toolbar.findViewById(R.id.tv__update_all); mTvUpdateAll.setOnClickListener(this); mTvUpdateAll.setVisibility(View.GONE); } @@ -76,7 +66,6 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic ActiveCountryTree.removeListener(mListenerSlotId); } - private BaseDownloadAdapter getDownloadAdapter() { return (BaseDownloadAdapter) getListView().getAdapter(); @@ -116,10 +105,8 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic return true; } else - { - getActivity().getSupportFragmentManager().popBackStack(); - startActivity(new Intent(getActivity(), MWMActivity.class)); - } + navigateUpToParent(); + return false; } diff --git a/android/src/com/mapswithme/country/DownloadedAdapter.java b/android/src/com/mapswithme/country/DownloadedAdapter.java index 8bb619266f..ac180837fc 100644 --- a/android/src/com/mapswithme/country/DownloadedAdapter.java +++ b/android/src/com/mapswithme/country/DownloadedAdapter.java @@ -250,9 +250,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter implements ActiveCoun { ActiveCountryTree.showOnMap(getGroupByAbsPosition(position), getPositionInGroup(position)); resetCountryListener(); - // TODO think about refactoring. - mFragment.onBackPressed(); - mFragment.onBackPressed(); + mFragment.navigateUpToParent(); } @Override diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 5281252548..81c5e28d8e 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -47,6 +47,7 @@ import com.mapswithme.country.DownloadFragment; import com.mapswithme.country.StorageOptions; import com.mapswithme.maps.Framework.OnBalloonListener; import com.mapswithme.maps.MapStorage.Index; +import com.mapswithme.maps.activity.CustomNavigateUpListener; import com.mapswithme.maps.ads.LikesManager; import com.mapswithme.maps.api.ParsedMmwRequest; import com.mapswithme.maps.base.BaseMwmFragmentActivity; @@ -92,7 +93,7 @@ import java.util.concurrent.TimeUnit; public class MWMActivity extends BaseMwmFragmentActivity implements LocationHelper.LocationListener, OnBalloonListener, View.OnTouchListener, BasePlacePageAnimationController.OnVisibilityChangedListener, - OnClickListener, Framework.RoutingListener, MapFragment.MapRenderingListener + OnClickListener, Framework.RoutingListener, MapFragment.MapRenderingListener, CustomNavigateUpListener { public static final String EXTRA_TASK = "map_task"; private final static String TAG = "MWMActivity"; @@ -1698,6 +1699,16 @@ public class MWMActivity extends BaseMwmFragmentActivity }); } + @Override + public void customOnNavigateUp() + { + if (popFragment()) + { + InputUtils.hideKeyboard(mBottomButtons); + mFadeView.fadeOut(); + } + } + public interface MapTask extends Serializable { public boolean run(MWMActivity target); diff --git a/android/src/com/mapswithme/maps/activity/CustomNavigateUpListener.java b/android/src/com/mapswithme/maps/activity/CustomNavigateUpListener.java new file mode 100644 index 0000000000..db454d0fdb --- /dev/null +++ b/android/src/com/mapswithme/maps/activity/CustomNavigateUpListener.java @@ -0,0 +1,10 @@ +package com.mapswithme.maps.activity; + +/** + * Interface for activities to implement to perform custom 'up' navigation + * (when up arrow in actionbar/toolbar is pressed) + */ +public interface CustomNavigateUpListener +{ + void customOnNavigateUp(); +} diff --git a/android/src/com/mapswithme/maps/base/BaseMwmListFragment.java b/android/src/com/mapswithme/maps/base/BaseMwmListFragment.java index cd6367e468..c62751c74f 100644 --- a/android/src/com/mapswithme/maps/base/BaseMwmListFragment.java +++ b/android/src/com/mapswithme/maps/base/BaseMwmListFragment.java @@ -1,11 +1,14 @@ package com.mapswithme.maps.base; +import android.app.Activity; import android.os.Bundle; import android.support.v4.app.ListFragment; +import android.support.v4.app.NavUtils; import android.support.v7.widget.Toolbar; import android.view.View; import com.mapswithme.maps.R; +import com.mapswithme.maps.activity.CustomNavigateUpListener; import com.mapswithme.util.UiUtils; public abstract class BaseMwmListFragment extends ListFragment @@ -26,7 +29,7 @@ public abstract class BaseMwmListFragment extends ListFragment @Override public void onClick(View v) { - getActivity().onBackPressed(); + navigateUpToParent(); } }); } @@ -50,4 +53,13 @@ public abstract class BaseMwmListFragment extends ListFragment super.onPause(); org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName()); } + + public void navigateUpToParent() + { + final Activity activity = getActivity(); + if (activity instanceof CustomNavigateUpListener) + ((CustomNavigateUpListener) activity).customOnNavigateUp(); + else + NavUtils.navigateUpFromSameTask(activity); + } }