|
@@ -24,12 +24,18 @@ class FragmentToolbar(context: Context, attrs: AttributeSet) : FrameLayout(conte
|
|
|
field = value
|
|
|
buttonHome.visibility = if (value) VISIBLE else GONE
|
|
|
}
|
|
|
+ private var isTimerVisible = true
|
|
|
+ set(value) {
|
|
|
+ field = value
|
|
|
+ countdownNum.visibility = if (value) VISIBLE else GONE
|
|
|
+ }
|
|
|
private var title = ""
|
|
|
set(value) {
|
|
|
field = value
|
|
|
materialToolbar.title = value
|
|
|
}
|
|
|
|
|
|
+ // 当值=-1时,不启用倒计时
|
|
|
private val countdownTime: Int
|
|
|
private var currentTime: Int = 0
|
|
|
private var countdownAutoStart = true
|
|
@@ -53,6 +59,7 @@ class FragmentToolbar(context: Context, attrs: AttributeSet) : FrameLayout(conte
|
|
|
|
|
|
buttonBack.setOnClickListener { backHandler?.invoke() }
|
|
|
buttonHome.setOnClickListener { homeHandler?.invoke() }
|
|
|
+ if (countdownTime <= 0) isTimerVisible = false
|
|
|
}
|
|
|
|
|
|
private lateinit var job: Job
|
|
@@ -68,6 +75,8 @@ class FragmentToolbar(context: Context, attrs: AttributeSet) : FrameLayout(conte
|
|
|
}
|
|
|
|
|
|
private fun startCountdown(repeatTime: Int = countdownTime) {
|
|
|
+ if (repeatTime <= 0) return
|
|
|
+
|
|
|
stopCountdown()
|
|
|
job = GlobalScope.launch(Dispatchers.Main) {
|
|
|
repeat(repeatTime) {
|