mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 20:10:04 +03:00
Implement share location popup.
This commit is contained in:
parent
d7e1cba45c
commit
ab151cddd1
3 changed files with 99 additions and 0 deletions
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.location.live.map
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.PopupWindow
|
||||
import androidx.core.content.ContextCompat
|
||||
import im.vector.app.R
|
||||
import im.vector.app.databinding.ViewLiveLocationMarkerPopupBinding
|
||||
|
||||
class LocationLiveMapMarkerOptionsDialog(
|
||||
context: Context,
|
||||
inflater: LayoutInflater,
|
||||
) : PopupWindow() {
|
||||
|
||||
interface Callback {
|
||||
fun onShareLocationClicked()
|
||||
}
|
||||
|
||||
private val views: ViewLiveLocationMarkerPopupBinding
|
||||
|
||||
var callback: Callback? = null
|
||||
|
||||
init {
|
||||
contentView = inflater.inflate(R.layout.view_live_location_marker_popup, null, false)
|
||||
|
||||
views = ViewLiveLocationMarkerPopupBinding.bind(contentView)
|
||||
|
||||
width = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
inputMethodMode = INPUT_METHOD_NOT_NEEDED
|
||||
isFocusable = true
|
||||
isTouchable = true
|
||||
elevation = 8f
|
||||
setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bg_live_location_marker_popup))
|
||||
|
||||
contentView.setOnClickListener {
|
||||
callback?.onShareLocationClicked()
|
||||
}
|
||||
}
|
||||
|
||||
fun show(anchorView: View) {
|
||||
contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
|
||||
showAsDropDown(anchorView, -contentView.measuredWidth / 2, 0)
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap
|
|||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment
|
||||
import com.mapbox.mapboxsdk.plugins.annotation.Symbol
|
||||
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
|
||||
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
|
||||
import com.mapbox.mapboxsdk.style.layers.Property
|
||||
|
@ -42,6 +43,7 @@ import im.vector.app.core.extensions.addChildFragment
|
|||
import im.vector.app.core.extensions.configureWith
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.core.utils.DimensionConverter
|
||||
import im.vector.app.core.utils.openLocation
|
||||
import im.vector.app.databinding.FragmentLocationLiveMapViewBinding
|
||||
import im.vector.app.features.location.UrlMapProvider
|
||||
import im.vector.app.features.location.zoomToBounds
|
||||
|
@ -120,6 +122,10 @@ class LocationLiveMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||
this@LocationLiveMapViewFragment.mapboxMap = WeakReference(mapboxMap)
|
||||
symbolManager = SymbolManager(mapFragment.view as MapView, mapboxMap, style).apply {
|
||||
iconAllowOverlap = true
|
||||
addClickListener {
|
||||
onSymbolClicked(it)
|
||||
true
|
||||
}
|
||||
}
|
||||
pendingLiveLocations
|
||||
.takeUnless { it.isEmpty() }
|
||||
|
@ -129,6 +135,31 @@ class LocationLiveMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||
}
|
||||
}
|
||||
|
||||
private fun onSymbolClicked(symbol: Symbol?) {
|
||||
symbol?.let {
|
||||
val screenLocation = mapboxMap?.get()?.projection?.toScreenLocation(it.latLng)
|
||||
views.liveLocationPopupAnchor.apply {
|
||||
x = screenLocation?.x ?: 0f
|
||||
y = (screenLocation?.y ?: 0f) - views.liveLocationPopupAnchor.height
|
||||
}
|
||||
|
||||
LocationLiveMapMarkerOptionsDialog(requireContext(), layoutInflater)
|
||||
.apply {
|
||||
callback = object : LocationLiveMapMarkerOptionsDialog.Callback {
|
||||
override fun onShareLocationClicked() {
|
||||
shareLocation(symbol)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
.show(views.liveLocationPopupAnchor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shareLocation(symbol: Symbol) {
|
||||
openLocation(requireActivity(), symbol.latLng.latitude, symbol.latLng.longitude)
|
||||
}
|
||||
|
||||
private fun getOrCreateSupportMapFragment() =
|
||||
childFragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG) as? SupportMapFragment
|
||||
?: run {
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_live_location_users_bottom_sheet">
|
||||
|
||||
<View
|
||||
android:id="@+id/liveLocationPopupAnchor"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/liveLocationMapFragmentContainer"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Add table
Reference in a new issue