mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Use SupportMapFragment instead of custom fragment
This commit is contained in:
parent
54d7d47dfc
commit
26cddd2d0d
4 changed files with 32 additions and 113 deletions
|
@ -64,7 +64,6 @@ import im.vector.app.features.home.room.list.RoomListFragment
|
|||
import im.vector.app.features.home.room.threads.list.views.ThreadListFragment
|
||||
import im.vector.app.features.location.LocationPreviewFragment
|
||||
import im.vector.app.features.location.LocationSharingFragment
|
||||
import im.vector.app.features.location.live.map.LocationLiveMapViewFragment
|
||||
import im.vector.app.features.login.LoginCaptchaFragment
|
||||
import im.vector.app.features.login.LoginFragment
|
||||
import im.vector.app.features.login.LoginGenericTextInputFormFragment
|
||||
|
@ -994,9 +993,4 @@ interface FragmentModule {
|
|||
@IntoMap
|
||||
@FragmentKey(LocationPreviewFragment::class)
|
||||
fun bindLocationPreviewFragment(fragment: LocationPreviewFragment): Fragment
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FragmentKey(LocationLiveMapViewFragment::class)
|
||||
fun bindLocationLiveMapViewFragment(fragment: LocationLiveMapViewFragment): Fragment
|
||||
}
|
||||
|
|
|
@ -39,8 +39,10 @@ fun ComponentActivity.registerStartForActivityResult(onResult: (ActivityResult)
|
|||
fun AppCompatActivity.addFragment(
|
||||
container: ViewGroup,
|
||||
fragment: Fragment,
|
||||
allowStateLoss: Boolean = false) {
|
||||
supportFragmentManager.commitTransaction(allowStateLoss) { add(container.id, fragment) }
|
||||
allowStateLoss: Boolean = false,
|
||||
tag: String? = null
|
||||
) {
|
||||
supportFragmentManager.commitTransaction(allowStateLoss) { add(container.id, fragment, tag) }
|
||||
}
|
||||
|
||||
fun <T : Fragment> AppCompatActivity.addFragment(
|
||||
|
|
|
@ -19,21 +19,31 @@ package im.vector.app.features.location.live.map
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.addFragment
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.databinding.ActivityLocationSharingBinding
|
||||
import im.vector.app.features.location.UrlMapProvider
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import javax.inject.Inject
|
||||
|
||||
@Parcelize
|
||||
data class LocationLiveMapViewArgs(
|
||||
val roomId: String
|
||||
) : Parcelable
|
||||
|
||||
/**
|
||||
* Screen showing a map with all the current users sharing their live location in room.
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class LocationLiveMapViewActivity : VectorBaseActivity<ActivityLocationSharingBinding>() {
|
||||
|
||||
@Inject lateinit var urlMapProvider: UrlMapProvider
|
||||
|
||||
override fun getBinding() = ActivityLocationSharingBinding.inflate(layoutInflater)
|
||||
|
||||
override fun initUiAndData() {
|
||||
|
@ -46,18 +56,30 @@ class LocationLiveMapViewActivity : VectorBaseActivity<ActivityLocationSharingBi
|
|||
.setTitle(getString(R.string.location_activity_title_preview))
|
||||
.allowBack()
|
||||
|
||||
if (isFirstCreation()) {
|
||||
addFragment(
|
||||
views.fragmentContainer,
|
||||
LocationLiveMapViewFragment::class.java,
|
||||
mapViewArgs
|
||||
)
|
||||
setupMap()
|
||||
}
|
||||
|
||||
private fun setupMap() {
|
||||
val mapFragment: SupportMapFragment? = if (isFirstCreation()) {
|
||||
val options = MapboxMapOptions.createFromAttributes(this, null)
|
||||
val fragment = SupportMapFragment.newInstance(options)
|
||||
addFragment(views.fragmentContainer, fragment, tag = MAP_FRAGMENT_TAG)
|
||||
fragment
|
||||
} else {
|
||||
supportFragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG) as? SupportMapFragment
|
||||
}
|
||||
|
||||
mapFragment?.getMapAsync { mapBoxMap ->
|
||||
lifecycleScope.launchWhenCreated {
|
||||
mapBoxMap.setStyle(urlMapProvider.getMapUrl())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_LOCATION_LIVE_MAP_VIEW_ARGS = "EXTRA_LOCATION_LIVE_MAP_VIEW_ARGS"
|
||||
private const val MAP_FRAGMENT_TAG = "im.vector.app.features.location.live.map"
|
||||
|
||||
fun getIntent(context: Context, locationLiveMapViewArgs: LocationLiveMapViewArgs): Intent {
|
||||
return Intent(context, LocationLiveMapViewActivity::class.java).apply {
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* 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.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.args
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.databinding.FragmentLocationPreviewBinding
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
|
||||
import im.vector.app.features.location.UrlMapProvider
|
||||
import java.lang.ref.WeakReference
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Screen showing a map with all the current users sharing their live location in room.
|
||||
*/
|
||||
class LocationLiveMapViewFragment @Inject constructor(
|
||||
private val urlMapProvider: UrlMapProvider,
|
||||
private val locationPinProvider: LocationPinProvider
|
||||
) : VectorBaseFragment<FragmentLocationPreviewBinding>() {
|
||||
|
||||
// TODO use a SupportMapFragment with FragmentManager
|
||||
// TODO align design with Figma
|
||||
|
||||
private val args: LocationLiveMapViewArgs by args()
|
||||
|
||||
// Keep a ref to handle properly the onDestroy callback
|
||||
private var mapView: WeakReference<MapView>? = null
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLocationPreviewBinding {
|
||||
return FragmentLocationPreviewBinding.inflate(layoutInflater, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
mapView = WeakReference(views.mapView)
|
||||
views.mapView.onCreate(savedInstanceState)
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
views.mapView.initialize(urlMapProvider.getMapUrl())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
views.mapView.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
views.mapView.onPause()
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onLowMemory() {
|
||||
views.mapView.onLowMemory()
|
||||
super.onLowMemory()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
views.mapView.onStart()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
views.mapView.onStop()
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
views.mapView.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
mapView?.get()?.onDestroy()
|
||||
mapView?.clear()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue