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-06 23:16:51 -08:00
|
|
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
2018-11-12 10:38:37 -08:00
|
|
|
import cash.z.android.wallet.R
|
2018-12-06 23:16:51 -08:00
|
|
|
import cash.z.android.wallet.extention.toAppColor
|
|
|
|
import cash.z.android.wallet.extention.toAppString
|
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-12-04 23:26:03 -08:00
|
|
|
import dagger.Module
|
|
|
|
import dagger.android.ContributesAndroidInjector
|
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
|
|
|
*/
|
2018-12-04 23:26:03 -08:00
|
|
|
class HomeFragment : BaseFragment() {
|
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-07 00:00:15 -08:00
|
|
|
// (view as MotionLayout).setShowPaths(true)
|
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 {
|
2018-12-06 23:16:51 -08:00
|
|
|
speedDial.addActionItem(it.createItem())
|
2018-12-02 20:45:59 -08:00
|
|
|
}
|
|
|
|
|
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-12-06 23:16:51 -08:00
|
|
|
private val createItem: HomeFab.() -> SpeedDialActionItem = {
|
|
|
|
SpeedDialActionItem.Builder(id, icon)
|
|
|
|
.setFabBackgroundColor(bgColor.toAppColor())
|
|
|
|
.setFabImageTintColor(R.color.zcashWhite.toAppColor())
|
|
|
|
.setLabel(label.toAppString())
|
|
|
|
.setLabelClickable(true)
|
|
|
|
.create()
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2018-12-04 23:26:03 -08:00
|
|
|
|
|
|
|
@Module
|
|
|
|
abstract class HomeFragmentModule {
|
|
|
|
@ContributesAndroidInjector
|
|
|
|
abstract fun contributeHomeFragment(): HomeFragment
|
|
|
|
}
|