Skip to content

Commit

Permalink
Display empty image in both orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Sep 18, 2023
1 parent 4f5371a commit 787313b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
33 changes: 26 additions & 7 deletions app/src/main/java/com/sample/tmdb/ui/bookmark/BookmarkScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.booleanResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -147,19 +148,14 @@ private fun <T : TMDbItem> TabContent(items: List<T>, onClick: (TMDbItem) -> Uni

@Composable
private fun EmptyView(@StringRes textResourceId: Int) {
val configuration = LocalConfiguration.current
val isPortrait = when (configuration.orientation) {
Configuration.ORIENTATION_PORTRAIT -> { true }
else -> { false }
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(bottom = Dimens.PaddingExtraLarge),
.padding(bottom = 64.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
if(isPortrait) {
if (isEmptyImageVisible()) {
Image(
modifier = Modifier.padding(bottom = Dimens.PaddingLarge),
painter = painterResource(id = R.drawable.ic_empty),
Expand All @@ -177,6 +173,29 @@ private fun EmptyView(@StringRes textResourceId: Int) {
}
}

@Composable
private fun isEmptyImageVisible(): Boolean {
val configuration = LocalConfiguration.current
val isPortrait = when (configuration.orientation) {
Configuration.ORIENTATION_PORTRAIT -> {
true
}

else -> {
false
}
}
if (isPortrait) {
return true
} else {
val isTablet = booleanResource(id = R.bool.is_tablet)
if (isTablet) {
return true
}
}
return false
}

enum class MediaTab(@StringRes val titleResourceId: Int) {
Movies(titleResourceId = R.string.movie),
TvShows(titleResourceId = R.string.tv_show)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-sw600dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_tablet">true</bool>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<dimen name="padding_normal">12dp</dimen>
<dimen name="padding_large">16dp</dimen>
<dimen name="padding_extra_large">32dp</dimen>
<bool name="is_tablet">false</bool>
</resources>

0 comments on commit 787313b

Please sign in to comment.