package com.okgoincar.slab
|
|
import android.content.Context
|
import android.os.Handler
|
import android.os.Looper
|
import android.view.Gravity
|
import android.view.KeyEvent
|
import android.view.ViewGroup
|
import android.widget.PopupWindow
|
import android.widget.Toast
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.RecyclerView
|
import cn.sinata.rxnetty.NettyClient
|
import cn.sinata.xldutils.netstatus.NetUtils
|
import cn.sinata.xldutils.utils.*
|
import com.amap.api.location.AMapLocation
|
import com.amap.api.location.AMapLocationListener
|
import com.google.gson.Gson
|
import com.okgoincar.R
|
import com.okgoincar.base.AMapKit
|
import com.okgoincar.base.BaseEvent
|
import com.okgoincar.base.MyApplication
|
import com.okgoincar.bean.*
|
import com.okgoincar.netUtls.Api
|
import com.okgoincar.netUtls.callNet
|
import com.okgoincar.netUtls.createView
|
import com.okgoincar.netUtls.getMapByAny
|
import com.okgoincar.slab.event.SlabMineEventActivity
|
import com.okgoincar.slab.util.DialogUtil
|
import com.okgoincar.ui.adapter.SlabStartAdapter
|
import com.okgoincar.utils.Cache.CacheKey
|
import com.okgoincar.utils.DateUtil
|
import com.okgoincar.utils.EasePopup.EasyPopup
|
import com.okgoincar.utils.PackageUtil
|
import com.okgoincar.utils.download.DownloadUtil
|
import com.okgoincar.utils.glide.GlideUtil
|
import kotlinx.android.synthetic.main.dialog_sure_and_del_slab.view.*
|
import kotlinx.android.synthetic.main.slab_activity_main.*
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
|
class SlabMainActivity : MySlabBaseActivity(), AMapLocationListener {
|
|
val mainFragment by lazy {
|
SlabMainFragment()
|
}
|
|
var homeDataBean: HomeDataBean? = null
|
|
override fun setContentView() {
|
setContentView(R.layout.slab_activity_main)
|
}
|
|
|
override fun setBlackMode(b: Boolean?) {
|
super.setBlackMode(b)
|
if (b!!) { //晚上
|
ct_bg.setBackgroundResource(R.color.black_191919)
|
ll_top.setBackgroundResource(R.drawable.bg_gray_top)
|
tv_server_ing.textColor(this, R.color.write)
|
iv_small.textColor(this, R.color.write)
|
tv_wait_server.textColor(this, R.color.write)
|
tv_code_num.textColor(this, R.color.write)
|
tv_name.textColor(this, R.color.write)
|
tv_car_num.textColor(this, R.color.write)
|
tv_star_num.textColor(this, R.color.write)
|
tv_current_time.textColor(this, R.color.write)
|
tv_company.textColor(this, R.color.write)
|
tv_time.textColor(this, R.color.write)
|
tv_car_statue.textColor(this, R.color.write)
|
tv_title.textColor(this, R.color.slab_yellow_zhong)
|
} else {
|
ll_top.setBackgroundResource(R.drawable.bg_green_top)
|
ct_bg.setBackgroundResource(R.drawable.write)
|
tv_server_ing.textColor(this, R.color.black)
|
iv_small.textColor(this, R.color.black)
|
tv_wait_server.textColor(this, R.color.black)
|
tv_code_num.textColor(this, R.color.black)
|
tv_name.textColor(this, R.color.black)
|
tv_car_num.textColor(this, R.color.black)
|
tv_star_num.textColor(this, R.color.black)
|
tv_current_time.textColor(this, R.color.black)
|
tv_company.textColor(this, R.color.black)
|
tv_time.textColor(this, R.color.black)
|
tv_car_statue.textColor(this, R.color.black)
|
tv_title.textColor(this, R.color.yellow_ffa72d)
|
}
|
}
|
|
override fun initView() {
|
if (NetUtils.isNetworkConnected(this)) {
|
setTitleText("OK出行司机")
|
showHeader(false)
|
showTitle(false)
|
callLogin {
|
view_mode.isSelected = !getNowTimeBlack()
|
addFragment(mainFragment, R.id.rl_container)
|
AMapKit.initLocation(this, this)
|
initCall()
|
NettyClient.getInstance().startService()
|
callPersion()
|
// showOrder("2221", "2", 100, 2)
|
callVersion()
|
}
|
} else {
|
showNoneNetDialog()
|
}
|
}
|
|
|
private fun callPersion() {
|
callNet(true, Api.queryInfo, getMapByAny()) {
|
var user = gson.fromJson<UserBean>(it, UserBean::class.java)
|
CacheKey.saveUserInfo(user.data)
|
showUI(user.data)
|
}
|
}
|
|
var popup: PopupWindow? = null
|
|
override fun onResume() {
|
super.onResume()
|
showNoneNetDialog()
|
try {
|
mainFragment?.refresh()
|
callPersion()
|
} catch (e: Exception) {
|
|
}
|
}
|
|
fun showNoneNetDialog() {
|
if (!NetUtils.isNetworkConnected(this)) {
|
popup = getSlabDelAndSurePopWindow(this, "刷新", "取消", "网络不通畅,是否刷新页面?", {}) {
|
if (!NetUtils.isNetworkConnected(this)) {
|
toast("无网络")
|
} else {
|
initView()
|
popup?.dismiss()
|
}
|
}
|
window.decorView.post {
|
popup?.showAtLocation(window.decorView, Gravity.CENTER, 0, 0);
|
// popup?.showCenter(window.decorView)
|
}
|
}
|
}
|
|
fun getSlabDelAndSurePopWindow(
|
context: Context,
|
sureStr: String,
|
cancelStr: String,
|
content: String,
|
clickClose: () -> Unit,
|
clickSure: () -> Unit
|
): PopupWindow {
|
var dialog = PopupWindow(createView(R.layout.dialog_sure_and_del_slab, context))
|
dialog.width = ViewGroup.LayoutParams.MATCH_PARENT
|
dialog.height = ViewGroup.LayoutParams.MATCH_PARENT
|
|
var view = dialog.contentView
|
view.tv_close_base.text = cancelStr
|
view.tv_sure_base.text = sureStr
|
view.tv_close_base.gone()
|
view.tv_close_base.setOnClickListener {
|
dialog.dismiss()
|
clickClose()
|
}
|
view.tv_sure_base.setOnClickListener {
|
clickSure()
|
}
|
view.tv_view_two_base.text = content
|
return dialog
|
}
|
|
private fun showUI(data: UserInfoBean?) {
|
data?.let {
|
if (Api.BASE_URL.contains("okyueche")){
|
textView_version.text = "版本-V" + PackageUtil.getVersionName(this)+"_online"
|
}else{
|
textView_version.text = "版本-V" + PackageUtil.getVersionName(this)+ "_测试"
|
}
|
tv_title_top.text = "服 务 监 督 卡"
|
if (data.taxiAptitudeCard.length > 7) {
|
tv_code_num.text = "资格证号:" + data.taxiAptitudeCard.substring(
|
0,
|
3
|
) + "*******" + data.taxiAptitudeCard.substring(
|
data.taxiAptitudeCard.length - 4,
|
data.taxiAptitudeCard.length
|
)
|
} else {
|
tv_code_num.text = "资格证号:" + data.taxiAptitudeCard
|
}
|
tv_name.text = "姓名:" + it.name
|
tv_car_num.text = "车牌:" + it.licensePlate
|
recycler_view_start.layoutManager =
|
LinearLayoutManager(
|
this,
|
RecyclerView.HORIZONTAL,
|
false
|
) as RecyclerView.LayoutManager?
|
recycler_view_start.adapter = SlabStartAdapter(it.score.toDouble())
|
var company = it.company
|
if (company.startsWith("广西")) {
|
company = company.substring(2, company.length)
|
}
|
tv_company.text = "公司:" + company
|
tv_time.text = "发证日期:" + it.networkCarlssueDate
|
GlideUtil.load(this, it.avatar, iv_head, 8)
|
tv_current_time.text = DateUtil.getTime(
|
DateUtil.TYPE7,
|
System.currentTimeMillis()
|
) + DateUtil.getWeek(System.currentTimeMillis())
|
}
|
}
|
|
private fun initCall() {
|
var map = getMapByAny()
|
callNet(true, Api.queryHomeData, map) {
|
var data = gson.fromJson<HomeDataBean>(it, HomeDataBean::class.java)
|
homeDataBean = data
|
tv_car.text = if (data.data.work == 1) "收车" else "出车"
|
if (data.data.work == 1) {
|
MyApplication.getTTsManager().setVideoText("您正在上班中")
|
} else {
|
// MyApplication.getTTsManager().setVideoText("您已下班")
|
var mapC = getMapByAny()
|
mapC["type"] = "2,4"
|
callNet(true, Api.work2, mapC) {
|
homeDataBean?.data?.work = 1
|
tv_car.text = "收车"
|
MyApplication.getTTsManager().setVideoText("您正在上班中")
|
}
|
}
|
}
|
|
|
callNet(true, Api.queryHomeNum, getMapByAny()) {
|
var data = gson.fromJson<MainInfoBean>(it, MainInfoBean::class.java)
|
if (!data.data.service.isNullOrEmpty() && data.data.service != "0")
|
tv_server_ing.text = "出租(" + data.data.service + ")"
|
if (!data.data.small.isNullOrEmpty() && data.data.small != "0")
|
iv_small.text = "小件(" + data.data.small + ")"
|
if (!data.data.reservation.isNullOrEmpty() && data.data.reservation != "0")
|
tv_wait_server.text = "预约(" + data.data.reservation + ")"
|
if (!data.data.activity.isNullOrEmpty() && data.data.activity != "0")
|
ll_task.text = "奖励活动(" + data.data.activity + ")"
|
}
|
}
|
|
|
override fun setOnclick() {
|
tv_server_ing.setOnClickListener {
|
tv_server_ing.textColor(this, R.color.main_yellow)
|
if (getNowTimeBlack()) {
|
tv_wait_server.textColor(this, R.color.white)
|
} else {
|
tv_wait_server.textColor(this, R.color.black)
|
}
|
mainFragment.state = 1
|
mainFragment.autoRefresh()
|
}
|
|
tv_wait_server.setOnClickListener {
|
tv_wait_server.textColor(this, R.color.main_yellow)
|
if (getNowTimeBlack()) {
|
tv_server_ing.textColor(this, R.color.white)
|
} else {
|
tv_server_ing.textColor(this, R.color.black)
|
}
|
mainFragment.state = 2
|
mainFragment.autoRefresh()
|
}
|
|
tv_name.clickDelay {
|
|
}
|
|
tv_car_num.clickDelay {
|
|
}
|
|
tv_star_num.clickDelay {
|
|
}
|
|
tv_more.clickDelay {
|
startActivity<SlabOrderListActivity>()
|
}
|
|
ll_task.clickDelay {
|
startActivity<SlabMineEventActivity>()
|
}
|
|
tv_title_top.clickDelay {
|
// showOrder("3170","2",100,1)
|
}
|
|
view_mode.clickDelay {
|
view_mode.isSelected = !view_mode.isSelected
|
if (getNowTimeBlack()) {
|
CacheKey.putKeyStr("date_mode", System.currentTimeMillis().toString())
|
CacheKey.putKeyStr("mode_now_time", "1")//记录为点击切换的颜色 1 白色 2 黑色
|
setBlackMode(false)
|
mainFragment.adapter.notifyDataSetChanged()
|
} else {
|
CacheKey.putKeyStr("date_mode", System.currentTimeMillis().toString())
|
CacheKey.putKeyStr("mode_now_time", "2")
|
setBlackMode(true)
|
mainFragment.adapter.notifyDataSetChanged()
|
}
|
|
|
}
|
|
tv_car.clickDelay {
|
|
// if (homeDataBean?.data?.work == 1) {
|
// callNet(true, Api.work2, getMapByAny()) {
|
// homeDataBean?.data?.work = 2
|
// tv_car.text = "出车"
|
// MyApplication.getTTsManager().setVideoText("您已下班")
|
// }
|
// } else {
|
// var map = getMapByAny()
|
// map["type"] = "2"
|
// callNet(true, Api.work2, map) {
|
// homeDataBean?.data?.work = 1
|
// tv_car.text = "收车"
|
// MyApplication.getTTsManager().setVideoText("您正在上班中")
|
// }
|
// }
|
}
|
|
}
|
|
|
private
|
var mBackAppTime: Long = 0
|
|
override fun onBackPressed() {
|
if (popup != null && popup!!.isShowing) {
|
return
|
}
|
if (System.currentTimeMillis() - mBackAppTime > 2000) {
|
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT)
|
.show()
|
mBackAppTime = System.currentTimeMillis()
|
} else {
|
moveTaskToBack(true)
|
}
|
}
|
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
if (popup != null && popup!!.isShowing) {
|
return false
|
}
|
return super.onKeyDown(keyCode, event)
|
}
|
|
override fun onEventMainThread(event: BaseEvent?) {
|
super.onEventMainThread(event)
|
when (event!!.code) {
|
BaseEvent.START_CAR -> {
|
initCall()
|
}
|
BaseEvent.REQUEST_CAR_INFO -> {
|
Handler(Looper.getMainLooper()).post {
|
toast("收到显示屏信息")
|
}
|
}
|
BaseEvent.UPDATA_MAIN_CAR -> {
|
try {
|
mainFragment.refresh()
|
} catch (e: Exception) {
|
}
|
}
|
BaseEvent.ERROR_INFO -> {
|
try {
|
mainFragment.refresh()
|
} catch (e: Exception) {
|
}
|
}
|
}
|
}
|
|
override fun onLocationChanged(p0: AMapLocation?) {
|
if (p0 == null) {
|
// toast("高德位置是空的")
|
return
|
}
|
if (p0.errorCode == 0) {
|
// toast("定位成功")
|
MyApplication.aMapLocation = p0
|
CacheKey.putKeyStr("location", Gson().toJson(p0))
|
} else {
|
p0.let {
|
// toast("定位失败" + it.errorCode.toString())
|
}
|
}
|
}
|
|
private fun callVersion() {
|
var map = getMapByAny()
|
callNet(false, Api.queryNewData_, map) {
|
var bean = gson.fromJson<VersionBean>(it, VersionBean::class.java)
|
if (bean.data.version != "" && bean.data.version != Utils.getAppVersion(this)) {
|
if (bean.data.mandatory == 0) {
|
var pop =
|
DialogUtil.getSlabDelAndSurePopWindow(
|
true,
|
this,
|
"确定",
|
"取消",
|
"有新版本是否更新",
|
{}) {
|
DownloadUtil(this).downloadAPK(bean.data.url, "ok出行车载端")
|
}
|
pop.showCenter(window.decorView)
|
} else {
|
var pop = DialogUtil.getSlabDelAndSurePopWindow(
|
false,
|
this,
|
"确定",
|
"取消",
|
"版本已过时,强制升级!",
|
{}) {
|
DownloadUtil(this).downloadAPK(bean.data.url, "ok出行车载端")
|
toast("后台开始下载,请等待")
|
}
|
pop.showCenter(window.decorView)
|
}
|
|
} else {
|
}
|
}
|
}
|
|
private fun callLogin(ok: () -> Unit) {
|
var jobNum = CacheKey.getKeyStr("jobNum")
|
var identification = CacheKey.getKeyStr("identification")
|
if (jobNum.isNotEmpty()) {
|
var map = getMapByAny()
|
map["taxiAptitudeCard"] = identification
|
callNet(this, Api.loginByTaxiAptitudeCard, map, {
|
var bean = Gson().fromJson<LoginBean>(it, LoginBean::class.java)
|
CacheKey.putKeyStr("identification", identification)
|
CacheKey.putKeyStr("appid", bean.data.appid)
|
CacheKey.putKeyStr("token", bean.data.token)
|
CacheKey.putKeyStr("userId", bean.data.id.toString())
|
CacheKey.putKeyStr("serverId", bean.data.serverId.toString())
|
CacheKey.putKeyStr("terminalName", bean.data.terminalId.toString())
|
ok()
|
}) {
|
ok()
|
}
|
} else if (identification.isNotEmpty()) {
|
var map = getMapByAny()
|
map["taxiAptitudeCard"] = identification
|
callNet(this, Api.loginByTaxiAptitudeCard, map, {
|
var bean = Gson().fromJson<LoginBean>(it, LoginBean::class.java)
|
CacheKey.putKeyStr("identification", identification)
|
CacheKey.putKeyStr("appid", bean.data.appid)
|
CacheKey.putKeyStr("token", bean.data.token)
|
CacheKey.putKeyStr("userId", bean.data.id.toString())
|
CacheKey.putKeyStr("serverId", bean.data.serverId.toString())
|
CacheKey.putKeyStr("terminalName", bean.data.terminalId.toString())
|
ok()
|
}) {
|
ok()
|
}
|
} else {
|
ok()
|
}
|
}
|
}
|