summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2017-11-23 08:17:09 +0100
committerGitHub <noreply@github.com>2017-11-23 08:17:09 +0100
commit405d141b9e9453fe57af0f5d6b6e22c5e3a0ac72 (patch)
tree0ed229f7cb058646af6e62db87d92769b7059847
parente2702c76ead76b77f2ac3621673ef74e532d38d7 (diff)
downloadqtlocation-mapboxgl-405d141b9e9453fe57af0f5d6b6e22c5e3a0ac72.tar.gz
[android] - update bottom sheet example with popable fragment backstack (#10506)
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
index 2c83f6d908..db7764bc82 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
@@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -35,7 +36,6 @@ public class BottomSheetActivity extends AppCompatActivity {
private static final String TAG_BOTTOM_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.bottom";
private boolean bottomSheetFragmentAdded;
- private int mapViewCounter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -45,7 +45,6 @@ public class BottomSheetActivity extends AppCompatActivity {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
}
findViewById(R.id.fabFragment).setOnClickListener(new View.OnClickListener() {
@@ -78,25 +77,29 @@ public class BottomSheetActivity extends AppCompatActivity {
@Override
public void onBackPressed() {
- super.onBackPressed();
- if (mapViewCounter > 0) {
- mapViewCounter--;
- Toast.makeText(this, "Amount of main map fragments: " + mapViewCounter, Toast.LENGTH_SHORT).show();
+ FragmentManager fragmentManager = getSupportFragmentManager();
+
+ if (fragmentManager.getBackStackEntryCount() > 0) {
+ fragmentManager.popBackStack();
+ } else {
+ super.onBackPressed();
}
}
private void addMapFragment() {
- FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
- MainMapFragment mainMapFragment = MainMapFragment.newInstance(mapViewCounter);
- if (mapViewCounter == 0) {
+ FragmentManager fragmentManager = getSupportFragmentManager();
+ int fragmentCount = fragmentManager.getBackStackEntryCount();
+
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ MainMapFragment mainMapFragment = MainMapFragment.newInstance(fragmentCount);
+ if (fragmentCount == 0) {
fragmentTransaction.add(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT);
} else {
fragmentTransaction.replace(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT);
}
- fragmentTransaction.addToBackStack(null);
+ fragmentTransaction.addToBackStack(String.valueOf(mainMapFragment.hashCode()));
fragmentTransaction.commit();
- mapViewCounter++;
- Toast.makeText(this, "Amount of main map fragments: " + mapViewCounter, Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, "Amount of main map fragments: " + (fragmentCount + 1), Toast.LENGTH_SHORT).show();
}
private void toggleBottomSheetMapFragment() {