add loading and error status, with a simple implementation

This commit is contained in:
Carlos Martinez
2020-02-03 13:52:11 -03:00
parent 83d243ec58
commit c1bb08ee8f
9 changed files with 154 additions and 4 deletions

View File

@@ -5,6 +5,34 @@ import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
fun View.enable() {
isEnabled = true
}
fun View.disable() {
isEnabled = false
}
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.transparent() {
alpha = 0f
}
fun View.opaque() {
alpha = 1f
}
fun View.gone() {
visibility = View.GONE
}
fun ViewGroup.inflate(@LayoutRes layout: Int, attachToRoot: Boolean = false): View =
LayoutInflater
.from(context)

View File

@@ -0,0 +1,18 @@
package com.hako.base.widgets
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import com.hako.base.R
import com.hako.base.extensions.inflate
class LoadingOverlay @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
init {
inflate(R.layout.loading_overlay, true)
}
}

View File

@@ -0,0 +1,18 @@
package com.hako.base.widgets
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import com.hako.base.R
import com.hako.base.extensions.inflate
class NetworkErrorOverlay @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
init {
inflate(R.layout.network_error_overlay, true)
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/soft_background">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/loading_overlay_animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_rawRes="@raw/loading_animation" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/soft_background">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/loading_overlay_animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.48"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/network_animation" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Network error!"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="@+id/loading_overlay_animation_view"
app:layout_constraintStart_toStartOf="@+id/loading_overlay_animation_view"
app:layout_constraintTop_toBottomOf="@+id/loading_overlay_animation_view" />
</androidx.constraintlayout.widget.ConstraintLayout>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long