Created a three vertical dots icon and use it in the MerchantsFragment's Toolbar. Then forced that icon to display a custom Popup menu to control which pins will appear on the map (merchants and/or tellers).

This commit is contained in:
Severiano Jaramillo 2019-01-25 20:03:22 -06:00
parent 285a4b6c49
commit b9497a2db4
10 changed files with 108 additions and 14 deletions

View file

@ -2,20 +2,21 @@ package cy.agorise.bitsybitshareswallet.fragments
import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import cy.agorise.bitsybitshareswallet.R
import android.preference.PreferenceManager
import android.view.*
import android.widget.PopupWindow
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
@ -58,7 +59,16 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
private var selectedMerchant: Merchant? = null
private var selectedTeller: Teller? = null
private var mPopupWindow: PopupWindow? = null
private var mToolbar: Toolbar? = null
private var screenWidth: Int = 0
private var popupWindowWidth: Int = 0
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
setHasOptionsMenu(true)
mToolbar = activity?.findViewById(R.id.toolbar)
return inflater.inflate(R.layout.fragment_merchants, container, false)
}
@ -70,6 +80,36 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
mapFragment.getMapAsync(this)
mMerchantViewModel = ViewModelProviders.of(this).get(MerchantViewModel::class.java)
setupPopupWindow()
// Gets the screen width to correctly place the merchants and tellers popup menu
val display = activity?.windowManager?.defaultDisplay
screenWidth = display?.width ?: screenWidth
}
private fun setupPopupWindow() {
val popupView = layoutInflater?.inflate(R.layout.popup_menu_merchants, null)
// TODO get references to the popup menu items
mPopupWindow = PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
popupWindowWidth = mPopupWindow?.width ?: popupWindowWidth
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_merchants, menu)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
if (item?.itemId == R.id.menu_filter) {
if (mPopupWindow?.isShowing == false)
mPopupWindow?.showAsDropDown(mToolbar, screenWidth - popupWindowWidth, 0)
else
mPopupWindow?.dismiss()
return true
}
return super.onOptionsItemSelected(item)
}
/** Handles the result from the location permission request */

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="10dp" />
<solid android:color="?android:colorBackground" />
</shape>

View file

@ -2,6 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -30,17 +31,17 @@
android:textAppearance="@style/TextAppearance.Bitsy.Subtitle1"
android:textStyle="bold"/>
<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchAutoClose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_different_topic"
android:switchPadding="12dp"
app:switchPadding="12dp"
android:text="@string/msg__close_timer"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchNightMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="8dp"
android:background="@drawable/popup_menu_merchants_background">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchMerchants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:switchPadding="48dp"
android:text="@string/title_merchants"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchTellers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:switchPadding="48dp"
android:text="@string/title_tellers"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textColor="?android:textColorPrimary"/>
<TextView
android:id="@+id/tvInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="About"
android:clickable="true"
android:focusable="true"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
</LinearLayout>

View file

@ -11,7 +11,7 @@
<item
android:id="@+id/merchants_dest"
android:icon="@drawable/ic_merchants"
android:title="@string/title_merchants"
android:title="@string/title_merchants_and_tellers"
app:showAsAction="always"/>
<item

View file

@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_settings"
android:icon="@drawable/ic_settings"
android:title="@string/title_settings"
app:showAsAction="never"/>
android:id="@+id/menu_filter"
android:icon="@drawable/ic_more_vert"
android:title="@string/title_filter"
app:showAsAction="always"/>
</menu>

View file

@ -45,7 +45,7 @@
<fragment
android:id="@+id/merchants_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.MerchantsFragment"
android:label="@string/title_merchants"
android:label="@string/title_merchants_and_tellers"
tools:layout="@layout/fragment_merchants"/>
<fragment

View file

@ -36,7 +36,7 @@
<!-- Home -->
<string name="title_transactions">Transacciones</string>
<string name="title_merchants">Comerciantes</string>
<string name="title_merchants_and_tellers">Comerciantes</string>
<string name="title_receive">Recibir</string>
<string name="title_balances">Balances</string>
<string name="title_send">Enviar</string>
@ -59,6 +59,8 @@
<string name="button__filter">Filtrar</string>
<!-- Merchants & Tellers -->
<string name="title_merchants">Comerciantes</string>
<string name="title_tellers">Tellers</string>
<string name="msg__location_permission_necessary">El permiso de localización es necesario para mostrar tu ubicación actual en el mapa.</string>
<!-- Send Transaction -->

View file

@ -36,7 +36,7 @@
<!-- Home -->
<string name="title_transactions">Transactions</string>
<string name="title_merchants">Merchants &amp; Tellers</string>
<string name="title_merchants_and_tellers">Merchants &amp; Tellers</string>
<string name="title_receive">Receive</string>
<string name="title_balances">Balances</string>
<string name="title_send">Send</string>
@ -59,6 +59,8 @@
<string name="button__filter">Filter</string>
<!-- Merchants & Tellers -->
<string name="title_merchants">Merchants</string>
<string name="title_tellers">Tellers</string>
<string name="msg__location_permission_necessary">Location permission is necessary to show your current location on the map.</string>
<!-- Send Transaction -->