Go back to previous activity, refactor
This commit is contained in:
parent
6c3eda0faa
commit
a992e4cefc
6 changed files with 66 additions and 61 deletions
|
@ -21,7 +21,6 @@ import net.osmand.plus.activities.PluginsFragment;
|
|||
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
|
||||
import net.osmand.plus.osmedit.OsmEditingFragment;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
@ -235,13 +234,6 @@ public class IntentHelper {
|
|||
}
|
||||
mapActivity.setIntent(null);
|
||||
}
|
||||
if (intent.hasExtra(OsmEditingFragment.OPEN_PLUGIN)) {
|
||||
boolean openPlugins = intent.getBooleanExtra(OsmEditingFragment.OPEN_PLUGIN, false);
|
||||
if (openPlugins) {
|
||||
OsmEditingFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||
}
|
||||
mapActivity.setIntent(null);
|
||||
}
|
||||
if (intent.hasExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
switch (intent.getStringExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
case BaseSettingsFragment.MAP_CONFIG:
|
||||
|
|
|
@ -60,6 +60,8 @@ public class FavoritesActivity extends TabActivity {
|
|||
private int tabSize;
|
||||
private ImportHelper importHelper;
|
||||
|
||||
private ViewPager viewPager;
|
||||
|
||||
private Bundle intentParams = null;
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +82,7 @@ public class FavoritesActivity extends TabActivity {
|
|||
List<TabItem> mTabs = getTabItems();
|
||||
setTabs(mTabs);
|
||||
|
||||
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
viewPager = findViewById(R.id.pager);
|
||||
if (savedInstanceState == null) {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.hasExtra(MapActivity.INTENT_PARAMS)) {
|
||||
|
@ -93,7 +95,7 @@ public class FavoritesActivity extends TabActivity {
|
|||
break;
|
||||
}
|
||||
}
|
||||
mViewPager.setCurrentItem(pagerItem, false);
|
||||
viewPager.setCurrentItem(pagerItem, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +193,17 @@ public class FavoritesActivity extends TabActivity {
|
|||
return mTabs;
|
||||
}
|
||||
|
||||
public Bundle storeCurrentState() {
|
||||
int currentItem = viewPager.getCurrentItem();
|
||||
if (currentItem >= 0 && currentItem < fragList.size()) {
|
||||
FavoritesFragmentStateHolder stateHolder = fragList.get(currentItem).get();
|
||||
if (stateHolder != null) {
|
||||
return stateHolder.storeState();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachFragment(Fragment fragment) {
|
||||
if (fragment instanceof FavoritesFragmentStateHolder) {
|
||||
|
|
|
@ -9,6 +9,8 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
@ -37,11 +39,8 @@ import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB;
|
|||
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener,
|
||||
OsmAuthorizationListener {
|
||||
|
||||
public static final String TAG = OsmEditingFragment.class.getName();
|
||||
|
||||
private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class);
|
||||
|
||||
public static final String OPEN_PLUGIN = "open_plugins";
|
||||
private static final String OSM_LOGOUT = "osm_logout";
|
||||
private static final String OPEN_OSM_EDITS = "open_osm_edits";
|
||||
public static final String OSM_LOGIN_DATA = "osm_login_data";
|
||||
|
@ -53,6 +52,17 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
|
||||
|
||||
FragmentActivity activity = requireMyActivity();
|
||||
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||
public void handleOnBackPressed() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.launchPrevActivityIntent();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,17 +210,4 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
public void authorizationCompleted() {
|
||||
updateAllSettings();
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager) {
|
||||
try {
|
||||
OsmEditingFragment fragment = new OsmEditingFragment();
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(TAG)
|
||||
.commitAllowingStateLoss();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
|
@ -31,16 +29,19 @@ import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
|||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem;
|
||||
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
|
||||
import net.osmand.plus.osmedit.OsmEditingFragment;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility;
|
||||
import net.osmand.plus.osmedit.UploadGPXFilesTask;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType.OPEN_STREET_MAP_EDITING;
|
||||
|
||||
public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = SendGpxBottomSheetFragment.class.getSimpleName();
|
||||
|
@ -105,8 +106,11 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
account.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
showOpenStreetMapScreen(activity);
|
||||
}
|
||||
dismiss();
|
||||
showOpenStreetMapScreen();
|
||||
}
|
||||
});
|
||||
RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view);
|
||||
|
@ -120,12 +124,21 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
items.add(titleItem);
|
||||
}
|
||||
|
||||
private void showOpenStreetMapScreen() {
|
||||
Bundle params = new Bundle();
|
||||
params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true);
|
||||
Context context = getView().getContext();
|
||||
Intent intent = getActivity().getIntent();
|
||||
MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params);
|
||||
protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) {
|
||||
if (activity instanceof MapActivity) {
|
||||
BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);
|
||||
} else {
|
||||
Bundle prevIntentParams = null;
|
||||
if (activity instanceof FavoritesActivity) {
|
||||
prevIntentParams = ((FavoritesActivity) activity).storeCurrentState();
|
||||
} else if (activity.getIntent() != null) {
|
||||
prevIntentParams = activity.getIntent().getExtras();
|
||||
}
|
||||
Bundle params = new Bundle();
|
||||
params.putString(BaseSettingsFragment.OPEN_SETTINGS, OPEN_STREET_MAP_EDITING.name());
|
||||
|
||||
MapActivity.launchMapActivityMoveToTop(activity, prevIntentParams, null, params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
@ -16,6 +14,7 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
@ -29,7 +28,6 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.osmedit.OsmEditingFragment;
|
||||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||
import net.osmand.plus.osmedit.OsmPoint;
|
||||
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
|
||||
|
@ -43,6 +41,7 @@ import org.apache.commons.logging.Log;
|
|||
import static net.osmand.plus.UiUtilities.setupDialogButton;
|
||||
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
|
||||
import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
|
||||
|
@ -136,8 +135,11 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
account.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
showOpenStreetMapScreen(activity);
|
||||
}
|
||||
dismiss();
|
||||
showOpenStreetMapScreen();
|
||||
}
|
||||
});
|
||||
final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
|
@ -184,14 +186,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
|
|||
}
|
||||
}
|
||||
|
||||
private void showOpenStreetMapScreen() {
|
||||
Bundle params = new Bundle();
|
||||
params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true);
|
||||
Context context = getView().getContext();
|
||||
Intent intent = getActivity().getIntent();
|
||||
MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogButtonType getRightBottomButtonType() {
|
||||
return (DialogButtonType.PRIMARY);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
|
@ -13,6 +11,7 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -25,7 +24,6 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||
import net.osmand.plus.osmedit.OsmEditingFragment;
|
||||
import net.osmand.plus.osmedit.OsmPoint;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -35,7 +33,10 @@ import org.apache.commons.logging.Log;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader;
|
||||
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
|
||||
|
||||
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
|
@ -92,8 +93,11 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
account.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
showOpenStreetMapScreen(activity);
|
||||
}
|
||||
dismiss();
|
||||
showOpenStreetMapScreen();
|
||||
}
|
||||
});
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
|
@ -102,14 +106,6 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
|||
items.add(titleItem);
|
||||
}
|
||||
|
||||
private void showOpenStreetMapScreen() {
|
||||
Bundle params = new Bundle();
|
||||
params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true);
|
||||
Context context = getView().getContext();
|
||||
Intent intent = getActivity().getIntent();
|
||||
MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params);
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
|
||||
try {
|
||||
if (!fm.isStateSaved()) {
|
||||
|
|
Loading…
Reference in a new issue