|
@@ -14,6 +14,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity
|
|
|
import com.swago.baseswago.dialog.BaseXDFragment
|
|
|
import com.swago.baseswago.model.mine.StoreItemBean
|
|
|
import com.swago.baseswago.util.AppContext
|
|
|
+import com.swago.baseswago.util.LogUtil
|
|
|
import com.swago.baseswago.util.NoDoubleClickListener
|
|
|
import com.swago.loadUrl
|
|
|
import com.swago.user.R
|
|
@@ -22,25 +23,26 @@ import com.swago.user.vm.StoreVm
|
|
|
import java.io.File
|
|
|
import java.net.URL
|
|
|
|
|
|
-class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
|
|
|
+class StoreBuyDialog : BaseStoreDFragment<DialogStoreDetailBinding>() {
|
|
|
private val storeVm by viewModels<StoreVm>()
|
|
|
|
|
|
private var svgaParser: SVGAParser? = null
|
|
|
- var storeBean: StoreItemBean ?= null
|
|
|
- var storeType:Int = 0
|
|
|
- var buySuccessFun:(()->Unit)? = null
|
|
|
+ var storeBean: StoreItemBean? = null
|
|
|
+ var storeType: Int = 0
|
|
|
+ var buySuccessFun: (() -> Unit)? = null
|
|
|
+
|
|
|
init {
|
|
|
setGravity(Gravity.BOTTOM)
|
|
|
setDimAmount(0.5f)
|
|
|
setCanCancel(true)
|
|
|
}
|
|
|
|
|
|
- companion object{
|
|
|
- fun newInstance(bean: StoreItemBean,storeType:Int): StoreBuyDialog {
|
|
|
+ companion object {
|
|
|
+ fun newInstance(bean: StoreItemBean, storeType: Int): StoreBuyDialog {
|
|
|
val dialog = StoreBuyDialog()
|
|
|
val bundle = Bundle()
|
|
|
- bundle.putParcelable("data" , bean)
|
|
|
- bundle.putInt("storeType",storeType)
|
|
|
+ bundle.putParcelable("data", bean)
|
|
|
+ bundle.putInt("storeType", storeType)
|
|
|
dialog.arguments = bundle
|
|
|
return dialog
|
|
|
}
|
|
@@ -51,63 +53,63 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
|
|
|
svgaParser = SVGAParser(activity)
|
|
|
arguments?.let {
|
|
|
storeBean = it.getParcelable("data")
|
|
|
- storeType = it.getInt("storeType",0)
|
|
|
+ storeType = it.getInt("storeType", 0)
|
|
|
}
|
|
|
storeBean?.let {
|
|
|
- binding.tvName.text = it.product_name
|
|
|
- binding.tvCoin.text = "${it.product_coin}"
|
|
|
- if (storeType == 1){
|
|
|
- binding.ivIcon.visibility = View.GONE
|
|
|
- binding.svgContent.visibility = View.VISIBLE
|
|
|
- binding.svgAvatar.visibility = View.GONE
|
|
|
+ binding?.tvName?.text = it.product_name
|
|
|
+ binding?.tvCoin?.text = "${it.product_coin}"
|
|
|
+ if (storeType == 1) {
|
|
|
+ binding?.ivIcon?.visibility = View.GONE
|
|
|
+ binding?.svgContent?.visibility = View.VISIBLE
|
|
|
+ binding?.svgAvatar?.visibility = View.GONE
|
|
|
it.product_svg_url?.let { svgUrl ->
|
|
|
- svgaParser?.decodeFromURL(URL(svgUrl), object : SVGAParser.ParseCompletion{
|
|
|
+ svgaParser?.decodeFromURL(URL(svgUrl), object : SVGAParser.ParseCompletion {
|
|
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
|
val drawable = SVGADrawable(videoItem)
|
|
|
- binding.svgContent.visibility = View.VISIBLE
|
|
|
- binding.svgAvatar.visibility = View.GONE
|
|
|
- binding.svgContent.setImageDrawable(drawable)
|
|
|
- binding.svgContent.startAnimation()
|
|
|
+ binding?.svgContent?.setImageDrawable(drawable)
|
|
|
+ binding?.svgContent?.startAnimation()
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
override fun onError() {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- } else if (storeType == 2){
|
|
|
- binding.ivIcon.visibility = View.GONE
|
|
|
- binding.svgContent.visibility = View.GONE
|
|
|
- binding.svgAvatar.visibility = View.VISIBLE
|
|
|
+ } else if (storeType == 2) {
|
|
|
+ binding?.ivIcon?.visibility = View.GONE
|
|
|
+ binding?.svgContent?.visibility = View.GONE
|
|
|
+ binding?.svgAvatar?.visibility = View.VISIBLE
|
|
|
it.product_svg_url?.let { svgUrl ->
|
|
|
- svgaParser?.decodeFromURL(URL(svgUrl), object : SVGAParser.ParseCompletion{
|
|
|
+ svgaParser?.decodeFromURL(URL(svgUrl), object : SVGAParser.ParseCompletion {
|
|
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
|
val drawable = SVGADrawable(videoItem)
|
|
|
- binding.svgContent.visibility = View.GONE
|
|
|
- binding.svgAvatar.visibility = View.VISIBLE
|
|
|
- binding.svgAvatar.setImageDrawable(drawable)
|
|
|
- binding.svgAvatar.startAnimation()
|
|
|
+ binding?.svgAvatar?.setImageDrawable(drawable)
|
|
|
+ binding?.svgAvatar?.startAnimation()
|
|
|
}
|
|
|
+
|
|
|
override fun onError() {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- }else {
|
|
|
- binding.svgContent.visibility = View.GONE
|
|
|
- binding.svgAvatar.visibility = View.GONE
|
|
|
- binding.ivIcon.visibility = View.VISIBLE
|
|
|
+ } else {
|
|
|
+ binding?.svgContent?.visibility = View.GONE
|
|
|
+ binding?.svgAvatar?.visibility = View.GONE
|
|
|
+ binding?.ivIcon?.visibility = View.VISIBLE
|
|
|
it.product_url?.let { imageUrl ->
|
|
|
- binding.ivIcon.loadUrl(AppContext.getContext(),imageUrl)
|
|
|
+ binding?.ivIcon?.loadUrl(AppContext.getContext(), imageUrl)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun initLiveData() {
|
|
|
- binding.tvBuy.setOnClickListener(object: NoDoubleClickListener(){
|
|
|
+ binding?.tvBuy?.setOnClickListener(object : NoDoubleClickListener() {
|
|
|
override fun onClick() {
|
|
|
storeBean?.let {
|
|
|
- if (it.product_status ==1){
|
|
|
+ if (it.product_status == 1) {
|
|
|
Toast.makeText(
|
|
|
AppContext.getContext(),
|
|
|
AppContext.getContext().resources.getString(R.string.this_product_has_been_purchased),
|
|
@@ -120,12 +122,12 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
|
|
|
|
|
|
}
|
|
|
})
|
|
|
- binding.svgContent.setOnClickListener {
|
|
|
+ binding?.svgContent?.setOnClickListener {
|
|
|
dismissAllowingStateLoss()
|
|
|
}
|
|
|
|
|
|
- storeVm.buyProductSuccess.observe(this){
|
|
|
- if (it){
|
|
|
+ storeVm.buyProductSuccess.observe(this) {
|
|
|
+ if (it) {
|
|
|
buySuccessFun?.invoke()
|
|
|
}
|
|
|
dismissAllowingStateLoss()
|