cleanup the fab logic and the generated fragment remnants
This commit is contained in:
parent
3f3783f22f
commit
2f2c94cd03
|
@ -1,11 +1,14 @@
|
||||||
package cash.z.android.wallet.ui.fragment
|
package cash.z.android.wallet.ui.fragment
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.app.Activity
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import cash.z.android.wallet.R
|
import cash.z.android.wallet.R
|
||||||
|
@ -13,40 +16,17 @@ import cash.z.android.wallet.ui.activity.MainActivity
|
||||||
import cash.z.wallet.sdk.jni.JniConverter
|
import cash.z.wallet.sdk.jni.JniConverter
|
||||||
import com.leinardi.android.speeddial.SpeedDialActionItem
|
import com.leinardi.android.speeddial.SpeedDialActionItem
|
||||||
import kotlinx.android.synthetic.main.fragment_home.*
|
import kotlinx.android.synthetic.main.fragment_home.*
|
||||||
import com.leinardi.android.speeddial.SpeedDialView
|
|
||||||
import android.widget.Toast
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
|
||||||
private const val ARG_PARAM1 = "param1"
|
|
||||||
private const val ARG_PARAM2 = "param2"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple [Fragment] subclass.
|
* Fragment representing the home screen of the app. This is the screen most often seen by the user when launching the
|
||||||
* Activities that contain this fragment must implement the
|
* application.
|
||||||
* [HomeFragment.OnFragmentInteractionListener] interface
|
|
||||||
* to handle interaction events.
|
|
||||||
* Use the [HomeFragment.newInstance] factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private var param1: String? = null
|
|
||||||
private var param2: String? = null
|
|
||||||
private var listener: OnFragmentInteractionListener? = null
|
|
||||||
|
|
||||||
|
// TODO: remove this test object. it is currently just used to exercise the rust code
|
||||||
var converter: JniConverter = JniConverter()
|
var converter: JniConverter = JniConverter()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
arguments?.let {
|
|
||||||
param1 = it.getString(ARG_PARAM1)
|
|
||||||
param2 = it.getString(ARG_PARAM2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
|
@ -57,10 +37,13 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
(activity as MainActivity).setSupportActionBar(toolbar)
|
(activity as MainActivity).let { mainActivity ->
|
||||||
(activity as MainActivity).setupNavigation()
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
(activity as MainActivity).supportActionBar?.setTitle(R.string.destination_title_home)
|
mainActivity.setupNavigation()
|
||||||
|
mainActivity.supportActionBar?.setTitle(R.string.destination_title_home)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO remove this test code
|
||||||
val seed = byteArrayOf(0x77, 0x78, 0x79)
|
val seed = byteArrayOf(0x77, 0x78, 0x79)
|
||||||
val result = converter.getAddress(seed)
|
val result = converter.getAddress(seed)
|
||||||
text_wallet_message.text = "Your address:\n$result"
|
text_wallet_message.text = "Your address:\n$result"
|
||||||
|
@ -68,100 +51,72 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
initFab()
|
initFab(activity!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initFab() {
|
/**
|
||||||
val theme = activity?.theme
|
* Initialize the Fab button and all its action items
|
||||||
|
*
|
||||||
|
* @param activity a helper parameter that forces this method to be called after the activity is created and not null
|
||||||
|
*/
|
||||||
|
private fun initFab(activity: Activity) {
|
||||||
val speedDial = sd_fab
|
val speedDial = sd_fab
|
||||||
speedDial.addActionItem(
|
|
||||||
SpeedDialActionItem.Builder(R.id.fab_request, R.drawable.ic_receipt_24dp)
|
|
||||||
.setFabBackgroundColor(ResourcesCompat.getColor(resources, R.color.icon_request, theme))
|
|
||||||
.setFabImageTintColor(ResourcesCompat.getColor(resources, R.color.zcashWhite, theme))
|
|
||||||
.setLabel(getString(R.string.destination_menu_label_request))
|
|
||||||
.setLabelClickable(true)
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
speedDial.addActionItem(
|
|
||||||
SpeedDialActionItem.Builder(R.id.fab_receive, R.drawable.ic_qrcode_24dp)
|
|
||||||
.setFabBackgroundColor(ResourcesCompat.getColor(resources, R.color.icon_receive, theme))
|
|
||||||
.setFabImageTintColor(ResourcesCompat.getColor(resources, R.color.zcashWhite, theme))
|
|
||||||
.setLabel(getString(R.string.destination_menu_label_receive))
|
|
||||||
.setLabelClickable(true)
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
speedDial.addActionItem(
|
|
||||||
SpeedDialActionItem.Builder(R.id.fab_send, R.drawable.ic_menu_send)
|
|
||||||
.setFabBackgroundColor(ResourcesCompat.getColor(resources, R.color.icon_send, theme))
|
|
||||||
.setFabImageTintColor(ResourcesCompat.getColor(resources, R.color.zcashWhite, theme))
|
|
||||||
.setLabel(getString(R.string.destination_menu_label_send))
|
|
||||||
.setLabelClickable(true)
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
|
|
||||||
val nav = (activity as MainActivity).navController
|
val nav = (activity as MainActivity).navController
|
||||||
|
|
||||||
|
HomeFab.values().forEach {
|
||||||
|
speedDial.addActionItem(it.createItem(activity))
|
||||||
|
}
|
||||||
|
|
||||||
speedDial.setOnActionSelectedListener { item ->
|
speedDial.setOnActionSelectedListener { item ->
|
||||||
when (item.id) {
|
HomeFab.fromId(item.id)?.destination?.apply { nav.navigate(this) }
|
||||||
R.id.fab_send -> {
|
|
||||||
nav.navigate(R.id.nav_send_fragment)
|
|
||||||
}
|
|
||||||
R.id.fab_receive -> {
|
|
||||||
nav.navigate(R.id.nav_receive_fragment)
|
|
||||||
}
|
|
||||||
R.id.fab_request -> {
|
|
||||||
nav.navigate(R.id.nav_request_fragment)
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
// TODO: do we need an else
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename method, update argument and hook method into UI event
|
|
||||||
fun onButtonPressed(uri: Uri) {
|
|
||||||
listener?.onFragmentInteraction(uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetach() {
|
|
||||||
super.onDetach()
|
|
||||||
listener = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface must be implemented by activities that contain this
|
* Defines the basic properties of each FAB button for use while initializing the FAB
|
||||||
* fragment to allow an interaction in this fragment to be communicated
|
|
||||||
* to the activity and potentially other fragments contained in that
|
|
||||||
* activity.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* See the Android Training lesson [Communicating with Other Fragments]
|
|
||||||
* (http://developer.android.com/training/basics/fragments/communicating.html)
|
|
||||||
* for more information.
|
|
||||||
*/
|
*/
|
||||||
interface OnFragmentInteractionListener {
|
enum class HomeFab(
|
||||||
// TODO: Update argument type and name
|
@IdRes val id:Int,
|
||||||
fun onFragmentInteraction(uri: Uri)
|
@DrawableRes val icon:Int,
|
||||||
|
@ColorRes val bgColor:Int,
|
||||||
|
@StringRes val label:Int,
|
||||||
|
@IdRes val destination:Int
|
||||||
|
) {
|
||||||
|
/* ordered by when they need to be added to the speed dial (i.e. reverse display order) */
|
||||||
|
REQUEST(
|
||||||
|
R.id.fab_request,
|
||||||
|
R.drawable.ic_receipt_24dp,
|
||||||
|
R.color.icon_request,
|
||||||
|
R.string.destination_menu_label_request,
|
||||||
|
R.id.nav_request_fragment
|
||||||
|
),
|
||||||
|
RECEIVE(
|
||||||
|
R.id.fab_receive,
|
||||||
|
R.drawable.ic_qrcode_24dp,
|
||||||
|
R.color.icon_receive,
|
||||||
|
R.string.destination_menu_label_receive,
|
||||||
|
R.id.nav_receive_fragment
|
||||||
|
),
|
||||||
|
SEND(
|
||||||
|
R.id.fab_send,
|
||||||
|
R.drawable.ic_menu_send,
|
||||||
|
R.color.icon_send,
|
||||||
|
R.string.destination_menu_label_send,
|
||||||
|
R.id.nav_send_fragment
|
||||||
|
);
|
||||||
|
|
||||||
|
fun createItem(activity: Activity): SpeedDialActionItem =
|
||||||
|
SpeedDialActionItem.Builder(id, icon)
|
||||||
|
.setFabBackgroundColor(ResourcesCompat.getColor(activity.resources, bgColor, activity.theme))
|
||||||
|
.setFabImageTintColor(ResourcesCompat.getColor(activity.resources, R.color.zcashWhite, activity.theme))
|
||||||
|
.setLabel(activity.getString(label))
|
||||||
|
.setLabelClickable(true)
|
||||||
|
.create()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromId(id: Int): HomeFab? = values().firstOrNull { it.id == id }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
/**
|
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
|
||||||
* @param param1 Parameter 1.
|
|
||||||
* @param param2 Parameter 2.
|
|
||||||
* @return A new instance of fragment HomeFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
@JvmStatic
|
|
||||||
fun newInstance(param1: String, param2: String) =
|
|
||||||
HomeFragment().apply {
|
|
||||||
arguments = Bundle().apply {
|
|
||||||
putString(ARG_PARAM1, param1)
|
|
||||||
putString(ARG_PARAM2, param2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue