GLDriver/app/src/main/java/com/dahe/gldriver/utils/CommonPopUtils.kt

165 lines
4.7 KiB
Kotlin

package com.dahe.gldriver.utils
import android.content.Context
import android.graphics.Color
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.dahe.gldriver.R
import com.dahe.gldriver.bean.AppVersion
import com.dahe.gldriver.bean.CarBean
import com.dahe.gldriver.callback.OnResultListener
import com.dahe.gldriver.mypop.AgreementAlert
import com.dahe.gldriver.mypop.OnCarSelectListener
import com.dahe.gldriver.mypop.PopBottomCar
import com.dahe.gldriver.weight.pop.UpAppPop
import com.dahe.mylibrary.base.SingletonNoPHolder
import com.dahe.mylibrary.utils.ConvertUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.interfaces.OnConfirmListener
import com.lxj.xpopup.interfaces.OnInputConfirmListener
import com.lxj.xpopup.util.SmartGlideImageLoader
/**
* @ClassName CommonPopUtils
* @Author john
* @Date 2024/3/5 15:48
* @Description TODO
*/
class CommonPopUtils private constructor() {
companion object : SingletonNoPHolder<CommonPopUtils>(::CommonPopUtils)
/**
* 选择车辆
* */
fun showCarList(context: Context, cars: MutableList<CarBean>, listener: OnCarSelectListener) {
XPopup.Builder(context)
.isViewMode(true)
// .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个
.asCustom(PopBottomCar(context, cars, listener))
.show()
}
/**
* 首次打开app弹窗
* @param context Context
* @param listener OnResultListener
*/
fun showCenterAgreement(context: Context, listener: OnResultListener) {
XPopup.Builder(context)
.dismissOnBackPressed(false)
.dismissOnTouchOutside(false)
.asCustom(
AgreementAlert(
context, "https://agreement.dahehuoyun.com/huawei/#/private",
"http://agreement.dahehuoyun.com/#/user", listener
)
)
.show()
}
/**
* 装货弹框
* */
fun showLoadPop(context: Context, carBean: CarBean, listener: OnConfirmListener) {
XPopup.Builder(context)
.isDestroyOnDismiss(true)
.asConfirm(
"去装货", """已选择:${carBean.vehicleNum},是否立即装货""",
"取消", "确定",
listener, null, false
)
.show()
}
/**
*
* @param context Context
* @param title String
* @param content String
* @param listener OnConfirmListener
*/
fun showCommCenterPop(
context: Context,
title: String = "提示",
content: String,
listener: OnConfirmListener,
) {
XPopup.Builder(context)
.isDestroyOnDismiss(true)
.asConfirm(
title, content,
"取消", "确定",
listener, null, false
)
.show()
}
/**
* 弹出带有输入框的
* @param context Context
* @param title String
* @param listener OnInputConfirmListener
*/
fun showCenterInputPop(context: Context, title: String, listener: OnInputConfirmListener) {
XPopup.Builder(context)
.hasStatusBarShadow(false)
.hasNavigationBar(false)
.autoOpenSoftInput(true)
.asInputConfirm(title, "", "请输入拒绝原因", listener)
.show()
}
/**
* 展示图片
* @param context Context
* @param position Int
* @param recyclerView RecyclerView
* @param mutableList MutableList<Any>
*/
fun showPics(
context: Context,
imageView: ImageView? = null,
position: Int,
recyclerView: RecyclerView,
mutableList: List<Any>
) {
XPopup.Builder(context) //.animationDuration(1000)
.isTouchThrough(true)
.asImageViewer(
imageView, position, mutableList,
false, true, -1, -1, ConvertUtils.dp2px(10F), false,
Color.rgb(32, 36, 46),
{ popupView, position ->
popupView.updateSrcView(recyclerView.getChildAt(position) as ImageView)
}, SmartGlideImageLoader(true, R.mipmap.ic_launcher), null
)
.show()
}
/**
* app版本检查
* @param context Context
* @param appVersion AppVersion
*/
fun showUpApp(context: Context, appVersion: AppVersion) {
XPopup.Builder(context)
.dismissOnBackPressed(false)
.dismissOnTouchOutside(false)
.asCustom(
UpAppPop(
context,
appVersion
)
)
.show()
}
}