Skip to content

Commit

Permalink
Including loading and error states
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorigaki committed May 31, 2020
1 parent 8bf7277 commit 80c4ba4
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 267 deletions.
170 changes: 0 additions & 170 deletions app/src/main/res/drawable/ic_launcher_background.xml

This file was deleted.

58 changes: 29 additions & 29 deletions app/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group android:scaleX="0.09364433"
android:scaleY="0.09364433"
android:translateX="33.71898"
android:translateY="32.4">
<path
android:pathData="M116.65,314.5c-2,0 -4,-0.06 -6,-0.24h12C120.65,314.44 118.65,314.5 116.65,314.5Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M134,346.43V461.32H99.26V346.43a108.33,108.33 0,0 0,34.72 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M333.89,346.55V461.32H299.17V346.55a117.78,117.78 0,0 0,17.39 1.28A116.47,116.47 0,0 0,333.89 346.55Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M66.65,215.2V16.69A16.66,16.66 0,0 1,83.31 0,16.43 16.43,0 0,1 95.07,4.93 16.43,16.43 0,0 1,100 16.69V215.2a16.67,16.67 0,1 1,-33.33 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M133.31,215.2V16.69A16.66,16.66 0,0 1,150 0a16.43,16.43 0,0 1,11.76 4.91,16.43 16.43,0 0,1 4.91,11.76V215.2a16.67,16.67 0,1 1,-33.33 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M433.15,116.59V231.18a116.65,116.65 0,0 1,-99.26 115.37V314.26H316.56A83.25,83.25 0,0 0,399.82 231V116.77a83.29,83.29 0,0 0,-166.58 0V231.18c0,1.69 -0.06,3.39 -0.12,5.09 -0.06,1.21 -0.13,2.36 -0.25,3.57a73.64,73.64 0,0 1,-0.72 7.33c-0.12,1 -0.31,2.07 -0.49,3.1a114.37,114.37 0,0 1,-3.51 15.08c-0.49,1.52 -1,3 -1.52,4.55s-1.15,3.21 -1.82,4.79a34.51,34.51 0,0 1,-1.33 3.27c-0.24,0.6 -0.54,1.27 -0.85,1.94 -0.48,1.09 -1,2.18 -1.57,3.27a81.21,81.21 0,0 1,-4.49 8.06,0.45 0.45,0 0,1 -0.12,0.24 45.21,45.21 0,0 1,-2.54 4c-0.61,1 -1.34,2 -2,3 -1.34,1.88 -2.67,3.7 -4.12,5.45 -0.79,1 -1.58,2 -2.43,2.91 -1.27,1.58 -2.66,3.09 -4,4.55 -0.84,0.85 -1.63,1.69 -2.42,2.42 -1.7,1.7 -3.39,3.33 -5.15,4.85a37,37 0,0 1,-3 2.54,114.43 114.43,0 0,1 -27.69,17c-1.22,0.49 -2.37,1 -3.58,1.46 -1.51,0.6 -3,1.15 -4.54,1.69H155c-1.46,0.55 -3,1 -4.55,1.52s-3.09,0.91 -4.66,1.27a83.44,83.44 0,0 1,-11.76 2.3,108.33 108.33,0 0,1 -34.72,0 92,92 0,0 1,-11.7 -2.3c-1.27,-0.3 -2.54,-0.67 -3.82,-1 -1.09,-0.3 -2.12,-0.61 -3.15,-1 -2.72,-0.85 -5.45,-1.88 -8.12,-3 -1.21,-0.48 -2.36,-1 -3.51,-1.51 -2.36,-1 -4.67,-2.19 -7,-3.4 -0.85,-0.42 -1.64,-0.91 -2.48,-1.39a53.27,53.27 0,0 1,-4.67 -2.79c-1.15,-0.67 -2.3,-1.39 -3.39,-2.18a8.83,8.83 0,0 1,-1.52 -1.09,45.51 45.51,0 0,1 -3.82,-2.73c-1.33,-1 -2.66,-2.06 -3.93,-3.15s-2.37,-2 -3.52,-3a116.85,116.85 0,0 1,-8.36 -8.3c-2.49,-2.73 -4.91,-5.64 -7.15,-8.61A116.06,116.06 0,0 1,0.61 243.11,109.93 109.93,0 0,1 0,231.18V16.66A16.65,16.65 0,0 1,16.66 0,16.43 16.43,0 0,1 28.42,4.91a16.42,16.42 0,0 1,4.91 11.75V231.18a83.24,83.24 0,0 0,77.32 83.08c2,0.18 4,0.24 6,0.24s4,-0.06 6,-0.24a83.23,83.23 0,0 0,77.26 -83.08V116.59a116.62,116.62 0,1 1,233.24 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M333.89,314.26v32.29a116.47,116.47 0,0 1,-17.33 1.28,117.78 117.78,0 0,1 -17.39,-1.28 116.59,116.59 0,0 1,-82.6 -55.32,81.21 81.21,0 0,0 4.49,-8.06c0.54,-1.09 1.09,-2.18 1.57,-3.27 0.31,-0.67 0.61,-1.34 0.85,-1.94a34.51,34.51 0,0 0,1.33 -3.27c0.67,-1.58 1.28,-3.22 1.82,-4.79s1,-3 1.52,-4.55a114.37,114.37 0,0 0,3.51 -15.08c0.18,-1 0.37,-2.07 0.49,-3.1a73.64,73.64 0,0 0,0.72 -7.33c0.12,-1.21 0.19,-2.36 0.25,-3.57 0.06,-1.7 0.12,-3.4 0.12,-5.09a83.3,83.3 0,0 0,83.32 83.08Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M244.24,461.32H188.9V433.65A27.66,27.66 0,0 1,216.57 406h0a27.66,27.66 0,0 1,27.67 27.66Z"
android:fillColor="#ffffff"/>
</group>
<group android:scaleX="0.09364433"
android:scaleY="0.09364433"
android:translateX="33.71898"
android:translateY="32.4">
<path
android:pathData="M116.65,314.5c-2,0 -4,-0.06 -6,-0.24h12C120.65,314.44 118.65,314.5 116.65,314.5Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M134,346.43V461.32H99.26V346.43a108.33,108.33 0,0 0,34.72 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M333.89,346.55V461.32H299.17V346.55a117.78,117.78 0,0 0,17.39 1.28A116.47,116.47 0,0 0,333.89 346.55Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M66.65,215.2V16.69A16.66,16.66 0,0 1,83.31 0,16.43 16.43,0 0,1 95.07,4.93 16.43,16.43 0,0 1,100 16.69V215.2a16.67,16.67 0,1 1,-33.33 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M133.31,215.2V16.69A16.66,16.66 0,0 1,150 0a16.43,16.43 0,0 1,11.76 4.91,16.43 16.43,0 0,1 4.91,11.76V215.2a16.67,16.67 0,1 1,-33.33 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M433.15,116.59V231.18a116.65,116.65 0,0 1,-99.26 115.37V314.26H316.56A83.25,83.25 0,0 0,399.82 231V116.77a83.29,83.29 0,0 0,-166.58 0V231.18c0,1.69 -0.06,3.39 -0.12,5.09 -0.06,1.21 -0.13,2.36 -0.25,3.57a73.64,73.64 0,0 1,-0.72 7.33c-0.12,1 -0.31,2.07 -0.49,3.1a114.37,114.37 0,0 1,-3.51 15.08c-0.49,1.52 -1,3 -1.52,4.55s-1.15,3.21 -1.82,4.79a34.51,34.51 0,0 1,-1.33 3.27c-0.24,0.6 -0.54,1.27 -0.85,1.94 -0.48,1.09 -1,2.18 -1.57,3.27a81.21,81.21 0,0 1,-4.49 8.06,0.45 0.45,0 0,1 -0.12,0.24 45.21,45.21 0,0 1,-2.54 4c-0.61,1 -1.34,2 -2,3 -1.34,1.88 -2.67,3.7 -4.12,5.45 -0.79,1 -1.58,2 -2.43,2.91 -1.27,1.58 -2.66,3.09 -4,4.55 -0.84,0.85 -1.63,1.69 -2.42,2.42 -1.7,1.7 -3.39,3.33 -5.15,4.85a37,37 0,0 1,-3 2.54,114.43 114.43,0 0,1 -27.69,17c-1.22,0.49 -2.37,1 -3.58,1.46 -1.51,0.6 -3,1.15 -4.54,1.69H155c-1.46,0.55 -3,1 -4.55,1.52s-3.09,0.91 -4.66,1.27a83.44,83.44 0,0 1,-11.76 2.3,108.33 108.33,0 0,1 -34.72,0 92,92 0,0 1,-11.7 -2.3c-1.27,-0.3 -2.54,-0.67 -3.82,-1 -1.09,-0.3 -2.12,-0.61 -3.15,-1 -2.72,-0.85 -5.45,-1.88 -8.12,-3 -1.21,-0.48 -2.36,-1 -3.51,-1.51 -2.36,-1 -4.67,-2.19 -7,-3.4 -0.85,-0.42 -1.64,-0.91 -2.48,-1.39a53.27,53.27 0,0 1,-4.67 -2.79c-1.15,-0.67 -2.3,-1.39 -3.39,-2.18a8.83,8.83 0,0 1,-1.52 -1.09,45.51 45.51,0 0,1 -3.82,-2.73c-1.33,-1 -2.66,-2.06 -3.93,-3.15s-2.37,-2 -3.52,-3a116.85,116.85 0,0 1,-8.36 -8.3c-2.49,-2.73 -4.91,-5.64 -7.15,-8.61A116.06,116.06 0,0 1,0.61 243.11,109.93 109.93,0 0,1 0,231.18V16.66A16.65,16.65 0,0 1,16.66 0,16.43 16.43,0 0,1 28.42,4.91a16.42,16.42 0,0 1,4.91 11.75V231.18a83.24,83.24 0,0 0,77.32 83.08c2,0.18 4,0.24 6,0.24s4,-0.06 6,-0.24a83.23,83.23 0,0 0,77.26 -83.08V116.59a116.62,116.62 0,1 1,233.24 0Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M333.89,314.26v32.29a116.47,116.47 0,0 1,-17.33 1.28,117.78 117.78,0 0,1 -17.39,-1.28 116.59,116.59 0,0 1,-82.6 -55.32,81.21 81.21,0 0,0 4.49,-8.06c0.54,-1.09 1.09,-2.18 1.57,-3.27 0.31,-0.67 0.61,-1.34 0.85,-1.94a34.51,34.51 0,0 0,1.33 -3.27c0.67,-1.58 1.28,-3.22 1.82,-4.79s1,-3 1.52,-4.55a114.37,114.37 0,0 0,3.51 -15.08c0.18,-1 0.37,-2.07 0.49,-3.1a73.64,73.64 0,0 0,0.72 -7.33c0.12,-1.21 0.19,-2.36 0.25,-3.57 0.06,-1.7 0.12,-3.4 0.12,-5.09a83.3,83.3 0,0 0,83.32 83.08Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M244.24,461.32H188.9V433.65A27.66,27.66 0,0 1,216.57 406h0a27.66,27.66 0,0 1,27.67 27.66Z"
android:fillColor="#ffffff"/>
</group>
</vector>
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ buildscript {
jcenter()
}
dependencies {
//classpath EnvironmentConfig.gradleTools
//classpath EnvironmentConfig.gradlePlugin
classpath "com.android.tools.build:gradle:4.0.0-rc01"
// classpath EnvironmentConfig.gradleTools
// classpath EnvironmentConfig.gradlePlugin
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
// classpath EnvironmentConfig.gradleTools
// classpath EnvironmentConfig.gradlePlugin

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package br.com.recipebook.recipecollection

import android.os.Bundle
import android.widget.Toast
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.observe
import br.com.recipebook.coreandroid.image.ImageResolver
import br.com.recipebook.designsystem.ListMarginItemDecoration
import br.com.recipebook.navigation.MainNavigator
import br.com.recipebook.navigation.R
import br.com.recipebook.navigation.intent.RecipeDetailIntent
import br.com.recipebook.recipecollection.databinding.RecipeCollectionActivityBinding
import br.com.recipebook.recipecollection.presentation.RecipeCollectionViewAction
import br.com.recipebook.recipecollection.presentation.RecipeCollectionViewModel
import br.com.recipebook.utilityandroid.MarginItemDecoration
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -55,22 +53,15 @@ class RecipeCollectionActivity : AppCompatActivity() {
}

private fun observeState(binding: RecipeCollectionActivityBinding) {
with(viewModel.viewState) {
recipes.observe(this@RecipeCollectionActivity) {
recipeCollectionAdapter.setData(it)
}
hasError.observe(this@RecipeCollectionActivity) {
if (it) {
Toast.makeText(
this@RecipeCollectionActivity,
"Error... improve this",
Toast.LENGTH_SHORT
).show()
}
}
isLoading.observe(this@RecipeCollectionActivity) {
binding.swipeRefresh.isRefreshing = it
}
viewModel.viewState.recipes.observe(this) {
recipeCollectionAdapter.setData(it)
}
viewModel.viewState.hasError.observe(this) {
binding.recipeCollectionErrorState.root.visibility = if (it) View.VISIBLE else View.GONE
}
viewModel.viewState.isLoading.observe(this) {
binding.swipeRefresh.isRefreshing = it
binding.recipeCollectionLoading.visibility = if (it) View.VISIBLE else View.GONE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RecipeCollectionViewModel(

private fun loadRecipeList() = viewModelScope.launch {
viewState.isLoading.value = true
viewState.hasError.value = false

when (val result = getRecipeCollection()) {
is ResultWrapper.Success -> onLoadRecipeListSuccess(result.data)
Expand All @@ -55,5 +56,6 @@ class RecipeCollectionViewModel(

private fun onLoadRecipeListError(error: CommonError) {
viewState.hasError.value = true
viewState.recipes.value = emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import br.com.recipebook.recipecollection.view.RecipeItem
class RecipeCollectionViewState {
val recipes = MutableLiveData<List<RecipeItem>>()
val isLoading = MutableLiveData<Boolean>()
val isFirstLoading = MutableLiveData<Boolean>()
val hasError = MutableLiveData<Boolean>()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand Down Expand Up @@ -35,7 +34,30 @@
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/recipe_card" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<include
android:id="@+id/recipe_collection_error_state"
layout="@layout/error_state_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"
tools:visibility="visible"/>

<ImageView
android:id="@+id/recipe_collection_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loading_icon"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ class RecipeDetailActivity : AppCompatActivity() {

private fun observeState(binding: RecipeDetailActivityBinding) {
viewModel.viewState.isLoading.observe(this) {

binding.recipeDetailLoading.visibility = if (it) View.VISIBLE else View.GONE
}
viewModel.viewState.hasError.observe(this) {
if (it) {
binding.recipeDetailErrorState.visibility = View.VISIBLE
binding.recipeDetailErrorState.root.visibility = View.VISIBLE
binding.appBarLayout.setExpanded(false)
} else {
binding.recipeDetailErrorState.visibility = View.GONE
binding.recipeDetailErrorState.root.visibility = View.GONE
}
}
viewModel.viewState.title.observe(this) {
Expand Down
Loading

0 comments on commit 80c4ba4

Please sign in to comment.