18034727885
2026-09-10 9404fc9fce1d2f8678a5d1e6da2374b7a67783fe
app/src/main/java/com/driver/igotrip/ui/main/MainActivity.kt
@@ -1,20 +1,23 @@
package com.driver.igotrip.ui.main
import android.Manifest
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
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 androidx.core.app.ActivityCompat
import androidx.core.net.toUri
import cn.sinata.rxnetty.LogHelper
import cn.sinata.rxnetty.NettyClient
import cn.sinata.xldutils.utils.SPUtils
import cn.sinata.xldutils.utils.clickDelay
@@ -41,6 +44,7 @@
import com.driver.igotrip.netUtls.Api
import com.driver.igotrip.netUtls.callNet
import com.driver.igotrip.netUtls.getMapByAny
import com.driver.igotrip.service.LocationForegroundService
import com.driver.igotrip.ui.DialogUtil
import com.driver.igotrip.ui.DialogUtil.getDelAndSureDialog
import com.driver.igotrip.ui.main.event.MineEventActivity
@@ -56,7 +60,6 @@
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.gson.Gson
import com.tbruyelle.rxpermissions2.RxPermissions
import com.wang.avi.AVLoadingIndicatorView
@@ -85,7 +88,6 @@
    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) }
@@ -306,7 +308,7 @@
                    R.string.您暂未开启手机定位
                ),
                {
                    onBackPressed()
                    onBackPressedHandle()
                }) {
                val intent = Intent()
                intent.action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
@@ -327,7 +329,7 @@
//        if (!MyUtils.canBackgroundStart(this)) {
//            DialogUtil.getDelAndSureDialog(this, getString(R.string.前往开启), getString(R.string.退出), getString(
//                            R.string.可能导致无法接单), {
//                onBackPressed()
//                onBackPressedHandle()
//            }) {
//                MyUtils.toSettingPro(this)
//            }
@@ -380,12 +382,10 @@
    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
            )
        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")
            toast(getString(R.string.没有定位权限提示))
        } else {
            if (!RxPermissions(this).isGranted(Manifest.permission.ACCESS_FINE_LOCATION)) {
                DialogUtil.getDelAndSureDialog(
@@ -394,57 +394,72 @@
                    getString(R.string.拒绝权限),
                    getString(R.string.定位权限说明),
                    {
                        LogHelper.logRecord("用户拒绝定位权限1")
                    }) {
                    val subscribe =
                        RxPermissions(this).request(Manifest.permission.ACCESS_FINE_LOCATION)
                            .subscribe {
                            .subscribe { it ->
                                if (!it) {
                                    toast("Without positioning permission, you will not be able to receive new order push notifications")
                                    toast(getString(R.string.没有定位权限提示))
                                    CacheKey.putKeyStr(Const.REFUSE_LOCATION, "1")
                                } else
                                    initLocation()
                                    LogHelper.logRecord("用户拒绝定位权限2")
                                } else {
                                    val subscribe = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                                        RxPermissions(this).request(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
                                            .subscribe {
                                                if (!it) {
                                                    toast(getString(R.string.没有定位权限提示))
                                                    CacheKey.putKeyStr(Const.REFUSE_LOCATION, "1")
                                                    LogHelper.logRecord("用户拒绝定位权限3")
                                                } else {
                                                    initLocation()
                                                    initFloatingWindow()
                                                }
                                            }
                                    } else {
                                        initLocation()
                                        initFloatingWindow()
                                    }
                                }
                            }
                }
            } else
            } else {
                initLocation()
        }
    }
    @SuppressLint("MissingPermission", "CheckResult")
    private fun initLocation() {
        val fragment = map_view as SupportMapFragment
        AMapKit.initMap(fragment) { it ->
            // zmc-remark 测试代码 给个初始位置
//            MyApplication.aMapLocation = LatLng(30.659221715540937,104.06676612263988)
            aMap = it
            aMap.isMyLocationEnabled = true
            aMap.setOnMyLocationChangeListener {
                it?.let {
                    Log.e("定位==============》", "${it.latitude},${it.longitude}")
                    MyApplication.setLocation(it.latitude, it.longitude)
                }
                initFloatingWindow()
            }
//                    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()
//                    )
        }
    }
    //初始化定位
    private fun initLocation() {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return
        }
        LocationForegroundService.start()
    }
    //初始化悬浮窗
    private fun initFloatingWindow() {
        if (!Settings.canDrawOverlays(this) && CacheKey.getKeyStr(Const.REFUSE_FLOATING_WINDOW) != "1") {
            DialogUtil.getDelAndSureDialog(
                this,
                getString(R.string.确认),
                getString(R.string.拒绝权限),
                getString(R.string.悬浮窗说明),
                {
                    CacheKey.putKeyStr(Const.REFUSE_FLOATING_WINDOW, "1")
                }) {
                val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, "package:${packageName}".toUri()).apply {
                    putExtra("package", packageName)
                }
                startActivity(intent)
            }
        }
    }
    override fun onResume() {
        super.onResume()
        MyApplication.couldShowFloatingWindow = Settings.canDrawOverlays(this) && CacheKey.getKeyStr(Const.REFUSE_FLOATING_WINDOW) != "1"
        mainFragment?.refresh()
        callNet(Api.needToSettle, getMapByAny()) {
            var bean = gson.fromJson(it, BooleanBean::class.java).data
@@ -480,6 +495,7 @@
            tv_lien_name.text = data.data.brand.toString()
            tv_car.text =
                if (data.data.work == 1) getString(R.string.下班) else getString(R.string.出车)
            MyApplication.isWorking = data.data.work == 1
            if (data.data.work == 1) {
                /*try {
                    vehicleReporter?.setVehicleState(RidesharingVehicleReporter.VehicleState.ONLINE)
@@ -569,6 +585,7 @@
                callNet(Api.work, getMapByAny()) {
                    homeDataBean?.data?.work = 2
                    tv_car.text = getString(R.string.出车)
                    MyApplication.isWorking = false
                    beOnDuty(false)
                    val bean = Gson().fromJson<UpCarInfo>(it, UpCarInfo::class.java)
                    MyApplication.getTTsManager().setVideoText(bean.data?.audioUrl)
@@ -732,7 +749,7 @@
    private
    var mBackAppTime: Long = 0
    override fun onBackPressed() {
    override fun onBackPressedHandle() {
        if (System.currentTimeMillis() - mBackAppTime > 2000) {
            Toast.makeText(this, getString(R.string.再按一次退出程序), Toast.LENGTH_SHORT).show()
            mBackAppTime = System.currentTimeMillis()
@@ -765,16 +782,6 @@
                mainFragment?.refresh()
            }
            BaseEvent.OFF_LINE -> {
                Thread() {
                    try {
                        /*  vehicleReporter?.disableLocationTracking()
                          RidesharingDriverApi.clearInstance()*/
                    } catch (e: Exception) {
                    }
                }.start()
            }
            BaseEvent.FORCED_OFFLINE -> {
                initCall()
            }
@@ -800,6 +807,8 @@
     */
    override fun onDestroy() {
        MyApplication.couldShowFloatingWindow = false
        LocationForegroundService.stop()
        super.onDestroy()
        MyApplication.removeOrderView(qeeOrderView)
    }