package com.igo.user.ui
|
|
import android.content.Intent
|
import android.graphics.Paint
|
import android.net.Uri
|
import android.util.Log
|
import android.view.View
|
import android.widget.ImageView
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import androidx.core.view.GravityCompat
|
import androidx.drawerlayout.widget.DrawerLayout
|
import cn.sinata.rxnetty.LogHelper
|
import cn.sinata.xldutils.utils.SPUtils
|
import cn.sinata.xldutils.utils.showAllowingStateLoss
|
import com.facebook.drawee.view.SimpleDraweeView
|
import com.google.android.gms.maps.model.LatLng
|
import com.google.gson.Gson
|
import com.igo.user.IGoApplication
|
import com.igo.user.R
|
import com.igo.user.databinding.ActivityHomeBinding
|
import com.igo.user.dialog.TipDialog
|
import com.igo.user.extension.setOnDurationClickListener
|
import com.igo.user.network.HttpManager
|
import com.igo.user.network.entity.Function
|
import com.igo.user.network.entity.UserInfo
|
import com.igo.user.network.request
|
import com.igo.user.ui.mine.ChangePwdActivity
|
import com.igo.user.ui.mine.FeedbackActivity
|
import com.igo.user.ui.mine.InvokeListActivity
|
import com.igo.user.ui.mine.MsgActivity
|
import com.igo.user.ui.mine.MyCouponActivity
|
import com.igo.user.ui.mine.OrderActivity
|
import com.igo.user.ui.mine.RedPackageActivity
|
import com.igo.user.ui.mine.SafetyActivity
|
import com.igo.user.ui.mine.ScoreActivity
|
import com.igo.user.ui.mine.ServiceActivity
|
import com.igo.user.ui.mine.SettingActivity
|
import com.igo.user.ui.mine.ShareAppActivity
|
import com.igo.user.ui.mine.UserInfoActivity
|
import com.igo.user.ui.mine.VerifyPhoneForUpdatePwdActivity
|
import com.igo.user.ui.mine.WalletActivity
|
import com.igo.user.utils.Const
|
import com.igo.user.utils.ImageUtils
|
import com.igo.user.utils.google.AMapKit
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.startActivityForResult
|
|
class HomeActivity : TransparentStatusBarForBindActivity() {
|
companion object {
|
var latHome = 0.0
|
|
var lonHome = 0.0
|
|
var isOpenHome = false
|
|
var funcHome = arrayListOf<Function>()
|
}
|
|
val bind by lazy {
|
ActivityHomeBinding.inflate(layoutInflater)
|
}
|
|
private val func by lazy {
|
arrayListOf<Function>()
|
}
|
|
private val isSetPassword by lazy {
|
intent.getStringExtra("isSetPassword")
|
}
|
|
override fun setContentView(): View {
|
return bind.root
|
}
|
|
private val tv_order by lazy { bind.root.find<TextView>(R.id.tv_order) }
|
private val tv_setting by lazy { bind.root.find<TextView>(R.id.tv_setting) }
|
private val tv_coupon by lazy { bind.root.find<TextView>(R.id.tv_coupon) }
|
private val tv_safe by lazy { bind.root.find<TextView>(R.id.tv_safe) }
|
private val tv_wallet by lazy { bind.root.find<TextView>(R.id.tv_wallet) }
|
private val tv_share by lazy { bind.root.find<TextView>(R.id.tv_share) }
|
private val tv_feed_back by lazy { bind.root.find<TextView>(R.id.tv_feed_back) }
|
private val tv_service by lazy { bind.root.find<TextView>(R.id.tv_service) }
|
private val tv_invoice by lazy { bind.root.find<View>(R.id.tv_invoice) }
|
private val tv_red by lazy { bind.root.find<View>(R.id.tv_red) }
|
override fun initClick() {
|
ImageUtils.load(bind.img2, SPUtils.instance().getString("imgUrlDelivery", ""))
|
ImageUtils.load(bind.img1, SPUtils.instance().getString("imgUrlTaxi", ""))
|
ImageUtils.load(bind.img3, SPUtils.instance().getString("imgUrlLogistics", ""))
|
|
bind.apply {
|
img1.setOnDurationClickListener {
|
if (checkLogin())
|
toHome(0)
|
}
|
img2.setOnDurationClickListener {
|
if (checkLogin())
|
toHome(1)
|
}
|
img3.setOnDurationClickListener {
|
if (checkLogin())
|
startActivity<H5Activity>(
|
"url" to "https://exp.hyuusoft.com/official-huoyun-new-h5",
|
"type" to 0,
|
"title" to "",
|
"fullScreen" to "1",
|
)
|
}
|
imguserinto.setOnDurationClickListener {
|
if (checkLogin())
|
if (!drawerMain.isDrawerOpen(GravityCompat.START))
|
drawerMain.openDrawer(GravityCompat.START)
|
}
|
imNews.setOnDurationClickListener {
|
if (checkLogin())
|
startActivity<MsgActivity>()
|
}
|
}
|
|
tv_score.setOnDurationClickListener {
|
userInfo?.apply {
|
startActivity<ScoreActivity>("score" to integral)
|
}
|
}
|
tv_order.setOnDurationClickListener {
|
startActivity<OrderActivity>()
|
}
|
tv_setting.setOnDurationClickListener {
|
startActivityForResult<SettingActivity>(500, "phone" to (userInfo?.phone ?: ""))
|
}
|
iv_header_home.setOnDurationClickListener {
|
userInfo?.let {
|
startActivity<UserInfoActivity>(
|
"nickName" to it.nickName,
|
"avatar" to it.avatar,
|
"birthday" to it.birthday,
|
"sex" to it.sex,
|
"mail" to it.email,
|
"firstName" to it.firstName,
|
"lastName" to it.lastName
|
)
|
}
|
}
|
tv_coupon.setOnDurationClickListener {
|
startActivity<MyCouponActivity>()
|
}
|
tv_safe.setOnDurationClickListener {
|
userInfo?.let {
|
startActivity<SafetyActivity>(
|
"state" to it.verified,
|
"emergency" to it.emergencyContact,
|
"phone" to it.emergencyContactNumber,
|
"myPhone" to it.phone
|
)
|
}
|
}
|
tv_wallet.setOnDurationClickListener {
|
userInfo?.let {
|
startActivity<WalletActivity>(
|
"balance" to it.balance,
|
"rechargeTotal" to it.rechargeAmountSum
|
)
|
}
|
}
|
tv_red.setOnDurationClickListener {
|
startActivity<RedPackageActivity>()
|
}
|
tv_share.setOnDurationClickListener {
|
startActivity<ShareAppActivity>()
|
}
|
|
tv_feed_back.setOnDurationClickListener {
|
startActivity<FeedbackActivity>()
|
}
|
tv_service.setOnDurationClickListener {
|
startActivity<ServiceActivity>()
|
}
|
tv_invoice.setOnDurationClickListener {
|
startActivity<InvokeListActivity>()
|
}
|
}
|
|
private fun toHome(pos: Int) {
|
if (latHome != 0.0 && lonHome != 0.0) {
|
startActivity<MainActivity>(
|
"isOpen" to true, "func" to funcHome,
|
"lat" to latHome, "lon" to lonHome, "pos" to pos
|
)
|
} else {
|
startActivity<MainActivity>("isOpen" to isOpenHome, "func" to func, "pos" to pos)
|
}
|
}
|
|
override fun onResume() {
|
super.onResume()
|
if (checkLogin(isLogin = false))
|
queryUserInfo()
|
refreshAD()
|
funcHome.clear()
|
funcHome.add(Function(1, getString(R.string.专车)))
|
funcHome.add(Function(4, getString(R.string.快件)))
|
|
func.clear()
|
func.add(Function(1, getString(R.string.专车)))
|
func.add(Function(4, getString(R.string.快件)))
|
}
|
|
var userInfo: UserInfo? = null
|
private val tv_nickname by lazy { bind.root.find<TextView>(R.id.tv_nickname) }
|
private val iv_header_home by lazy { bind.root.find<SimpleDraweeView>(R.id.iv_header_home) }
|
private val tv_score by lazy { bind.root.find<TextView>(R.id.tv_score) }
|
private fun queryUserInfo() {
|
HttpManager.queryUserInfo().request(this) { _, data ->
|
userInfo = data
|
Log.e("queryUserInfo: ", Gson().toJson(userInfo))
|
data?.run {
|
SPUtils.instance().put(Const.User.PHONE, phone).apply()
|
iv_header_home.setImageURI(avatar)
|
tv_nickname.text = nickName
|
tv_score.text =
|
getString(R.string.当前积分, if (integral.isEmpty()) "0" else integral)
|
tv_score.paintFlags = tv_score.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
IGoApplication.emergency = emergencyContactNumber
|
IGoApplication.phone = phone
|
IGoApplication.phoneOperator = phoneOperator
|
if (isOpenHome && func.isNotEmpty() && (firstName.isEmpty() || lastName.isEmpty()) && !IGoApplication.isNotifyEmail) {
|
IGoApplication.isNotifyEmail = true //只提醒一次
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf(
|
"msg" to getString(R.string.请完善你的姓名),
|
"ok" to getString(R.string.前往),
|
"cancel" to getString(R.string.取消),
|
"isNotifyRed" to true
|
)
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
startActivity<UserInfoActivity>(
|
"nickName" to nickName,
|
"avatar" to avatar,
|
"birthday" to birthday,
|
"sex" to sex,
|
"mail" to email,
|
"firstName" to firstName,
|
"lastName" to lastName
|
)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
tipDialog.showAllowingStateLoss(supportFragmentManager, "email")
|
}
|
}
|
}
|
}
|
|
override fun initView() {
|
bind.apply {
|
drawerMain.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
}
|
if (checkLogin())
|
queryUserInfo()
|
|
HttpManager.queryHomeEntrance().request(this) { _, data ->
|
SPUtils.instance().put("imgUrlDelivery", data?.imgUrlDelivery).apply()
|
SPUtils.instance().put("imgUrlTaxi", data?.imgUrlTaxi).apply()
|
SPUtils.instance().put("imgUrlLogistics", data?.imgUrlLogistics).apply()
|
|
ImageUtils.load(bind.img2, data?.imgUrlDelivery)
|
ImageUtils.load(bind.img1, data?.imgUrlTaxi)
|
ImageUtils.load(bind.img3, data?.imgUrlLogistics)
|
}
|
showNoticeSetPasswordDialog()
|
}
|
|
override fun onNewIntent(intent: Intent?) {
|
super.onNewIntent(intent)
|
showNoticeSetPasswordDialog()
|
}
|
|
//刷新广告
|
private fun refreshAD() {
|
if (checkLogin(isLogin = false))
|
initLocation { it ->
|
HttpManager.getAds(2, it.latitude.toString(), it.longitude.toString())
|
.request(this) { _, data ->
|
bind.llAds.removeAllViews()
|
data?.forEach {
|
val view = layoutInflater.inflate(R.layout.item_img_ads, null)
|
val ivImg = view.find<ImageView>(R.id.iv_img)
|
ImageUtils.load(
|
ivImg,
|
it.imgUrl,
|
cn.sinata.xldutils.R.color.page_bg,
|
cn.sinata.xldutils.R.color.page_bg,
|
6
|
)
|
ivImg.setOnClickListener { _ ->
|
if (it.isJump == 1) { //要跳转
|
if (it.jumpType == "2")
|
startActivity<H5Activity>(
|
"title" to it.name,
|
"url" to it.content
|
)
|
else {
|
val intent = Intent()
|
intent.action = "android.intent.action.VIEW"
|
intent.data = Uri.parse(it.jumpUrl)
|
startActivity(intent)
|
}
|
}
|
}
|
bind.llAds.addView(view)
|
}
|
}
|
}
|
|
}
|
|
//初始化定位
|
private fun initLocation(block: (LatLng) -> Unit) {
|
if (!IGoApplication.hadInitLocation()) {
|
AMapKit.initLocation(this, success = {
|
val latLng = it.latLng
|
if (latLng == null) {
|
LogHelper.logRecord("定位失败")
|
return@initLocation
|
}
|
latHome = latLng.latitude
|
lonHome = latLng.longitude
|
LogHelper.logRecord("定位成功:latitude=${latLng.latitude} longitude=${latLng.longitude}")
|
IGoApplication.setLocation(latLng)
|
block.invoke(latLng)
|
}) {
|
LogHelper.logRecord("定位失败")
|
}
|
return
|
}
|
block.invoke(IGoApplication.getCurrentLocation())
|
}
|
|
//显示提示设置密码弹窗
|
private fun showNoticeSetPasswordDialog() {
|
if (isSetPassword == "1") {
|
HttpManager.queryUserInfo().request(this) { _, data ->
|
data?.also {
|
SPUtils.instance().put(Const.User.PHONE, it.phone).apply()
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf(
|
"msg" to getString(R.string.请设置密码),
|
"ok" to getString(R.string.前往),
|
"cancel" to getString(R.string.取消),
|
"isNotifyRed" to true
|
)
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
startActivity<ChangePwdActivity>("phone" to Const.User.PHONE)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
tipDialog.showAllowingStateLoss(supportFragmentManager, "setPassword")
|
}
|
}
|
}
|
}
|
}
|