[android] Fix of crash with bookmark.

This commit is contained in:
Dmitry Yunitsky 2015-07-21 14:01:41 +03:00 committed by Alex Zolotarev
parent ab311a6796
commit e7538cf070
7 changed files with 29 additions and 38 deletions

View file

@ -59,8 +59,8 @@ import com.mapswithme.maps.dialog.RoutingErrorDialogFragment;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPredictor;
import com.mapswithme.maps.search.SearchActivity;
import com.mapswithme.maps.search.SearchToolbarController;
import com.mapswithme.maps.search.SearchFragment;
import com.mapswithme.maps.search.SearchToolbarController;
import com.mapswithme.maps.settings.SettingsActivity;
import com.mapswithme.maps.settings.StoragePathManager;
import com.mapswithme.maps.settings.StoragePathManager.SetStoragePathListener;
@ -74,10 +74,10 @@ import com.mapswithme.util.BottomSheetHelper;
import com.mapswithme.util.Constants;
import com.mapswithme.util.InputUtils;
import com.mapswithme.util.LocationUtils;
import com.mapswithme.util.sharing.ShareAction;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.Yota;
import com.mapswithme.util.sharing.ShareAction;
import com.mapswithme.util.sharing.SharingHelper;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
@ -1413,7 +1413,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
private void showRoutingDisclaimer()
{
StringBuilder builder = new StringBuilder();
for (int resId : new int[] {R.string.dialog_routing_disclaimer_priority, R.string.dialog_routing_disclaimer_precision,
for (int resId : new int[]{R.string.dialog_routing_disclaimer_priority, R.string.dialog_routing_disclaimer_precision,
R.string.dialog_routing_disclaimer_recommendations, R.string.dialog_routing_disclaimer_beware})
builder.append(getString(resId)).append("\n\n");
@ -1494,19 +1494,11 @@ public class MWMActivity extends BaseMwmFragmentActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
if (resultCode == RESULT_OK && requestCode == ChooseBookmarkCategoryActivity.REQUEST_CODE_BOOKMARK_SET)
{
if (requestCode == ChooseBookmarkCategoryActivity.REQUEST_CODE_EDIT_BOOKMARK)
{
final Point bmk = ((ParcelablePoint) data.getParcelableExtra(ChooseBookmarkCategoryActivity.BOOKMARK)).getPoint();
onBookmarkActivated(bmk.x, bmk.y);
}
else if (requestCode == ChooseBookmarkCategoryActivity.REQUEST_CODE_SET)
{
final Point pin = ((ParcelablePoint) data.getParcelableExtra(ChooseBookmarkCategoryActivity.BOOKMARK)).getPoint();
final Bookmark bookmark = BookmarkManager.INSTANCE.getBookmark(pin.x, pin.y);
mPlacePage.setMapObject(bookmark);
}
final Point bookmarkAndCategory = ((ParcelablePoint) data.getParcelableExtra(ChooseBookmarkCategoryActivity.BOOKMARK)).getPoint();
final Bookmark bookmark = BookmarkManager.INSTANCE.getBookmark(bookmarkAndCategory.x, bookmarkAndCategory.y);
mPlacePage.setMapObject(bookmark);
}
super.onActivityResult(requestCode, resultCode, data);
}

View file

@ -61,7 +61,7 @@ public class BookmarkCategoriesFragment extends BaseMwmListFragment
public void onListItemClick(ListView l, View v, int position, long id)
{
startActivity(new Intent(getActivity(), BookmarkListActivity.class)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, position));
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, position));
}
@Override

View file

@ -45,7 +45,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
{
super.onCreate(savedInstanceState);
mCategoryIndex = getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, -1);
mCategoryIndex = getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, -1);
mCategory = BookmarkManager.INSTANCE.getCategoryById(mCategoryIndex);
}

View file

@ -7,10 +7,9 @@ import com.mapswithme.maps.base.BaseMwmFragmentActivity;
public class ChooseBookmarkCategoryActivity extends BaseMwmFragmentActivity
{
public static final String BOOKMARK = "pin";
public static final String BOOKMARK_SET = "pin_set";
public static final int REQUEST_CODE_SET = 0x1;
public static final int REQUEST_CODE_EDIT_BOOKMARK = 0x2;
public static final String BOOKMARK = "Bookmark";
public static final String BOOKMARK_CATEGORY_INDEX = "BoookmarkCategoryIndex";
public static final int REQUEST_CODE_BOOKMARK_SET = 0x1;
@Override
protected String getFragmentClassName()

View file

@ -24,7 +24,7 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment implemen
{
super.onViewCreated(view, savedInstanceState);
mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, 0));
mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, 0));
setListAdapter(mAdapter);
mBookmark = getBookmarkFromIntent();
}
@ -70,7 +70,7 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment implemen
final int category = BookmarkManager.INSTANCE.createCategory(name);
mBookmark.setCategoryId(category);
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category)
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, category)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));
mAdapter.chooseItem(category);

View file

@ -118,9 +118,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
private void selectBookmarkSet()
{
final Intent intent = new Intent(getActivity(), ChooseBookmarkCategoryActivity.class)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, mBookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, mBookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));
getActivity().startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_SET);
getActivity().startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_BOOKMARK_SET);
}
private void selectBookmarkColor()

View file

@ -274,7 +274,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
public MapObject getMapObject()
{
saveBookmarkNameIfUpdated();
saveBookmarkNameIfUpdated(null);
return mMapObject;
}
@ -283,7 +283,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
if (hasMapObject(mapObject))
return;
saveBookmarkNameIfUpdated();
saveBookmarkNameIfUpdated(mapObject);
mMapObject = mapObject;
refreshViews();
}
@ -566,17 +566,14 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
checkApiWasCanceled();
}
// TODO remove that method completely. host activity should check that itself
private void checkApiWasCanceled()
{
if ((mMapObject.getType() == MapObjectType.API_POINT) && !ParsedMwmRequest.hasRequest())
{
setMapObject(null);
// FIXME
// mAnimationController.hidePlacePage();
}
}
// TODO refactor processing of bookmarks.
private void checkBookmarkWasDeleted()
{
// We need to check, if content of body is still valid
@ -610,9 +607,12 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
}
}
private void saveBookmarkNameIfUpdated()
private void saveBookmarkNameIfUpdated(MapObject newObject)
{
if (mMapObject == null || !(mMapObject instanceof Bookmark))
// 1. Can't save bookmark name if current object is not bookmark.
// 2. If new object is bookmark, we should NOT try to save old one, cause it might be just old bookmark moved to the new set.
// In that case old bookmark is already saved.
if (mMapObject == null || !(mMapObject instanceof Bookmark) || newObject instanceof Bookmark)
return;
final Bookmark bookmark = (Bookmark) mMapObject;
@ -626,7 +626,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
switch (v.getId())
{
case R.id.iv__bookmark_color:
saveBookmarkNameIfUpdated();
saveBookmarkNameIfUpdated(null);
selectBookmarkColor();
break;
case R.id.rl__bookmark:
@ -675,7 +675,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
getContext().startActivity(intent);
break;
case R.id.tv__bookmark_group:
saveBookmarkNameIfUpdated();
saveBookmarkNameIfUpdated(null);
selectBookmarkSet();
break;
case R.id.av__direction:
@ -760,9 +760,9 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
final Activity activity = (Activity) getContext();
final Bookmark bookmark = (Bookmark) mMapObject;
final Intent intent = new Intent(activity, ChooseBookmarkCategoryActivity.class)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, bookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_CATEGORY_INDEX, bookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(bookmark.getCategoryId(), bookmark.getBookmarkId()));
activity.startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_SET);
activity.startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_BOOKMARK_SET);
}
private void selectBookmarkColor()