refactoring 2
This commit is contained in:
parent
e34ed50487
commit
d83f80d65e
3 changed files with 48 additions and 48 deletions
|
@ -146,9 +146,7 @@ public class NotesFragment extends OsmAndListFragment implements FragmentStateHo
|
|||
listAdapter.setListener(createAdapterListener());
|
||||
listAdapter.setPortrait(portrait);
|
||||
listView.setAdapter(listAdapter);
|
||||
if (getActivity() != null && getActivity() instanceof FavoritesActivity) {
|
||||
restoreState(((FavoritesActivity) getActivity()).getItemPosition());
|
||||
}
|
||||
restoreState(getArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -577,8 +575,10 @@ public class NotesFragment extends OsmAndListFragment implements FragmentStateHo
|
|||
getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15,
|
||||
new PointDescription(recording.getSearchHistoryType(), recording.getName(getActivity(), true)),
|
||||
true, recording);
|
||||
Bundle b = itemPosition >= 0 ? storeState(NOTE_TAB, itemPosition) : null;
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity(), b);
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(SCROLL_POSITION, itemPosition);
|
||||
b.putInt(TAB_TO_OPEN, NOTE_TAB);
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
|
||||
}
|
||||
|
||||
private void editNote(final Recording recording) {
|
||||
|
@ -619,22 +619,22 @@ public class NotesFragment extends OsmAndListFragment implements FragmentStateHo
|
|||
}
|
||||
|
||||
@Override
|
||||
public Bundle storeState(int tabId, int itemPosition) {
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(SCROLL_POSITION, itemPosition);
|
||||
b.putInt(TAB_TO_OPEN, tabId);
|
||||
return b;
|
||||
public Bundle storeState(Bundle bundle) {
|
||||
return bundle;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void restoreState(int position) {
|
||||
int itemsCount = getListView().getAdapter().getCount();
|
||||
if (itemsCount > 0 && itemsCount > position) {
|
||||
if (position == 1) {
|
||||
getListView().setSelection(0);
|
||||
} else {
|
||||
getListView().setSelection(position);
|
||||
}
|
||||
public void restoreState(Bundle bundle) {
|
||||
if (bundle != null && bundle.containsKey(SCROLL_POSITION)) {
|
||||
int position= bundle.getInt(SCROLL_POSITION, 0);
|
||||
int itemsCount = getListView().getAdapter().getCount();
|
||||
if (itemsCount > 0 && itemsCount > position) {
|
||||
if (position == 1) {
|
||||
getListView().setSelection(0);
|
||||
} else {
|
||||
getListView().setSelection(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ public class FavoritesActivity extends TabActivity {
|
|||
int tab = intent.getIntExtra(TAB_TO_OPEN, FAV_TAB);
|
||||
if (mTabs.get(n).mTitle.equals(getString(tab))) {
|
||||
mViewPager.setCurrentItem(n, false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -209,6 +210,11 @@ public class FavoritesActivity extends TabActivity {
|
|||
|
||||
@Override
|
||||
public void onAttachFragment(Fragment fragment) {
|
||||
if (fragment instanceof FragmentStateHolder && getIntent() != null) {
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(SCROLL_POSITION, getIntent().getIntExtra(SCROLL_POSITION, 0));
|
||||
fragment.setArguments(b);
|
||||
}
|
||||
fragList.add(new WeakReference<>(fragment));
|
||||
}
|
||||
|
||||
|
@ -268,16 +274,10 @@ public class FavoritesActivity extends TabActivity {
|
|||
}
|
||||
|
||||
public interface FragmentStateHolder {
|
||||
|
||||
Bundle storeState(int tabId, int itemPosition);
|
||||
|
||||
void restoreState(int position);
|
||||
}
|
||||
|
||||
public int getItemPosition() {
|
||||
int p = itemPosition;
|
||||
itemPosition = 0;
|
||||
return p;
|
||||
|
||||
Bundle storeState(Bundle bundle);
|
||||
|
||||
void restoreState(Bundle bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.NOTE_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.OSM_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.SCROLL_POSITION;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_TO_OPEN;
|
||||
|
@ -409,9 +410,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
fetchData();
|
||||
if (getActivity() != null && getActivity() instanceof FavoritesActivity) {
|
||||
restoreState(((FavoritesActivity) getActivity()).getItemPosition());
|
||||
}
|
||||
restoreState(getArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -656,7 +655,10 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText());
|
||||
getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15,
|
||||
new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(OSM_TAB, itemPosition));
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(SCROLL_POSITION, itemPosition);
|
||||
b.putInt(TAB_TO_OPEN, OSM_TAB);
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
|
||||
}
|
||||
|
||||
private void deletePoint(OsmPoint osmPoint) {
|
||||
|
@ -902,23 +904,21 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle storeState(int tabId, int itemPosition) {
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(SCROLL_POSITION, itemPosition);
|
||||
b.putInt(TAB_TO_OPEN, tabId);
|
||||
return b;
|
||||
public Bundle storeState(Bundle bundle) {
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreState(int position) {
|
||||
int itemsCount = getListView().getAdapter().getCount();
|
||||
if (itemsCount > 0 && itemsCount > position) {
|
||||
if (position == 1) {
|
||||
getListView().setSelection(0);
|
||||
} else {
|
||||
getListView().setSelection(position);
|
||||
|
||||
public void restoreState(Bundle bundle) {
|
||||
if (bundle != null && bundle.containsKey(SCROLL_POSITION)) {
|
||||
int position= bundle.getInt(SCROLL_POSITION, 0);
|
||||
int itemsCount = getListView().getAdapter().getCount();
|
||||
if (itemsCount > 0 && itemsCount > position) {
|
||||
if (position == 1) {
|
||||
getListView().setSelection(0);
|
||||
} else {
|
||||
getListView().setSelection(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue