diff --git a/views/build.gradle b/views/build.gradle index 623cb8b..e76deb5 100644 --- a/views/build.gradle +++ b/views/build.gradle @@ -1,10 +1,19 @@ apply from: "../android-configs/lib-config.gradle" +apply plugin: 'kotlin-android' + +android { + buildFeatures { + viewBinding true + } +} dependencies { implementation project(":utils") + implementation project(":kotlin-extensions") implementation project(":logging") implementation "com.google.android.material:material" + implementation "androidx.core:core-ktx" constraints { implementation("com.google.android.material:material") { @@ -12,5 +21,19 @@ dependencies { require '1.0.0' } } + implementation("androidx.core:core-ktx") { + version { + require '1.3.1' + } + } + implementation("org.jetbrains.kotlin:kotlin-stdlib") { + version { + require '1.3.0' + } + } } } + +repositories { + mavenCentral() +} diff --git a/views/src/main/java/ru/touchin/widget/LoadingContentView.kt b/views/src/main/java/ru/touchin/widget/LoadingContentView.kt new file mode 100644 index 0000000..f079bf5 --- /dev/null +++ b/views/src/main/java/ru/touchin/widget/LoadingContentView.kt @@ -0,0 +1,69 @@ +package ru.touchin.widget + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.core.content.withStyledAttributes +import ru.touchin.extensions.observable +import ru.touchin.extensions.setOnRippleClickListener +import ru.touchin.roboswag.components.views.R +import ru.touchin.roboswag.components.views.databinding.ProgressViewBinding +import kotlin.properties.Delegates + +//TODO make customizable views list and views style +class LoadingContentView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : Switcher(context, attrs) { + + private val binding = ProgressViewBinding.inflate(LayoutInflater.from(context), this) + + var state by Delegates.observable(State.Loading, this::updateView) + + init { + if (attrs != null) { + context.withStyledAttributes(attrs, R.styleable.LoadingContentView, defStyleAttr, 0) { + if (hasValue(R.styleable.LoadingContentView_stubText)) { + setStubText(getString(R.styleable.LoadingContentView_stubText)) + } + } + } + } + + private fun setStubText(text: String?) { + binding.textStub.text = text + } + + private fun updateView(state: State) { + if (state == State.ShowContent) { + getChildAt(childCount - 1)?.let { showChild(it.id) } + } else { + when (state) { + is State.Stub -> { + setStubText(state.stubText) + showChild(R.id.text_stub) + } + is State.Loading -> { + showChild(R.id.progress_bar) + } + is State.Error -> { + binding.apply { + errorText.text = state.errorText + errorRepeatButton.setOnRippleClickListener { state.action.invoke() } + errorRepeatButton.text = state.repeatButtonText + showChild(R.id.error_with_repeat) + } + } + } + } + } + + sealed class State { + object ShowContent : State() + data class Stub(val stubText: String) : State() + object Loading : State() + data class Error(val action: () -> Unit, val errorText: String, val repeatButtonText: String) : State() + } + +} diff --git a/views/src/main/res/drawable/light_button_background.xml b/views/src/main/res/drawable/light_button_background.xml new file mode 100644 index 0000000..5719816 --- /dev/null +++ b/views/src/main/res/drawable/light_button_background.xml @@ -0,0 +1,9 @@ + + + diff --git a/views/src/main/res/font/roboto.ttf b/views/src/main/res/font/roboto.ttf new file mode 100644 index 0000000..2c97eea Binary files /dev/null and b/views/src/main/res/font/roboto.ttf differ diff --git a/views/src/main/res/font/roboto_medium.ttf b/views/src/main/res/font/roboto_medium.ttf new file mode 100644 index 0000000..1a7f3b0 Binary files /dev/null and b/views/src/main/res/font/roboto_medium.ttf differ diff --git a/views/src/main/res/layout/progress_view.xml b/views/src/main/res/layout/progress_view.xml new file mode 100644 index 0000000..6e82f03 --- /dev/null +++ b/views/src/main/res/layout/progress_view.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + diff --git a/views/src/main/res/values/attrs.xml b/views/src/main/res/values/attrs.xml index 06d1d83..bf3eacc 100644 --- a/views/src/main/res/values/attrs.xml +++ b/views/src/main/res/values/attrs.xml @@ -30,4 +30,8 @@ + + + + diff --git a/views/src/main/res/values/colors.xml b/views/src/main/res/values/colors.xml new file mode 100644 index 0000000..9c0944f --- /dev/null +++ b/views/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #8D8EA6 + #999BBF + #141233 + \ No newline at end of file diff --git a/views/src/main/res/values/styles.xml b/views/src/main/res/values/styles.xml index 0dbe7b6..06eee69 100644 --- a/views/src/main/res/values/styles.xml +++ b/views/src/main/res/values/styles.xml @@ -4,4 +4,17 @@ @android:anim/fade_in @android:anim/fade_out + + + + + + +