forked from github/szkolny

* [DB] Add Room schema export location. * [DB] Add Note entity and migration 96. * Add correct database schema * [Notes] Implement basic note list UI. * [DB] Implement Noteable in Full entities. Add note relation and filtering. * [Notes] Make Note searchable. * [UI] Disable onClick listeners in adapters when null. * [UI] Implement showing note list in dialog. * [UI] Update note dialogs UI. * [Notes] Add note details dialog. * [Notes] Extract note dialogs header into a separate layout. * [Notes] Add note editor dialog. * [Notes] Show note icons in dialogs and lists. * [Notes] Add showing substitute text. * [Notes] Add replacing notes icon. * [Notes] Add sharing and receiving notes. * [Notes] Add notes list UI fragment. * [Notes] Implement adding notes without owner. * [Notes] Add color names. * [Notes] Add notes card on home screen. * [Notes] Add notes card migration.
84 lines
2.4 KiB
Kotlin
84 lines
2.4 KiB
Kotlin
/*
|
|
* Copyright (c) Kuba Szczodrzyński 2019-11-11.
|
|
*/
|
|
package pl.szczodrzynski.edziennik
|
|
|
|
import android.graphics.Paint
|
|
import android.view.View
|
|
import android.widget.TextView
|
|
import androidx.core.view.isVisible
|
|
import androidx.databinding.BindingAdapter
|
|
import pl.szczodrzynski.edziennik.ext.dp
|
|
|
|
object Binding {
|
|
@JvmStatic
|
|
@BindingAdapter("strikeThrough")
|
|
fun strikeThrough(textView: TextView, strikeThrough: Boolean) {
|
|
if (strikeThrough) {
|
|
textView.paintFlags = textView.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
|
} else {
|
|
textView.paintFlags = textView.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
}
|
|
}
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:isVisible")
|
|
fun isVisible(view: View, isVisible: Boolean) {
|
|
view.isVisible = isVisible
|
|
}
|
|
|
|
private fun resizeDrawable(textView: TextView, index: Int, size: Int) {
|
|
val drawables = textView.compoundDrawables
|
|
drawables[index]?.setBounds(0, 0, size, size)
|
|
textView.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3])
|
|
}
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableLeftAutoSize")
|
|
fun drawableLeftAutoSize(textView: TextView, enable: Boolean) = resizeDrawable(
|
|
textView,
|
|
index = 0,
|
|
size = textView.textSize.toInt(),
|
|
)
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableRightAutoSize")
|
|
fun drawableRightAutoSize(textView: TextView, enable: Boolean) = resizeDrawable(
|
|
textView,
|
|
index = 2,
|
|
size = textView.textSize.toInt(),
|
|
)
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableLeftSize")
|
|
fun drawableLeftSize(textView: TextView, sizeDp: Int) = resizeDrawable(
|
|
textView,
|
|
index = 0,
|
|
size = sizeDp.dp,
|
|
)
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableTopSize")
|
|
fun drawableTopSize(textView: TextView, sizeDp: Int) = resizeDrawable(
|
|
textView,
|
|
index = 1,
|
|
size = sizeDp.dp,
|
|
)
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableRightSize")
|
|
fun drawableRightSize(textView: TextView, sizeDp: Int) = resizeDrawable(
|
|
textView,
|
|
index = 2,
|
|
size = sizeDp.dp,
|
|
)
|
|
|
|
@JvmStatic
|
|
@BindingAdapter("android:drawableBottomSize")
|
|
fun drawableBottomSize(textView: TextView, sizeDp: Int) = resizeDrawable(
|
|
textView,
|
|
index = 3,
|
|
size = sizeDp.dp,
|
|
)
|
|
}
|