Information toast in reader
parent
a371bb6514
commit
ed70ca4e18
@ -0,0 +1,56 @@
|
||||
package org.koitharu.kotatsu.reader.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.swiperefreshlayout.widget.CircularProgressDrawable
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
import org.koitharu.kotatsu.utils.anim.Duration
|
||||
import org.koitharu.kotatsu.utils.anim.Motion
|
||||
import org.koitharu.kotatsu.utils.ext.hideAnimated
|
||||
import org.koitharu.kotatsu.utils.ext.showAnimated
|
||||
|
||||
class ReaderToastView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : MaterialTextView(context, attrs, defStyleAttr) {
|
||||
|
||||
private var hideRunnable = Runnable {
|
||||
hide()
|
||||
}
|
||||
|
||||
fun show(message: CharSequence, isLoading: Boolean) {
|
||||
removeCallbacks(hideRunnable)
|
||||
text = message
|
||||
this.showAnimated(Motion.Toast, Duration.SHORT)
|
||||
}
|
||||
|
||||
fun show(@StringRes messageId: Int, isLoading: Boolean) {
|
||||
show(context.getString(messageId), isLoading)
|
||||
}
|
||||
|
||||
fun showTemporary(message: CharSequence, duration: Long) {
|
||||
show(message, false)
|
||||
postDelayed(hideRunnable, duration)
|
||||
}
|
||||
|
||||
fun hide() {
|
||||
removeCallbacks(hideRunnable)
|
||||
this.hideAnimated(Motion.Toast, Duration.SHORT)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
removeCallbacks(hideRunnable)
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
|
||||
// FIXME use it as compound drawable
|
||||
private fun createProgressDrawable(): CircularProgressDrawable {
|
||||
val drawable = CircularProgressDrawable(context)
|
||||
drawable.setStyle(CircularProgressDrawable.DEFAULT)
|
||||
drawable.arrowEnabled = false
|
||||
drawable.setColorSchemeColors(Color.WHITE)
|
||||
drawable.centerRadius = lineHeight / 3f
|
||||
return drawable
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package org.koitharu.kotatsu.utils.ext
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isGone
|
||||
|
||||
var TextView.textAndVisible: CharSequence?
|
||||
inline get() = text?.takeIf { visibility == View.VISIBLE }
|
||||
set(value) {
|
||||
text = value
|
||||
isGone = value.isNullOrEmpty()
|
||||
}
|
||||
|
||||
var TextView.drawableStart: Drawable?
|
||||
inline get() = compoundDrawablesRelative[0]
|
||||
set(value) {
|
||||
val dr = compoundDrawablesRelative
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(value, dr[1], dr[2], dr[3])
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="16dp" />
|
||||
<solid android:color="@color/dim" />
|
||||
<padding
|
||||
android:bottom="8dp"
|
||||
android:left="12dp"
|
||||
android:right="12dp"
|
||||
android:top="8dp" />
|
||||
</shape>
|
||||
Loading…
Reference in New Issue