robinchew
12/24/2018, 8:17 PMval f: (Context) -> View = ::TextView
val text = f(activity)
how do I check that text
is an 'instance' of f
?Andreas Sinz
12/24/2018, 8:21 PMrobinchew
12/24/2018, 8:25 PMf
and text
.Andreas Sinz
12/24/2018, 8:26 PMtext
was returned by f
?robinchew
12/24/2018, 8:26 PMf = TextView
text = f(activity)
you can check text
is an instance of f
by doing:
isinstance(text, f)
vnsgbt
12/24/2018, 8:27 PMval isString = when (foo) { is String -> true }
Andreas Sinz
12/24/2018, 8:28 PMtext is TextView
robinchew
12/24/2018, 8:28 PMTextView
out of f
?robinchew
12/24/2018, 8:29 PMAndreas Sinz
12/24/2018, 8:30 PMf
is just an ordinary function that creates an instance of TextView
, so you cant get the type out of itrobinchew
12/24/2018, 8:31 PMAndreas Sinz
12/24/2018, 8:32 PMwhen(text) {
is TextView -> ...
is Button -> ...
...
}
Andreas Sinz
12/24/2018, 8:33 PMvnsgbt
12/24/2018, 8:34 PMContext -> View
an alias, and use is
to check it.robinchew
12/24/2018, 8:35 PMrobinchew
12/24/2018, 8:37 PMval manyViewClasses = listOf(TextView, SomeView)
And I loop them to instantiate:
val manyViews = manyViewClasses.map {cls ->
cls(activity)
}
It won't work, because I'm missing contsructorsrobinchew
12/24/2018, 8:38 PMmanyViewClasses
was:
val manyViewClasses = listOf(::TextView, ::SomeView)
robinchew
12/24/2018, 8:42 PMmanyViews
and manyViewClasses
like so:
manyViews.zip(manyViewClasses).forEach {(view, cls) ->
if (view.class == cls) {
println('match')
}
}
robinchew
12/24/2018, 8:43 PMcls
is a function, not a classrobinchew
12/24/2018, 9:29 PMval manyViewClasses = listOf(::TextView, ::SomeView)
val manyViews = manyViewClasses.map {con ->
con(activity)
}
val manyViewClasses2 = myChangesTo(manyViewClasses)
manyViews.zip(manyViewClasses2).forEach {(view, con) ->
val newView = con(activity) // <- workaround
if (view::class == newView::class) {
println('match')
}
}
Andreas Sinz
12/24/2018, 9:35 PMview
has the same class as con
?Dico
12/25/2018, 1:08 AMDico
12/25/2018, 1:08 AMDico
12/25/2018, 1:10 AMinterface View
and then implement it with class TextView : View
and class OtherView : View
Dico
12/25/2018, 1:11 AMDico
12/25/2018, 1:12 AMDico
12/25/2018, 1:12 AMrobinchew
12/25/2018, 1:43 PMlistOf(TextView, SomeView)
and I try to render a similar listOf(TextView, SomeView)
on top of it, nothing will be applied because it's considered the same.robinchew
12/25/2018, 1:44 PMlistOf(TextView, ImageView)
My program can see that the 2nd View has changed, and replaces SomeView
with ImageView
, while leaving TextView
as is.robinchew
12/25/2018, 1:51 PMm(::LinearLayout,
children(
m(::TextView, attrs(text("Hello"), color("red"))),
m(::SomeView)))
m(::LinearLayout,
children(
m(::TextView, attrs(text("Hello"), color("red"))),
m(::ImageView, attrs(url("<http://www.site.com/image.gif|www.site.com/image.gif>")))))
Andreas Sinz
12/25/2018, 8:30 PMAndreas Sinz
12/25/2018, 8:47 PMDico
12/25/2018, 9:43 PMinterface View {
val type: ViewType
}
enum class ViewType(val ktype: KClass<out View>, val ctor: () -> View) {
TEXT(TextView::class, ::TextView),
// more
;
}
Dico
12/25/2018, 9:44 PMDico
12/25/2018, 9:46 PMrobinchew
12/28/2018, 4:02 PMrobinchew
12/28/2018, 4:05 PMrobinchew
12/28/2018, 4:09 PM