From 9404fc9fce1d2f8678a5d1e6da2374b7a67783fe Mon Sep 17 00:00:00 2001
From: 18034727885 <973609879@qq.com>
Date: 星期四, 10 九月 2026 16:55:57 +0800
Subject: [PATCH] 修复问题,升级版本
---
app/src/main/java/com/driver/igotrip/base/MyApplication.kt | 187 ++++++++++++++++++++++++++++++++++++----------
1 files changed, 146 insertions(+), 41 deletions(-)
diff --git a/app/src/main/java/com/driver/igotrip/base/MyApplication.kt b/app/src/main/java/com/driver/igotrip/base/MyApplication.kt
index 9ac11c8..30293d7 100644
--- a/app/src/main/java/com/driver/igotrip/base/MyApplication.kt
+++ b/app/src/main/java/com/driver/igotrip/base/MyApplication.kt
@@ -12,6 +12,8 @@
import android.os.*
import android.util.Log
import android.view.View
+import android.widget.ImageView
+import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import cn.sinata.rxnetty.LogHelper.initLogs
@@ -24,16 +26,31 @@
import com.driver.igotrip.bean.OrderSimpleData
import com.driver.igotrip.bean.websocket.HeartBean
import com.driver.igotrip.netUtls.*
+import com.driver.igotrip.service.LocationForegroundService
+import com.driver.igotrip.ui.main.MainActivity
import com.driver.igotrip.ui.main.small_cargo.SmallCargoActivity
import com.driver.igotrip.ui.pub.LoginActivity
import com.driver.igotrip.utils.AudioRecoderUtils
import com.driver.igotrip.utils.Cache.CacheKey
import com.driver.igotrip.utils.Cache.CacheUtil
+import com.driver.igotrip.utils.LanguageSP
+import com.driver.igotrip.utils.LanguageSP.LanguageConst
import com.driver.igotrip.utils.LogUtils
import com.driver.igotrip.utils.crash.CrashHandler
+import com.driver.igotrip.utils.glide.GlideUtil
import com.google.android.gms.maps.model.LatLng
import com.google.cloud.texttospeech.v1.*
import com.google.gson.Gson
+import com.petterp.floatingx.app.AppHost
+import com.petterp.floatingx.core.FloatingX
+import com.petterp.floatingx.core.FxControl
+import com.petterp.floatingx.core.FxListener
+import com.petterp.floatingx.core.layout.FxAdsorb
+import com.petterp.floatingx.core.layout.FxEdge
+import com.petterp.floatingx.core.layout.FxGravity
+import com.petterp.floatingx.core.storage.FxSpStorage
+import com.petterp.floatingx.system.permission.FxPermissionStrategy
+import com.petterp.floatingx.system.systemHost
import com.xuexiang.xui.XUI
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
@@ -92,7 +109,7 @@
private val MSG_ORDER_CANCEL = 1002
@SuppressLint("HandlerLeak")
- private val mHandler: Handler = object : Handler() {
+ private val mHandler: Handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
super.handleMessage(msg)
when (msg.what) {
@@ -158,32 +175,6 @@
}
}
-// private val mAliasCallback =
-// TagAliasCallback { code, alias, tags ->
-// val logs: String
-// when (code) {
-// 0 -> {
-// logs = "Set tag and alias success"
-// Log.i("TAG", logs)
-// }
-//
-// 6002 -> {
-// logs = "Failed to set alias and tags due to timeout. Try again after 60s."
-// Log.i("TAG", logs)
-// // 延迟 60 秒来调用 Handler 设置别名
-// var alisa = "DRIVER" + CacheKey.getUserId()
-// Handler().postDelayed({
-// JPushInterface.setAliasAndTags(this, alisa, null, null)
-// }, 60 * 1000)
-// }
-//
-// else -> {
-// logs = "Failed with errorCode = $code"
-// Log.e("TAG", logs)
-// }
-// }
-// }
-
private fun initSocket() {
NettyClient.getInstance().init(this, Api.SOCKET_SERVER, Api.SOCKET_PORT, true)
NettyClient.getInstance().addOnMessageListener { message: String ->
@@ -220,6 +211,8 @@
CacheUtil.get().clear()
CacheKey.putKeyStr("isAgreen", "1")
NettyClient.getInstance().stopService()
+ couldShowFloatingWindow = false
+ LocationForegroundService.stop()
isLogin = false
val intent = Intent()
intent.setClass(this, LoginActivity::class.java)
@@ -391,18 +384,15 @@
logRecord("socket==>订单超时:$jsob")
val act = getTopActivity()
- /**
- * 司机超时推送
- * @param timeOutType 超时类型(1=用户可免费取消提醒,2=预约单接单提醒,3=超时循环提醒)
- * @param orderId 订单id
- * @param orderType 订单类型(1=打车,4=包裹)
- * @param describe 展示内容
- * @param audioUrl 语音播报音频地址
- */
+ //超时类型(1=用户可免费取消提醒,2=预约单接单提醒,3=超时循环提醒)
val timeOutType = jsob.optString("timeOutType")
+ //订单id
val orderId = jsob.optString("orderId")
+ //订单类型(1=打车,4=包裹)
val orderType = jsob.optString("orderType")
+ //展示内容
val describe = jsob.optString("describe")
+ //语音播报音频地址
val audioUrl = jsob.optString("audioUrl")
if (timeOutType == "1" || timeOutType == "3") { // 仅提示
@@ -528,6 +518,31 @@
var lastPlayTime = 0L //上次提示播放时间
var hasAutoGoTripping = false //true 本次启动已经自动跳转过
var isLogin: Boolean = true
+
+ //是否在上班
+ var isWorking = false
+ set(value) {
+ field = value
+ refreshFloatingWindow()
+ }
+ private var aMapLocation: LatLng? = null
+ var currentOrderId: String = ""
+ var currentOrderType: String = ""
+ var orderStatueViews: MutableList<OrderStatueView> = mutableListOf()
+
+ //悬浮窗tag
+ private const val FLOATING_X_TAG = "GO POST DRIVER"
+
+ //是否能显示悬浮窗
+ @JvmStatic
+ var couldShowFloatingWindow = false
+ set(value) {
+ field = value
+ if (!value) {
+ dismissFloatingWindow()
+ }
+ }
+
fun getInstance(): MyApplication? {
if (appContext == null) {
appContext = MyApplication()
@@ -545,11 +560,6 @@
fun getLocation(): LatLng? {
return aMapLocation
}
-
- private var aMapLocation: LatLng? = null
- var currentOrderId: String = ""
- var currentOrderType: String = ""
- var orderStatueViews: MutableList<OrderStatueView> = mutableListOf()
//设置定位
fun setLocation(latLng: LatLng) {
@@ -570,12 +580,94 @@
fun removeOrderView(view: OrderStatueView?) {
orderStatueViews.remove(view)
}
+
+ //显示悬浮窗
+ fun showFloatingWindow() {
+ (FloatingX.controlOrNull(FLOATING_X_TAG) ?: FloatingX.install(FLOATING_X_TAG) {
+ view { ctx ->
+ View.inflate(ctx, R.layout.fx_card, null).apply {
+ findViewById<TextView>(R.id.tv1).apply {
+ val language = LanguageSP.getLanguage(ctx)
+ text = when (language) {
+ LanguageConst.ZH_CN -> {
+ if (isWorking) "听单中" else "休息中"
+ }
+
+ LanguageConst.EN_US -> {
+ if (isWorking) "GO" else "On break"
+ }
+
+ else -> {
+ if (isWorking) "Aller" else "En pause"
+ }
+ }
+ }
+ findViewById<ImageView>(R.id.iv_logo).apply {
+ GlideUtil.loadResource(this, R.mipmap.ic_launcher, true)
+ }
+ }
+ }
+ anchor(FxGravity.CENTER_START)
+ adsorb(FxAdsorb.Edges(setOf(FxEdge.START, FxEdge.END)))
+ persist(FxSpStorage(appContext!!))
+ enableLog("GO POST floating")
+ systemHost(appContext!!) {
+ theme(R.style.Theme_FloatingX)
+ permission(FxPermissionStrategy.auto())
+ // this. 消歧:这里的 fallback / keyboard 既是 Builder 方法名也是本函数的参数名
+ this.fallback(AppHost.builder(appContext!!).theme(R.style.Theme_FloatingX).build())
+ }
+ }.also {
+ it.addListener(object : FxListener {
+ override fun onClick(control: FxControl, view: View) {
+ dismissFloatingWindow()
+ val activity = appContext?.getTopActivity()
+ if (activity == null) {
+ view.context.startActivity(Intent(view.context, MainActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ })
+ } else {
+ activity.startActivity<MainActivity>()
+ }
+ }
+
+ override fun onLongClick(control: FxControl, view: View) {
+
+ }
+ })
+ }).show()
+ }
+
+ //隐藏悬浮窗
+ @JvmStatic
+ fun dismissFloatingWindow() {
+ FloatingX.controlOrNull(FLOATING_X_TAG)?.hide()
+ }
+
+ //刷新悬浮窗
+ fun refreshFloatingWindow() {
+ val language = LanguageSP.getLanguage(appContext)
+ FloatingX.controlOrNull(FLOATING_X_TAG)?.contentView?.findViewById<TextView>(R.id.tv1)?.text =
+ when (language) {
+ LanguageConst.ZH_CN -> {
+ if (isWorking) "听单中" else "休息中"
+ }
+
+ LanguageConst.EN_US -> {
+ if (isWorking) "GO" else "On break"
+ }
+
+ else -> {
+ if (isWorking) "Aller" else "En pause"
+ }
+ }
+ }
}
private val activities = ArrayList<Activity?>()
//获取顶部activity
- private fun getTopActivity(): Activity? {
+ fun getTopActivity(): Activity? {
return activities.lastOrNull()
}
@@ -621,6 +713,7 @@
override fun onActivityStarted(activity: Activity) {
showNum++
+ dismissFloatingWindow()
}
override fun onActivityResumed(activity: Activity) {
@@ -643,15 +736,27 @@
}
isPlayVoice = true
}, 600)
+ if (showNum == 0 && couldShowFloatingWindow) {
+ showFloatingWindow()
+ }
}
override fun onActivityDestroyed(activity: Activity) {
logRecord("onActivityDestroyed: " + activity.javaClass.name)
activities.remove(activity)
+ if (activities.isEmpty()) {
+ couldShowFloatingWindow = false
+ dismissFloatingWindow()
+ }
}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
// logRecord("onActivitySaveInstanceState: " + activity.javaClass.name)
}
+ override fun onTerminate() {
+ super.onTerminate()
+ couldShowFloatingWindow = false
+ LocationForegroundService.stop()
+ }
}
\ No newline at end of file
--
Gitblit v1.7.1