Skip to content

Commit

Permalink
[新增]加载框关闭方法
Browse files Browse the repository at this point in the history
  • Loading branch information
awakem committed May 17, 2023
1 parent 77513ce commit 01f24ad
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class DialogBuilder : BaseDialogBuilder() {
activity: AppCompatActivity,
msg: String = DialogHelp.getString(R.string.loading),
callback: ILoadingCallback? = null
) {
): LoadingDialogFragment{
val mFragmentManage = activity.supportFragmentManager
val mHistoryDialog = mFragmentManage.findFragmentByTag("LoadingDialog")
if (mHistoryDialog != null && mHistoryDialog is LoadingDialogFragment) {
Expand All @@ -220,6 +220,7 @@ class DialogBuilder : BaseDialogBuilder() {
mLoadingDialog.setMainTextInfo(mMainTextInfo)
mLoadingDialog.setCallback(callback)
mLoadingDialog.showNow(mFragmentManage, "LoadingDialog")
return mLoadingDialog
}

/**
Expand Down
19 changes: 19 additions & 0 deletions EaseDialogModule/src/main/java/com/night/dialog/DialogTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.night.dialog

import android.view.Gravity
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hjq.toast.ToastParams
import com.hjq.toast.Toaster
import com.night.dialog.callback.IBindView
import com.night.dialog.tools.ToastHelp
import com.night.dialog.ui.loading.LoadingDialogFragment

object DialogTools {

Expand Down Expand Up @@ -43,10 +45,27 @@ object DialogTools {
}
}
}

/**
* 关闭Toast
*/
fun dismissToast() {
Toaster.cancel()
}

/**
* 关闭加载框
*
* @param activity AppCompatActivity
*/
fun dismissLoadingDialog(activity: AppCompatActivity) {
val mFragmentManage = activity.supportFragmentManager
val mHistoryDialog = mFragmentManage.findFragmentByTag("LoadingDialog")
if (mHistoryDialog != null && mHistoryDialog is LoadingDialogFragment) {
mHistoryDialog.dismiss()
}
}

fun getDialogBuilder(): DialogBuilder {
return DialogBuilder()
}
Expand Down
294 changes: 150 additions & 144 deletions app/src/main/java/com/night/easedialog/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.night.easedialog
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.MotionEvent
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
Expand Down Expand Up @@ -41,163 +43,167 @@ class MainActivity : AppCompatActivity() {
"周日", "周一", "周二", "周三", "周四", "周五", "周六", "黑色星期一"
)
private val mSelectMultipleIndex = mutableListOf<Int>()

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mTipsView = findViewById(R.id.btn_tips_dialog)
mWarnView = findViewById(R.id.btn_warn_dialog)
mSingleView = findViewById(R.id.btn_single_dialog)
mMultipleView = findViewById(R.id.btn_multiple_dialog)
mSingleMenuleView = findViewById(R.id.btn_single_menu)
mDateTimePickerleView = findViewById(R.id.btn_date_time_picker)
mAddressPickerleView = findViewById(R.id.btn_address_picker)
mColorPickerleView = findViewById(R.id.btn_color_picker)
mLoadingView = findViewById(R.id.btn_loading)
mToastView = findViewById(R.id.btn_toast)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mTipsView = findViewById(R.id.btn_tips_dialog)
mWarnView = findViewById(R.id.btn_warn_dialog)
mSingleView = findViewById(R.id.btn_single_dialog)
mMultipleView = findViewById(R.id.btn_multiple_dialog)
mSingleMenuleView = findViewById(R.id.btn_single_menu)
mDateTimePickerleView = findViewById(R.id.btn_date_time_picker)
mAddressPickerleView = findViewById(R.id.btn_address_picker)
mColorPickerleView = findViewById(R.id.btn_color_picker)
mLoadingView = findViewById(R.id.btn_loading)
mToastView = findViewById(R.id.btn_toast)

//提示性质模态框
mTipsView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("允许日历联网")
.setMainText("下载或更新节假日、班休、历法、订阅等信息。")
.setPositiveTextColor(Color.RED)
.toTipsDialog(this, object : ITipsModalCallback {
override fun onPositive() {
DialogTools.getToastBuilder().toToast("点击确定")
}
//提示性质模态框
mTipsView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("允许日历联网")
.setMainText("下载或更新节假日、班休、历法、订阅等信息。")
.setPositiveTextColor(Color.RED)
.toTipsDialog(this, object : ITipsModalCallback {
override fun onPositive() {
DialogTools.getToastBuilder().toToast("点击确定")
}

override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//警告性质模态框
mWarnView.setOnClickListener {
DialogTools.getDialogBuilder()
.setMainText("确定删除当前联系人?")
.setPositiveTextColor(Color.RED)
.setPositiveText("删除")
.toWarnDialog(this, object : IWarnModalCallback {
override fun onPositive() {
DialogTools.getToastBuilder().toToast("点击确定")
override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//警告性质模态框
mWarnView.setOnClickListener {
DialogTools.getDialogBuilder()
.setMainText("确定删除当前联系人?")
.setPositiveTextColor(Color.RED)
.setPositiveText("删除")
.toWarnDialog(this, object : IWarnModalCallback {
override fun onPositive() {
DialogTools.getToastBuilder().toToast("点击确定")
}

override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
})
}
//底部单选菜单
mSingleView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("重复")
.toSingleMenu(
this,
mSingleList,
mSelectSingleIndex,
object : ISingleMenuCallback {
override fun onPositive(title: String, menuIndex: Int) {
mSelectSingleIndex = menuIndex
DialogTools.getToastBuilder().toToast("选中内容:$title")
}
//底部单选菜单
mSingleView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("重复")
.toSingleMenu(
this,
mSingleList,
mSelectSingleIndex,
object : ISingleMenuCallback {
override fun onPositive(title: String, menuIndex: Int) {
mSelectSingleIndex = menuIndex
DialogTools.getToastBuilder().toToast("选中内容:$title")
}

override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//底部多选菜单
mMultipleView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("重复")
.toMultipleMenu(this, mMultipleList, mSelectMultipleIndex,
object : IMultipleMenuCallback {
override fun onPositive(title: List<String>, menuIndex: List<Int>) {
mSelectMultipleIndex.clear()
mSelectMultipleIndex.addAll(menuIndex)
DialogTools.getToastBuilder().toToast("选中内容:${menuIndex.size}")
}
override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//底部多选菜单
mMultipleView.setOnClickListener {
DialogTools.getDialogBuilder()
.setTitleText("重复")
.toMultipleMenu(this, mMultipleList, mSelectMultipleIndex,
object : IMultipleMenuCallback {
override fun onPositive(title: List<String>, menuIndex: List<Int>) {
mSelectMultipleIndex.clear()
mSelectMultipleIndex.addAll(menuIndex)
DialogTools.getToastBuilder().toToast("选中内容:${menuIndex.size}")
}

override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//时间日期选择器
mDateTimePickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择日期和时间")
.setMinDateTime(mStartDateTime)
.setMaxDateTime(mEndDateTime)
.setSelDateTime(mSelectDateTime)
.toDateTimePicker(this, PICKER_ALL, object : IDateTimeCallback {
override fun onPositive(result: EaseDateTimeEntity) {
DialogTools.getToastBuilder()
.toToast(result.getDateTime())
override fun onCancel() {
DialogTools.getToastBuilder().toToast("点击取消")
}
})
}
//时间日期选择器
mDateTimePickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择日期和时间")
.setMinDateTime(mStartDateTime)
.setMaxDateTime(mEndDateTime)
.setSelDateTime(mSelectDateTime)
.toDateTimePicker(this, PICKER_ALL, object : IDateTimeCallback {
override fun onPositive(result: EaseDateTimeEntity) {
DialogTools.getToastBuilder()
.toToast(result.getDateTime())
}

override fun onCancel() {
super.onCancel()
DialogTools.getToastBuilder()
.toToast("取消")
override fun onCancel() {
super.onCancel()
DialogTools.getToastBuilder()
.toToast("取消")
}
})
}
})
}
//地址选择器
mAddressPickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择地址")
.setSelectProvince(mProvince)
.setSelectCity(mCity)
.setSelectCounty(mCounty)
.toAddressPicker(this, PICKER_ADDRESS_PROVINCE_CITY, object : ILocationCallback {
override fun onPositive(
province: EaseLocationEntity,
city: EaseLocationEntity,
county: EaseLocationEntity
) {
mProvince = province
mCity = city
mCounty = county
DialogTools.getToastBuilder().toToast(province.name + city.name + county.name)
//地址选择器
mAddressPickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择地址")
.setSelectProvince(mProvince)
.setSelectCity(mCity)
.setSelectCounty(mCounty)
.toAddressPicker(this, PICKER_ADDRESS_PROVINCE_CITY, object : ILocationCallback {
override fun onPositive(
province: EaseLocationEntity,
city: EaseLocationEntity,
county: EaseLocationEntity
) {
mProvince = province
mCity = city
mCounty = county
DialogTools.getToastBuilder().toToast(province.name + city.name + county.name)
}
})
}
})
}
//颜色选择器
mColorPickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择颜色")
.toColorPicker(this, object : IColorSelectCallback {
override fun onPositive(red: Int, green: Int, blue: Int) {
DialogTools.getToastBuilder()
.toToast("R:".plus(red).plus("|G:").plus(green).plus("|B:").plus(blue))
//颜色选择器
mColorPickerleView.setOnClickListener {
DialogTools.getPickerBuilder()
.setTitleText("请选择颜色")
.toColorPicker(this, object : IColorSelectCallback {
override fun onPositive(red: Int, green: Int, blue: Int) {
DialogTools.getToastBuilder()
.toToast("R:".plus(red).plus("|G:").plus(green).plus("|B:").plus(blue))
}
})
}
})
}
//加载框
mLoadingView.setOnClickListener {
DialogTools.getDialogBuilder()
.toLoadingDialog(this, "正在加载中...")
}
//Toast
mToastView.setOnClickListener {
DialogTools.getToastBuilder()
.toToast("文件删除成功~")
}
//单选菜单
//加载框
mLoadingView.setOnClickListener {
val mLoading = DialogTools.getDialogBuilder()
.toLoadingDialog(this, "3秒...")
Handler(Looper.getMainLooper()).postDelayed({
mLoading.dismiss()
},3000)

mSingleMenuleView.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) {
DialogTools.getDialogBuilder()
.setTouchCoordinate(event.x, event.y, event.rawX, event.rawY)
.toPopMenu(this, v, mutableListOf("删除", "编辑", "复制"), object : IPopMenuCallback {
override fun onPositive(title: String, menuIndex: Int) {
DialogTools.getToastBuilder().toToast(title)
}
})
}
true
}
}
//Toast
mToastView.setOnClickListener {
DialogTools.getToastBuilder()
.toToast("文件删除成功~")
}
//单选菜单
mSingleMenuleView.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) {
DialogTools.getDialogBuilder()
.setTouchCoordinate(event.x, event.y, event.rawX, event.rawY)
.toPopMenu(this, v, mutableListOf("删除", "编辑", "复制"), object : IPopMenuCallback {
override fun onPositive(title: String, menuIndex: Int) {
DialogTools.getToastBuilder().toToast(title)
}
})
}
true
}
}
}

0 comments on commit 01f24ad

Please sign in to comment.