From dce2313723c582d2d125bb160d45aeba99af616c Mon Sep 17 00:00:00 2001 From: Emin Date: Fri, 7 Jun 2024 20:15:38 +0500 Subject: [PATCH] show route on map from another screen --- android/app/build.gradle | 1 + .../java/app/organicmaps/MwmActivity.java | 24 +++++++++++++++++++ .../src/main/java/app/tourism/MainActivity.kt | 5 ++++ .../java/app/tourism/data/dto/SiteLocation.kt | 13 ++++++++++ 4 files changed, 43 insertions(+) create mode 100644 android/app/src/main/java/app/tourism/data/dto/SiteLocation.kt diff --git a/android/app/build.gradle b/android/app/build.gradle index 765b91da10..417937c94b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -54,6 +54,7 @@ if (googleFirebaseServicesEnabled) { apply plugin: 'com.github.triplet.play' apply plugin: 'ru.cian.huawei-publish-gradle-plugin' apply plugin: 'org.jetbrains.kotlin.android' +apply plugin: 'kotlin-parcelize' def run(cmd) { def stdout = new ByteArrayOutputStream() diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index 150f863b90..8477c53aa7 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -12,6 +12,8 @@ import android.location.Location; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.text.method.LinkMovementMethod; import android.view.KeyEvent; @@ -46,6 +48,7 @@ import app.organicmaps.base.BaseMwmFragmentActivity; import app.organicmaps.base.OnBackPressListener; import app.organicmaps.bookmarks.BookmarkCategoriesActivity; import app.organicmaps.bookmarks.data.BookmarkManager; +import app.organicmaps.bookmarks.data.FeatureId; import app.organicmaps.bookmarks.data.MapObject; import app.organicmaps.display.DisplayChangedListener; import app.organicmaps.display.DisplayManager; @@ -107,6 +110,8 @@ import app.organicmaps.widget.menu.MainMenu; import app.organicmaps.widget.placepage.PlacePageController; import app.organicmaps.widget.placepage.PlacePageData; import app.organicmaps.widget.placepage.PlacePageViewModel; +import app.tourism.data.dto.SiteLocation; + import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.ArrayList; @@ -544,6 +549,25 @@ public class MwmActivity extends BaseMwmFragmentActivity */ if (Map.isEngineCreated()) onRenderingInitializationFinished(); + + routeForSiteFromMainActivityHandling(); + } + + private void routeForSiteFromMainActivityHandling() { + + Handler handler = new Handler(Looper.getMainLooper()); + Runnable delayedAction = new Runnable() { + @Override + public void run() { + showRouteForSiteFromMainActivity(); + } + }; + handler.postDelayed(delayedAction, 1000); + } + + private void showRouteForSiteFromMainActivity() { + SiteLocation endPoint = getIntent().getParcelableExtra("end_point"); + startLocationToPoint(endPoint.toMapObject()); } private void refreshLightStatusBar() diff --git a/android/app/src/main/java/app/tourism/MainActivity.kt b/android/app/src/main/java/app/tourism/MainActivity.kt index bf92fa197d..ee48163d52 100644 --- a/android/app/src/main/java/app/tourism/MainActivity.kt +++ b/android/app/src/main/java/app/tourism/MainActivity.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.core.content.ContextCompat.startActivity import app.organicmaps.DownloadResourcesLegacyActivity +import app.tourism.data.dto.SiteLocation import app.tourism.ui.theme.OrganicMapsTheme @@ -48,6 +49,10 @@ fun Greeting(name: String, modifier: Modifier = Modifier) { Button( onClick = { val intent = Intent(context, DownloadResourcesLegacyActivity::class.java) + intent.putExtra( + "end_point", + SiteLocation("Name", 38.573, 68.807) + ) startActivity(context, intent, null) }, ) { diff --git a/android/app/src/main/java/app/tourism/data/dto/SiteLocation.kt b/android/app/src/main/java/app/tourism/data/dto/SiteLocation.kt new file mode 100644 index 0000000000..c273862e7e --- /dev/null +++ b/android/app/src/main/java/app/tourism/data/dto/SiteLocation.kt @@ -0,0 +1,13 @@ +package app.tourism.data.dto + +import android.os.Parcelable +import app.organicmaps.bookmarks.data.FeatureId +import app.organicmaps.bookmarks.data.MapObject +import kotlinx.parcelize.Parcelize + +@Parcelize +data class SiteLocation(val name: String, val lat: Double, val lon: Double) : Parcelable { + fun toMapObject() = MapObject.createMapObject( + FeatureId.EMPTY, MapObject.POI, name, "", lat, lon + ); +} \ No newline at end of file