diff --git a/app/src/main/java/ru/impression/ui_generator_example/Ext.kt b/app/src/main/java/ru/impression/ui_generator_example/Ext.kt index 741ae05..3520975 100644 --- a/app/src/main/java/ru/impression/ui_generator_example/Ext.kt +++ b/app/src/main/java/ru/impression/ui_generator_example/Ext.kt @@ -1,14 +1,28 @@ package ru.impression.ui_generator_example import android.view.View +import androidx.core.view.isGone import androidx.core.view.isInvisible +import androidx.core.view.isVisible import androidx.databinding.BindingAdapter object DataBindingExt { @JvmStatic @BindingAdapter("isInvisible") - fun setIsVisible(view: View, value: Boolean) { + fun setIsInvisible(view: View, value: Boolean) { view.isInvisible = value } + + @JvmStatic + @BindingAdapter("isVisible") + fun setIsVisible(view: View, value: Boolean) { + view.isVisible = value + } + + @JvmStatic + @BindingAdapter("isGone") + fun setIsGone(view: View, value: Boolean) { + view.isGone = value + } } \ No newline at end of file diff --git a/app/src/main/java/ru/impression/ui_generator_example/MainFragment.kt b/app/src/main/java/ru/impression/ui_generator_example/MainFragment.kt index 6df3da3..6bb8e80 100644 --- a/app/src/main/java/ru/impression/ui_generator_example/MainFragment.kt +++ b/app/src/main/java/ru/impression/ui_generator_example/MainFragment.kt @@ -2,6 +2,7 @@ package ru.impression.ui_generator_example import androidx.fragment.app.Fragment import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.launch import ru.impression.ui_generator_annotations.MakeComponent import ru.impression.ui_generator_annotations.Prop @@ -17,6 +18,20 @@ class MainFragment : class MainFragmentViewModel : CoroutineViewModel() { + var countDown by state(flow { + delay(1000) + emit(3) + delay(1000) + emit(2) + delay(1000) + emit(1) + delay(1000) + emit(0) + }) + + val countDownIsLoading get() = ::countDown.isLoading + + @Prop var welcomeText by state(null) @@ -34,9 +49,6 @@ class MainFragmentViewModel : CoroutineViewModel() { val currentTimeIsLoading get() = ::currentTime.isLoading fun reloadCurrentTime() { - launch { - ::currentTime.reload().join() - toastMessage = "Current time reloaded" - } + ::currentTime.reload() } } \ No newline at end of file diff --git a/app/src/main/res/layout/main_fragment.xml b/app/src/main/res/layout/main_fragment.xml index 8b4e54e..46768eb 100644 --- a/app/src/main/res/layout/main_fragment.xml +++ b/app/src/main/res/layout/main_fragment.xml @@ -10,85 +10,108 @@ - + android:layout_height="match_parent"> - + android:layout_gravity="center" /> - + android:layout_gravity="center" + android:text="@{String.valueOf(viewModel.countDown)}" + android:textSize="24sp" + android:textStyle="bold" + tools:text="3..2..1" /> - + + + android:text="@{viewModel.welcomeText}" + android:textSize="24sp" + android:textStyle="bold" /> - - - - - - - - - + android:layout_marginTop="32dp" + android:orientation="horizontal"> + + + + + + + + + android:layout_marginTop="32dp" + android:text="Current time is:" + android:textStyle="bold" /> - + android:layout_marginTop="8dp"> - + -