Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
added a lottie animation when data is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Dec 27, 2022
1 parent d6b06fc commit e65de6b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ dependencies {
annotationProcessor("androidx.room:room-compiler:$room_version")
ksp("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")
//lottie
implementation 'com.airbnb.android:lottie-compose:5.2.0'
}
49 changes: 24 additions & 25 deletions app/src/main/java/io/github/yamin8000/owl/content/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ import androidx.lifecycle.lifecycleScope
import io.github.yamin8000.owl.R
import io.github.yamin8000.owl.content.MainBottomBar
import io.github.yamin8000.owl.content.MainTopBar
import io.github.yamin8000.owl.ui.composable.InternetAwareComposable
import io.github.yamin8000.owl.ui.composable.LockScreenOrientation
import io.github.yamin8000.owl.ui.composable.MySnackbar
import io.github.yamin8000.owl.ui.composable.PersianText
import io.github.yamin8000.owl.ui.composable.*
import io.github.yamin8000.owl.ui.theme.PreviewTheme
import kotlinx.coroutines.launch
import java.util.*
Expand Down Expand Up @@ -153,30 +150,32 @@ fun HomeContent(

val addedToFavourites = stringResource(R.string.added_to_favourites)

state.rawWordSearchBody.value?.let { word ->
WordCard(
locale.toLanguageTag(),
word.word,
word.pronunciation,
onShareWord = onShareWord,
onAddToFavourite = {
state.scope.launch {
state.addToFavourite(word.word)
state.snackbarHostState.showSnackbar(addedToFavourites)
if (state.rawWordSearchBody.value != null || state.searchResult.value.item.isNotEmpty()) {
state.rawWordSearchBody.value?.let { word ->
WordCard(
locale.toLanguageTag(),
word.word,
word.pronunciation,
onShareWord = onShareWord,
onAddToFavourite = {
state.scope.launch {
state.addToFavourite(word.word)
state.snackbarHostState.showSnackbar(addedToFavourites)
}
}
)
}

WordDefinitionsList(
locale.toLanguageTag(),
state.listState,
state.searchResult.value,
onWordChipClick = {
state.searchText = it
state.lifecycleOwner.lifecycleScope.launch { state.searchForDefinitionHandler() }
}
)
}

WordDefinitionsList(
locale.toLanguageTag(),
state.listState,
state.searchResult.value,
onWordChipClick = {
state.searchText = it
state.lifecycleOwner.lifecycleScope.launch { state.searchForDefinitionHandler() }
}
)
} else EmptyList()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.airbnb.lottie.compose.*
import io.github.yamin8000.owl.R
import io.github.yamin8000.owl.util.Constants.DNS_SERVERS
import io.github.yamin8000.owl.util.Constants.INTERNET_CHECK_DELAY
import io.github.yamin8000.owl.util.TTS
Expand All @@ -46,6 +48,19 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import java.util.*

@Composable
fun EmptyList() {
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.empty_list))
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever
)
LottieAnimation(
composition = composition,
progress = { progress },
)
}

@Composable
fun MySnackbar(
modifier: Modifier = Modifier,
Expand Down
Loading

0 comments on commit e65de6b

Please sign in to comment.