| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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) } |
| | |
| | | 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( |
| | |
| | | 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 |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | mainFragment?.refresh() |
| | | } |
| | | |
| | | BaseEvent.OFF_LINE -> { |
| | | Thread() { |
| | | try { |
| | | /* vehicleReporter?.disableLocationTracking() |
| | | RidesharingDriverApi.clearInstance()*/ |
| | | } catch (e: Exception) { |
| | | } |
| | | }.start() |
| | | } |
| | | |
| | | BaseEvent.FORCED_OFFLINE -> { |
| | | initCall() |
| | | } |
| | |
| | | |
| | | */ |
| | | override fun onDestroy() { |
| | | MyApplication.couldShowFloatingWindow = false |
| | | LocationForegroundService.stop() |
| | | super.onDestroy() |
| | | MyApplication.removeOrderView(qeeOrderView) |
| | | } |