Make sure the MerchantsFragment's custom popup dialog is dismissed if it is open and the user clicks anywhere else in the map.
This commit is contained in:
parent
52c2cf8211
commit
0c41c76097
2 changed files with 37 additions and 6 deletions
|
@ -19,6 +19,7 @@ import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory
|
import com.google.android.gms.maps.CameraUpdateFactory
|
||||||
import com.google.android.gms.maps.model.*
|
import com.google.android.gms.maps.model.*
|
||||||
import com.google.maps.android.MarkerManager
|
import com.google.maps.android.MarkerManager
|
||||||
|
@ -58,6 +59,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
private var selectedMerchant: Merchant? = null
|
private var selectedMerchant: Merchant? = null
|
||||||
private var selectedTeller: Teller? = null
|
private var selectedTeller: Teller? = null
|
||||||
|
|
||||||
|
// Variables used to create a custom popup menu to show the merchants and tellers switches
|
||||||
private var mPopupWindow: PopupWindow? = null
|
private var mPopupWindow: PopupWindow? = null
|
||||||
private var mToolbar: Toolbar? = null
|
private var mToolbar: Toolbar? = null
|
||||||
private var screenWidth: Int = 0
|
private var screenWidth: Int = 0
|
||||||
|
@ -65,6 +67,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
|
|
||||||
|
// Get a reference to the toolbar, to correctly place the merchants and tellers popup menu
|
||||||
mToolbar = activity?.findViewById(R.id.toolbar)
|
mToolbar = activity?.findViewById(R.id.toolbar)
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_merchants, container, false)
|
return inflater.inflate(R.layout.fragment_merchants, container, false)
|
||||||
|
@ -91,6 +94,14 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
|
|
||||||
// TODO get references to the popup menu items
|
// TODO get references to the popup menu items
|
||||||
|
|
||||||
|
val tvAbout = popupView?.findViewById<TextView>(R.id.tvAbout)
|
||||||
|
tvAbout?.setOnClickListener {
|
||||||
|
val context = context ?: return@setOnClickListener
|
||||||
|
MaterialDialog(context)
|
||||||
|
.message(text = "Anything")
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
mPopupWindow = PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
mPopupWindow = PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +111,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||||
if (item?.itemId == R.id.menu_filter) {
|
if (item?.itemId == R.id.menu_filter) {
|
||||||
|
// Try to show or dismiss the custom popup window with the merchants and tellers switches
|
||||||
if (mPopupWindow?.isShowing == false)
|
if (mPopupWindow?.isShowing == false)
|
||||||
mPopupWindow?.showAsDropDown(mToolbar, screenWidth, -20)
|
mPopupWindow?.showAsDropDown(mToolbar, screenWidth, -20)
|
||||||
else
|
else
|
||||||
|
@ -156,6 +168,11 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
mMap.setInfoWindowAdapter(mMarkerManager)
|
mMap.setInfoWindowAdapter(mMarkerManager)
|
||||||
|
|
||||||
|
// Try to dismiss the
|
||||||
|
mMap.setOnMapClickListener {
|
||||||
|
dismissPopupWindow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyMapTheme() {
|
private fun applyMapTheme() {
|
||||||
|
@ -194,8 +211,12 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
val merchantRenderer = MerchantClusterRenderer(context, mMap, mMerchantClusterManager)
|
val merchantRenderer = MerchantClusterRenderer(context, mMap, mMerchantClusterManager)
|
||||||
mMerchantClusterManager?.renderer = merchantRenderer
|
mMerchantClusterManager?.renderer = merchantRenderer
|
||||||
|
|
||||||
mMerchantClusterManager?.setOnClusterClickListener { onClusterClick(it as Cluster<ClusterItem>) }
|
mMerchantClusterManager?.setOnClusterClickListener {
|
||||||
|
dismissPopupWindow()
|
||||||
|
onClusterClick(it as Cluster<ClusterItem>)
|
||||||
|
}
|
||||||
mMerchantClusterManager?.setOnClusterItemClickListener { merchant ->
|
mMerchantClusterManager?.setOnClusterItemClickListener { merchant ->
|
||||||
|
dismissPopupWindow()
|
||||||
selectedMerchant = merchant
|
selectedMerchant = merchant
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -216,8 +237,12 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
val tellerRenderer = TellerClusterRenderer(context, mMap, mTellerClusterManager)
|
val tellerRenderer = TellerClusterRenderer(context, mMap, mTellerClusterManager)
|
||||||
mTellerClusterManager?.renderer = tellerRenderer
|
mTellerClusterManager?.renderer = tellerRenderer
|
||||||
|
|
||||||
mTellerClusterManager?.setOnClusterClickListener { onClusterClick(it as Cluster<ClusterItem>) }
|
mTellerClusterManager?.setOnClusterClickListener {
|
||||||
|
dismissPopupWindow()
|
||||||
|
onClusterClick(it as Cluster<ClusterItem>)
|
||||||
|
}
|
||||||
mTellerClusterManager?.setOnClusterItemClickListener { teller ->
|
mTellerClusterManager?.setOnClusterItemClickListener { teller ->
|
||||||
|
dismissPopupWindow()
|
||||||
selectedTeller = teller
|
selectedTeller = teller
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -344,10 +369,14 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
private fun dismissPopupWindow() {
|
||||||
super.onPause()
|
|
||||||
|
|
||||||
if (mPopupWindow?.isShowing == true)
|
if (mPopupWindow?.isShowing == true)
|
||||||
mPopupWindow?.dismiss()
|
mPopupWindow?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
|
||||||
|
dismissPopupWindow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:switchPadding="48dp"
|
app:switchPadding="48dp"
|
||||||
|
android:checked="true"
|
||||||
android:text="@string/title_merchants"
|
android:text="@string/title_merchants"
|
||||||
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
||||||
android:textColor="?android:textColorPrimary"/>
|
android:textColor="?android:textColorPrimary"/>
|
||||||
|
@ -22,12 +23,13 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
app:switchPadding="48dp"
|
app:switchPadding="48dp"
|
||||||
|
android:checked="true"
|
||||||
android:text="@string/title_tellers"
|
android:text="@string/title_tellers"
|
||||||
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
||||||
android:textColor="?android:textColorPrimary"/>
|
android:textColor="?android:textColorPrimary"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvInfo"
|
android:id="@+id/tvAbout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
|
|
Loading…
Reference in a new issue