Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 69169a15 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor(search): update UI and text for empty results

parent 832d2350
Loading
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -18,22 +18,20 @@

package foundation.e.apps.ui.compose.components

import androidx.compose.foundation.Image
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign.Companion.Center
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -41,7 +39,7 @@ import foundation.e.apps.R
import foundation.e.apps.ui.compose.theme.AppTheme

@Composable
fun SearchPlaceholder(modifier: Modifier = Modifier) {
fun SearchPlaceholder(@StringRes stringResource: Int, modifier: Modifier = Modifier) {
    Box(
        modifier = modifier
            .fillMaxSize(),
@@ -51,21 +49,23 @@ fun SearchPlaceholder(modifier: Modifier = Modifier) {
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(12.dp),
        ) {
            Image(
                painter = painterResource(id = R.drawable.ic_error_circular),
                contentDescription = stringResource(id = R.string.menu_search),
                contentScale = ContentScale.Fit,
                modifier = Modifier
                    .padding(bottom = 4.dp)
                    .size(96.dp),
            )
            Text(
                text = stringResource(id = R.string.no_apps_found),
                text = stringResource(id = stringResource),
                style = MaterialTheme.typography.bodyMedium.copy(
                    fontSize = 18.sp
                ),
                color = colorResource(id = R.color.light_grey),
                textAlign = androidx.compose.ui.text.style.TextAlign.Center,
                color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.87f),
                textAlign = Center,
            )
            Text(
                text = stringResource(R.string.search_empty_results_body),
                modifier = Modifier.padding(horizontal = 32.dp),
                textAlign = Center,
                style = MaterialTheme.typography.bodyMedium.copy(
                    fontSize = 14.sp,
                    fontWeight = FontWeight.Normal
                ),
                color = MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.38f)
            )
        }
    }
@@ -75,6 +75,6 @@ fun SearchPlaceholder(modifier: Modifier = Modifier) {
@Composable
private fun SearchPlaceholderPreview() {
    AppTheme(darkTheme = true) {
        SearchPlaceholder()
        SearchPlaceholder(stringResource = R.string.search_empty_results_title_playstore)
    }
}
+22 −3
Original line number Diff line number Diff line
@@ -187,10 +187,22 @@ private fun SearchTabPage(
    installButtonStateProvider: (Application) -> InstallButtonState,
    modifier: Modifier = Modifier,
) {
    val items = when (tab) {
        SearchTabType.COMMON_APPS -> playStoreItems
        SearchTabType.OPEN_SOURCE -> fossItems
        SearchTabType.PWA -> pwaItems
    }

    val emptyResultsStringResource = when (tab) {
        SearchTabType.COMMON_APPS -> R.string.search_empty_results_title_playstore
        SearchTabType.OPEN_SOURCE -> R.string.search_empty_results_title_open_source
        SearchTabType.PWA -> R.string.search_empty_results_title_pwa
    }

    when (tab) {
        SearchTabType.OPEN_SOURCE -> {
            PagingSearchResultList(
                items = fossItems,
                items = items,
                searchVersion = searchVersion,
                tab = tab,
                getScrollPosition = getScrollPosition,
@@ -200,13 +212,14 @@ private fun SearchTabPage(
                onShowMoreClick = onShowMoreClick,
                onPrivacyClick = onPrivacyClick,
                installButtonStateProvider = installButtonStateProvider,
                emptyResultsStringResource = emptyResultsStringResource,
                modifier = modifier,
            )
        }

        SearchTabType.PWA -> {
            PagingSearchResultList(
                items = pwaItems,
                items = items,
                searchVersion = searchVersion,
                tab = tab,
                getScrollPosition = getScrollPosition,
@@ -216,13 +229,14 @@ private fun SearchTabPage(
                onShowMoreClick = onShowMoreClick,
                onPrivacyClick = onPrivacyClick,
                installButtonStateProvider = installButtonStateProvider,
                emptyResultsStringResource = emptyResultsStringResource,
                modifier = modifier,
            )
        }

        SearchTabType.COMMON_APPS -> {
            PagingPlayStoreResultList(
                items = playStoreItems,
                items = items,
                searchVersion = searchVersion,
                getScrollPosition = getScrollPosition,
                onScrollPositionChange = onScrollPositionChange,
@@ -231,6 +245,7 @@ private fun SearchTabPage(
                onShowMoreClick = onShowMoreClick,
                onPrivacyClick = onPrivacyClick,
                installButtonStateProvider = installButtonStateProvider,
                emptyResultsStringResource = emptyResultsStringResource,
                modifier = modifier,
            )
        }
@@ -248,6 +263,7 @@ private fun PagingPlayStoreResultList(
    onShowMoreClick: (Application) -> Unit,
    onPrivacyClick: (Application) -> Unit,
    installButtonStateProvider: (Application) -> InstallButtonState,
    emptyResultsStringResource: Int,
    modifier: Modifier = Modifier,
) {
    val lazyItems = items ?: return
@@ -314,6 +330,7 @@ private fun PagingPlayStoreResultList(

            isEmpty -> {
                SearchPlaceholder(
                    stringResource = emptyResultsStringResource,
                    modifier = Modifier
                        .fillMaxWidth()
                        .align(Alignment.Center)
@@ -388,6 +405,7 @@ private fun PagingSearchResultList(
    onShowMoreClick: (Application) -> Unit,
    onPrivacyClick: (Application) -> Unit,
    installButtonStateProvider: (Application) -> InstallButtonState,
    emptyResultsStringResource: Int,
    modifier: Modifier = Modifier,
) {
    val lazyItems = items ?: return
@@ -452,6 +470,7 @@ private fun PagingSearchResultList(

            isEmpty -> {
                SearchPlaceholder(
                    stringResource = emptyResultsStringResource,
                    modifier = Modifier
                        .fillMaxWidth()
                        .align(Alignment.Center)
+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@
    <string name="search_error">This page or resource is unavailable due to maintenance.</string>
    <string name="search_error_title">Please try again later</string>
    <string name="search_error_icon_cd">Search error</string>
    <string name="search_empty_results_title_playstore">No results in Apps</string>
    <string name="search_empty_results_title_open_source">No results in Open Source</string>
    <string name="search_empty_results_title_pwa">No results in Web Apps</string>
    <string name="search_empty_results_body">Other app sources may be able to provide results, please check the other tabs/your settings.</string>

    <!-- Categories Fragment -->
    <string name="apps" weblate_ctx="categories_applications">Applications</string>