Skip to content

Commit

Permalink
Merge pull request #77 from Spikeysanju/Add-Empty-State
Browse files Browse the repository at this point in the history
Add empty state
  • Loading branch information
Spikeysanju authored May 4, 2021
2 parents eb77b6c + 2a152d6 commit 526ec2f
Show file tree
Hide file tree
Showing 5 changed files with 13,647 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.2.0"
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -106,7 +106,6 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"


// Dagger Hilt
implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
Expand All @@ -116,4 +115,7 @@ dependencies {
implementation "androidx.hilt:hilt-common:1.0.0-beta01"
kapt "com.google.dagger:hilt-compiler:2.33-beta"

// Lottie
implementation ("com.airbnb.android:lottie-compose:1.0.0-beta03-1")

}
102 changes: 102 additions & 0 deletions app/src/main/java/www/spikeysanju/jetquotes/components/EmptyScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
*
* *
* * * MIT License
* * *
* * * Copyright (c) 2020 Sanju S
* * *
* * * Permission is hereby granted, free of charge, to any person obtaining a copy
* * * of this software and associated documentation files (the "Software"), to deal
* * * in the Software without restriction, including without limitation the rights
* * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* * * copies of the Software, and to permit persons to whom the Software is
* * * furnished to do so, subject to the following conditions:
* * *
* * * The above copyright notice and this permission notice shall be included in all
* * * copies or substantial portions of the Software.
* * *
* * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* * * SOFTWARE.
* *
*
*/

package www.spikeysanju.jetquotes.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieAnimationSpec
import com.airbnb.lottie.compose.LottieAnimationState
import com.airbnb.lottie.compose.rememberLottieAnimationState
import www.spikeysanju.jetquotes.R
import www.spikeysanju.jetquotes.navigation.MainActions
import www.spikeysanju.jetquotes.ui.typography


@Composable
fun EmptyScreen(actions: MainActions) {
Column(
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally
) {
Loader()
Text(
text = "Your wish list is empty!",
modifier = Modifier.fillMaxWidth(),
style = typography.h6,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Explore more and add some quotes!",
modifier = Modifier.fillMaxWidth(),
style = typography.body2,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.onPrimary.copy(.7f)
)
Spacer(modifier = Modifier.height(24.dp))
androidx.compose.material.Button(
onClick = { actions.upPress() }, colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.colors.onPrimary,
contentColor = MaterialTheme.colors.background
)
) {
Text(text = "Back to home")
}
}
}

@Composable
fun Loader() {
val animationSpec: LottieAnimationSpec.RawRes =
remember { LottieAnimationSpec.RawRes(R.raw.empty) }
val animationState: LottieAnimationState =
rememberLottieAnimationState(autoPlay = true, repeatCount = Integer.MAX_VALUE)

LottieAnimation(
animationSpec,
modifier = Modifier.size(300.dp),
animationState = animationState
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.components.EmptyScreen
import www.spikeysanju.jetquotes.components.QuotesCard
import www.spikeysanju.jetquotes.components.TopBarWithBack
import www.spikeysanju.jetquotes.navigation.MainActions
Expand All @@ -79,9 +80,7 @@ fun FavouritesScreen(viewModel: MainViewModel, actions: MainActions) {
}, content = {
// pass quote & author params to details card
when (val result = viewModel.favState.collectAsState().value) {
is FavouriteViewState.Empty -> {
Text(text = "Empty List")
}
is FavouriteViewState.Empty -> EmptyScreen(actions)
is FavouriteViewState.Success -> {
LazyColumn {
items(result.quote) { quote ->
Expand Down
Loading

0 comments on commit 526ec2f

Please sign in to comment.