| | |
| | | package com.igo.user.ui |
| | | |
| | | import android.Manifest |
| | | import android.content.pm.PackageManager |
| | | import android.os.Bundle |
| | | import android.os.CountDownTimer |
| | | import android.util.Log |
| | | import android.view.Window |
| | | import android.view.WindowManager |
| | | import androidx.core.app.ActivityCompat |
| | | import androidx.core.os.bundleOf |
| | | import cn.sinata.rxnetty.LogHelper |
| | | import cn.sinata.xldutils.activity.BaseActivity |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import cn.sinata.xldutils.utils.myToast |
| | | import cn.sinata.xldutils.utils.optString |
| | | import com.google.android.gms.maps.model.LatLng |
| | | import com.google.gson.Gson |
| | | import com.igo.user.IGoApplication |
| | | import com.igo.user.IGoApplication.Companion.currentLatLng |
| | | import com.igo.user.IGoApplication.Companion.lat |
| | | import com.igo.user.IGoApplication.Companion.lon |
| | | import com.igo.user.R |
| | | import com.igo.user.dialog.UserRuleDialog |
| | | import com.igo.user.network.HttpManager |
| | |
| | | import com.igo.user.ui.HomeActivity.Companion.lonHome |
| | | import com.igo.user.utils.Const |
| | | import com.igo.user.utils.google.AMapKit |
| | | import com.tbruyelle.rxpermissions2.RxPermissions |
| | | import com.twitter.sdk.android.core.DefaultLogger |
| | | import com.twitter.sdk.android.core.Twitter |
| | | import com.twitter.sdk.android.core.TwitterAuthConfig |
| | |
| | | } |
| | | |
| | | private fun requestLocation() { |
| | | if (ActivityCompat.checkSelfPermission( |
| | | this, |
| | | Manifest.permission.ACCESS_FINE_LOCATION |
| | | ) == PackageManager.PERMISSION_GRANTED |
| | | ) { |
| | | initLocationOption() |
| | | } else { |
| | | startMain(false) |
| | | val subscribe = RxPermissions(this).request( |
| | | Manifest.permission.ACCESS_FINE_LOCATION, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION |
| | | ).subscribe { |
| | | if (it) { |
| | | initLocationOption() |
| | | } else { |
| | | startMain(false) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * 高德定位设置 |
| | | */ |
| | | private fun initLocationOption() { |
| | | // zmc-remark 测试代码 给个初始位置 |
| | | // lat = 30.659221715540937 |
| | | // lon = 104.06676612263988 |
| | | // IGoApplication.chooseCityName = "成都" |
| | | // IGoApplication.chooseCountry = "CN" |
| | | // func.add(Function(1, getString(R.string.专车))) |
| | | // func.add(Function(4, getString(R.string.快件))) |
| | | |
| | | currentLatLng = LatLng(lat, lon) |
| | | AMapKit.initLocation(this, success = { |
| | | lat = it.latLng?.latitude ?: 0.0 |
| | | lon = it.latLng?.longitude ?: 0.0 |
| | | currentLatLng = LatLng(lat, lon) |
| | | // ToastUtils.showLong("定位成功 lat = $lat , lon = $lon") |
| | | val latLng = it.latLng |
| | | if (latLng == null) { |
| | | myToast(getString(R.string.定位失败)) |
| | | LogHelper.logRecord("定位失败") |
| | | startMain(false) |
| | | return@initLocation |
| | | } |
| | | LogHelper.logRecord("定位成功:latitude=${latLng.latitude} longitude=${latLng.longitude}") |
| | | IGoApplication.setLocation(latLng) |
| | | |
| | | latHome = it.latLng?.latitude ?: 0.0 |
| | | lonHome = it.latLng?.longitude ?: 0.0 |
| | | latHome = latLng.latitude |
| | | lonHome = latLng.longitude |
| | | |
| | | Log.e("定位==============》", "${latHome},${lonHome}") |
| | | Log.i("zmc-test", "initLocationOption: lat = $lat , lon = $lon") |
| | | |
| | | Log.e("城市", ("城市" + lonHome)) |
| | | HttpManager.isOpenCity(lat.toString(), lon.toString()) |
| | | HttpManager.isOpenCity(latLng.latitude.toString(), latLng.longitude.toString()) |
| | | .request(this, success = { _, data -> |
| | | data?.run { |
| | | Log.i("zmc-test", "initLocationOption: ${Gson().toJson(data)}") |
| | | LogHelper.logRecord("城市信息: $it") |
| | | |
| | | if (!optString("name").isNullOrEmpty()) {//当前城市属于已开通城市 |
| | | if (optString("name").isNotEmpty()) {//当前城市属于已开通城市 |
| | | IGoApplication.chooseCityName = optString("name") |
| | | |
| | | Log.e("城市", ("城市" + optString("name"))) |
| | |
| | | func.add(Function(4, getString(R.string.快件))) |
| | | startMain(true) |
| | | } else {//未开通 |
| | | Log.e("zmc-test", "initLocationOption: 当前城市未开通") |
| | | LogHelper.logRecord("当前城市未开通") |
| | | myToast(getString(R.string.当前城市未开通)) |
| | | startMain(false) |
| | | } |
| | | } |
| | | }, error = { code, msg -> |
| | | Log.e("zmc-test", "initLocationOption: code = $code , msg = $msg") |
| | | LogHelper.logRecord("查询开通城市: code = $code , msg = $msg") |
| | | startMain(false) |
| | | }) |
| | | }) { |
| | | // ToastUtils.showLong("定位失败 $it") |
| | | if (!isFinishing) { |
| | | myToast(getString(R.string.定位失败)) |
| | | Log.e("zmc-test", "initLocationOption: 定位失败") |
| | | startMain(false) |
| | | } |
| | | myToast(getString(R.string.定位失败)) |
| | | LogHelper.logRecord("定位失败") |
| | | startMain(false) |
| | | } |
| | | startTimer() //开启时间检查,5秒没走完就直接进首页选择城市 |
| | | } |