refactoring 2

This commit is contained in:
madwasp79 2019-06-25 14:28:35 +03:00
parent 507d1e9032
commit 9d0333734f
5 changed files with 41 additions and 32 deletions

View file

@ -48,7 +48,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesActivity.FragmentStateHolder;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -66,7 +66,7 @@ import java.util.Set;
public class FavoritesTreeFragment extends OsmandExpandableListFragment implements
FragmentStateHolder {
FavoritesFragmentStateHolder {
public static final int SEARCH_ID = -1;
// public static final int EXPORT_ID = 0;
// public static final int IMPORT_ID = 1;
@ -210,7 +210,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
});
if (getArguments() != null) {
groupNameToShow = getArguments().getString(FavoritesActivity.GROUP_NAME_TO_SHOW);
groupNameToShow = getArguments().getString(GROUP_NAME_TO_SHOW);
}
if (groupNameToShow != null) {
@ -707,8 +707,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
true,
point); //$NON-NLS-1$
Bundle b = new Bundle();
b.putInt(FavoritesActivity.GROUP_POSITION, groupPos);
b.putInt(FavoritesActivity.ITEM_POSITION, childPos);
b.putInt(GROUP_POSITION, groupPos);
b.putInt(ITEM_POSITION, childPos);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
@ -721,8 +721,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
@Override
public void restoreState(Bundle bundle) {
if (bundle != null) {
int group = bundle.getInt(FavoritesActivity.GROUP_POSITION, 0);
int child = bundle.getInt(FavoritesActivity.ITEM_POSITION, 0);
int group = bundle.getInt(GROUP_POSITION, 0);
int child = bundle.getInt(ITEM_POSITION, 0);
listView.setSelectedChild(group, child, true);
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.audionotes;
import static net.osmand.plus.myplaces.FavoritesActivity.NOTES_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.ITEM_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import android.content.Context;
@ -52,7 +51,7 @@ import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesActivity.FragmentStateHolder;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import org.apache.commons.logging.Log;
import java.io.File;
@ -65,7 +64,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class NotesFragment extends OsmAndListFragment implements FragmentStateHolder {
public class NotesFragment extends OsmAndListFragment implements FavoritesFragmentStateHolder {
public static final Recording SHARE_LOCATION_FILE = new Recording(new File("."));

View file

@ -79,7 +79,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity.FragmentStateHolder;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
@ -103,10 +103,9 @@ import java.util.Set;
import java.util.regex.Pattern;
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FragmentStateHolder {
FavoritesFragmentStateHolder {
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
public static final int SEARCH_ID = -1;
// public static final int ACTION_ID = 0;
// protected static final int DELETE_ACTION_ID = 1;

View file

@ -43,18 +43,17 @@ public class FavoritesActivity extends TabActivity {
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
private static final int IMPORT_FAVOURITES_REQUEST = 1007;
public static final String GROUP_NAME_TO_SHOW = "group_name_to_show";
public static final String TAB_ID = "selected_tab_id";
public static final String ITEM_POSITION = "item_position";
public static final String GROUP_POSITION = "group_position";
public static final int GPX_TAB = R.string.shared_string_tracks;
public static final int FAV_TAB = R.string.shared_string_my_favorites;
public static final int NOTES_TAB = R.string.notes;
public static final int OSM_TAB = R.string.osm_edits;
protected List<WeakReference<FragmentStateHolder>> fragList = new ArrayList<>();
protected List<WeakReference<FavoritesFragmentStateHolder>> fragList = new ArrayList<>();
private int tabSize;
private ImportHelper importHelper;
@ -158,8 +157,8 @@ public class FavoritesActivity extends TabActivity {
private AvailableGPXFragment getGpxFragment() {
AvailableGPXFragment gpxFragment = null;
for (WeakReference<FragmentStateHolder> f : fragList) {
FragmentStateHolder frag = f.get();
for (WeakReference<FavoritesFragmentStateHolder> f : fragList) {
FavoritesFragmentStateHolder frag = f.get();
if (frag instanceof AvailableGPXFragment) {
gpxFragment = (AvailableGPXFragment) frag;
}
@ -194,25 +193,32 @@ public class FavoritesActivity extends TabActivity {
@Override
public void onAttachFragment(Fragment fragment) {
if (fragment instanceof FragmentStateHolder) {
if (fragment instanceof FavoritesFragmentStateHolder) {
if (intentParams != null && intentParams.getInt(TAB_ID, -1) != -1) {
Bundle b = new Bundle();
int tabId = intentParams.getInt(TAB_ID, FAV_TAB);
if (tabId == FAV_TAB && fragment instanceof FavoritesTreeFragment) {
b.putString(GROUP_NAME_TO_SHOW, intentParams.getString(GROUP_NAME_TO_SHOW));
b.putInt(GROUP_POSITION, intentParams.getInt(GROUP_POSITION, 0));
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
b.putString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW,
intentParams.getString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW));
b.putInt(FavoritesFragmentStateHolder.GROUP_POSITION, intentParams.getInt(
FavoritesFragmentStateHolder.GROUP_POSITION, 0));
b.putInt(FavoritesFragmentStateHolder.ITEM_POSITION,
intentParams.getInt(FavoritesFragmentStateHolder.ITEM_POSITION, 0));
} else if (tabId == GPX_TAB && fragment instanceof AvailableGPXFragment) {
b.putInt(GROUP_POSITION, intentParams.getInt(GROUP_POSITION, 0));
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
b.putInt(FavoritesFragmentStateHolder.GROUP_POSITION,
intentParams.getInt(FavoritesFragmentStateHolder.GROUP_POSITION, 0));
b.putInt(FavoritesFragmentStateHolder.ITEM_POSITION,
intentParams.getInt(FavoritesFragmentStateHolder.ITEM_POSITION, 0));
} else if (tabId == NOTES_TAB && fragment instanceof NotesFragment) {
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
b.putInt(FavoritesFragmentStateHolder.ITEM_POSITION,
intentParams.getInt(FavoritesFragmentStateHolder.ITEM_POSITION, 0));
} else if (tabId == OSM_TAB && fragment instanceof OsmEditsFragment) {
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
b.putInt(FavoritesFragmentStateHolder.ITEM_POSITION,
intentParams.getInt(FavoritesFragmentStateHolder.ITEM_POSITION, 0));
}
fragment.setArguments(b);
}
fragList.add(new WeakReference<>((FragmentStateHolder) fragment));
fragList.add(new WeakReference<>((FavoritesFragmentStateHolder) fragment));
}
}
@ -271,7 +277,13 @@ public class FavoritesActivity extends TabActivity {
}
}
public interface FragmentStateHolder {
public interface FavoritesFragmentStateHolder {
String ITEM_POSITION = "item_position";
String GROUP_POSITION = "group_position";
String GROUP_NAME_TO_SHOW = "group_name_to_show";
Bundle storeState(Bundle bundle);

View file

@ -1,7 +1,6 @@
package net.osmand.plus.osmedit;
import static net.osmand.plus.myplaces.FavoritesActivity.OSM_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.ITEM_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import android.app.Dialog;
@ -52,7 +51,7 @@ import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesActivity.FragmentStateHolder;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import net.osmand.plus.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener;
import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener;
import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener;
@ -74,7 +73,7 @@ import java.util.List;
import java.util.Map;
public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener,
FragmentStateHolder {
FavoritesFragmentStateHolder {
public static final int EXPORT_TYPE_ALL = 0;
public static final int EXPORT_TYPE_POI = 1;