2018-11-12 10:38:37 -08:00
|
|
|
package cash.z.android.wallet.ui.fragment
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2018-12-05 14:19:38 -08:00
|
|
|
import android.text.SpannableString
|
|
|
|
import android.text.Spanned
|
2018-12-30 17:37:43 -08:00
|
|
|
import android.util.Log
|
2018-11-12 10:38:37 -08:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-12-05 14:19:38 -08:00
|
|
|
import android.widget.TextView
|
2018-12-04 23:26:03 -08:00
|
|
|
import cash.z.android.qrecycler.QRecycler
|
2018-11-12 10:38:37 -08:00
|
|
|
import cash.z.android.wallet.R
|
2018-11-13 21:16:53 -08:00
|
|
|
import cash.z.android.wallet.ui.activity.MainActivity
|
2018-12-06 07:22:07 -08:00
|
|
|
import cash.z.android.wallet.ui.util.AddressPartNumberSpan
|
2019-02-16 00:47:39 -08:00
|
|
|
import cash.z.wallet.sdk.data.Synchronizer
|
2018-12-05 14:19:38 -08:00
|
|
|
import cash.z.wallet.sdk.jni.JniConverter
|
2019-02-07 19:18:32 -08:00
|
|
|
import cash.z.wallet.sdk.secure.Wallet
|
2018-12-04 23:26:03 -08:00
|
|
|
import dagger.Module
|
|
|
|
import dagger.android.ContributesAndroidInjector
|
|
|
|
import kotlinx.android.synthetic.main.fragment_receive.*
|
|
|
|
import javax.inject.Inject
|
2018-11-12 10:38:37 -08:00
|
|
|
|
|
|
|
/**
|
2018-12-05 14:19:38 -08:00
|
|
|
* Fragment representing the receive screen of the app. This is the screen used for receiving funds.
|
2018-11-12 10:38:37 -08:00
|
|
|
*/
|
2018-12-04 23:26:03 -08:00
|
|
|
class ReceiveFragment : BaseFragment() {
|
2018-11-12 10:38:37 -08:00
|
|
|
|
2018-12-04 23:26:03 -08:00
|
|
|
@Inject
|
|
|
|
lateinit var qrecycler: QRecycler
|
2018-11-12 10:38:37 -08:00
|
|
|
|
2018-12-05 14:19:38 -08:00
|
|
|
@Inject
|
2019-02-16 00:47:39 -08:00
|
|
|
lateinit var synchronizer: Synchronizer
|
2018-12-05 14:19:38 -08:00
|
|
|
|
|
|
|
lateinit var addressParts: Array<TextView>
|
|
|
|
|
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_receive, container, false)
|
|
|
|
}
|
|
|
|
|
2018-11-13 21:16:53 -08:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2018-12-05 14:19:38 -08:00
|
|
|
addressParts = arrayOf(
|
|
|
|
text_address_part_1,
|
|
|
|
text_address_part_2,
|
|
|
|
text_address_part_3,text_address_part_4,
|
|
|
|
text_address_part_5,
|
|
|
|
text_address_part_6,
|
|
|
|
text_address_part_7,
|
|
|
|
text_address_part_8
|
|
|
|
)
|
|
|
|
}
|
2019-02-20 22:37:09 -08:00
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
|
super.onActivityCreated(savedInstanceState)
|
2019-02-21 20:38:06 -08:00
|
|
|
mainActivity?.setToolbarShown(true)
|
2019-02-20 22:37:09 -08:00
|
|
|
}
|
2018-12-12 14:36:54 -08:00
|
|
|
|
2018-12-05 14:19:38 -08:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
|
|
|
|
// TODO: replace these with channels. For now just wire the logic together
|
|
|
|
onAddressLoaded(loadAddress())
|
2018-12-30 17:37:43 -08:00
|
|
|
// converter.scanBlocks()
|
2018-12-05 14:19:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun onAddressLoaded(address: String) {
|
2019-02-12 16:09:06 -08:00
|
|
|
Log.e("TWIG", "onAddressLoaded: $address")
|
2018-12-12 14:36:54 -08:00
|
|
|
qrecycler.load(address)
|
|
|
|
.withQuietZoneSize(3)
|
|
|
|
.withCorrectionLevel(QRecycler.CorrectionLevel.MEDIUM)
|
|
|
|
.into(receive_qr_code)
|
|
|
|
|
2018-12-05 14:19:38 -08:00
|
|
|
address.chunked(address.length/8).forEachIndexed { i, part ->
|
|
|
|
setAddressPart(i, part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setAddressPart(index: Int, addressPart: String) {
|
|
|
|
val thinSpace = "\u2005" // 0.25 em space
|
|
|
|
val textSpan = SpannableString("${index + 1}$thinSpace$addressPart")
|
|
|
|
|
2018-12-06 07:22:07 -08:00
|
|
|
textSpan.setSpan(AddressPartNumberSpan(), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
2018-12-05 14:19:38 -08:00
|
|
|
|
|
|
|
addressParts[index].text = textSpan
|
|
|
|
}
|
2018-11-13 21:16:53 -08:00
|
|
|
|
2018-12-05 14:19:38 -08:00
|
|
|
// TODO: replace with tiered load. First check memory reference (textview contents?) then check DB, then load from JNI and write to DB
|
|
|
|
private fun loadAddress(): String {
|
2019-02-16 00:47:39 -08:00
|
|
|
return synchronizer.getAddress()
|
2018-11-12 10:38:37 -08:00
|
|
|
}
|
|
|
|
|
2018-12-04 23:26:03 -08:00
|
|
|
}
|
2018-11-12 10:38:37 -08:00
|
|
|
|
2018-12-04 23:26:03 -08:00
|
|
|
@Module
|
|
|
|
abstract class ReceiveFragmentModule {
|
|
|
|
@ContributesAndroidInjector
|
|
|
|
abstract fun contributeReceiveFragment(): ReceiveFragment
|
2018-11-12 10:38:37 -08:00
|
|
|
}
|