Make the MerchantsFragment's custom translucent Toolbar works with the up button, and menu items, looks good in day and night modes and make sure everything goes back to normal when returning to the HomeFragment.
This commit is contained in:
parent
4d8ed68912
commit
28e0e9df52
4 changed files with 20 additions and 10 deletions
|
@ -21,7 +21,7 @@ import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
|
|||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import android.os.Build
|
||||
import android.content.res.ColorStateList
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
@ -34,11 +34,15 @@ class HomeFragment : Fragment() {
|
|||
val nightMode = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, false)
|
||||
|
||||
// Sets the toolbar background color to primaryColor and forces shows the Bitsy icon to the left
|
||||
// Forces to show the Bitsy icon to the left of the toolbar and also fix the toolbar color and visibility after
|
||||
// returning from other fragments that change those properties, such as SendTransactionFragment (color) and
|
||||
// MerchantsFragment (visibility)
|
||||
val toolbar: Toolbar? = activity?.findViewById(R.id.toolbar)
|
||||
(activity as AppCompatActivity).setSupportActionBar(toolbar)
|
||||
toolbar?.navigationIcon = resources.getDrawable(R.drawable.ic_bitsy_logo_2, null)
|
||||
toolbar?.setBackgroundResource(if (!nightMode) R.color.colorPrimary else R.color.colorToolbarDark)
|
||||
toolbar?.visibility = View.VISIBLE
|
||||
toolbar?.title = getString(R.string.app_name)
|
||||
|
||||
// Makes sure the Navigation and Status bar are not translucent after returning from the MerchantsFragment
|
||||
val window = activity?.window
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.util.Log
|
|||
import android.view.*
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
|
@ -48,6 +49,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
|||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.fragment_merchants.*
|
||||
import java.math.BigInteger
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.collections.ArrayList
|
||||
|
@ -92,7 +94,6 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
|
|||
|
||||
// Variables used to create a custom popup menu to show the merchants and tellers switches
|
||||
private var mPopupWindow: PopupWindow? = null
|
||||
private var mToolbar: Toolbar? = null
|
||||
private var screenWidth: Int = 0
|
||||
|
||||
// Variables used to decide whether or not to display the merchants and tellers markers on the map
|
||||
|
@ -102,11 +103,9 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
|
|||
private var showTellerMarkers = true
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
// Get a reference to the toolbar, to correctly place the merchants and tellers popup menu
|
||||
mToolbar = activity?.findViewById(R.id.toolbar)
|
||||
mToolbar?.visibility = View.GONE
|
||||
// Hide the activity's Toolbar so that we can make the trick of the translucent navigation and status bars
|
||||
val activityToolbar: Toolbar? = activity?.findViewById(R.id.toolbar)
|
||||
activityToolbar?.visibility = View.GONE
|
||||
|
||||
// Sets the Navigation and Status bars translucent so that the map can be viewed through them
|
||||
val window = activity?.window
|
||||
|
@ -119,6 +118,11 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// Set the fragment's toolbar as the activity toolbar just for this fragment
|
||||
(activity as AppCompatActivity).setSupportActionBar(toolbar)
|
||||
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
mapFragment.getMapAsync(this)
|
||||
|
@ -297,7 +301,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
|
|||
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)
|
||||
mPopupWindow?.showAsDropDown(mToolbar, screenWidth, -20)
|
||||
mPopupWindow?.showAsDropDown(toolbar, screenWidth, -20)
|
||||
else
|
||||
mPopupWindow?.dismiss()
|
||||
return true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
<vector android:height="24dp" android:tint="?android:textColorPrimary"
|
||||
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"/>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -15,6 +16,7 @@
|
|||
android:layout_marginTop="24dp"
|
||||
android:background="@color/semiTransparent"
|
||||
android:elevation="4dp"
|
||||
app:title="@string/title_merchants_and_tellers"
|
||||
android:theme="@style/ThemeOverlay.MaterialComponents" />
|
||||
|
||||
<fragment
|
||||
|
|
Loading…
Reference in a new issue