Code review fixes.

This commit is contained in:
Onuray Sahin 2022-06-28 15:06:42 +03:00
parent 320915e0a1
commit 2fe03a0016
2 changed files with 30 additions and 11 deletions

View file

@ -24,6 +24,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -68,6 +70,29 @@ class LocationSharingFragment @Inject constructor(
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 {
return FragmentLocationSharingBinding.inflate(inflater, container, false)
}
@ -75,6 +100,8 @@ class LocationSharingFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.supportFragmentManager?.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
mapView = WeakReference(views.mapView)
views.mapView.onCreate(savedInstanceState)
@ -195,12 +222,6 @@ class LocationSharingFragment @Inject constructor(
}
}
private val liveLocationLabsFlagPromotionListener = object : VectorBaseBottomSheetDialogFragment.ResultListener {
override fun onBottomSheetResult(resultCode: Int, data: Any?) {
handleLiveLocationLabsFlagPromotionResult(resultCode, data)
}
}
private fun handleLiveLocationLabsFlagPromotionResult(resultCode: Int, data: Any?) {
if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK && (data as? Boolean) == true) {
vectorPreferences.setLiveLocationLabsEnabled(isEnabled = true)
@ -212,7 +233,7 @@ class LocationSharingFragment @Inject constructor(
if (vectorPreferences.labsEnableLiveLocation()) {
startLiveLocationSharing()
} else {
LiveLocationLabsFlagPromotionBottomSheet.newInstance(liveLocationLabsFlagPromotionListener)
LiveLocationLabsFlagPromotionBottomSheet.newInstance()
.show(requireActivity().supportFragmentManager, "DISPLAY_LIVE_LOCATION_LABS_FLAG_PROMOTION")
}
}

View file

@ -50,10 +50,8 @@ class LiveLocationLabsFlagPromotionBottomSheet :
}
companion object {
fun newInstance(resultListener: ResultListener): LiveLocationLabsFlagPromotionBottomSheet {
return LiveLocationLabsFlagPromotionBottomSheet().also {
it.resultListener = resultListener
}
fun newInstance(): LiveLocationLabsFlagPromotionBottomSheet {
return LiveLocationLabsFlagPromotionBottomSheet()
}
}
}