mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-16 08:26:38 +08:00
38 lines
1.0 KiB
Kotlin
38 lines
1.0 KiB
Kotlin
package com.lizongying.mytv
|
|
|
|
import android.app.AlertDialog
|
|
import android.app.Dialog
|
|
import android.os.Bundle
|
|
import androidx.fragment.app.DialogFragment
|
|
|
|
class ConfirmationFragment(
|
|
private val listener: ConfirmationListener,
|
|
private val message: String
|
|
) : DialogFragment() {
|
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
return activity?.let {
|
|
val builder = AlertDialog.Builder(it)
|
|
builder.setTitle("确定更新吗?")
|
|
.setMessage(message)
|
|
.setPositiveButton(
|
|
"确定"
|
|
) { _, _ ->
|
|
listener.onConfirm()
|
|
}
|
|
.setNegativeButton(
|
|
"取消"
|
|
) { _, _ ->
|
|
listener.onCancel()
|
|
}
|
|
builder.create()
|
|
} ?: throw IllegalStateException("Activity cannot be null")
|
|
}
|
|
|
|
interface ConfirmationListener {
|
|
fun onConfirm()
|
|
fun onCancel()
|
|
}
|
|
}
|
|
|