-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antoine Robiez
committed
Mar 15, 2024
1 parent
d454bf5
commit ac3a572
Showing
11 changed files
with
82 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
shared/di/src/iosMain/kotlin/fr/androidmakers/di/DomainModule.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package fr.androidmakers.di | ||
|
||
import fr.androidmakers.domain.interactor.OpenMapUseCase | ||
import fr.androidmakers.domain.utils.UrlOpener | ||
import org.koin.dsl.module | ||
|
||
actual val domainPlatformModule = module { | ||
single { | ||
UrlOpener() | ||
} | ||
|
||
factory { OpenMapUseCase() } | ||
} |
27 changes: 27 additions & 0 deletions
27
...omain/src/androidMain/kotlin/fr/androidmakers/domain/interactor/OpenMapUseCase.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.androidmakers.domain.interactor | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import fr.androidmakers.domain.utils.UrlOpener | ||
|
||
actual class OpenMapUseCase( | ||
private val context: Context, | ||
private val urlOpener: UrlOpener | ||
) { | ||
actual operator fun invoke(coordinates: String, name: String) { | ||
val venueCoordinatesUri = Uri.parse( | ||
"geo:" + coordinates + | ||
"?q=" + Uri.encode(name) | ||
) | ||
try { | ||
val intent = Intent(Intent.ACTION_VIEW, venueCoordinatesUri) | ||
context.startActivity(intent) | ||
} catch (e: Exception) { | ||
// Open in Webview | ||
urlOpener.openUrl( | ||
url = "https://www.google.com/maps/?q=" + coordinates.replace(" ", "") | ||
) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/OpenMapUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fr.androidmakers.domain.interactor | ||
|
||
expect class OpenMapUseCase { | ||
operator fun invoke(coordinates: String, name: String) | ||
} |
34 changes: 34 additions & 0 deletions
34
shared/domain/src/iosMain/kotlin/fr/androidmakers/domain/interactor/OpenMapUseCase.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.androidmakers.domain.interactor | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.NativePtr | ||
import kotlinx.cinterop.cValuesOf | ||
import kotlinx.cinterop.objcPtr | ||
import platform.CoreLocation.CLGeocoder | ||
import platform.CoreLocation.CLLocationCoordinate2D | ||
import platform.CoreLocation.CLLocationCoordinate2DMake | ||
import platform.CoreLocation.CLLocationDegrees | ||
import platform.Foundation.NSLocale | ||
import platform.Foundation.NSNumberFormatter | ||
import platform.Foundation.NSNumberFormatterDecimalStyle | ||
import platform.Foundation.NSNumberFormatterStyle | ||
import platform.MapKit.MKMapItem | ||
import platform.MapKit.MKPlacemark | ||
|
||
actual class OpenMapUseCase { | ||
@OptIn(ExperimentalForeignApi::class) | ||
actual operator fun invoke(coordinates: String, name: String) { | ||
val coordinateArray = coordinates.split(",") | ||
if (coordinateArray.size == 2) { | ||
val latitude = coordinateArray[0].toDoubleOrNull() | ||
val longitude = coordinateArray[1].toDoubleOrNull() | ||
if (latitude != null && longitude != null) { | ||
val coordinate = CLLocationCoordinate2DMake(latitude, longitude) | ||
val placemark = MKPlacemark(coordinate, addressDictionary = null) | ||
val mapItem = MKMapItem(placemark) | ||
mapItem.name = name | ||
mapItem.openInMapsWithLaunchOptions(emptyMap<Any?, Any>()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters