ursus
07/24/2018, 10:59 PMgildor
07/24/2018, 11:24 PMgildor
07/24/2018, 11:25 PM?
rather than !!
Also good approach to create scoped component with view lifecycleursus
07/24/2018, 11:26 PMgildor
07/24/2018, 11:26 PMgildor
07/24/2018, 11:27 PMursus
07/24/2018, 11:27 PMursus
07/24/2018, 11:27 PMgildor
07/24/2018, 11:32 PMursus
07/24/2018, 11:33 PMursus
07/24/2018, 11:33 PMgildor
07/24/2018, 11:34 PMursus
07/24/2018, 11:34 PMgildor
07/24/2018, 11:34 PMgildor
07/24/2018, 11:35 PMgildor
07/24/2018, 11:35 PMgildor
07/24/2018, 11:36 PMgildor
07/24/2018, 11:36 PMursus
07/24/2018, 11:36 PMursus
07/24/2018, 11:37 PMgildor
07/24/2018, 11:40 PMgildor
07/24/2018, 11:41 PMursus
07/24/2018, 11:42 PMclass SearchFragment {
fun override onCreateView() {
disposables += viewModel.searchStateObservable()
.throwingSubscribe { handleSearchState(it) } }
private fun handleSearchState(searchState: SearchState) {
textView1!!.setText
textView2!!.setText
textView3!!.setText
}
}
class SearchFragment {
private var component: Component? = null
fun override onCreateView() {
this.component = Component(view)
disposables += viewModel.searchStateObservable()
.throwingSubscribe { component.handleSearchState(it) } }
}
}
so youre saying this?gildor
07/24/2018, 11:42 PMursus
07/24/2018, 11:43 PMgildor
07/25/2018, 1:23 AMclass SearchFragment : Fragment {
private val viewModel: SearchViewModel = TODO("Create ViewModel or inject it")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
SearchBinding(view, viewModel, lifecycle)
}
}
class SearchBinding(root: View, viewModel: SearchViewModel, lifecycle: Lifecycle) {
private val textView1: TextView = root.findViewById(R.id.view1)
private val textView2: TextView = root.findViewById(R.id.view2)
private val textView3: TextView = root.findViewById(R.id.view3)
init {
val disposable = viewModel.searchStateObservable().throwingSubscribe(::handleSearchState)
lifecycle.onDestroy(disposable::dispose)
}
private fun handleSearchState(searchState: SearchState) {
textView1.text = searchState.text1
textView2.text = searchState.text2
textView3.text = searchState.text3
}
}
gildor
07/25/2018, 1:25 AMgildor
07/25/2018, 1:36 AMinit {
viewModel
.searchStateObservable()
.throwingSubscribe(::handleSearchState)
.bindTo(lifecycle)
}
ursus
07/25/2018, 1:44 AMursus
07/25/2018, 1:44 AMursus
07/25/2018, 1:45 AMgildor
07/25/2018, 1:46 AMneeded some other fragment callbacks, permissions, activityOf course, activity/fragment have to delegate such component specific things
ursus
07/25/2018, 1:48 AMursus
07/25/2018, 1:49 AMgildor
07/25/2018, 1:49 AMsome other fragment callbacksAndroid Team already tries to extract as much as possible features of fragments, like navigation, so hope in future it will be even more simple. And nothing prevent you from delegate activity/fragment events to binding, or what I mean mentioning Architecture, delegate those calls not to binding or views, but to ViewModel, presenter or any other part that works with business logic
gildor
07/25/2018, 1:49 AMursus
07/25/2018, 1:51 AMgildor
07/25/2018, 1:51 AMursus
07/25/2018, 1:52 AMgildor
07/25/2018, 1:52 AMbut if nobody references you, you can get gced, regardless of your references
gildor
07/25/2018, 1:52 AMgildor
07/25/2018, 1:53 AMursus
07/25/2018, 1:55 AMursus
07/25/2018, 1:55 AMgildor
07/25/2018, 1:56 AMursus
07/25/2018, 1:57 AMgildor
07/25/2018, 1:58 AMursus
07/25/2018, 1:59 AMursus
07/25/2018, 2:00 AMgildor
07/25/2018, 2:00 AMgildor
07/25/2018, 2:00 AMgildor
07/25/2018, 2:01 AMgildor
07/25/2018, 2:01 AMursus
07/25/2018, 2:01 AMgildor
07/25/2018, 2:01 AMursus
07/25/2018, 2:01 AMursus
07/25/2018, 2:02 AMgildor
07/25/2018, 2:02 AMgildor
07/25/2018, 2:02 AMgildor
07/25/2018, 2:03 AMursus
07/25/2018, 2:03 AMursus
07/25/2018, 2:03 AMgildor
07/25/2018, 2:04 AMursus
07/25/2018, 2:04 AMursus
07/25/2018, 2:05 AMgildor
07/25/2018, 2:05 AMursus
07/25/2018, 2:06 AMgildor
07/25/2018, 2:07 AMursus
07/25/2018, 2:08 AMgildor
07/25/2018, 2:08 AMgildor
07/25/2018, 2:09 AMursus
07/25/2018, 2:12 AMursus
07/25/2018, 2:13 AMThe object will not become a candidate for garbage collection until all references to it are discarded. Java objects are assigned by reference so when you had....
gildor
07/25/2018, 2:21 AMneed view reference to findViewByIds?
gildor
07/25/2018, 2:22 AMThe object will not become a candidate for garbage collection until all references to it are discardedCorrect. Why do you confused? In your example view doesn’t have reference to SearchBinding, but observable has and lifecycle has those references (because of callbacks)
ursus
07/25/2018, 2:22 AMursus
07/25/2018, 2:23 AMursus
07/25/2018, 2:23 AMursus
07/25/2018, 2:24 AMgildor
07/25/2018, 2:25 AMursus
07/25/2018, 2:26 AMursus
07/25/2018, 2:28 AMursus
07/25/2018, 2:36 AMgildor
07/25/2018, 2:38 AMgildor
07/25/2018, 2:38 AMursus
07/25/2018, 2:38 AMursus
07/25/2018, 2:40 AMgildor
07/25/2018, 2:40 AMursus
07/25/2018, 2:41 AMursus
07/25/2018, 2:41 AMgildor
07/25/2018, 2:47 AMursus
07/25/2018, 2:48 AMgildor
07/25/2018, 2:48 AMgildor
07/25/2018, 2:50 AMfun Foo.Companion.bar()
so can use Foo.bar()
from Kotlinursus
07/25/2018, 2:50 AMursus
07/25/2018, 2:51 AMobject
syntactic sugar for process scoped things, so I kind of dont see the poitn of them being there honestly