diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8a465d42b4a0390d464b83b99e8465bba7..b589d56e9f285d8cfdc6c270853a5d439021a278 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000000000000000000000000000000000000..0c0c3383890637b4721df1f49d0b229e55c0f361 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000000000000000000000000000000000000..db5436b36ad239564258b56e945082e0491ca603 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index a4029a3f74549f6da9503d7e41abbd93b7707214..932d7db821e5f98fe82e766ace58871c0ca68c72 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,10 +4,8 @@ diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index e1eea1d6b9d84faa7006e37a676609e51525b125..0fc3113136756acc4597486432227a66d5ebe736 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8051a6f973e69a86e6f07f1a1c87f17a31c7235 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d87ec42295ca2119514992cc0487b75fd5002146..ebbea0f5e57c5219447d9294de0e3fe94dce8d8d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - - + diff --git a/LibDialog/build.gradle b/LibDialog/build.gradle index b9b49a4648cdd09c8e08155b5fd1e930de653969..64b610bd6f16ad8a0161ad814c5e96710f78ebcd 100644 --- a/LibDialog/build.gradle +++ b/LibDialog/build.gradle @@ -18,11 +18,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = JavaVersion.VERSION_17 } namespace 'com.mx.dialog' } @@ -41,6 +41,5 @@ afterEvaluate { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compileOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' } \ No newline at end of file diff --git a/LibDialog/src/main/java/com/mx/dialog/MXDialog.kt b/LibDialog/src/main/java/com/mx/dialog/MXDialog.kt index 37e51becc6439d555dd63bfd3de53fac9aefa4d5..16b981b1a0e0cf4a55e7fad281fbdc2f2e95fe31 100644 --- a/LibDialog/src/main/java/com/mx/dialog/MXDialog.kt +++ b/LibDialog/src/main/java/com/mx/dialog/MXDialog.kt @@ -55,7 +55,7 @@ object MXDialog { dialog.setMaxContentRatio(maxContentRatio) dialog.setCancelable(cancelable) dialog.setCanceledOnTouchOutside(cancelableOnTouchOutside) - dialog.setActionBtn(text = actionButtonText) { onActionClick?.invoke(true) } + dialog.addActionBtn(text = actionButtonText) { onActionClick?.invoke(true) } if (cancelable) { dialog.setCancelBtn(text = cancelButtonText) { onActionClick?.invoke(false) @@ -118,7 +118,7 @@ object MXDialog { dialog.setDismissDelay(dismissDelay) dialog.setCancelBtn(visible = false) - dialog.setActionBtn( + dialog.addActionBtn( text = actionButtonText ?: context.resources.getString(R.string.mx_dialog_button_action_text) ) diff --git a/LibDialog/src/main/java/com/mx/dialog/tip/MXTipBaseDialog.kt b/LibDialog/src/main/java/com/mx/dialog/tip/MXTipBaseDialog.kt index cbc2788a4811cb14703028598fd700cf2daf6e0e..2c5339d84d45c7fc820d05ba2d02163c61dc5822 100644 --- a/LibDialog/src/main/java/com/mx/dialog/tip/MXTipBaseDialog.kt +++ b/LibDialog/src/main/java/com/mx/dialog/tip/MXTipBaseDialog.kt @@ -3,6 +3,7 @@ package com.mx.dialog.tip import android.content.Context import android.os.Bundle import android.view.Gravity +import android.view.LayoutInflater import android.view.View import android.widget.FrameLayout import android.widget.ImageView @@ -23,13 +24,12 @@ abstract class MXTipBaseDialog(context: Context) : MXBaseCardDialog(context) { private var delayTxv: TextView? = null private var cancelBtn: TextView? = null private var btnDivider: View? = null - private var actionBtn: TextView? = null private var titleStr: CharSequence? = null private var titleGravity: Int = Gravity.LEFT private var cancelProp: MXTextProp? = null - private var actionProp: MXTextProp? = null + private val actionProps = ArrayList() private var buttonStyle = MXButtonStyle.ActionFocus private var tipType = MXDialogType.NONE @@ -67,7 +67,6 @@ abstract class MXTipBaseDialog(context: Context) : MXBaseCardDialog(context) { delayTxv = findViewById(R.id.mxDelayTxv) cancelBtn = findViewById(R.id.mxCancelBtn) btnDivider = findViewById(R.id.mxBtnDivider) - actionBtn = findViewById(R.id.mxOkBtn) } override fun onDismissTicket(maxSecond: Int, remindSecond: Int) { @@ -92,16 +91,22 @@ abstract class MXTipBaseDialog(context: Context) : MXBaseCardDialog(context) { kotlin.run { // 处理按钮 processCancelBtn() - processActionBtn() - if (cancelBtn?.visibility == View.VISIBLE || actionBtn?.visibility == View.VISIBLE) { - btnLay?.visibility = View.VISIBLE - val cornerDP = getCardBackgroundRadiusDP() - MXButtonStyle.attach( - buttonStyle, btnLay, cancelBtn, - actionBtn, btnDivider, cornerDP - ) - } else { - btnLay?.visibility = View.GONE + + val btnLay = btnLay + if (btnLay != null) { + (0..btnLay.childCount).mapNotNull { + btnLay.getChildAt(it) + }.forEachIndexed { index, view -> + if (index > 0) btnLay.removeView(view) + } + actionProps.forEachIndexed { index, actionProp -> + processActionBtn(actionProp) + } + if (cancelBtn?.visibility == View.VISIBLE || actionProps.isNotEmpty()) { + btnLay.visibility = View.VISIBLE + } else { + btnLay.visibility = View.GONE + } } } @@ -109,14 +114,17 @@ abstract class MXTipBaseDialog(context: Context) : MXBaseCardDialog(context) { MXDialogType.NONE -> { tipTypeImg?.visibility = View.GONE } + MXDialogType.SUCCESS -> { tipTypeImg?.visibility = View.VISIBLE tipTypeImg?.setImageResource(R.drawable.mx_dialog_icon_success) } + MXDialogType.WARN -> { tipTypeImg?.visibility = View.VISIBLE tipTypeImg?.setImageResource(R.drawable.mx_dialog_icon_warn) } + MXDialogType.ERROR -> { tipTypeImg?.visibility = View.VISIBLE tipTypeImg?.setImageResource(R.drawable.mx_dialog_icon_error) @@ -150,52 +158,68 @@ abstract class MXTipBaseDialog(context: Context) : MXBaseCardDialog(context) { } } - private fun processActionBtn() { - val button = actionBtn ?: return - val prop = actionProp + private fun processActionBtn(prop: MXTextProp?): TextView? { + val btnLay = btnLay ?: return null + val showActionBtn = (prop == null || prop.visible) - if (showActionBtn) { - val actionProp = prop ?: MXTextProp( - context.resources.getString(R.string.mx_dialog_button_action_text), - true, - context.resources.getColor(R.color.mx_dialog_color_text_action), - 15f - ) - button.text = actionProp.text - actionProp.attachTextColor(button, R.color.mx_dialog_color_text_action) - actionProp.attachTextSize(button, R.dimen.mx_dialog_text_size_button) - button.setOnClickListener { - dismiss() - actionProp.onclick?.invoke() - } + if (!showActionBtn) return null - button.visibility = View.VISIBLE - } else { - button.visibility = View.GONE + LayoutInflater.from(context).inflate( + R.layout.mx_content_action_btn, btnLay, true + ) + val button = (btnLay.getChildAt(btnLay.childCount - 1) as TextView?) ?: return null + val actionProp = prop ?: MXTextProp( + context.resources.getString(R.string.mx_dialog_button_action_text), + true, + context.resources.getColor(R.color.mx_dialog_color_text_action), + 15f + ) + button.text = actionProp.text + actionProp.attachTextColor(button, R.color.mx_dialog_color_text_action) + actionProp.attachTextSize(button, R.dimen.mx_dialog_text_size_button) + button.setOnClickListener { + dismiss() + actionProp.onclick?.invoke() } + button.visibility = View.VISIBLE + + val cornerDP = getCardBackgroundRadiusDP() + MXButtonStyle.attach( + buttonStyle, btnLay, cancelBtn, + button, btnDivider, cornerDP + ) + return button } /** * 设置活动按钮 */ - fun setActionBtn( + fun addActionBtn( text: CharSequence? = null, visible: Boolean = true, textColor: Int? = null, textSizeSP: Float? = null, onclick: (() -> Unit)? = null ) { - actionProp = MXTextProp( - text ?: context.resources.getString(R.string.mx_dialog_button_action_text), - visible, - textColor, - textSizeSP, - onclick = onclick + actionProps.add( + MXTextProp( + text ?: context.resources.getString(R.string.mx_dialog_button_action_text), + visible, textColor, textSizeSP, onclick = onclick + ) ) initDialog() } + /** + * 清空活动按钮 + */ + fun cleanActionBtn() { + actionProps.clear() + + initDialog() + } + /** * 设置取消按钮 * @param visible 按钮是否可见 diff --git a/LibDialog/src/main/java/com/mx/dialog/utils/MXUtils.kt b/LibDialog/src/main/java/com/mx/dialog/utils/MXUtils.kt index e31d51602b31acb465efd39194b59924ccd7172c..9d8651707d0b02641dc80dd7554291766fb4b018 100644 --- a/LibDialog/src/main/java/com/mx/dialog/utils/MXUtils.kt +++ b/LibDialog/src/main/java/com/mx/dialog/utils/MXUtils.kt @@ -4,14 +4,13 @@ import android.animation.ObjectAnimator import android.animation.ValueAnimator import android.content.Context import android.view.View -import com.mx.dialog.BuildConfig import java.text.DecimalFormat import kotlin.math.max import kotlin.math.min import kotlin.math.roundToInt internal object MXUtils { - private var debug = BuildConfig.DEBUG + private var debug = false fun setDebug(debug: Boolean) { this.debug = debug } diff --git a/LibDialog/src/main/res/layout/mx_content_action_btn.xml b/LibDialog/src/main/res/layout/mx_content_action_btn.xml new file mode 100644 index 0000000000000000000000000000000000000000..16e0f99b3e0dd7d481da23b85aa7e175147b258a --- /dev/null +++ b/LibDialog/src/main/res/layout/mx_content_action_btn.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/LibDialog/src/main/res/layout/mx_content_tip.xml b/LibDialog/src/main/res/layout/mx_content_tip.xml index 982adce0853ab8dea25446460ead719624a81250..83d0fa7dd81d7bbd5708446bf3cbfcdbcd74fbd1 100644 --- a/LibDialog/src/main/res/layout/mx_content_tip.xml +++ b/LibDialog/src/main/res/layout/mx_content_tip.xml @@ -72,19 +72,5 @@ style="@style/mx_dialog_style_cancel_btn" android:background="@drawable/mx_dialog_btn_bg_cancel_circular" android:text="@string/mx_dialog_button_cancel_text" /> - - - - diff --git a/app/build.gradle b/app/build.gradle index 1d9176f49f08b05ac571bd04c62d8435b9a0193d..6d0a67e94d9c800dd2d3ef3da1df0af2b6dc075b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,8 +1,6 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -androidExtensions { - experimental = true +plugins { + id 'com.android.application' + id 'kotlin-android' } android { @@ -16,7 +14,9 @@ android { multiDexEnabled true } - + viewBinding { + enabled = true + } buildTypes { release { minifyEnabled false @@ -24,24 +24,23 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = JavaVersion.VERSION_17 } namespace 'com.mx.example' } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' - implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.8.0' + implementation 'com.google.android.material:material:1.9.0' implementation 'com.squareup.okhttp3:okhttp:4.9.3' implementation 'com.squareup.okio:okio:2.10.0' diff --git a/app/src/main/java/com/mx/example/TipDialogActivity.kt b/app/src/main/java/com/mx/example/TipDialogActivity.kt index 572860434cb44d6148c25501c94e1e5e9f299c44..dbd93e55a0e14bfdb56b3537793833349942a2bb 100644 --- a/app/src/main/java/com/mx/example/TipDialogActivity.kt +++ b/app/src/main/java/com/mx/example/TipDialogActivity.kt @@ -12,14 +12,15 @@ import com.mx.dialog.tip.MXDialogPosition import com.mx.dialog.tip.MXDialogType import com.mx.dialog.tip.MXTipDialog import com.mx.dialog.utils.MXButtonStyle -import kotlinx.android.synthetic.main.activity_tip_dialog.* +import com.mx.example.databinding.ActivityTipDialogBinding class TipDialogActivity : AppCompatActivity() { + private val binding by lazy { ActivityTipDialogBinding.inflate(layoutInflater) } private val tipDialog by lazy { MXTipDialog(this) } private val position = MXDialogPosition() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_tip_dialog) + setContentView(binding.root) initView() } @@ -29,18 +30,18 @@ class TipDialogActivity : AppCompatActivity() { tipDialog.setOnCancelListener { Toast.makeText(this, "取消操作", Toast.LENGTH_SHORT).show() } - titleEdt.addTextChangedListener { + binding.titleEdt.addTextChangedListener { tipDialog.setTitle(it) } - infoEdt.addTextChangedListener { + binding.infoEdt.addTextChangedListener { tipDialog.setMessage(it) } - widthRatioEdt.addTextChangedListener { + binding.widthRatioEdt.addTextChangedListener { tipDialog.setMaxContentRatio(it?.toString()?.toFloatOrNull() ?: 0f) } tipDialog.setMaxContentRatio(0.6f) - radioSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + binding.radioSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { tipDialog.setCardBackgroundRadius(progress.toFloat()) } @@ -54,21 +55,21 @@ class TipDialogActivity : AppCompatActivity() { } }) - positionGroup.children.forEachIndexed { index, view -> + binding.positionGroup.children.forEachIndexed { index, view -> val gravitys = arrayOf(Gravity.TOP, Gravity.CENTER, Gravity.BOTTOM) view.setOnClickListener { position.gravity = gravitys[index] tipDialog.show() } } - backgroundGroup.children.forEachIndexed { index, view -> + binding.backgroundGroup.children.forEachIndexed { index, view -> val colors = arrayOf("#33000000", "#66000000", "#99000000") view.setOnClickListener { tipDialog.setDialogBackGroundColor(Color.parseColor(colors[index])) tipDialog.show() } } - iconGroup.children.forEachIndexed { index, view -> + binding.iconGroup.children.forEachIndexed { index, view -> val types = arrayOf( MXDialogType.NONE, MXDialogType.SUCCESS, @@ -80,7 +81,7 @@ class TipDialogActivity : AppCompatActivity() { tipDialog.show() } } - actionGroup.children.forEachIndexed { index, view -> + binding.actionGroup.children.forEachIndexed { index, view -> val types = arrayOf( MXButtonStyle.Rounded, MXButtonStyle.FillBackground, @@ -91,12 +92,15 @@ class TipDialogActivity : AppCompatActivity() { tipDialog.show() } } - marginEdt.addTextChangedListener { + binding.marginEdt.addTextChangedListener { tipDialog.setCardMargin(it?.toString()?.toFloatOrNull() ?: 0f) } - tipDialog.setActionBtn { + tipDialog.addActionBtn { Toast.makeText(this, "点击确认", Toast.LENGTH_SHORT).show() } +// tipDialog.setAction2Btn("Action2") { +// Toast.makeText(this, "点击确认2", Toast.LENGTH_SHORT).show() +// } tipDialog.setCancelBtn { Toast.makeText(this, "点击取消", Toast.LENGTH_SHORT).show() } diff --git a/build.gradle b/build.gradle index 238ec3850aa055bb8f7c80a26c8fa9456cd3fc9e..21427cd030ed5bbf82dfc5a05598308b60cff1d3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,36 +1,19 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - ext.kotlin_version = "1.7.20" - repositories { - maven { url 'https://maven.aliyun.com/repository/google' } - maven { url 'https://maven.aliyun.com/repository/public' } - maven { url 'https://jitpack.io' } - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } +plugins { + id 'com.android.application' version '8.5.1' apply false + id 'com.android.library' version '8.5.1' apply false + id 'org.jetbrains.kotlin.android' version '1.8.10' apply false } -allprojects { - repositories { - maven { url 'https://maven.aliyun.com/repository/google' } - maven { url 'https://maven.aliyun.com/repository/public' } - maven { url 'https://jitpack.io' } - google() +task clean(type: Delete) { + for (project in allprojects) { + delete project.buildDir } } - ext { compileSdkVersion = 33 targetSdkVersion = 33 minSdkVersion = 19 versionCode = 1 - versionName = "1.6.3" + versionName = "1.6.4" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f0d4593a4e4e5a76ccb28698a40fa1d25c590b5e..4f6979d67ca72c1e2efdcf596d138f0ae8f04855 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Aug 09 13:56:32 CST 2021 +#Tue Oct 13 19:36:38 CST 2020 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip diff --git a/settings.gradle b/settings.gradle index eb4ce8ab3cd4d510a6762104571374c3a66eb7dc..70b84ef020e97d7fd7ca1c6232b87ff190c3c80f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,26 @@ +pluginManagement { + repositories { + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://jitpack.io' } + maven { url "https://mvn.mob.com/android" } + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) + repositories { + maven { url 'https://maven.aliyun.com/repository/google' } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://jitpack.io' } + maven { url "https://mvn.mob.com/android" } + google() + mavenCentral() + } +} + rootProject.name = "MXDialog" include ':app' -include ':LibDialog' +include ':LibDialog' \ No newline at end of file