diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt index 665310b..de31db2 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt @@ -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 diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt index 5885644..11c5200 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt @@ -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 diff --git a/app/src/main/res/drawable/ic_more_vert.xml b/app/src/main/res/drawable/ic_more_vert.xml index c097d3e..b4cc17e 100644 --- a/app/src/main/res/drawable/ic_more_vert.xml +++ b/app/src/main/res/drawable/ic_more_vert.xml @@ -1,4 +1,4 @@ - diff --git a/app/src/main/res/layout/fragment_merchants.xml b/app/src/main/res/layout/fragment_merchants.xml index c85e810..e35ec02 100644 --- a/app/src/main/res/layout/fragment_merchants.xml +++ b/app/src/main/res/layout/fragment_merchants.xml @@ -1,6 +1,7 @@