Code review fix.
This commit is contained in:
parent
2fe03a0016
commit
3ec8c77d17
|
@ -24,8 +24,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.setFragmentResultListener
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
|
@ -70,38 +69,22 @@ class LocationSharingFragment @Inject constructor(
|
||||||
|
|
||||||
private var hasRenderedUserAvatar = false
|
private var hasRenderedUserAvatar = false
|
||||||
|
|
||||||
private val liveLocationLabsFlagPromotionListener = object : VectorBaseBottomSheetDialogFragment.ResultListener {
|
|
||||||
override fun onBottomSheetResult(resultCode: Int, data: Any?) {
|
|
||||||
handleLiveLocationLabsFlagPromotionResult(resultCode, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
|
|
||||||
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
|
|
||||||
if (f is LiveLocationLabsFlagPromotionBottomSheet) {
|
|
||||||
f.resultListener = liveLocationLabsFlagPromotionListener
|
|
||||||
}
|
|
||||||
super.onFragmentResumed(fm, f)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
|
|
||||||
if (f is LiveLocationLabsFlagPromotionBottomSheet) {
|
|
||||||
f.resultListener = null
|
|
||||||
}
|
|
||||||
super.onFragmentPaused(fm, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLocationSharingBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLocationSharingBinding {
|
||||||
return FragmentLocationSharingBinding.inflate(inflater, container, false)
|
return FragmentLocationSharingBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
setFragmentResultListener(LiveLocationLabsFlagPromotionBottomSheet.REQUEST_KEY) { _, bundle ->
|
||||||
|
val isApproved = bundle.getBoolean(LiveLocationLabsFlagPromotionBottomSheet.BUNDLE_KEY_LABS_APPROVAL)
|
||||||
|
handleLiveLocationLabsFlagPromotionResult(isApproved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
activity?.supportFragmentManager?.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
|
||||||
|
|
||||||
mapView = WeakReference(views.mapView)
|
mapView = WeakReference(views.mapView)
|
||||||
views.mapView.onCreate(savedInstanceState)
|
views.mapView.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
@ -222,8 +205,8 @@ class LocationSharingFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLiveLocationLabsFlagPromotionResult(resultCode: Int, data: Any?) {
|
private fun handleLiveLocationLabsFlagPromotionResult(isApproved: Boolean) {
|
||||||
if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK && (data as? Boolean) == true) {
|
if (isApproved) {
|
||||||
vectorPreferences.setLiveLocationLabsEnabled(isEnabled = true)
|
vectorPreferences.setLiveLocationLabsEnabled(isEnabled = true)
|
||||||
startLiveLocationSharing()
|
startLiveLocationSharing()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.setFragmentResult
|
||||||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||||
import im.vector.app.databinding.BottomSheetLiveLocationLabsFlagPromotionBinding
|
import im.vector.app.databinding.BottomSheetLiveLocationLabsFlagPromotionBinding
|
||||||
|
|
||||||
|
@ -44,12 +45,18 @@ class LiveLocationLabsFlagPromotionBottomSheet :
|
||||||
private fun initOkButton() {
|
private fun initOkButton() {
|
||||||
views.promoteLiveLocationFlagOkButton.debouncedClicks {
|
views.promoteLiveLocationFlagOkButton.debouncedClicks {
|
||||||
val enableLabsFlag = views.promoteLiveLocationFlagSwitch.isChecked
|
val enableLabsFlag = views.promoteLiveLocationFlagSwitch.isChecked
|
||||||
resultListener?.onBottomSheetResult(ResultListener.RESULT_OK, enableLabsFlag)
|
setFragmentResult(REQUEST_KEY, Bundle().apply {
|
||||||
|
putBoolean(BUNDLE_KEY_LABS_APPROVAL, enableLabsFlag)
|
||||||
|
})
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
const val REQUEST_KEY = "LiveLocationLabsFlagPromotionBottomSheetRequest"
|
||||||
|
const val BUNDLE_KEY_LABS_APPROVAL = "BUNDLE_KEY_LABS_APPROVAL"
|
||||||
|
|
||||||
fun newInstance(): LiveLocationLabsFlagPromotionBottomSheet {
|
fun newInstance(): LiveLocationLabsFlagPromotionBottomSheet {
|
||||||
return LiveLocationLabsFlagPromotionBottomSheet()
|
return LiveLocationLabsFlagPromotionBottomSheet()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue