android: fix bugs

This commit is contained in:
Emin 2025-02-14 21:26:40 +05:00
parent f592cb23dd
commit f25019b8f8
5 changed files with 50 additions and 7 deletions

View file

@ -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 =

View file

@ -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()
},
)
},
)
}
}
}
}

View file

@ -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()
}

View file

@ -2242,4 +2242,6 @@
<string name="all_images_were_downloaded">Все изображения былы загружены успешно</string>
<string name="most_images_were_downloaded">Большинство изображений было загружено</string>
<string name="not_all_images_were_downloaded">Ошибка, не все изображения былы загружены</string>
<string name="enable_location">Включить локацию</string>
<string name="enable_location_longer">Пожалуйста, включите локацию чтоб использовать данную функцию</string>
</resources>

View file

@ -2284,4 +2284,6 @@
<string name="all_images_were_downloaded">All images were downloaded successfully</string>
<string name="most_images_were_downloaded">Most images were downloaded</string>
<string name="not_all_images_were_downloaded">Error, not all images were downloaded</string>
<string name="enable_location">Enable Location</string>
<string name="enable_location_longer">Please enable location services to use this feature</string>
</resources>