diff --git a/android/app/src/main/cpp/app/organicmaps/Framework.cpp b/android/app/src/main/cpp/app/organicmaps/Framework.cpp index 0daa35680b..3180a2e208 100644 --- a/android/app/src/main/cpp/app/organicmaps/Framework.cpp +++ b/android/app/src/main/cpp/app/organicmaps/Framework.cpp @@ -583,11 +583,21 @@ void Framework::ReplaceBookmark(kml::MarkId markId, kml::BookmarkData & bm) m_work.GetBookmarkManager().GetEditSession().UpdateBookmark(markId, bm); } +void Framework::ReplaceTrack(kml::TrackId trackId, kml::TrackData & trackData) +{ + m_work.GetBookmarkManager().GetEditSession().UpdateTrack(trackId, trackData); +} + void Framework::MoveBookmark(kml::MarkId markId, kml::MarkGroupId curCat, kml::MarkGroupId newCat) { m_work.GetBookmarkManager().GetEditSession().MoveBookmark(markId, curCat, newCat); } +void Framework::MoveTrack(kml::TrackId trackId, kml::MarkGroupId curCat, kml::MarkGroupId newCat) +{ + m_work.GetBookmarkManager().GetEditSession().MoveTrack(trackId, curCat, newCat); +} + void Framework::ExecuteMapApiRequest() { return m_work.ExecuteMapApiRequest(); diff --git a/android/app/src/main/cpp/app/organicmaps/Framework.hpp b/android/app/src/main/cpp/app/organicmaps/Framework.hpp index c8253d270f..4da7be85e3 100644 --- a/android/app/src/main/cpp/app/organicmaps/Framework.hpp +++ b/android/app/src/main/cpp/app/organicmaps/Framework.hpp @@ -159,7 +159,9 @@ namespace android void Scale(m2::PointD const & centerPt, int targetZoom, bool animate); void ReplaceBookmark(kml::MarkId markId, kml::BookmarkData & bm); + void ReplaceTrack(kml::TrackId trackId, kml::TrackData & trackData); void MoveBookmark(kml::MarkId markId, kml::MarkGroupId curCat, kml::MarkGroupId newCat); + void MoveTrack(kml::TrackId trackId, kml::MarkGroupId curCat, kml::MarkGroupId newCat); ::Framework * NativeFramework(); diff --git a/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp b/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp index b6434cd6c9..908cc08c64 100644 --- a/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp +++ b/android/app/src/main/cpp/app/organicmaps/bookmarks/data/BookmarkManager.cpp @@ -790,6 +790,32 @@ Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeSetBookmarkParams( g_framework->ReplaceBookmark(static_cast(bmk), bmData); } +JNIEXPORT void JNICALL +Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeSetTrackParams( + JNIEnv * env, jclass, jlong trackId, + jstring name, jint color, jstring descr) +{ + auto const * nTrack = frm()->GetBookmarkManager().GetTrack(static_cast(trackId)); + ASSERT(nTrack, ("Track must not be null with id:", trackId)); + + kml::TrackData trackData(nTrack->GetData()); + auto const trkName = jni::ToNativeString(env, name); + if (nTrack->GetName() != trkName) + kml::SetDefaultStr(trackData.m_name, trkName); + if (descr) + kml::SetDefaultStr(trackData.m_description, jni::ToNativeString(env, descr)); + trackData.m_layers[0].m_color.m_rgba = static_cast((color << 8) + 255); + + g_framework->ReplaceTrack(static_cast(trackId), trackData); +} + +JNIEXPORT jstring JNICALL +Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeGetTrackDescription( + JNIEnv * env, jclass, jlong trackId) +{ + return jni::ToJavaString(env, frm()->GetBookmarkManager().GetTrack(static_cast(trackId))->GetDescription()); +} + JNIEXPORT void JNICALL Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeChangeBookmarkCategory( JNIEnv *, jclass, jlong oldCat, jlong newCat, jlong bmk) @@ -798,6 +824,14 @@ Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeChangeBookmarkCategory static_cast(newCat)); } +JNIEXPORT void JNICALL +Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeChangeTrackCategory( + JNIEnv *, jclass, jlong oldCat, jlong newCat, jlong trackId) +{ + g_framework->MoveTrack(static_cast(trackId), static_cast(oldCat), + static_cast(newCat)); +} + JNIEXPORT jobject JNICALL Java_app_organicmaps_bookmarks_data_BookmarkManager_nativeGetBookmarkXY( JNIEnv * env, jclass, jlong bmk) diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java index bce9cd17b9..6abffb38fb 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java @@ -677,6 +677,20 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment + { + if (movedFromCategory) + resetSearchAndSort(); + else + getBookmarkListAdapter().notifyDataSetChanged(); + }); + } + private void onDeleteActionSelected() { BookmarkListAdapter adapter = getBookmarkListAdapter(); @@ -742,6 +756,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment getTrackMenuItems(final Track track) { ArrayList items = new ArrayList<>(); + items.add(new MenuBottomSheetItem(R.string.edit, R.drawable.ic_edit, this::onTrackEditActionSelected)); items.add(new MenuBottomSheetItem(R.string.delete, R.drawable.ic_delete, () -> onDeleteTrackSelected(track.getTrackId()))); return items; } diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java index 46869cde27..dc82737f49 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/data/BookmarkManager.java @@ -608,6 +608,11 @@ public enum BookmarkManager return nativeGetBookmarkDescription(bookmarkId); } + public String getTrackDescription(@IntRange(from = 0) long trackId) + { + return nativeGetTrackDescription(trackId); + } + public double getBookmarkScale(@IntRange(from = 0) long bookmarkId) { return nativeGetBookmarkScale(bookmarkId); @@ -625,6 +630,12 @@ public enum BookmarkManager nativeSetBookmarkParams(bookmarkId, name, color, descr); } + public void setTrackParams(@IntRange(from = 0) long trackId, @NonNull String name, + @Icon.PredefinedColor int color, @NonNull String descr) + { + nativeSetTrackParams(trackId, name, color, descr); + } + public void changeBookmarkCategory(@IntRange(from = 0) long oldCatId, @IntRange(from = 0) long newCatId, @IntRange(from = 0) long bookmarkId) @@ -632,6 +643,13 @@ public enum BookmarkManager nativeChangeBookmarkCategory(oldCatId, newCatId, bookmarkId); } + public void changeTrackCategory(@IntRange(from = 0) long oldCatId, + @IntRange(from = 0) long newCatId, + @IntRange(from = 0) long trackId) + { + nativeChangeTrackCategory(oldCatId, newCatId, trackId); + } + @NonNull public String getBookmarkAddress(@IntRange(from = 0) long bookmarkId) { @@ -647,6 +665,15 @@ public enum BookmarkManager changeBookmarkCategory(bookmarkInfo.getCategoryId(), catId, bookmarkInfo.getBookmarkId()); } + public void notifyCategoryChanging(@NonNull Track track, + @IntRange(from = 0) long catId) + { + if (catId == track.getCategoryId()) + return; + + changeTrackCategory(track.getCategoryId(), catId, track.getTrackId()); + } + public void notifyCategoryChanging(@NonNull Bookmark bookmark, @IntRange(from = 0) long catId) { if (catId == bookmark.getCategoryId()) @@ -682,6 +709,16 @@ public enum BookmarkManager } } + public void notifyParametersUpdating(@NonNull Track track, @NonNull String name, + @Nullable int color, @NonNull String description) + { + if (!name.equals(track.getName()) || !(color == track.getColor()) || + !description.equals(getTrackDescription(track.getTrackId()))) + { + setTrackParams(track.getTrackId(), name, color, description); + } + } + public double getElevationCurPositionDistance(long trackId) { return nativeGetElevationCurPositionDistance(trackId); @@ -818,6 +855,7 @@ public enum BookmarkManager @NonNull private static native String nativeGetBookmarkDescription(@IntRange(from = 0) long bookmarkId); + private static native String nativeGetTrackDescription(@IntRange(from = 0) long trackId); private static native double nativeGetBookmarkScale(@IntRange(from = 0) long bookmarkId); @NonNull @@ -829,10 +867,19 @@ public enum BookmarkManager @Icon.PredefinedColor int color, @NonNull String descr); + private static native void nativeSetTrackParams(@IntRange(from = 0) long trackId, + @NonNull String name, + @Icon.PredefinedColor int color, + @NonNull String descr); + private static native void nativeChangeBookmarkCategory(@IntRange(from = 0) long oldCatId, @IntRange(from = 0) long newCatId, @IntRange(from = 0) long bookmarkId); + private static native void nativeChangeTrackCategory(@IntRange(from = 0) long oldCatId, + @IntRange(from = 0) long newCatId, + @IntRange(from = 0) long trackId); + @NonNull private static native String nativeGetBookmarkAddress(@IntRange(from = 0) long bookmarkId); diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/data/Track.java b/android/app/src/main/java/app/organicmaps/bookmarks/data/Track.java index 07352597d9..8646c700f2 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/data/Track.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/data/Track.java @@ -33,4 +33,9 @@ public class Track public long getTrackId() { return mTrackId; } public long getCategoryId() { return mCategoryId; } + + public String getTrackDescription() + { + return BookmarkManager.INSTANCE.getTrackDescription(mTrackId); + } } diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java b/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java index 82a5be0351..76243603c4 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/EditBookmarkFragment.java @@ -28,6 +28,7 @@ import app.organicmaps.bookmarks.data.BookmarkCategory; import app.organicmaps.bookmarks.data.BookmarkInfo; import app.organicmaps.bookmarks.data.BookmarkManager; import app.organicmaps.bookmarks.data.Icon; +import app.organicmaps.bookmarks.data.Track; import app.organicmaps.util.Graphics; import app.organicmaps.util.InputUtils; import app.organicmaps.util.UiUtils; @@ -41,6 +42,8 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. { public static final String EXTRA_CATEGORY_ID = "CategoryId"; public static final String EXTRA_BOOKMARK_ID = "BookmarkId"; + public static final String EXTRA_BOOKMARK_TYPE = "BookmarkType"; + public static final String EXTRA_TRACK_ID = "TrackId"; private TextInputEditText mEtDescription; private TextInputEditText mEtName; @@ -55,6 +58,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. private BookmarkInfo mBookmark; @Nullable private EditBookmarkListener mListener; + private Track mTrack; + private int mType; + private int mColor = -1; public interface EditBookmarkListener { @@ -66,6 +72,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. @Nullable EditBookmarkListener listener) { final Bundle args = new Bundle(); + args.putInt(EXTRA_BOOKMARK_TYPE, 1); args.putLong(EXTRA_CATEGORY_ID, categoryId); args.putLong(EXTRA_BOOKMARK_ID, bookmarkId); String name = EditBookmarkFragment.class.getName(); @@ -76,6 +83,20 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. fragment.show(manager, name); } + public static void editTrack(long categoryId, long trackId, Context context, FragmentManager manager, @Nullable EditBookmarkListener listener) + { + final Bundle args = new Bundle(); + args.putInt(EXTRA_BOOKMARK_TYPE, 2); + args.putLong(EXTRA_CATEGORY_ID, categoryId); + args.putLong(EXTRA_TRACK_ID, trackId); + String name = EditBookmarkFragment.class.getName(); + final FragmentFactory factory = manager.getFragmentFactory(); + final EditBookmarkFragment fragment = (EditBookmarkFragment) factory.instantiate(context.getClassLoader(), name); + fragment.setArguments(args); + fragment.setEditBookmarkListener(listener); + fragment.show(manager, name); + } + public EditBookmarkFragment() {} @Override @@ -95,12 +116,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { final Bundle args = getArguments(); - long categoryId = args.getLong(EXTRA_CATEGORY_ID); - mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId); - long bookmarkId = args.getLong(EXTRA_BOOKMARK_ID); - mBookmark = BookmarkManager.INSTANCE.getBookmarkInfo(bookmarkId); - if (mBookmark != null) - mIcon = mBookmark.getIcon(); + mType = args.getInt(EXTRA_BOOKMARK_TYPE); mEtName = view.findViewById(R.id.et__bookmark_name); clearNameBtn = view.findViewById(R.id.edit_bookmark_name_input); clearNameBtn.setEndIconOnClickListener(v -> clearAndFocus(mEtName)); @@ -123,8 +139,35 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. mTvBookmarkGroup.setOnClickListener(this); mIvColor = view.findViewById(R.id.iv__bookmark_color); mIvColor.setOnClickListener(this); - refreshBookmark(); - initToolbar(view); + + switch (mType) + { + case 1: + { + long categoryId = args.getLong(EXTRA_CATEGORY_ID); + mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId); + long bookmarkId = args.getLong(EXTRA_BOOKMARK_ID); + mBookmark = BookmarkManager.INSTANCE.getBookmarkInfo(bookmarkId); + if (mBookmark != null) + mIcon = mBookmark.getIcon(); + refreshBookmark(); + initToolbar(view); + break; + } + case 2: + { + long categoryId = args.getLong(EXTRA_CATEGORY_ID); + mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId); + long trackId = args.getLong(EXTRA_TRACK_ID); + mTrack = BookmarkManager.INSTANCE.getTrack(trackId); + mColor = mTrack.getColor(); + refreshTrack(); + initToolbar(view); + break; + } + } + + } @Override @@ -150,7 +193,13 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. ViewCompat.setOnApplyWindowInsetsListener(toolbar, PaddingInsetsListener.excludeBottom()); final ImageView imageView = toolbar.findViewById(R.id.save); - imageView.setOnClickListener(v -> saveBookmark()); + switch (mType) + { + case 1: + imageView.setOnClickListener(v -> saveBookmark()); + case 2: + imageView.setOnClickListener(v -> saveTrack()); + } UiUtils.showHomeUpButton(toolbar); toolbar.setTitle(R.string.placepage_edit_bookmark_button); toolbar.setNavigationOnClickListener(v -> dismiss()); @@ -174,6 +223,25 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. dismiss(); } + private void saveTrack() + { + if (mTrack == null) + { + dismiss(); + return; + } + boolean movedFromCategory = mTrack.getCategoryId() != mBookmarkCategory.getId(); + if (movedFromCategory) + BookmarkManager.INSTANCE.notifyCategoryChanging(mTrack, mBookmarkCategory.getId()); + BookmarkManager.INSTANCE.notifyParametersUpdating(mTrack, mEtName.getText() + .toString(), mColor, mEtDescription.getText() + .toString()); + + if (mListener != null) + mListener.onBookmarkSaved(mTrack.getTrackId(), movedFromCategory); + dismiss(); + } + @Override public void onClick(View v) { @@ -186,7 +254,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. private void selectBookmarkSet() { - if (mBookmark == null) + if (mBookmark == null && mTrack == null) return; final Bundle args = new Bundle(); @@ -205,28 +273,48 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. private void selectBookmarkColor() { - if (mIcon == null) + if (mIcon == null && mTrack == null) return; final Bundle args = new Bundle(); - args.putInt(BookmarkColorDialogFragment.ICON_TYPE, mIcon.getColor()); - + if (mTrack != null) + args.putInt(BookmarkColorDialogFragment.ICON_TYPE, mTrack.getColor()); + else + args.putInt(BookmarkColorDialogFragment.ICON_TYPE, mIcon.getColor()); final FragmentManager manager = getChildFragmentManager(); String className = BookmarkColorDialogFragment.class.getName(); final FragmentFactory factory = manager.getFragmentFactory(); final BookmarkColorDialogFragment dialogFragment = (BookmarkColorDialogFragment) factory.instantiate(getContext().getClassLoader(), className); dialogFragment.setArguments(args); - dialogFragment.setOnColorSetListener(colorPos -> { - final Icon newIcon = BookmarkManager.ICONS.get(colorPos); - final String from = mIcon.getName(); - final String to = newIcon.getName(); - if (TextUtils.equals(from, to)) - return; + switch (mType) + { + case 1: + { + dialogFragment.setOnColorSetListener(colorPos -> { + final Icon newIcon = BookmarkManager.ICONS.get(colorPos); + final String from = mTrack.getName(); + final String to = newIcon.getName(); + if (TextUtils.equals(from, to)) + return; - mIcon = newIcon; - refreshColorMarker(); - }); + mIcon = newIcon; + refreshColorMarker(); + }); + } + case 2: + { + dialogFragment.setOnColorSetListener(colorPos -> { + int from = mTrack.getColor(); + int to = BookmarkManager.ICONS.get(colorPos).argb(); + if (from == to) + return; + mColor = to; + refreshTrackColor(); + }); + break; + } + } dialogFragment.show(requireActivity().getSupportFragmentManager(), null); } @@ -244,6 +332,16 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. } } + public void refreshTrackColor() + { + if (mColor == -1) + return; + Drawable circle = Graphics.drawCircle(mColor, + R.dimen.track_circle_size, + requireContext().getResources()); + mIvColor.setImageDrawable(circle); + } + private void refreshCategory() { mTvBookmarkGroup.setText(mBookmarkCategory.getName()); @@ -266,6 +364,22 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View. refreshColorMarker(); } + private void refreshTrack() + { + if (mTrack == null) + return; + + if (TextUtils.isEmpty(mEtName.getText())) + mEtName.setText(mTrack.getName()); + + if (TextUtils.isEmpty(mEtDescription.getText())) + { + mEtDescription.setText(BookmarkManager.INSTANCE.getTrackDescription(mTrack.getTrackId())); + } + refreshCategory(); + refreshTrackColor(); + } + @Override public void onCategoryChanged(BookmarkCategory newCategory) { diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index d818adf77e..15f0ce0e54 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -2316,6 +2316,19 @@ void BookmarkManager::UpdateBookmark(kml::MarkId bmID, kml::BookmarkData const & SetLastEditedBmColor(bookmark->GetColor()); } +void BookmarkManager::UpdateTrack(kml::TrackId trackId, kml::TrackData const & trackData) +{ + CHECK_THREAD_CHECKER(m_threadChecker, ()); + auto * track = GetTrackForEdit(trackId); + +// auto const prevColor = track->GetColor(0); + track->setData(trackData); + ASSERT(track->GetGroupId() != kml::kInvalidTrackId, ()); + +// if (prevColor != track->GetColor()) +// SetLastEditedBmColor(track->GetColor()); +} + kml::MarkGroupId BookmarkManager::LastEditedBMCategory() { CHECK_THREAD_CHECKER(m_threadChecker, ()); @@ -3636,6 +3649,11 @@ void BookmarkManager::EditSession::UpdateBookmark(kml::MarkId bmId, kml::Bookmar return m_bmManager.UpdateBookmark(bmId, bm); } +void BookmarkManager::EditSession::UpdateTrack(kml::TrackId trackId, kml::TrackData const & trackData) +{ + return m_bmManager.UpdateTrack(trackId,trackData); +} + void BookmarkManager::EditSession::AttachBookmark(kml::MarkId bmId, kml::MarkGroupId groupId) { m_bmManager.AttachBookmark(bmId, groupId); diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 7cfaa375e6..e3f219b726 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -145,6 +145,7 @@ public: void MoveBookmark(kml::MarkId bmID, kml::MarkGroupId curGroupID, kml::MarkGroupId newGroupID); void UpdateBookmark(kml::MarkId bmId, kml::BookmarkData const & bm); + void UpdateTrack(kml::TrackId trackId, kml::TrackData const & trackData); void AttachBookmark(kml::MarkId bmId, kml::MarkGroupId groupId); void DetachBookmark(kml::MarkId bmId, kml::MarkGroupId groupId); @@ -599,6 +600,7 @@ private: void MoveBookmark(kml::MarkId bmID, kml::MarkGroupId curGroupID, kml::MarkGroupId newGroupID); void UpdateBookmark(kml::MarkId bmId, kml::BookmarkData const & bm); + void UpdateTrack(kml::TrackId trackId, kml::TrackData const & trackData); UserMark const * GetMark(kml::MarkId markId) const; diff --git a/map/track.cpp b/map/track.cpp index 8d68e3bc6d..b44153c1d4 100644 --- a/map/track.cpp +++ b/map/track.cpp @@ -132,6 +132,17 @@ void Track::SetName(std::string const & name) kml::SetDefaultStr(m_data.m_name, name); } +std::string Track::GetDescription() const +{ + return GetPreferredBookmarkStr(m_data.m_description); +} + +void Track::setData(kml::TrackData const & data) +{ + m_isDirty = true; + m_data = data; +} + m2::RectD Track::GetLimitRect() const { if (m_interactionData) diff --git a/map/track.hpp b/map/track.hpp index 9a2e070a7a..32b9c43c9e 100644 --- a/map/track.hpp +++ b/map/track.hpp @@ -19,9 +19,11 @@ public: void ResetChanges() const override { m_isDirty = false; } kml::TrackData const & GetData() const { return m_data; } + void setData(kml::TrackData const & data); std::string GetName() const; void SetName(std::string const & name); + std::string GetDescription() const; m2::RectD GetLimitRect() const; double GetLengthMeters() const;