彈框?qū)崿F(xiàn) 盡量使用Activity dialog只能寄托在activity或者activity的context上连舍,使用application的context會報錯害碾。
實現(xiàn)步驟
1详幽、
<activity
android:name=".module.v2.home.activity.NotifyActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/tran_style" />
<style name="tran_style" parent="Theme.AppCompat.Light">
<!-- 是否支持透window明度 -->
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@color/transparent_20</item>
<item name="android:windowNoTitle">true</item>
<!-- 隱藏狀態(tài)欄 -->
<item name="android:windowFullscreen">false</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
2畜份、
package com.cias.vas.lib.module.v2.home.activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.cias.core.utils.AppManager
import com.cias.core.utils.ToastUtil
import com.cias.vas.lib.R
import com.cias.vas.lib.base.model.BaseResponseV2Model
import com.cias.vas.lib.common.pushconst.PushModel
import com.cias.vas.lib.common.zdqconst.IntentConstant
import com.cias.vas.lib.data.RetrofitRiskClient
import com.cias.vas.lib.module.v2.home.model.PushDataModel
import com.cias.vas.lib.module.v2.order.activity.AuditDetailActivity
import com.cias.vas.lib.module.v2.order.activity.GrabOrderDetailActivity
import com.cias.vas.lib.module.v2.order.activity.OrderDetailActivity
import com.cias.vas.lib.module.v2.order.activity.TakeOrderDetailActivity
import com.cias.vas.lib.module.v2.order.model.*
import com.google.gson.Gson
import com.gyf.immersionbar.ImmersionBar
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
/**
*
* @Description:
* @Author: zhoudequn
* @CreateDate: 2022/2/24 10:51
*/
class NotifyActivity : AppCompatActivity() {
companion object {
val CONTENT: String = "content"
val MESSAGE_TYPE: String = "messageType"
val DATA: String = "data"
}
lateinit var mTvTitle: TextView
lateinit var mTvContent: TextView
lateinit var mTvOk: TextView
lateinit var mTvLook: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ImmersionBar.with(this).fitsSystemWindows(false)
.statusBarColor(R.color.white).statusBarDarkFont(true, 0.2f)
.init()
supportActionBar?.hide()
setContentView(R.layout.activity_notify)
mTvTitle = findViewById(R.id.tv_title)
mTvContent = findViewById<TextView>(R.id.tv_content)
mTvOk = findViewById(R.id.tv_ok)
mTvLook = findViewById(R.id.tv_look)
findViewById<TextView>(R.id.tv_ok)
.setOnClickListener {
finish()
}
intentGetTypeAndContent()
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intentGetTypeAndContent()
}
private fun intentGetTypeAndContent() {
val msgType = intent?.getStringExtra(MESSAGE_TYPE)
val content = intent?.getStringExtra(CONTENT)
val data = intent?.getStringExtra(DATA)
var pushdataModel: PushDataModel? = null
if (!TextUtils.isEmpty(data)) {
pushdataModel = Gson().fromJson(data, PushDataModel::class.java)
}
mTvContent.text = content
when (msgType) {
PushModel.CREATE_ORDER -> {
mTvLook.visibility = View.GONE
mTvOk.text = getString(R.string.vas_sure)
mTvOk.setOnClickListener {
finish()
}
}
PushModel.CANCEL_ORDER -> {
mTvLook.visibility = View.GONE
mTvOk.text = "關(guān)閉"
mTvOk.setOnClickListener {
//隅很、在訂單詳情頁(含搶單詳情頁面)寄症,當(dāng)前訂單任務(wù)狀態(tài)流轉(zhuǎn)至 已取消 或 已辦理 或 服務(wù)人員變更
// 序愚,有推送彈窗憔披,關(guān)閉彈窗后返回到【作業(yè)列表】頁面
closeByTaskStatus(pushdataModel)
// finish()
}
}
PushModel.RE_AUDIT_ORDER -> {
mTvLook.visibility = View.VISIBLE
mTvOk.text = "稍后查看"
mTvLook.setOnClickListener {
//進入詳情訂單
jumpDetailByOrderInfo(pushdataModel!!)
finish()
}
mTvOk.setOnClickListener {
finish()
}
}
PushModel.CANCEL_REJECT -> {
mTvLook.visibility = View.VISIBLE
mTvOk.text = "稍后查看"
mTvLook.setOnClickListener {
//請求詳情接口 然后跳轉(zhuǎn)到詳情頁面
val reqModel = OrderDetailReqModel()
reqModel.orderNo = pushdataModel!!.orderNo
reqModel.taskNo = pushdataModel!!.taskNo
queryOrderDetail(reqModel)
finish()
}
mTvOk.setOnClickListener {
finish()
}
}
PushModel.UPDATE_ORDER, PushModel.REMIND_ORDER -> {
mTvLook.visibility = View.GONE
mTvOk.text = "我知道了"
mTvOk.setOnClickListener {
finish()
}
}
//產(chǎn)品變更 單獨設(shè)置標(biāo)題 內(nèi)容
PushModel.CHANGE_ORDER -> {
mTvTitle.text = "產(chǎn)品變更"
mTvLook.visibility = View.GONE
mTvOk.text = "關(guān)閉"
if (!TextUtils.isEmpty(data)) {
val productChangeModel =
Gson().fromJson(data, PushProductChangeEventModel::class.java)
productChange(productChangeModel)
}
mTvOk.setOnClickListener {
goHome()
finish()
}
}
}
}
private fun closeByTaskStatus(item: PushDataModel?) {
var tempTaskNo: String? = null
//如果任務(wù)棧中有訂單詳情 并且任務(wù)號一樣 點擊關(guān)閉回到列表
val currentAct = AppManager.getAppManager().currentActivity()
if (currentAct != null) {
if (currentAct is GrabOrderDetailActivity) {
tempTaskNo = currentAct.mTaskNo
}
if (currentAct is TakeOrderDetailActivity) {
tempTaskNo = currentAct.mTaskNo
}
}
if (item?.taskNo.equals(tempTaskNo)) {
goHome()
}
finish()
}
private fun goHome() {
val intent = Intent(this, HomeV2Activity::class.java)
startActivity(intent)
}
private fun jumpDetailByOrderInfo(item: PushDataModel) {
when (item.cateGoryCode) {
OrderServiceType.RESCUE_NO_DESTINATION, OrderServiceType.RESCUE_HAS_DESTINATION -> {
when (item.orderStatus) {
OrderStatusType.AUDIT_RETURN, OrderStatusType.SETTLEMENT_RETURN -> {
jumpAuditDetail(item)
}
else -> {
when (item.taskStatus) {
TaskStatus.TAKE, TaskStatus.START, TaskStatus.ARRIVE,
TaskStatus.WORK_START, TaskStatus.WORK_END,
-> {
jumpNewOrderDetail(item)
}
else -> {
jumpAuditDetail(item)
}
}
}
}
}
else -> {
jumpOldOrderDetail(item)
}
}
}
private fun productChange(model: PushProductChangeEventModel) {
val sb = StringBuilder()
sb.append("變更后\n\n")
sb.append(model.changeRemark + "\n\n")
sb.append("優(yōu)惠內(nèi)容:")
if (!TextUtils.isEmpty(model.rightTypeName)) {
sb.append(model.rightTypeName + ",")
}
model?.extraProductDiscount?.forEach {
if (it == model?.extraProductDiscount!!.last()) {
sb.append(it.name)
if (it.value > 0) {
sb.append("(" + it.value + ")")
}
} else {
sb.append(it.name)
if (it.value > 0) {
sb.append("(" + it.value + "),")
}
}
}
mTvContent.text = sb.toString()
}
private fun jumpNewOrderDetail(item: PushDataModel) {
val intent = Intent(this, TakeOrderDetailActivity::class.java)
intent.putExtra(IntentConstant.INTENT_KEY_1, item.orderNo)
intent.putExtra(IntentConstant.INTENT_KEY_2, item.taskNo)
startActivity(intent)
}
private fun jumpAuditDetail(item: PushDataModel) {
val intent = Intent(this, AuditDetailActivity::class.java)
intent.putExtra(IntentConstant.INTENT_KEY_1, item.orderNo)
intent.putExtra(IntentConstant.INTENT_KEY_2, item.taskNo)
startActivity(intent)
}
private fun jumpOldOrderDetail(item: PushDataModel) {
val intent = Intent(this, OrderDetailActivity::class.java)
intent.putExtra(IntentConstant.INTENT_KEY_1, item.orderNo)
intent.putExtra(IntentConstant.INTENT_KEY_2, item.taskNo)
startActivity(intent)
}
fun queryOrderDetail(reqModel: OrderDetailReqModel) {
RetrofitRiskClient.getInstance().apiService.queryOrderDetail(reqModel)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<BaseResponseV2Model<OrderInfoModel>> {
override fun onNext(t: BaseResponseV2Model<OrderInfoModel>) {
if (200 == t.code && t?.data != null) {
val model = PushDataModel()
model.orderNo = t.data.orderNo
model.taskNo = t.data.taskNo
model.cateGoryCode = t.data.appServiceType
model.orderStatus = t.data.orderStatus
model.taskStatus = t.data.taskStatus
jumpDetailByOrderInfo(model)
}
}
override fun onSubscribe(d: Disposable) {
}
override fun onError(e: Throwable) {
ToastUtil.show(e.message)
}
override fun onComplete() {
}
})
}
override fun onBackPressed() {
}
}