diff --git a/OsmAnd-telegram/src/net/osmand/aidl/maplayer/point/AMapPoint.java b/OsmAnd-telegram/src/net/osmand/aidl/maplayer/point/AMapPoint.java index 622e67d00b..cda77501c5 100644 --- a/OsmAnd-telegram/src/net/osmand/aidl/maplayer/point/AMapPoint.java +++ b/OsmAnd-telegram/src/net/osmand/aidl/maplayer/point/AMapPoint.java @@ -13,6 +13,7 @@ import java.util.Map; public class AMapPoint implements Parcelable { public static final int POINT_IMAGE_SIZE_PX = 160; public static final String POINT_IMAGE_URI_PARAM = "point_image_uri_param"; + public static final String POINT_STALE_LOC_PARAM = "point_stale_loc_param"; private String id; private String shortName; diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index e08b9f33d0..4500f2bf69 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -2,7 +2,6 @@ package net.osmand.telegram.helpers import android.content.Intent import android.graphics.Color -import android.net.Uri import android.os.AsyncTask import android.text.TextUtils import net.osmand.aidl.map.ALatLon @@ -53,7 +52,7 @@ class ShowLocationHelper(private val app: TelegramApplication) { Color.WHITE, ALatLon(item.latLon!!.latitude, item.latLon!!.longitude), null, - generatePhotoParams(if (stale) item.grayscalePhotoPath else item.photoPath, stale) + generatePointParams(if (stale) item.grayscalePhotoPath else item.photoPath, stale) ) } } @@ -102,7 +101,7 @@ class ShowLocationHelper(private val app: TelegramApplication) { userName = message.senderUserId.toString() } setupMapLayer() - val params = generatePhotoParams(photoPath, stale) + val params = generatePointParams(photoPath, stale) if (update) { osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, "${chatId}_${message.senderUserId}", userName, userName, chatTitle, Color.WHITE, ALatLon(content.location.latitude, content.location.longitude), null, params) @@ -115,10 +114,10 @@ class ShowLocationHelper(private val app: TelegramApplication) { setupMapLayer() if (update) { osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name, - chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePhotoParams(null, stale)) + chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePointParams(null, stale)) } else { osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name, - chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePhotoParams(null, stale)) + chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePointParams(null, stale)) } } } @@ -219,31 +218,28 @@ class ShowLocationHelper(private val app: TelegramApplication) { return null } } - - - private fun generatePhotoParams(photoPath: String?, stale: Boolean = false): Map? { - val photoUri = if (TextUtils.isEmpty(photoPath)) { - val resId = if (stale) { - R.drawable.img_user_picture - } else { - R.drawable.img_user_picture_active - } - AndroidUtils.resourceToUri(app, resId) - } else { - AndroidUtils.getUriForFile(app, File(photoPath)) - } - return generatePhotoParamsFromUri(photoUri) - } - - private fun generatePhotoParamsFromUri(photoUri: Uri): Map? { + + private fun generatePointParams(photoPath: String?, stale: Boolean): Map { + val photoUri = generatePhotoUri(photoPath, stale) app.grantUriPermission( app.settings.appToConnectPackage, photoUri, Intent.FLAG_GRANT_READ_URI_PERMISSION ) - return mapOf(AMapPoint.POINT_IMAGE_URI_PARAM to photoUri.toString()) + return mapOf( + AMapPoint.POINT_IMAGE_URI_PARAM to photoUri.toString(), + AMapPoint.POINT_STALE_LOC_PARAM to stale.toString() + ) } + private fun generatePhotoUri(photoPath: String?, stale: Boolean) = + if (TextUtils.isEmpty(photoPath)) { + val id = if (stale) R.drawable.img_user_picture else R.drawable.img_user_picture_active + AndroidUtils.resourceToUri(app, id) + } else { + AndroidUtils.getUriForFile(app, File(photoPath)) + } + private fun removeMapPoint(chatId: Long, message: TdApi.Message) { val content = message.content if (content is TdApi.MessageLocation) { diff --git a/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java b/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java index 1c11ea24a1..b61ec928c7 100644 --- a/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java +++ b/OsmAnd/src/net/osmand/aidl/maplayer/point/AMapPoint.java @@ -14,6 +14,7 @@ public class AMapPoint implements Parcelable { public static final String POINT_IMAGE_URI_PARAM = "point_image_uri_param"; public static final String POINT_SPEED_PARAM = "point_speed_param"; public static final String POINT_TYPE_ICON_NAME_PARAM = "point_type_icon_name_param"; + public static final String POINT_STALE_LOC_PARAM = "point_stale_loc_param"; private String id; private String shortName; diff --git a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java index 1e83ff3742..bed13acc57 100644 --- a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java @@ -57,6 +57,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private Bitmap circle; private Bitmap smallIconBg; private Bitmap bigIconBg; + private Bitmap bigIconBgStale; private Bitmap placeholder; private int smallIconSize; @@ -103,6 +104,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider ? R.drawable.map_pin_user_location_small_night : R.drawable.map_pin_user_location_small_day); bigIconBg = BitmapFactory.decodeResource(res, night ? R.drawable.map_pin_user_location_night : R.drawable.map_pin_user_location_day); + bigIconBgStale = BitmapFactory.decodeResource(res, night + ? R.drawable.map_pin_user_stale_location_night : R.drawable.map_pin_user_stale_location_day); placeholder = BitmapFactory.decodeResource(res, R.drawable.img_user_picture); smallIconSize = AndroidUtils.dpToPx(map, SMALL_ICON_SIZE_DP); @@ -173,9 +176,10 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider canvas.drawBitmap(image, null, getDstRect(x, y, smallIconSize / 2), bitmapPaint); } else if (pointsType == PointsType.BIG_ICON) { bitmapPaint.setColorFilter(null); - float vOffset = bigIconBg.getHeight() * 0.91f; - int imageCenterY = (int) (y - vOffset + bigIconBg.getHeight() / 2); - canvas.drawBitmap(bigIconBg, x - bigIconBg.getWidth() / 2, y - vOffset, bitmapPaint); + Bitmap bg = isStale(point) ? bigIconBgStale : bigIconBg; + float vOffset = bg.getHeight() * 0.91f; + int imageCenterY = (int) (y - vOffset + bg.getHeight() / 2); + canvas.drawBitmap(bg, x - bg.getWidth() / 2, y - vOffset, bitmapPaint); canvas.drawBitmap(image, null, getDstRect(x, imageCenterY, bigIconSize / 2), bitmapPaint); } } @@ -194,6 +198,10 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider return rect; } + private boolean isStale(AMapPoint point) { + return Boolean.parseBoolean(point.getParams().get(AMapPoint.POINT_STALE_LOC_PARAM)); + } + @Override public void destroyLayer() { }