Please note - the code below has potential concurrent issues:
if (mView.isVisible != true)
if (isUIThread)
mView.isVisible = true
else
mView.post { mView.isVisible = true }
However if you want to achieve this behaviour, I can advice the following:
fun <TView: View> setVisible(newValue: Boolean) {
if (isVisible != newValue)
if (isUIThread)
isVisible = newValue
else
post { isVisible = newValue }
}
Next if you have another view, which can have interface (for example - interface Countable { var count: Int; }, you can do something like this:
fun <TView> setVisible(newCount: Int)
where TView: View, Countable {
if (count != newValue)
if (isUIThread)
count = newValue
else
post { count = newValue } // <-- View inheritance is needed for post method
}