Skip to content

Commit

Permalink
Add Refresh icon for desktop platform
Browse files Browse the repository at this point in the history
  • Loading branch information
mr3y-the-programmer committed Oct 28, 2023
1 parent eaf8498 commit 8279075
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ import androidx.compose.runtime.CompositionLocalProvider

@Composable
actual fun ProvideCompositionLocalValues(content: @Composable () -> Unit) = CompositionLocalProvider(content = content)

actual fun isDesktopPlatform() = false
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.unit.dp
import com.mr3y.ludi.shared.ui.resources.isDesktopPlatform

@Composable
fun LudiErrorBox(modifier: Modifier = Modifier) {
Expand All @@ -27,8 +28,12 @@ fun LudiErrorBox(modifier: Modifier = Modifier) {
contentDescription = null,
tint = MaterialTheme.colorScheme.error
)
val errorMessage = if (isDesktopPlatform()) {
"Unexpected Error happened. try to refresh, and see if the problem persists."
} else
"Unexpected Error happened. pull to refresh, and see if the problem persists."
Text(
text = "Unexpected Error happened. pull to refresh, and see if the problem persists.",
text = errorMessage,
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurface
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mr3y.ludi.shared.ui.components

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import cafe.adriel.lyricist.LocalStrings

@Composable
fun RefreshIconButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
tint: Color = MaterialTheme.colorScheme.inverseSurface
) {
val strings = LocalStrings.current
IconButton(
onClick = onClick,
modifier = modifier
.requiredSize(48.dp)
.semantics {
contentDescription = strings.click_to_refresh
}
) {
Icon(
imageVector = Icons.Filled.Refresh,
contentDescription = null,
modifier = Modifier
.padding(8.dp)
.fillMaxSize(),
tint = tint
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ val EnLudiStrings = LudiStrings(
edit_preferences_page_game_content_description = { "Remove $it from my favourites" },
edit_preferences_page_genre_on_state_desc = { "Remove $it Genre from my favourites" },
edit_preferences_page_genre_off_state_desc = { "Add $it Genre to my favourites" },
click_to_refresh = "Click to Refresh",
now = "now",
news_no_releases_to_show = "No New Releases to show",
news_no_news_to_show = "No New News to show",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data class LudiStrings(
val edit_preferences_page_game_content_description: (String) -> String,
val edit_preferences_page_genre_on_state_desc: (String) -> String,
val edit_preferences_page_genre_off_state_desc: (String) -> String,
val click_to_refresh: String,
val now: String,
val news_no_releases_to_show: String,
val news_no_news_to_show: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ import androidx.compose.runtime.Composable
*/
@Composable
expect fun ProvideCompositionLocalValues(content: @Composable () -> Unit)

expect fun isDesktopPlatform(): Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ fun DealsScreen(
onFilterClicked = onToggleFilters,
showSearchBar = dealsState.selectedTab == 0,
scrollBehavior = scrollBehavior,
onRefreshDeals = onRefreshDeals,
onRefreshGiveaways = onRefreshGiveaways,
modifier = Modifier
.fillMaxWidth()
.height(IntrinsicSize.Min)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.mr3y.ludi.shared.ui.screens.deals

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand Down Expand Up @@ -39,13 +41,17 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import cafe.adriel.lyricist.LocalStrings
import com.mr3y.ludi.shared.ui.components.RefreshIconButton
import com.mr3y.ludi.shared.ui.resources.isDesktopPlatform

@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun SearchFilterBar(
searchQuery: String,
onSearchQueryValueChanged: (String) -> Unit,
onFilterClicked: () -> Unit,
onRefreshDeals: () -> Unit,
onRefreshGiveaways: () -> Unit,
showSearchBar: Boolean,
scrollBehavior: TopAppBarScrollBehavior,
modifier: Modifier = Modifier
Expand Down Expand Up @@ -103,6 +109,12 @@ fun SearchFilterBar(
}
},
actions = {
if (isDesktopPlatform()) {
RefreshIconButton(
onClick = if (showSearchBar) onRefreshDeals else onRefreshGiveaways
)
Spacer(modifier = Modifier.width(8.dp))
}
val contentDescription = strings.deals_filter_icon_content_description
IconButton(
onClick = onFilterClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ fun DiscoverScreen(
searchQuery = searchQuery,
onSearchQueryValueChanged = onUpdatingSearchQueryText,
onTuneClicked = { openFilters = !openFilters },
onRefresh = {
onRefresh() // notify ViewModel to update state
refresh++
},
modifier = Modifier
.padding(vertical = 8.dp)
.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mr3y.ludi.shared.ui.screens.discover

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand Down Expand Up @@ -36,12 +38,15 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import cafe.adriel.lyricist.LocalStrings
import com.mr3y.ludi.shared.ui.components.RefreshIconButton
import com.mr3y.ludi.shared.ui.resources.isDesktopPlatform

@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun DiscoverTopBar(
searchQuery: String,
onSearchQueryValueChanged: (String) -> Unit,
onRefresh: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
onTuneClicked: () -> Unit,
modifier: Modifier = Modifier
Expand Down Expand Up @@ -93,6 +98,10 @@ fun DiscoverTopBar(
},
modifier = modifier,
actions = {
if (isDesktopPlatform()) {
RefreshIconButton(onClick = onRefresh)
Spacer(modifier = Modifier.width(8.dp))
}
IconButton(
onClick = onTuneClicked,
modifier = Modifier.requiredSize(48.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ import com.mr3y.ludi.shared.di.getScreenModel
import com.mr3y.ludi.shared.ui.components.AnimatedNoInternetBanner
import com.mr3y.ludi.shared.ui.components.LudiErrorBox
import com.mr3y.ludi.shared.ui.components.LudiSectionHeader
import com.mr3y.ludi.shared.ui.components.RefreshIconButton
import com.mr3y.ludi.shared.ui.navigation.BottomBarTab
import com.mr3y.ludi.shared.ui.navigation.PreferencesType
import com.mr3y.ludi.shared.ui.presenter.NewsViewModel
import com.mr3y.ludi.shared.ui.presenter.model.NewsState
import com.mr3y.ludi.shared.ui.presenter.model.NewsStateEvent
import com.mr3y.ludi.shared.ui.resources.isDesktopPlatform
import com.mr3y.ludi.shared.ui.screens.settings.EditPreferencesScreen

object NewsScreenTab : Screen, BottomBarTab {
Expand Down Expand Up @@ -137,6 +139,10 @@ fun NewsScreen(
TopAppBar(
title = {},
actions = {
if (isDesktopPlatform()) {
RefreshIconButton(onClick = onRefresh)
Spacer(modifier = Modifier.width(8.dp))
}
IconButton(
onClick = onTuneClick,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ import com.mr3y.ludi.shared.core.model.Game
import com.mr3y.ludi.shared.ui.components.AnimatedNoInternetBanner
import com.mr3y.ludi.shared.ui.components.AsyncImage
import com.mr3y.ludi.shared.ui.components.LudiErrorBox
import com.mr3y.ludi.shared.ui.components.RefreshIconButton
import com.mr3y.ludi.shared.ui.components.placeholder.PlaceholderHighlight
import com.mr3y.ludi.shared.ui.components.placeholder.defaultPlaceholder
import com.mr3y.ludi.shared.ui.components.placeholder.fade
import com.mr3y.ludi.shared.ui.presenter.model.FavouriteGame
import com.mr3y.ludi.shared.ui.presenter.model.OnboardingGames
import com.mr3y.ludi.shared.ui.resources.isDesktopPlatform
import com.mr3y.ludi.shared.ui.theme.rating_star

@OptIn(ExperimentalComposeUiApi::class)
Expand All @@ -92,6 +94,7 @@ fun SelectingFavouriteGamesPage(
favouriteUserGames: List<FavouriteGame>,
onAddingGameToFavourites: (FavouriteGame) -> Unit,
onRemovingGameFromFavourites: (FavouriteGame) -> Unit,
onRefresh: () -> Unit,
refreshSignal: Int,
modifier: Modifier = Modifier,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
Expand Down Expand Up @@ -127,69 +130,77 @@ fun SelectingFavouriteGamesPage(
)
}

TextField(
value = searchQueryText,
onValueChange = onUpdatingSearchQueryText,
colors = TextFieldDefaults.colors(
disabledIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
focusedContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
disabledContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
errorContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
unfocusedContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
),
leadingIcon = {
IconButton(
onClick = { },
modifier = Modifier.clearAndSetSemantics { }
) {
Icon(
painter = rememberVectorPainter(image = Icons.Filled.Search),
contentDescription = null,
modifier = Modifier.fillMaxHeight()
)
}
},
trailingIcon = if (searchQueryText.isNotEmpty()) {
{
Row(
modifier = Modifier.align(Alignment.CenterHorizontally),
verticalAlignment = Alignment.CenterVertically
) {
TextField(
value = searchQueryText,
onValueChange = onUpdatingSearchQueryText,
colors = TextFieldDefaults.colors(
disabledIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
focusedContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
disabledContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
errorContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp),
unfocusedContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
),
leadingIcon = {
IconButton(
onClick = { onUpdatingSearchQueryText("") },
modifier = Modifier.clearAndSetSemantics {
contentDescription = strings.games_page_clear_search_query_desc
onClick {
onUpdatingSearchQueryText("")
true
}
}
onClick = { },
modifier = Modifier.clearAndSetSemantics { }
) {
Icon(
painter = rememberVectorPainter(image = Icons.Filled.Close),
painter = rememberVectorPainter(image = Icons.Filled.Search),
contentDescription = null,
modifier = Modifier.fillMaxHeight()
)
}
}
} else {
null
},
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { softwareKeyboard?.hide() }),
modifier = Modifier
.clip(RoundedCornerShape(50))
.align(Alignment.CenterHorizontally)
.shadow(elevation = 8.dp, shape = RoundedCornerShape(50))
.semantics {
focused = true
contentDescription = strings.games_page_search_field_desc
imeAction = ImeAction.Done
performImeAction {
softwareKeyboard?.hide() ?: return@performImeAction false
true
},
trailingIcon = if (searchQueryText.isNotEmpty()) {
{
IconButton(
onClick = { onUpdatingSearchQueryText("") },
modifier = Modifier.clearAndSetSemantics {
contentDescription = strings.games_page_clear_search_query_desc
onClick {
onUpdatingSearchQueryText("")
true
}
}
) {
Icon(
painter = rememberVectorPainter(image = Icons.Filled.Close),
contentDescription = null,
modifier = Modifier.fillMaxHeight()
)
}
}
}
)
} else {
null
},
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { softwareKeyboard?.hide() }),
modifier = Modifier
.clip(RoundedCornerShape(50))
.shadow(elevation = 8.dp, shape = RoundedCornerShape(50))
.semantics {
focused = true
contentDescription = strings.games_page_search_field_desc
imeAction = ImeAction.Done
performImeAction {
softwareKeyboard?.hide() ?: return@performImeAction false
true
}
}
)
if (isDesktopPlatform()) {
Spacer(modifier = Modifier.width(16.dp))
RefreshIconButton(onClick = onRefresh)
}
}
AnimatedNoInternetBanner(modifier = Modifier.padding(vertical = 8.dp))
Text(
text = strings.games_page_suggestions_label,
Expand Down
Loading

0 comments on commit 8279075

Please sign in to comment.