Orhan Tozan
10/15/2020, 1:05 PMviewModel.notes.observeInLifecycleScope { notes ->
viewBinding.informationTextInput.text = notes
// Fix for mysterious bug when the family notes textview doesnt update when navigated from home screen.
lifecycleScope.launch {
viewBinding.informationTextInput.isVisible = false
viewBinding.informationTextInput.isVisible = true
repeat(10) {
delay(100)
viewBinding.informationTextInput.isVisible = false
viewBinding.informationTextInput.isVisible = true
}
}
}
There is this mysterious bug where screen A works fine when navigated from screen B(screen B -> screen A) . But when navigated from screen C -> screen A, there is this small chance the textview showing weird, empty content. The code under the comment hilariously fixes that issue... but still have no clue why 😂Lazar Ristic91
10/15/2020, 1:17 PMOrhan Tozan
10/15/2020, 1:34 PMOrhan Tozan
10/15/2020, 1:35 PMOrhan Tozan
10/15/2020, 1:36 PMOrhan Tozan
10/15/2020, 1:38 PMIan Lake
10/15/2020, 3:06 PMobserveInLifecycleScope
doing? Make sure it is using the viewLifecycleOwner
and not the Fragment itself for getting the lifecycleScope
Orhan Tozan
10/15/2020, 3:06 PM// BaseFragment.kt
protected fun <T> LiveData<T>.observeInLifecycleScope(observer: (T) -> Unit) {
observe(viewLifecycleOwner, observer)
}
Orhan Tozan
10/16/2020, 3:38 PMIan Lake
10/16/2020, 3:39 PMOrhan Tozan
10/16/2020, 3:39 PMOrhan Tozan
10/16/2020, 3:39 PMLazar Ristic91
10/16/2020, 3:40 PMOrhan Tozan
10/16/2020, 3:40 PMOrhan Tozan
10/16/2020, 3:41 PMOrhan Tozan
10/16/2020, 3:44 PMLazar Ristic91
10/16/2020, 3:49 PMOrhan Tozan
10/16/2020, 3:50 PMOrhan Tozan
10/16/2020, 3:50 PM<TextView
android:id="@+id/start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@{viewModel.startDate}"
app:layout_constraintStart_toEndOf="@id/left_label_guideline"
app:layout_constraintTop_toBottomOf="@+id/barrier6"
tools:text="Do 5 dec. 2019" />
<TextView
android:id="@+id/start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).startTime : ""}'
android:textAppearance="@style/TextAppearance.Hello247.Body1"
app:isVisible="@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent}"
app:layout_constraintEnd_toStartOf="@+id/right_bound_guideline"
app:layout_constraintTop_toTopOf="@+id/start_date"
tools:text="17:30" />
<TextView
android:id="@+id/end_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@{viewModel.endDate}"
android:textAppearance="@style/TextAppearance.Hello247.Body1"
app:layout_constraintStart_toStartOf="@+id/start_date"
app:layout_constraintTop_toBottomOf="@+id/start_date"
tools:text="Do 5 dec. 2019" />
<TextView
android:id="@+id/end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).endTime : ""}'
android:textAppearance="@style/TextAppearance.Hello247.Body1"
app:isVisible="@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent}"
app:layout_constraintEnd_toStartOf="@+id/right_bound_guideline"
app:layout_constraintTop_toTopOf="@+id/end_date"
tools:text="18:30" />
Lazar Ristic91
10/16/2020, 5:10 PMconstraintEnd
at start_time
and end_time
and you do not have constraintStart
? Can you try with out constraintEnd
?
2. Can you put this into function
@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).startTime : ""}
I had bad experience with coding in xml.
Please replay me with results when you try this.Orhan Tozan
10/17/2020, 1:57 PM