2018-11-12 10:38:37 -08:00
|
|
|
package cash.z.android.wallet.ui.fragment
|
|
|
|
|
2018-12-02 20:45:59 -08:00
|
|
|
import android.app.Activity
|
2018-11-12 10:38:37 -08:00
|
|
|
import android.os.Bundle
|
2018-11-21 02:11:48 -08:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-12-02 20:45:59 -08:00
|
|
|
import androidx.annotation.ColorRes
|
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
import androidx.annotation.IdRes
|
|
|
|
import androidx.annotation.StringRes
|
2018-12-02 19:21:23 -08:00
|
|
|
import androidx.core.content.res.ResourcesCompat
|
2018-11-12 10:38:37 -08:00
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import cash.z.android.wallet.R
|
2018-11-13 15:51:40 -08:00
|
|
|
import cash.z.android.wallet.ui.activity.MainActivity
|
2018-11-21 02:11:48 -08:00
|
|
|
import cash.z.wallet.sdk.jni.JniConverter
|
2018-12-02 19:21:23 -08:00
|
|
|
import com.leinardi.android.speeddial.SpeedDialActionItem
|
2018-11-13 21:16:53 -08:00
|
|
|
import kotlinx.android.synthetic.main.fragment_home.*
|
2018-11-12 10:38:37 -08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-12-02 20:45:59 -08:00
|
|
|
* Fragment representing the home screen of the app. This is the screen most often seen by the user when launching the
|
|
|
|
* application.
|
2018-11-12 10:38:37 -08:00
|
|
|
*/
|
|
|
|
class HomeFragment : Fragment() {
|
|
|
|
|
2018-12-02 20:45:59 -08:00
|
|
|
// TODO: remove this test object. it is currently just used to exercise the rust code
|
2018-11-21 02:11:48 -08:00
|
|
|
var converter: JniConverter = JniConverter()
|
|
|
|
|
2018-11-12 10:38:37 -08:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
// Inflate the layout for this fragment
|
|
|
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
|
|
|
}
|
|
|
|
|
2018-11-13 21:16:53 -08:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2018-12-02 20:45:59 -08:00
|
|
|
(activity as MainActivity).let { mainActivity ->
|
|
|
|
mainActivity.setSupportActionBar(toolbar)
|
|
|
|
mainActivity.setupNavigation()
|
|
|
|
mainActivity.supportActionBar?.setTitle(R.string.destination_title_home)
|
|
|
|
}
|
2018-11-21 02:11:48 -08:00
|
|
|
|
2018-12-02 20:45:59 -08:00
|
|
|
// TODO remove this test code
|
2018-11-21 12:15:28 -08:00
|
|
|
val seed = byteArrayOf(0x77, 0x78, 0x79)
|
|
|
|
val result = converter.getAddress(seed)
|
|
|
|
text_wallet_message.text = "Your address:\n$result"
|
2018-11-13 21:16:53 -08:00
|
|
|
}
|
|
|
|
|
2018-12-02 19:21:23 -08:00
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
|
super.onActivityCreated(savedInstanceState)
|
2018-12-02 20:45:59 -08:00
|
|
|
initFab(activity!!)
|
2018-12-02 19:21:23 -08:00
|
|
|
}
|
|
|
|
|
2018-12-02 20:45:59 -08:00
|
|
|
/**
|
|
|
|
* 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) {
|
2018-12-02 19:21:23 -08:00
|
|
|
val speedDial = sd_fab
|
|
|
|
val nav = (activity as MainActivity).navController
|
2018-12-02 20:45:59 -08:00
|
|
|
|
|
|
|
HomeFab.values().forEach {
|
|
|
|
speedDial.addActionItem(it.createItem(activity))
|
|
|
|
}
|
|
|
|
|
2018-12-02 19:21:23 -08:00
|
|
|
speedDial.setOnActionSelectedListener { item ->
|
2018-12-02 20:45:59 -08:00
|
|
|
HomeFab.fromId(item.id)?.destination?.apply { nav.navigate(this) }
|
2018-12-02 19:21:23 -08:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 10:38:37 -08:00
|
|
|
/**
|
2018-12-02 20:45:59 -08:00
|
|
|
* Defines the basic properties of each FAB button for use while initializing the FAB
|
2018-11-12 10:38:37 -08:00
|
|
|
*/
|
2018-12-02 20:45:59 -08:00
|
|
|
enum class HomeFab(
|
|
|
|
@IdRes val id:Int,
|
|
|
|
@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()
|
2018-11-12 10:38:37 -08:00
|
|
|
|
2018-12-02 20:45:59 -08:00
|
|
|
companion object {
|
|
|
|
fun fromId(id: Int): HomeFab? = values().firstOrNull { it.id == id }
|
|
|
|
}
|
2018-11-12 10:38:37 -08:00
|
|
|
}
|
2018-12-02 20:45:59 -08:00
|
|
|
|
2018-11-12 10:38:37 -08:00
|
|
|
}
|