From f25019b8f857b9bcc8f57da106647701735ae863 Mon Sep 17 00:00:00 2001 From: Emin Date: Fri, 14 Feb 2025 21:26:40 +0500 Subject: [PATCH] android: fix bugs --- .../data/repositories/PlacesRepository.kt | 4 +-- .../place_details/description/Description.kt | 16 ++++++--- .../app/tourism/ui/utils/enableLocation.kt | 33 +++++++++++++++++++ .../app/src/main/res/values-ru/strings.xml | 2 ++ android/app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 android/app/src/main/java/app/tourism/ui/utils/enableLocation.kt diff --git a/android/app/src/main/java/app/tourism/data/repositories/PlacesRepository.kt b/android/app/src/main/java/app/tourism/data/repositories/PlacesRepository.kt index 7c87882dab..d6ad3584e6 100644 --- a/android/app/src/main/java/app/tourism/data/repositories/PlacesRepository.kt +++ b/android/app/src/main/java/app/tourism/data/repositories/PlacesRepository.kt @@ -232,7 +232,6 @@ class PlacesRepository( val filesDownloaded = filesTotalNum - notDownloadedImages.size val percentage = (filesDownloaded * 100) / filesTotalNum - Log.d("", "percentage: $percentage") return percentage < 90 } @@ -253,7 +252,7 @@ class PlacesRepository( suspend fun getPlacesByCategoryFromApiIfThereIsChange(id: Long) { val hash = hashesDao.getHash(id) - val favorites = placesDao.getFavoritePlaces("", language) + val favorites = placesDao.getFavoritePlaces("%%", language) val resource = handleResponse(call = { api.getPlacesByCategory(id, hash?.value ?: "") }, context) @@ -261,7 +260,6 @@ class PlacesRepository( resource.data?.let { categoryDto -> if (categoryDto.hash.isBlank()) return // update places - Log.d("dsf", "Before update places, categoryDto: $categoryDto") val placesEn = categoryDto.en.map { placeDto -> var placeFull = placeDto.toPlaceFull(false, "en") placeFull = diff --git a/android/app/src/main/java/app/tourism/ui/screens/main/place_details/description/Description.kt b/android/app/src/main/java/app/tourism/ui/screens/main/place_details/description/Description.kt index e1b454c914..c81a1dcad8 100644 --- a/android/app/src/main/java/app/tourism/ui/screens/main/place_details/description/Description.kt +++ b/android/app/src/main/java/app/tourism/ui/screens/main/place_details/description/Description.kt @@ -11,15 +11,16 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import app.organicmaps.R import app.tourism.Constants import app.tourism.ui.common.VerticalSpace -import app.tourism.ui.common.WebView import app.tourism.ui.common.buttons.PrimaryButton import app.tourism.ui.theme.TextStyles +import app.tourism.ui.utils.enableLocation import app.tourism.utils.getAnnotatedStringFromHtml @Composable @@ -27,6 +28,7 @@ fun DescriptionScreen( description: String?, onCreateRoute: (() -> Unit)?, ) { + val context = LocalContext.current Box( modifier = Modifier .fillMaxSize() @@ -50,9 +52,15 @@ fun DescriptionScreen( .align(Alignment.BottomCenter) .offset(y = (-32).dp), label = stringResource(id = R.string.show_route), - onClick = { onCreateRoute() }, + onClick = { + enableLocation( + context = context, + onSuccess = { + onCreateRoute() + }, + ) + }, ) } } - -} \ No newline at end of file +} diff --git a/android/app/src/main/java/app/tourism/ui/utils/enableLocation.kt b/android/app/src/main/java/app/tourism/ui/utils/enableLocation.kt new file mode 100644 index 0000000000..e1df0bdaef --- /dev/null +++ b/android/app/src/main/java/app/tourism/ui/utils/enableLocation.kt @@ -0,0 +1,33 @@ +package app.tourism.ui.utils + +import android.app.AlertDialog +import android.content.Context +import android.content.Context.LOCATION_SERVICE +import android.content.Intent +import android.location.LocationManager +import android.provider.Settings +import androidx.core.content.ContextCompat.startActivity +import app.organicmaps.R + +fun enableLocation(context: Context, onSuccess: () -> Unit) { + val locationManager = context.getSystemService(LOCATION_SERVICE) as LocationManager + if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + showEnableLocationDialog(context) + } else { + onSuccess() + } +} + +private fun showEnableLocationDialog(context: Context) { + AlertDialog.Builder(context) + .setTitle(context.getString(R.string.enable_location)) + .setMessage(context.getString(R.string.enable_location_longer)) + .setPositiveButton(context.getString(R.string.ok)) { _, _ -> + // Open location settings + val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) + startActivity(context, intent, null) + } + .setNegativeButton(context.getString(R.string.cancel), null) + .create() + .show() +} diff --git a/android/app/src/main/res/values-ru/strings.xml b/android/app/src/main/res/values-ru/strings.xml index ce45cf0919..6d11651df1 100644 --- a/android/app/src/main/res/values-ru/strings.xml +++ b/android/app/src/main/res/values-ru/strings.xml @@ -2242,4 +2242,6 @@ Все изображения былы загружены успешно Большинство изображений было загружено Ошибка, не все изображения былы загружены + Включить локацию + Пожалуйста, включите локацию чтоб использовать данную функцию diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 467cbb82a9..28172127e1 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -2284,4 +2284,6 @@ All images were downloaded successfully Most images were downloaded Error, not all images were downloaded + Enable Location + Please enable location services to use this feature