|
|
@@ -1,12 +1,16 @@
|
|
|
package com.miekir.ym.ui.home.coupon.detail
|
|
|
|
|
|
import android.os.Bundle
|
|
|
+import android.view.Menu
|
|
|
+import android.view.MenuItem
|
|
|
import android.webkit.WebChromeClient
|
|
|
import android.webkit.WebSettings
|
|
|
import android.webkit.WebViewClient
|
|
|
import com.miekir.common.utils.ToastTool
|
|
|
+import com.miekir.mvp.presenter.InjectPresenter
|
|
|
import com.miekir.ym.R
|
|
|
import com.miekir.ym.base.YangActivity
|
|
|
+import com.miekir.ym.manager.UserInfoManager
|
|
|
import com.miekir.ym.ui.home.coupon.CouponBean
|
|
|
import kotlinx.android.synthetic.main.activity_coupon_detail.*
|
|
|
|
|
|
@@ -17,12 +21,15 @@ import kotlinx.android.synthetic.main.activity_coupon_detail.*
|
|
|
* @date 2020/11/25 16:46
|
|
|
* Description: 优惠券详情
|
|
|
*/
|
|
|
-class CouponDetailActivity : YangActivity() {
|
|
|
+class CouponDetailActivity : YangActivity(), IFavView {
|
|
|
companion object {
|
|
|
const val KEY_COUPON_DETAIL = "coupon_detail"
|
|
|
}
|
|
|
|
|
|
- private var couponBean : CouponBean? = null;
|
|
|
+ private var mCouponBean : CouponBean? = null
|
|
|
+
|
|
|
+ @InjectPresenter
|
|
|
+ var favPresenter: FavPresenter? = null
|
|
|
|
|
|
override fun getLayoutId(): Int {
|
|
|
return R.layout.activity_coupon_detail
|
|
|
@@ -30,9 +37,9 @@ class CouponDetailActivity : YangActivity() {
|
|
|
|
|
|
override fun initViews(savedInstanceState: Bundle?) {
|
|
|
setTitle("优惠详情")
|
|
|
- couponBean = intent.getSerializableExtra(KEY_COUPON_DETAIL) as CouponBean
|
|
|
+ mCouponBean = intent.getSerializableExtra(KEY_COUPON_DETAIL) as CouponBean
|
|
|
|
|
|
- if (couponBean == null) {
|
|
|
+ if (mCouponBean == null) {
|
|
|
ToastTool.showShort("获取优惠链接失败")
|
|
|
return
|
|
|
}
|
|
|
@@ -58,7 +65,7 @@ class CouponDetailActivity : YangActivity() {
|
|
|
wv_coupon_detail.webChromeClient = WebChromeClient()
|
|
|
wv_coupon_detail.webViewClient = WebViewClient()
|
|
|
// 解决中文乱码
|
|
|
- wv_coupon_detail.loadUrl(couponBean!!.jumpUrl)
|
|
|
+ wv_coupon_detail.loadUrl(mCouponBean!!.jumpUrl)
|
|
|
}
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
@@ -66,17 +73,51 @@ class CouponDetailActivity : YangActivity() {
|
|
|
wv_coupon_detail.destroy()
|
|
|
}
|
|
|
|
|
|
-// private var item: MenuItem? = null
|
|
|
-// override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
-// // todo 收藏与取消收藏
|
|
|
-// menuInflater.inflate(R.menu.menu_done, menu)
|
|
|
-// item = menu.findItem(R.id.action_done)
|
|
|
-// if (couponBean!!.isFavorite) {
|
|
|
-// item!!.title = "已收藏"
|
|
|
-// } else {
|
|
|
-// item!!.title = "收藏"
|
|
|
-// }
|
|
|
-// return super.onCreateOptionsMenu(menu)
|
|
|
-// }
|
|
|
+ private var item: MenuItem? = null
|
|
|
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
+ // 没登录的话,就不要显示收藏按钮
|
|
|
+ if (!UserInfoManager.getInstance().isLogin) {
|
|
|
+ return super.onCreateOptionsMenu(menu)
|
|
|
+ }
|
|
|
+ // 收藏与取消收藏
|
|
|
+ menuInflater.inflate(R.menu.menu_done, menu)
|
|
|
+ item = menu.findItem(R.id.action_done)
|
|
|
+ if (mCouponBean!!.favorite) {
|
|
|
+ item!!.title = "已收藏"
|
|
|
+ } else {
|
|
|
+ item!!.title = "收藏"
|
|
|
+ }
|
|
|
+ return super.onCreateOptionsMenu(menu)
|
|
|
+ }
|
|
|
|
|
|
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
+ when (item.itemId) {
|
|
|
+ R.id.action_done -> {
|
|
|
+ // 收藏或者取消收藏
|
|
|
+ showLoading()
|
|
|
+ favPresenter?.favGoods(mCouponBean!!.id)
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFavResult(success: Boolean, code: Int) {
|
|
|
+ if (success) {
|
|
|
+ mCouponBean!!.favorite = !mCouponBean!!.favorite
|
|
|
+ if (mCouponBean!!.favorite) {
|
|
|
+ item!!.title = "已收藏"
|
|
|
+ } else {
|
|
|
+ item!!.title = "收藏"
|
|
|
+ }
|
|
|
+ setResult(
|
|
|
+ RESULT_OK,
|
|
|
+ intent.putExtra(KEY_COUPON_DETAIL, mCouponBean)
|
|
|
+ )
|
|
|
+ ToastTool.showShort("操作成功")
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort("操作失败")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|