弹框实现 尽量使用Activity dialog只能寄托在activity或者activity的context上,使用application的context会报错。
实现步骤
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>
<!-- 隐藏状态栏 -->
<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 = "关闭"
mTvOk.setOnClickListener {
//、在订单详情页(含抢单详情页面),当前订单任务状态流转至 已取消 或 已办理 或 服务人员变更
// ,有推送弹窗,关闭弹窗后返回到【作业列表】页面
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 {
//请求详情接口 然后跳转到详情页面
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()
}
}
//产品变更 单独设置标题 内容
PushModel.CHANGE_ORDER -> {
mTvTitle.text = "产品变更"
mTvLook.visibility = View.GONE
mTvOk.text = "关闭"
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
//如果任务栈中有订单详情 并且任务号一样 点击关闭回到列表
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("优惠内容:")
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() {
}
}
网友评论