[6.2.10][蘑方功能优化] ui修正
This commit is contained in:
@@ -14,16 +14,18 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.devatools.*
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import kotlinx.android.synthetic.main.view_blue_tooth.view.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
/**
|
||||
* 魔戒蓝牙控件
|
||||
* 放置于StatusBar右侧位置
|
||||
*/
|
||||
open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListener, IMoGoAutopilotStatusListener {
|
||||
open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListener, IMoGoAutopilotStatusListener, NetworkUtils.OnNetworkStatusChangedListener {
|
||||
|
||||
constructor(context: Context) : this(context, null)
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
@@ -33,8 +35,6 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
LayoutInflater.from(context).inflate(R.layout.view_blue_tooth
|
||||
, this, true)
|
||||
visibility = View.GONE
|
||||
clipChildren = false
|
||||
clipToPadding = false
|
||||
onClick {
|
||||
runCatching {
|
||||
val mofang = CallerDevaToolsManager.mofang()
|
||||
@@ -50,6 +50,8 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
private const val TAG = "BlueToothView"
|
||||
}
|
||||
|
||||
private val power by lazy { AtomicInteger(1) }
|
||||
|
||||
private val prevTime by lazy { AtomicLong(0) }
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
@@ -66,6 +68,34 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
}
|
||||
CallerDevaToolsManager.mofang()?.registerMoFangStatusListener(TAG, this)
|
||||
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this)
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
post {
|
||||
runCatching {
|
||||
ivMoFangStatus?.background = (ContextCompat.getDrawable(context, R.drawable.icon_mofang_ipc_disconnected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConnected(networkType: NetworkUtils.NetworkType?) {
|
||||
when(power.get()) {
|
||||
-1 -> {
|
||||
post {
|
||||
runCatching {
|
||||
ivMoFangStatus?.background = (ContextCompat.getDrawable(context, R.drawable.icon_mofang_low_power))
|
||||
}
|
||||
}
|
||||
}
|
||||
1 -> {
|
||||
post {
|
||||
runCatching {
|
||||
ivMoFangStatus?.background = (ContextCompat.getDrawable(context, R.drawable.icon_mofang_normal_power))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
@@ -84,6 +114,7 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
super.onDetachedFromWindow()
|
||||
CallerDevaToolsManager.mofang()?.unRegisterMoFangStatusListener(this)
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this)
|
||||
}
|
||||
|
||||
override fun onMoFangConnected() {
|
||||
@@ -99,6 +130,7 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
override fun onMoFangBatteryChanged(battery: Int) {
|
||||
if (CallerAutoPilotStatusListenerManager.isConnect()) {
|
||||
if (battery <= 30) {
|
||||
power.set(-1)
|
||||
post {
|
||||
runCatching {
|
||||
val prev = prevTime.get()
|
||||
@@ -111,6 +143,7 @@ open class BlueToothView: LinearLayout, IMoGoMoFangProvider.OnMoFangStatusListen
|
||||
}
|
||||
}
|
||||
} else {
|
||||
power.set(1)
|
||||
post {
|
||||
runCatching {
|
||||
ivMoFangStatus?.background = (ContextCompat.getDrawable(context, R.drawable.icon_mofang_normal_power))
|
||||
|
||||
Reference in New Issue
Block a user