Skip to content

Commit

Permalink
displaying geolocation in a message
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorpionstvo committed Jul 12, 2023
1 parent d134eb6 commit 0b6c85a
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class PickGeolocationActivity : AppCompatActivity() {

@Deprecated("Deprecated in Java")
override fun onBackPressed() {

if (binding.bottomBubble.isVisible) {
binding.tvLocationTitle.text = ""
binding.tvLocationCoordinates.text = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.xabber.presentation.application.fragments.chat.message

import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
Expand All @@ -14,6 +21,10 @@ import com.xabber.presentation.application.fragments.chat.ChatSettingsManager
import com.xabber.utils.StringUtils
import com.xabber.utils.custom.ShapeOfView
import com.xabber.utils.dp
import okhttp3.*
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
import java.util.*

class GeoLocationBuilder {
Expand All @@ -23,10 +34,11 @@ class GeoLocationBuilder {
.inflate(R.layout.geo_location_box, parent, false)
}

@SuppressLint("ClickableViewAccessibility")
fun addGeoLocationBox(
view: View, message: MessageDto,
latitude: Double,
longitude: Double
longitude: Double, onViewClickListener: MessageAdapter.OnViewClickListener?
) {
val mapImage = view.findViewById<ImageView>(R.id.map_image)
val shape = view.findViewById<ShapeOfView>(R.id.geo_shape)
Expand Down Expand Up @@ -54,7 +66,21 @@ class GeoLocationBuilder {
)
val shapeDrawable = ShapeDrawable(RoundRectShape(cornerRadii, null, null))
shape.setDrawable(shapeDrawable)
// получить картинку по координатам и загрузить в mapImage
val map = view.findViewById<MapView>(R.id.map)
map.apply {
val location = GeoPoint(latitude, longitude)
map.controller.setCenter(location)
map.setTileSource(TileSourceFactory.MAPNIK)
map.isTilesScaledToDpi = true
map.controller?.setZoom(15.5)
}
map?.zoomController?.onDetach()
map?.setOnTouchListener { _, motionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_UP -> onViewClickListener?.onLocationClick(latitude, longitude)
}; true

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ abstract class MessageViewHolder(
val geoLocationBox = GeoLocationBuilder()
val geoLocationView: View =
geoLocationBox.inflateView(messageContainer!!)
geoLocationBox.addGeoLocationBox(geoLocationView, message, latitude, longitude)
geoLocationBox.addGeoLocationBox(geoLocationView, message, latitude, longitude, onViewClickListener)
messageContainer?.addView(geoLocationView)
geoLocationView.setOnClickListener { onViewClickListener?.onLocationClick(latitude, longitude) }
}

private fun addVoiceMessageBox(path: String, message: MessageDto) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.xabber.presentation.application.fragments.contacts

import java.util.*

object UniqueKeyGenerator {
var a = 0
fun generatePrimaryKey(): String { val uuid: UUID = UUID.randomUUID()
a+=1
return uuid.toString() + a.toString()

}}
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_add_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/blue_700" />
</shape>
</item>
<item
android:width="24dp"
android:height="24dp"
android:bottom="12dp"
android:drawable="@drawable/ic_plus_white"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
</layer-list>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/attachment_action_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@
android:layout_height="wrap_content"
android:drawableTop="@drawable/music_circle"
android:text="@string/music_label" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/add_messages"
style="@style/AttachmentBottomSheetAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_add_circle"
android:text="@string/music_label" />
</LinearLayout>
</HorizontalScrollView>
6 changes: 5 additions & 1 deletion app/src/main/res/layout/geo_location_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
android:layout_height="174dp"
android:paddingVertical="2dp"
android:paddingHorizontal="4dp">
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<com.xabber.utils.custom.ShapeOfView
android:id="@+id/geo_shape"
Expand All @@ -14,7 +18,7 @@
<ImageView
android:background="@color/green_500"
android:outlineProvider="background"
android:src="@drawable/img_2"

android:id="@+id/map_image"
android:scaleType="centerCrop"
android:layout_width="match_parent"
Expand Down

0 comments on commit 0b6c85a

Please sign in to comment.