| | |
| | | import android.content.Intent |
| | | import android.os.Bundle |
| | | import android.util.Log |
| | | import androidx.appcompat.app.AppCompatActivity |
| | | import androidx.core.os.bundleOf |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.fragment.app.FragmentManager |
| | | import androidx.lifecycle.lifecycleScope |
| | | import androidx.lifecycle.withResumed |
| | | import cn.sinata.rxnetty.LogHelper.initLogs |
| | | import cn.sinata.rxnetty.LogHelper.logRecord |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.activity.BaseActivity |
| | | import cn.sinata.xldutils.application.BaseApplication |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import cn.sinata.xldutils.utils.myToast |
| | | import com.amap.api.col.sln3.it |
| | | import com.google.android.gms.maps.MapsInitializer |
| | | import com.google.android.libraries.places.api.Places |
| | | import com.google.gson.Gson |
| | | import com.igo.user.dialog.ChooseCardDialog |
| | | import com.igo.user.dialog.PayDialog |
| | | import com.igo.user.dialog.TipDialog |
| | | import com.igo.user.interfaces.OrderStateChangeListener |
| | | import com.igo.user.interfaces.StringCallback |
| | | import com.igo.user.network.Apis |
| | | import com.igo.user.network.HttpManager |
| | | import com.igo.user.network.entity.TrippingInfo |
| | | import com.igo.user.network.request |
| | | import com.igo.user.network.requestByF |
| | | import com.igo.user.ui.MainActivity |
| | | import com.igo.user.ui.SplashActivity |
| | | import com.igo.user.ui.login.LoginActivity |
| | | import com.igo.user.ui.trip.TripActivity |
| | | import com.igo.user.utils.Const |
| | | import com.igo.user.utils.pay.PayListener |
| | | import com.igo.user.utils.pay.PayUtil |
| | | import com.sinata.download.DownloadLibrary |
| | | import com.umeng.commonsdk.UMConfigure |
| | | import com.umeng.socialize.PlatformConfig |
| | | //import com.umeng.commonsdk.UMConfigure |
| | | //import com.umeng.socialize.PlatformConfig |
| | | import io.reactivex.Flowable |
| | | import io.reactivex.disposables.Disposable |
| | | import kotlinx.coroutines.CoroutineScope |
| | | import kotlinx.coroutines.Dispatchers |
| | | import kotlinx.coroutines.launch |
| | | import org.jetbrains.anko.runOnUiThread |
| | | import org.jetbrains.anko.startActivity |
| | | import org.json.JSONObject |
| | | import java.util.concurrent.TimeUnit |
| | | import com.google.android.gms.maps.model.LatLng |
| | | |
| | | class IGoApplication : BaseApplication(), Application.ActivityLifecycleCallbacks { |
| | | private val TAG = "IGoApplication" |
| | | override fun getSPName() = "IgoSp" |
| | | private var heartSubscribe: Disposable? = null |
| | | private val listeners = ArrayList<OrderStateChangeListener>() |
| | |
| | | null, |
| | | packageName |
| | | ) |
| | | initLogs() |
| | | initNetty() |
| | | UMConfigure.init(this, Const.UMENG_KEY, "", UMConfigure.DEVICE_TYPE_PHONE, "") |
| | | PlatformConfig.setWeixin(Const.WX_APP_ID, Const.WX_SECRET) |
| | | PlatformConfig.setWXFileProvider("com.igo.user.FileProvider") |
| | | UMConfigure.setLogEnabled(true) |
| | | // UMConfigure.init(this, Const.UMENG_KEY, "", UMConfigure.DEVICE_TYPE_PHONE, "") |
| | | // PlatformConfig.setWeixin(Const.WX_APP_ID, Const.WX_SECRET) |
| | | // PlatformConfig.setWXFileProvider("com.igo.user.FileProvider") |
| | | // UMConfigure.setLogEnabled(true) |
| | | Places.initialize(this, Const.google_key) |
| | | MapsInitializer.initialize( |
| | | this, MapsInitializer.Renderer.LATEST |
| | |
| | | val json = JSONObject(message) |
| | | val method = json.optString("method") |
| | | val code = json.optString("code") |
| | | if (method != "OK") { |
| | | Log.d("zmc-socket", message) |
| | | } |
| | | |
| | | if (code == "200") { |
| | | Log.e("物流需要补差价: ", "状态${method}") |
| | | when (method) { |
| | | |
| | | Const.Method.PING_RECEIVE -> {//心跳 |
| | |
| | | } |
| | | |
| | | Const.Method.DIFFERENCE -> {//物流需要补差价 |
| | | Log.e("物流需要补差价: ", "物流需要补差价") |
| | | val order = json.optJSONObject("data") |
| | | val data = Gson().fromJson(order.toString(), TrippingInfo::class.java) |
| | | order?.let { |
| | | val topAct = activities[activities.lastIndex] |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf( |
| | | "msg" to topAct.getString(R.string.补差价提示) |
| | | .format(data.orderId, data.money), |
| | | "ok" to topAct.getString(R.string.同意), |
| | | "cancel" to topAct.getString(R.string.不同意) |
| | | ) |
| | | tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | HttpManager.confirmDifferencePrice( |
| | | data.orderId, |
| | | data.money, |
| | | 2 |
| | | ).request(topAct as BaseActivity) { _, _ -> |
| | | } |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | HttpManager.confirmDifferencePrice( |
| | | data.orderId, |
| | | data.money, |
| | | 3 |
| | | ).request(topAct as BaseActivity) { _, _ -> |
| | | } |
| | | } |
| | | }) |
| | | tipDialog.show( |
| | | (topAct as BaseActivity).supportFragmentManager, |
| | | "diff" |
| | | ) |
| | | } |
| | | Log.e("zmc-socket", "物流需要补差价") |
| | | payTheDifference(json.optJSONObject("data")) |
| | | // val order = json.optJSONObject("data") |
| | | // val data = Gson().fromJson(order.toString(), TrippingInfo::class.java) |
| | | // |
| | | // order?.let { |
| | | // val topAct = activities[activities.lastIndex] |
| | | // val tipDialog = TipDialog() |
| | | // tipDialog.arguments = bundleOf( |
| | | // "msg" to topAct.getString(R.string.补差价提示) |
| | | // .format(data.orderId, data.money), |
| | | // "ok" to topAct.getString(R.string.同意), |
| | | // "cancel" to topAct.getString(R.string.不同意) |
| | | // ) |
| | | // tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | // override fun onOk() { |
| | | // HttpManager.confirmDifferencePrice( |
| | | // data.orderId, |
| | | // data.money, |
| | | // 2 |
| | | // ).request(topAct as BaseActivity) { _, _ -> |
| | | // } |
| | | // } |
| | | // |
| | | // override fun onCancel() { |
| | | // HttpManager.confirmDifferencePrice( |
| | | // data.orderId, |
| | | // data.money, |
| | | // 3 |
| | | // ).request(topAct as BaseActivity) { _, _ -> |
| | | // } |
| | | // } |
| | | // }) |
| | | // tipDialog.show( |
| | | // (topAct as BaseActivity).supportFragmentManager, |
| | | // "diff" |
| | | // ) |
| | | // } |
| | | } |
| | | |
| | | Const.Method.REASSIGN -> {//订单改派 |
| | |
| | | } |
| | | |
| | | Const.Method.DRIVER_POSITION -> {//司机位置 |
| | | logRecord(TAG,"received DRIVER_POSITION message $json, listeners size ${listeners.size}") |
| | | val jb = json.optJSONObject("data") |
| | | jb?.let { |
| | | val data = Gson().fromJson(jb.toString(), TrippingInfo::class.java) |
| | |
| | | } |
| | | } |
| | | |
| | | private fun payTheDifference(data: JSONObject?) { |
| | | data?.let { data -> |
| | | val topAct = activities[activities.lastIndex] as BaseActivity |
| | | topAct.lifecycleScope.launchWhenResumed { |
| | | val orderId = data.optInt("orderId") |
| | | val money = data.optDouble("money") |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf( |
| | | "msg" to topAct.getString(R.string.补差价提示).format(orderId, money), |
| | | "ok" to topAct.getString(R.string.同意), |
| | | "cancel" to topAct.getString(R.string.不同意) |
| | | ) |
| | | tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | confirmDifferencePrice(topAct, orderId, money, 2){ |
| | | getUserInfoWhenPay(topAct, orderId, money) |
| | | } |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | confirmDifferencePrice(topAct, orderId, money, 3) |
| | | } |
| | | }) |
| | | tipDialog.show((topAct).supportFragmentManager, "diff") |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun getUserInfoWhenPay(topAct: BaseActivity, orderId: Int, money: Double) { |
| | | HttpManager.queryUserInfo().request(topAct, showDialog = true) { _, data -> |
| | | data?.let { |
| | | val payDialog = PayDialog() |
| | | payDialog.arguments = bundleOf( |
| | | "money" to money, |
| | | "isLogistics" to true, |
| | | "balance" to it.balance |
| | | ) |
| | | payDialog.setCallback(object : PayDialog.Callback { |
| | | override fun onOk(way: Int, couponId: Int, useRed: Boolean) { |
| | | if (way == 2) { |
| | | val dialog = ChooseCardDialog() |
| | | dialog.setCallback(object : StringCallback { |
| | | override fun onRlt(rlt: String) { |
| | | pay(topAct, orderId, way, money) |
| | | } |
| | | }) |
| | | dialog.show(topAct.supportFragmentManager, "card") |
| | | } else { |
| | | pay(topAct, orderId, way, money) |
| | | } |
| | | payDialog.dismiss() |
| | | } |
| | | |
| | | override fun onClose() { |
| | | confirmDifferencePrice(topAct, orderId, money, 3) |
| | | } |
| | | }) |
| | | payDialog.show(topAct.supportFragmentManager, "pay") |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private fun pay(act: BaseActivity, orderId: Int, way: Int, money: Double) { |
| | | HttpManager.payOrderLogisticsSpread(orderId, way).request(act, showDialog = true) { _, data -> |
| | | myToast(getString(R.string.支付成功)) |
| | | } |
| | | } |
| | | |
| | | private fun confirmDifferencePrice(act: BaseActivity, orderId: Int, money: Double, state: Int, block: (() -> Unit)? = null) { |
| | | HttpManager.confirmDifferencePrice(orderId, money, state).request(act, showDialog = true) { _, _ -> |
| | | block?.invoke() |
| | | } |
| | | } |
| | | |
| | | private fun sendHeart() { |
| | | val userId = SPUtils.instance().getInt(Const.User.USER_ID) |
| | | val token = SPUtils.instance().getString(Const.User.TOKEN) |
| | |
| | | var lat = 6.833333 |
| | | var lon = -5.25 |
| | | |
| | | var currentLatLng: LatLng = LatLng(lat, lon) // 实际定位 永远不变 上那个会被修改 |
| | | |
| | | var cityCode = "" //定位城市编码 |
| | | var address = "" //定位地址 |
| | | var chooseCityName = "——" //选择城市 |
| | |
| | | |
| | | } |
| | | |
| | | override fun onActivityStarted(p0: Activity) { |
| | | override fun onActivityStarted(activity: Activity) { |
| | | Log.d("zmc-pageA", "onActivityStarted: " + activity.javaClass.name) |
| | | } |
| | | |
| | | override fun onActivityDestroyed(p0: Activity) { |
| | | activities.remove(p0) |
| | | override fun onActivityDestroyed(activity: Activity) { |
| | | activities.remove(activity) |
| | | Log.d("zmc-pageA", "onActivityDestroyed: " + activity.javaClass.name) |
| | | } |
| | | |
| | | override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) { |
| | | } |
| | | |
| | | override fun onActivityStopped(p0: Activity) { |
| | | override fun onActivityStopped(activity: Activity) { |
| | | Log.e("zmc-pageA", "onActivityStopped: " + activity.javaClass.name) |
| | | } |
| | | |
| | | override fun onActivityCreated(p0: Activity, p1: Bundle?) { |
| | | activities.add(p0) |
| | | override fun onActivityCreated(activity: Activity, p1: Bundle?) { |
| | | activities.add(activity) |
| | | Log.i("zmc-pageA", "onActivityCreated: " + activity.javaClass.name) |
| | | if (activity is AppCompatActivity) { |
| | | activity.supportFragmentManager.registerFragmentLifecycleCallbacks(object : |
| | | FragmentManager.FragmentLifecycleCallbacks() { |
| | | override fun onFragmentCreated(fm: FragmentManager, f: Fragment, savedInstanceState: Bundle?) { |
| | | super.onFragmentCreated(fm, f, savedInstanceState) |
| | | Log.i("zmc-pageF", "onFragmentCreated: " + f.javaClass.name) |
| | | } |
| | | |
| | | override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) { |
| | | super.onFragmentDestroyed(fm, f) |
| | | Log.e("zmc-pageF", "onFragmentDestroyed: " + f.javaClass.name) |
| | | } |
| | | }, true) |
| | | } |
| | | } |
| | | |
| | | override fun onActivityResumed(p0: Activity) { |