18034727885
2026-03-18 cdb6a87fcd370b814b62a76e00d9e8554bc1f0b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
package com.driver.igotrip.ui.main
 
import android.Manifest
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.provider.Settings
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import cn.sinata.rxnetty.NettyClient
import cn.sinata.xldutils.utils.SPUtils
import cn.sinata.xldutils.utils.Utils
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.doubleOne
import cn.sinata.xldutils.utils.gone
import cn.sinata.xldutils.utils.setDrawableLeft
import cn.sinata.xldutils.utils.textColor
import com.driver.igotrip.R
import com.driver.igotrip.base.BaseEvent
import com.driver.igotrip.base.Const
import com.driver.igotrip.base.MyApplication
import com.driver.igotrip.base.MyBaseActivity
import com.driver.igotrip.base.OrderTimeOutManager
import com.driver.igotrip.base.gaode.AMapKit
import com.driver.igotrip.bean.BooleanBean
import com.driver.igotrip.bean.HomeDataBean
import com.driver.igotrip.bean.MyCarBean
import com.driver.igotrip.bean.OrderSimpleData
import com.driver.igotrip.bean.SelectServerModeBean
import com.driver.igotrip.bean.TimeBean
import com.driver.igotrip.bean.UpCarInfo
import com.driver.igotrip.bean.UserBean
import com.driver.igotrip.bean.VersionBean
import com.driver.igotrip.netUtls.Api
import com.driver.igotrip.netUtls.callNet
import com.driver.igotrip.netUtls.getMapByAny
import com.driver.igotrip.ui.DialogUtil
import com.driver.igotrip.ui.DialogUtil.getDelAndSureDialog
import com.driver.igotrip.ui.main.event.MineEventActivity
import com.driver.igotrip.ui.mine.BalanceTopupActivity
import com.driver.igotrip.ui.mine.ChangeCarActivity
import com.driver.igotrip.ui.mine.DriverAttestationActivity
import com.driver.igotrip.ui.mine.MineActivity
import com.driver.igotrip.ui.mine.MsgActivity
import com.driver.igotrip.ui.mine.OfflinePayActivity
import com.driver.igotrip.utils.Cache.CacheKey
import com.driver.igotrip.utils.DateUtil
import com.driver.mask_talk.utils.toTime
import com.driver.mask_talk.utils.toTimeEnglish
import com.driver.mask_talk.utils.toTimeFrench
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.gson.Gson
import com.tbruyelle.rxpermissions2.RxPermissions
import com.wang.avi.AVLoadingIndicatorView
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.browse
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
 
class MainActivity : MyBaseActivity()/*, DriverContext.DriverStatusListener*/ {
 
    val mainFragment by lazy {
        MainFragment()
    }
 
    var homeDataBean: HomeDataBean? = null
   /* var navigator: Navigator? = null
    var vehicleReporter: RidesharingVehicleReporter? = null*/
 
    private val MSG_REFRESH_LOCATIAON = 1
 
    private val iv_main_icon by lazy { find<ImageView>(R.id.iv_main_icon) }
    private val tv_active by lazy { find<TextView>(R.id.tv_active) }
    private val tv_today_time by lazy { find<TextView>(R.id.tv_today_time) }
    private val tv_week_time by lazy { find<TextView>(R.id.tv_week_time) }
    private val tv_month_time by lazy { find<TextView>(R.id.tv_month_time) }
    private val map_view by lazy { supportFragmentManager.findFragmentById(R.id.map_view) }
    private val avv_anim by lazy { find<AVLoadingIndicatorView>(R.id.avv_anim) }
    private val tv_up_avv by lazy { find<TextView>(R.id.tv_up_avv) }
    private val tv_order_num by lazy { find<TextView>(R.id.tv_order_num) }
    private val tv_month_order by lazy { find<TextView>(R.id.tv_month_order) }
    private val tv_task by lazy { find<TextView>(R.id.tv_task) }
    private val tv_car_num by lazy { find<TextView>(R.id.tv_car_num) }
    private val tv_core by lazy { find<TextView>(R.id.tv_core) }
    private val tv_lien_name by lazy { find<TextView>(R.id.tv_lien_name) }
    private val tv_time by lazy { find<TextView>(R.id.tv_time) }
    private val tv_car by lazy { find<TextView>(R.id.tv_car) }
    private val tv_server_ing by lazy { find<TextView>(R.id.tv_server_ing) }
    private val tv_history_order by lazy { find<TextView>(R.id.tv_history_order) }
    private val tv_wait_server by lazy { find<TextView>(R.id.tv_wait_server) }
    private val ll_task by lazy { find<LinearLayout>(R.id.ll_task) }
 
    private val handler by lazy {
        object : Handler(Looper.getMainLooper()) {
            override fun handleMessage(msg: Message) {
                super.handleMessage(msg)
                if (msg.what == MSG_REFRESH_LOCATIAON) { //刷新位置信息 Refresh location information
//                    AMapKit.initLocation(this@MainActivity){
//                        MyApplication.aMapLocation = it
//                    }
                }
            }
        }
    }
 
 
    override fun setContentView() {
        setContentView(R.layout.activity_main)
       /* lifecycleScope.launch {
            while (true){
                delay(5000)
                var map = getMapByAny()
                callNet(false,getDriverOrderMessage, map) {
                    Log.e("长连接接口消息: ",it.toString() )
                }
            }
        }*/
    }
 
    override fun initView() {
       // setTitleText(getString(R.string.IGO司机))
        tv_Left.setDrawableLeft(R.mipmap.icon_nav_user)
       // iv_right_title.setImageResource(R.mipmap.icon_nav_news)
 
        findViewById<View>(R.id.img_leftuser).setOnClickListener {
            startActivity<MineActivity>()
        }
 
        findViewById<View>(R.id.iv_right_titlenew).setOnClickListener {
            startActivity<MsgActivity>()
        }
        addFragment(mainFragment, R.id.rl_container)
//        AMapKit.initLocation(this){
//            MyApplication.aMapLocation = it
//        }
        iv_main_icon.clickDelay {
//            AMapKit.initLocation(this){
//                MyApplication.aMapLocation = it
//            }
//            showOrder("","12634","1",10,1)
        }
 
       // initDriver()
        MyApplication.isLogin = true
        beOnDuty(false)
        initCall()
        NettyClient.getInstance().startService()
        callVersion()
        checkGps()
        MyApplication.addOrderView(qeeOrderView)
        callcarAll()
        toastTo()
        callTime("1")
 
        showTitle(false)
        showHeader(false)
 
        /*lifecycleScope.launch {
            while (true){
 
                var map = getMapByAny()
                callNet(showDialog=false,getDriverOrderMessage, map) {
                    Log.e("获取消息: ",it .toString())
                }
 
                delay(5000)
            }
        }*/
    }
 
    /**
     * 初始化司机sdk
     */
   /* private fun initDriver() {
        if (CacheKey.getKeyStr("vehicleId").isNullOrEmpty())
            return
        NavigationApi.getNavigator(
            this, // Activity
            object : NavigationApi.NavigatorListener {
                override fun onError(p0: Int) {
                    Log.e(Const.GoogleDriver.TAG, "初始化司机sdk失败$p0")
                }
 
                override fun onNavigatorReady(navigator: Navigator) {
                    // Keep a reference to the Navigator (used to configure and start nav)
                    this@MainActivity.navigator = navigator
                    Log.e(Const.GoogleDriver.TAG, "初始化司机sdk成功")
                    val driverContext =
                        DriverContext.builder(application)
                            //.setProviderId("i-go-odrd-testing")
                            .setProviderId("gopost-475301")
                            .setVehicleId(CacheKey.getKeyStr("vehicleId"))
                            .setAuthTokenFactory(JsonAuthTokenFactory())
                            .setNavigator(navigator)
                            .setRoadSnappedLocationProvider(
                                NavigationApi.getRoadSnappedLocationProvider(
                                    application
                                )
                            )
                            .setDriverStatusListener(this@MainActivity)
                            .build()
                    val ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext)
                    vehicleReporter = ridesharingDriverApi.ridesharingVehicleReporter
                    vehicleReporter!!.enableLocationTracking()
                }
            }
        )
    }*/
 
    override fun onRestart() {
        super.onRestart()
        callTime("1")
    }
 
    @Subscribe
    fun onStopLocation(e: BaseEvent) {
        if (e.code == 542)
            handler?.removeMessages(MSG_REFRESH_LOCATIAON)
    }
 
    private fun callTime(type: String) {
        OrderTimeOutManager.instance.init()
        var map = getMapByAny()
        callNet(Api.getDriverOnlineTime, map) {
            var bean = gson.fromJson<TimeBean>(it, TimeBean::class.java)
            if (bean.data.attendance == 0.0) {
                tv_active.text = "0.0h"
            } else {
                tv_active.text = doubleOne(bean.data.attendance / 60 / 60) + "h"
            }
            if (bean.data.today == 0.0) {
                tv_today_time.text = "0.0h"
            } else {
                tv_today_time.text = doubleOne(bean.data.today / 60 / 60) + "h"
            }
            if (bean.data.thisWeek == 0.0) {
                tv_week_time.text = "0.0h"
            } else {
                tv_week_time.text = doubleOne(bean.data.thisWeek / 60 / 60) + "h"
            }
            if (bean.data.thisMonth == 0.0) {
                tv_month_time.text = "0.0h"
            } else {
                tv_month_time.text = doubleOne(bean.data.thisMonth / 60 / 60) + "h"
            }
 
        }
    }
 
 
    private fun toastTo() {
        var jumpCode = CacheKey.getKeyStr("jumpCode")
        if (jumpCode == "100000") {
            DialogUtil.getDelAndSureDialog(this, getString(R.string.是否完善个人资料), {}, {
                startActivity<DriverAttestationActivity>()
            })
        }
    }
 
    private fun callcarAll() {
        callNet(Api.queryMyCar, getMapByAny()) {
            var bean = gson.fromJson<MyCarBean>(it, MyCarBean::class.java)
            if (bean.data.car.isNullOrEmpty()) {
                DialogUtil.getDelAndSureDialog(this, getString(R.string.您还没有完善车辆信息), {}, {
                    startActivity<ChangeCarActivity>()
                })
            }
        }
    }
 
    var qeeOrderView = object : MyApplication.OrderStatueView {
        override fun orderInfo(data: OrderSimpleData?) {
            data?.let {
                when (it.orderType) {
                    1, 2, 3 -> {
                        if (it.status == 10 || it.status == 12) {
                            Handler(Looper.getMainLooper()).post {
                                mainFragment?.refresh()
//                                MyApplication.getTTsManager().setVideoText(getString(R.string.有用户订单被取消或改派))
                            }
                        }
                    }
                }
 
            }
        }
    }
 
    private fun checkGps() {
        if (!AMapKit.isLocServiceEnable(this)) {
            DialogUtil.getDelAndSureDialog(this,
                getString(R.string.查看定位),
                getString(R.string.退出),
                getString(
                    R.string.您暂未开启手机定位
                ),
                {
                    onBackPressed()
                }) {
                val intent = Intent()
                intent.action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
                try {
                    startActivity(intent)
                } catch (ex: ActivityNotFoundException) { //如果页面无法打开,进入设置页面
                    intent.action = Settings.ACTION_SETTINGS
                    try {
                        startActivity(intent)
                    } catch (e: Exception) {
                        e.printStackTrace()
                    }
                }
            }
        }
 
//        if (!MyUtils.canBackgroundStart(this)) {
//            DialogUtil.getDelAndSureDialog(this, getString(R.string.前往开启), getString(R.string.退出), getString(
//                            R.string.可能导致无法接单), {
//                onBackPressed()
//            }) {
//                MyUtils.toSettingPro(this)
//            }
//        }
    }
 
    private fun callVersion() {
        var map = getMapByAny()
//        map["id"] = CacheKey.getUserId()
        callNet(Api.queryNewData, map) {
            var data = gson.fromJson<VersionBean>(it, VersionBean::class.java)
            if (data.data.version != "" && data.data.version != Utils.getAppVersion(this)) {
                if (data.data.mandatory == 2) {
                    DialogUtil.getDelAndSureDialog(
                        this,
                        getString(R.string.新版本更新),
                        data.data.content,
                        {},
                        {
                            browse(data.data.url)
                        })
                } else if (data.data.mandatory == 1) {
                    DialogUtil.getDelAndSureDialog(
                        this,
                        getString(R.string.新版本更新),
                        data.data.content,
                        {
                            EventBus.getDefault().post(BaseEvent(BaseEvent.OUT_APP))
                        },
                        {
                            browse(data.data.url)
                        })
                } else {
//                    toast("已经是最新版本")
                }
            } else {
//                toast("已经是最新版本")
            }
        }
    }
 
    lateinit var aMap: GoogleMap
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (CacheKey.getKeyStr(Const.REFUSE_LOCATION)
                .isNotEmpty() && !RxPermissions(this).isGranted(
                Manifest.permission.ACCESS_FINE_LOCATION
            )
        ) {
            toast("Without positioning permission, you will not be able to receive new order push notifications")
        } else {
            if (!RxPermissions(this).isGranted(Manifest.permission.ACCESS_FINE_LOCATION)) {
                DialogUtil.getDelAndSureDialog(
                    this,
                    getString(R.string.确认),
                    getString(R.string.拒绝权限),
                    getString(R.string.定位权限说明),
                    {
                    }) {
                    val subscribe =
                        RxPermissions(this).request(Manifest.permission.ACCESS_FINE_LOCATION)
                            .subscribe {
                                if (!it) {
                                    toast("Without positioning permission, you will not be able to receive new order push notifications")
                                    CacheKey.putKeyStr(Const.REFUSE_LOCATION, "1")
                                } else
                                    initLocation()
                            }
                }
            } else
                initLocation()
        }
    }
 
    @SuppressLint("MissingPermission", "CheckResult")
    private fun initLocation() {
        val fragment = map_view as SupportMapFragment
        AMapKit.initMap(fragment) {
            // zmc-remark 测试代码 给个初始位置
//            MyApplication.aMapLocation = LatLng(30.659221715540937,104.06676612263988)
 
            aMap = it
            RxPermissions(this).request(Manifest.permission.ACCESS_FINE_LOCATION).subscribe {
                if (it) {
                    aMap.isMyLocationEnabled = true
                    aMap.setOnMyLocationChangeListener {
                        it.let { latlon ->
                            Log.e("定位==============》", "${it.latitude},${it.longitude}")
                            MyApplication.aMapLocation = LatLng(it.latitude, it.longitude)
                        }
                    }
 
 
//                    val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
//                    val locationRequest = LocationRequest.create().apply {
//                        interval = 10000  // 10秒间隔
//                        priority = LocationRequest.PRIORITY_HIGH_ACCURACY
//                    }
//
//                    fusedLocationClient.requestLocationUpdates(locationRequest,
//                        object : LocationCallback() {
//                            override fun onLocationResult(it: LocationResult) {
//                                // 处理位置更新
//                                Log.e("定位 by fusedLocationClient ==============》","${it.lastLocation?.latitude},${it.lastLocation?.longitude}")
//                            }
//                        }, Looper.getMainLooper()
//                    )
 
                } else {
 
                }
            }
        }
    }
 
 
    override fun onResume() {
        super.onResume()
        mainFragment?.refresh()
        callNet(Api.needToSettle, getMapByAny()) {
            var bean = gson.fromJson(it, BooleanBean::class.java).data
            if (bean) {
                showPayDialog()
            }
        }
    }
 
    fun beOnDuty(b: Boolean) {
        if (b) {
           // avv_anim.visible()
          //  tv_up_avv.visible()
        } else {
            avv_anim.gone()
            tv_up_avv.gone()
        }
    }
 
 
    private fun initCall() {
        var map = getMapByAny()
        callNet(Api.queryHomeData, map) {
            var data = gson.fromJson<HomeDataBean>(it, HomeDataBean::class.java)
            homeDataBean = data
            clickCallOrder()
            tv_order_num.text = data.data.dayNum.toString()
            tv_month_order.text = data.data.mouthNum.toString()
//            tv_grade.text = getFormatOne(data.data.score)
            tv_task.text = data.data.activity.toString()
            tv_car_num.text = data.data.licensePlate
            tv_core.text = doubleOne(data.data.score).toString()
            tv_lien_name.text = data.data.brand.toString()
            tv_car.text =
                if (data.data.work == 1) getString(R.string.下班) else getString(R.string.出车)
            if (data.data.work == 1) {
                /*try {
                    vehicleReporter?.setVehicleState(RidesharingVehicleReporter.VehicleState.ONLINE)
                } catch (e: Exception) {
 
                }*/
//                MyApplication.getTTsManager().setVideoText(getString(R.string.您正在上班中))
                beOnDuty(true)
            } else {
//                MyApplication.getTTsManager().setVideoText(getString(R.string.您已下班))
                beOnDuty(false)
            }
            tv_time.text = getFormantDay(System.currentTimeMillis()) + "  " + DateUtil.getWeek(
                this,
                System.currentTimeMillis()
            )
        }
    }
 
    fun callNum() {
        var map = getMapByAny()
        callNet(Api.queryHomeData, map) {
            var data = gson.fromJson<HomeDataBean>(it, HomeDataBean::class.java)
            homeDataBean = data
            tv_order_num.text = data.data.dayNum.toString()
            tv_month_order.text = data.data.mouthNum.toString()
//            tv_grade.text = getFormatOne(data.data.score)
            tv_task.text = data.data.activity.toString()
            tv_car_num.text = data.data.licensePlate
            tv_lien_name.text = data.data.brand.toString()
            tv_time.text = getFormantDay(System.currentTimeMillis()) + "  " + DateUtil.getWeek(
                this,
                System.currentTimeMillis()
            )
        }
    }
 
    /**
     * 根据语言格式化日期显示
     */
    private fun getFormantDay(time: Long): String {
        val language = SPUtils.getString(Const.language)
        return if (language == "en") time.toTimeEnglish() else if (language == "fr") time.toTimeFrench() else time.toTime(
            "MM月dd日"
        )
    }
 
 
    override fun setOnclick() {
        tv_server_ing.setOnClickListener {
            tv_server_ing.textColor(this, R.color.blue_1)
            tv_wait_server.textColor(this, R.color.main_gray)
            mainFragment.state = 1
            mainFragment.autoRefresh()
        }
 
        tv_wait_server.setOnClickListener {
            tv_server_ing.textColor(this, R.color.main_gray)
            tv_wait_server.textColor(this, R.color.blue_1)
            mainFragment.state = 2
            mainFragment.autoRefresh()
        }
 
 
        tv_Left.clickDelay {
            startActivity<MineActivity>()
        }
 
        iv_right_title.clickDelay {
 
        }
 
        tv_history_order.clickDelay {
            startActivity<HistoryOrderActivity>()
        }
 
        ll_task.clickDelay {
            startActivity<MineEventActivity>()
        }
 
        clickCallOrder()
    }
 
    private fun clickCallOrder(){
        tv_car.clickDelay {
            if (homeDataBean?.data?.work == 1) {
                callNet(Api.work, getMapByAny()) {
                    homeDataBean?.data?.work = 2
                    tv_car.text = getString(R.string.出车)
                    beOnDuty(false)
                    val bean = Gson().fromJson<UpCarInfo>(it, UpCarInfo::class.java)
                    MyApplication.getTTsManager().setVideoText(bean.data?.audioUrl)
                }
            } else {
                callNet(Api.needToSettle, getMapByAny()) {
                    var bean = gson.fromJson(it, BooleanBean::class.java).data
                    if (bean) {
                        showPayDialog()
                    } else {
                        judgeAccountEffective {
                            callNet(Api.queryMyBusiness, getMapByAny()) {
                                var bean = gson.fromJson(it, SelectServerModeBean::class.java).data
                                if (bean.isEmpty()) {
                                    toast(getString(R.string.请选择接单业务))
                                    return@callNet
                                }
                                if (bean.size > 1) {
                                    startActivity<SelectServerModeActivity>()
                                } else {
                                    var map = getMapByAny()
                                    map["type"] = bean[0].id
                                    callNet(Api.work, map) {
                                        var carinfo = gson.fromJson<UpCarInfo>(
                                            it,
                                            UpCarInfo::class.java
                                        )
                                        if (carinfo.data?.jumpCode == "200000") {
                                            DialogUtil.getDelAndSureDialog(
                                                this,
                                                getString(R.string.您还没有完善车辆信息),
                                                {},
                                                {
                                                    startActivity<ChangeCarActivity>()
                                                })
                                        } else {
                                            toast(getString(R.string.上班成功))
                                            beOnDuty(true)
                                            MyApplication.getTTsManager()
                                                .setVideoText(carinfo.data?.audioUrl)
                                            CacheKey.putKeyStr(
                                                "vehicleId",
                                                carinfo.data?.vehicleId ?: ""
                                            )
                                            EventBus.getDefault()
                                                .post(BaseEvent(BaseEvent.START_CAR))
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 
    /**判断账户是否有效
     * @param effectiveCallback 能够操作的回调*/
    private fun judgeAccountEffective(effectiveCallback: () -> Unit) {
        callNet(Api.queryInfo, getMapByAny()) {
            val user = gson.fromJson<UserBean>(it, UserBean::class.java)
            if (user.data == null) {
                return@callNet
            }
            val min = 40000
            if (user.data.accountBalance < min) {
                showNoticeAccountBalanceDialog(min)
                return@callNet
            }
            effectiveCallback.invoke()
        }
    }
 
    /**显示提示账户余额弹窗
     * @param min 最低金额*/
    private fun showNoticeAccountBalanceDialog(min: Int) {
        val l = SPUtils.getString(Const.language)
        val sure: String
        val cancel: String
        val content: String
        val warn: String
        when (l) {
            "fr" -> {
                sure = getString(R.string.充值)
                cancel = "Fermer"
                warn = "Rappel"
                content = "Solde inférieur à $min xifa, s'il vous plaît recharger d'abord"
            }
 
            "ch", "zh" -> {
                sure = getString(R.string.充值)
                cancel = "关闭"
                warn = "提示"
                content = "余额不足${min}西法,请先充值"
            }
 
            else -> {
                sure = getString(R.string.充值)
                cancel = "Close"
                warn = "Reminder"
                content = "The balance is less than $min Spanish francs, please recharge first"
            }
        }
        val delAndSureDialog = getDelAndSureDialog(
            this,
            sure,
            cancel,
            content,
            {}) {
            startActivity<BalanceTopupActivity>()
        }
        delAndSureDialog.window?.decorView?.let {
            it.find<TextView>(R.id.tv_hint_base).text = warn
        }
    }
    private fun showPayDialog() {
        val l = SPUtils.getString(Const.language)
        val pay:String
        val off:String
        val msg:String
        val warn:String
        when(l){
            "fr"->{
                pay = "Payer"
                off = "Fermer"
                warn = "Rappel"
                msg = "Vous avez des frais de règlement en attente de paiement, vous ne pouvez recevoir des commandes qu’après paiement, veuillez payer dès que possible"
            }
            "ch","zh"->{
                pay = "支付"
                off = "关闭"
                warn = "提示"
                msg = "您有一笔结算费待支付,须支付后才能接单,请尽快支付"
            }
            else->{
                pay = "Pay"
                off = "Close"
                warn = "Reminder"
                msg = "You have a settlement fee pending payment, you can only receive orders after payment, please pay as soon as possible"
            }
        }
        val delAndSureDialog = getDelAndSureDialog(this,
            pay,
            off,
            msg,
            {}) {
            startActivity<OfflinePayActivity>()
        }
        delAndSureDialog.window?.decorView?.let {
            it.find<TextView>(R.id.tv_hint_base).text = warn
        }
    }
 
 
    private
    var mBackAppTime: Long = 0
 
    override fun onBackPressed() {
        if (System.currentTimeMillis() - mBackAppTime > 2000) {
            Toast.makeText(this, getString(R.string.再按一次退出程序), Toast.LENGTH_SHORT).show()
            mBackAppTime = System.currentTimeMillis()
        } else {
            closeAll()
            MyApplication.hasAutoGoTripping = false
        }
    }
 
    override fun onEventMainThread(event: BaseEvent?) {
        super.onEventMainThread(event)
        when (event!!.code) {
            BaseEvent.START_CAR -> {
                beOnDuty(true)
               /* if (vehicleReporter == null) {
                    initDriver()
                }*/
                initCall()
            }
 
            BaseEvent.CHANGE_CAR_SUCCESS -> {
                initCall()
            }
 
            BaseEvent.CALL_NUM_MAIN -> {
                callNum()
            }
 
            BaseEvent.REFREASH_MAIN -> {
                mainFragment?.refresh()
            }
 
            BaseEvent.OFF_LINE -> {
                Thread() {
                    try {
                      /*  vehicleReporter?.disableLocationTracking()
                        RidesharingDriverApi.clearInstance()*/
                    } catch (e: Exception) {
                    }
                }.start()
            }
 
            BaseEvent.FORCED_OFFLINE -> {
                initCall()
            }
        }
    }
 
    override fun onStop() {
        super.onStop()
    }
 
 
   /* override fun updateStatus(
        p0: DriverContext.DriverStatusListener.StatusLevel,
        p1: DriverContext.DriverStatusListener.StatusCode,
        p2: String,
        p3: Throwable?,
    ) {
        Log.e(
            Const.GoogleDriver.TAG,
            "StatusLevel:${p0.name},StatusCode:${p1},p2:${p2},错误信息:${p3?.message}"
        )
    }
 
    override fun onDestroy() {
        super.onDestroy()
        RidesharingDriverApi.clearInstance()
    }*/
}