Skip to content

Commit

Permalink
添加方法注释,完善方法
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenBen committed May 18, 2021
1 parent 4c48043 commit 72decdb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {
```kotlin
// 创建自定义LoadingDialog
val loadingDialog = LoadingDialog.Builder(context, R.style.LoadingDialog)
.setCancelable(true)//[Dialog.setCancelable]
.setCanceledOnTouchOutside(true)//[Dialog.setCanceledOnTouchOutside]
.setCancelable(false)//[Dialog.setCancelable]
.setCanceledOnTouchOutside(false)//[Dialog.setCanceledOnTouchOutside]
.setHintText("加载中...")//设置显示的提示性文字内容
.showHintText(true)//是否显示提示性文字
.create()
Expand All @@ -40,5 +40,6 @@ val loadingDialog = LoadingDialog.Builder(context, R.style.LoadingDialog)
loadingDialog.dismiss()//or loadingDialog.cancel()

//快速创建默认配置的LoadingDialog
val defaultLoadingDialog = LoadingDialog.createDefault(context)
val defaultLoadingDialog1 = LoadingDialog.createDefault(context)
val defaultLoadingDialog2 = LoadingDialog.createDefault(context, R.style.LoadingDialog)
```
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.squareup.leakcanary:leakcanary-android:2.7'
// implementation project(path: ':lib')
implementation 'com.github.shenbengit:LoadingDialog:1.0.1'
implementation project(path: ':lib')
// implementation 'com.github.shenbengit:LoadingDialog:1.0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import android.widget.Button
import com.shencoder.loadingdialog.LoadingDialog

class MainActivity : AppCompatActivity() {
private val loadingDialog by lazy { LoadingDialog.createDefault(this) }
private lateinit var loadingDialog: LoadingDialog

private val mHandler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loadingDialog = LoadingDialog.Builder(this, R.style.LoadingDialog)
.setCancelable(false)
.setCanceledOnTouchOutside(false)
.setHintText("请稍后...")
.showHintText(true)
.create()
findViewById<Button>(R.id.btnShow).setOnClickListener {
loadingDialog.show()
mHandler.postDelayed({ loadingDialog.dismiss() }, 3000L)
Expand Down
35 changes: 32 additions & 3 deletions lib/src/main/java/com/shencoder/loadingdialog/LoadingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.annotation.StyleRes
* @date 2021/05/17 11:12
* @email 714081644@qq.com
*/
class LoadingDialog(
class LoadingDialog internal constructor(
builder: Builder
) : Dialog(builder.context, builder.themeResId) {

Expand All @@ -24,15 +24,32 @@ class LoadingDialog(
* 创建默认配置的[LoadingDialog]
*/
fun createDefault(context: Context) = Builder(context).create()

/**
* 创建默认配置的[LoadingDialog]
*/
fun createDefault(context: Context, @StyleRes themeResId: Int) =
Builder(context, themeResId).create()
}

init {
setContentView(R.layout.dialog_loading)
setCancelable(builder.mCancelable)
setCanceledOnTouchOutside(builder.mTouchOutsideCancelable)
mTvHint = findViewById(R.id.tvHint)
mTvHint.text = builder.mHintText
mTvHint.visibility = if (builder.isShowHintText) View.VISIBLE else View.GONE
setHintText(builder.mHintText)
showHintText(builder.isShowHintText)
}

/**
* 动态设置提示文字
*/
fun setHintText(text: String) {
mTvHint.text = text
}

fun showHintText(isShow: Boolean) {
mTvHint.visibility = if (isShow) View.VISIBLE else View.GONE
}

class Builder @JvmOverloads constructor(
Expand All @@ -43,16 +60,28 @@ class LoadingDialog(
private const val DEFAULT_HINT_TEXT = "请稍后..."
}

/**
* @see [Dialog.setCancelable]
*/
internal var mCancelable = false
fun setCancelable(cancelable: Boolean) = apply { this.mCancelable = cancelable }

/**
* @see [Dialog.setCanceledOnTouchOutside]
*/
internal var mTouchOutsideCancelable = false
fun setCanceledOnTouchOutside(cancelable: Boolean) =
apply { this.mTouchOutsideCancelable = cancelable }

/**
* 是否显示提示性文字
*/
internal var isShowHintText = true
fun showHintText(isShow: Boolean) = apply { this.isShowHintText = isShow }

/**
* 设置显示的提示性文字内容
*/
internal var mHintText = DEFAULT_HINT_TEXT
fun setHintText(text: String) = apply { this.mHintText = text }

Expand Down

0 comments on commit 72decdb

Please sign in to comment.