Skip to content

Commit

Permalink
Fixup ui somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Oct 22, 2024
1 parent 82848a2 commit 180acb6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
package net.mullvad.mullvadvpn.compose.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
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.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.core.text.HtmlCompat
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.extensions.toAnnotatedString
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.relaylist.MIN_SEARCH_LENGTH

@Composable
fun LocationsEmptyText(searchTerm: String) {
if (searchTerm.length >= MIN_SEARCH_LENGTH) {
val firstRow =
HtmlCompat.fromHtml(
textResource(id = R.string.select_location_empty_text_first_row, searchTerm),
HtmlCompat.FROM_HTML_MODE_COMPACT,
)
.toAnnotatedString(boldFontWeight = FontWeight.ExtraBold)
val secondRow = textResource(id = R.string.select_location_empty_text_second_row)
Column(
modifier = Modifier.padding(horizontal = Dimens.selectLocationTitlePadding),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = firstRow,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
Text(
text = secondRow,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Text(
text = textResource(R.string.search_location_empty_text, searchTerm),
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(Dimens.screenVerticalMargin),
)
} else {
Text(
text = stringResource(R.string.no_locations_found),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ fun LazyListScope.relayListContent(
}
)
},
locationHeader: @Composable LazyItemScope.() -> Unit = {
RelayLocationHeader()
}
locationHeader: @Composable LazyItemScope.() -> Unit = { RelayLocationHeader() },
) {
itemsIndexed(
items = relayListItems,
Expand All @@ -61,17 +59,7 @@ fun LazyListScope.relayListContent(
HorizontalDivider(color = backgroundColor)
}
when (listItem) {
RelayListItem.CustomListHeader ->
/*CustomListHeader(
onShowCustomListBottomSheet = {
onUpdateBottomSheetState(
ShowCustomListsBottomSheet(
editListEnabled = customLists.isNotEmpty()
)
)
}
)*/
customListHeader()
RelayListItem.CustomListHeader -> customListHeader()
is RelayListItem.CustomListItem ->
CustomListItem(
listItem,
Expand Down Expand Up @@ -103,7 +91,7 @@ fun LazyListScope.relayListContent(
},
)
is RelayListItem.CustomListFooter -> CustomListFooter(listItem)
RelayListItem.LocationHeader -> locationHeader()//RelayLocationHeader()
RelayListItem.LocationHeader -> locationHeader()
is RelayListItem.GeoLocationItem ->
RelayLocationItem(
listItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ fun SearchLocationScreen(
onRemoveOwnershipFilter = onRemoveOwnershipFilter,
onRemoveProviderFilter = onRemoveProviderFilter,
)
searchResultTitle(onBackgroundColor = onBackgroundColor)
when (state) {
is SearchSelectLocationUiState.NoQuery -> {
noQuery()
Expand All @@ -279,6 +278,18 @@ fun SearchLocationScreen(
onUpdateBottomSheetState = { newSheetState ->
locationBottomSheetState = newSheetState
},
customListHeader = {
Title(
text = stringResource(R.string.custom_lists),
onBackgroundColor = onBackgroundColor,
)
},
locationHeader = {
Title(
text = stringResource(R.string.locations),
onBackgroundColor = onBackgroundColor,
)
},
)
}
}
Expand Down Expand Up @@ -343,7 +354,7 @@ private fun SearchBar(
private fun LazyListScope.noQuery() {
item(contentType = ContentType.DESCRIPTION) {
Text(
text = "Type at least 2 characters to start searching",
text = stringResource(R.string.search_query_empty),
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant,
Expand All @@ -360,13 +371,9 @@ private fun LazyListScope.filterRow(
) {
if (filters.isNotEmpty()) {
item {
Text(
Title(
text = stringResource(R.string.filters),
color = onBackgroundColor,
modifier =
Modifier.fillMaxWidth()
.padding(horizontal = Dimens.sideMargin, vertical = Dimens.smallPadding),
style = MaterialTheme.typography.labelMedium,
onBackgroundColor = onBackgroundColor,
)
}
item {
Expand All @@ -380,15 +387,14 @@ private fun LazyListScope.filterRow(
}
}

private fun LazyListScope.searchResultTitle(onBackgroundColor: Color) {
item {
Text(
text = stringResource(R.string.search_results),
color = onBackgroundColor,
modifier =
Modifier.fillMaxWidth()
.padding(horizontal = Dimens.sideMargin, vertical = Dimens.smallPadding),
style = MaterialTheme.typography.labelMedium,
)
}
@Composable
private fun Title(text: String, onBackgroundColor: Color) {
Text(
text = text,
color = onBackgroundColor,
modifier =
Modifier.fillMaxWidth()
.padding(horizontal = Dimens.sideMargin, vertical = Dimens.smallPadding),
style = MaterialTheme.typography.labelMedium,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private fun createCustomListSection(
val customListItems =
createCustomListRelayItems(customLists, selectedItem, disabledItem, isExpanded)
addAll(customListItems)
add(RelayListItem.CustomListFooter(customListItems.isNotEmpty()))
// Do not show the footer in the search view
if (!isSearching) {
add(RelayListItem.CustomListFooter(customListItems.isNotEmpty()))
}
}
}

Expand All @@ -84,7 +87,8 @@ private fun createCustomListRelayItems(
isSelected = selectedItem == customList.id,
isEnabled =
disabledItem != customList.id &&
disabledItem != customList.locations.singleOrNull()?.id,
customList.locations.singleOrNull()?.id?.let { it != disabledItem } !=
false,
expanded = expanded,
)
)
Expand Down
6 changes: 2 additions & 4 deletions android/lib/resource/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@
<string name="wireguard_port_title">WireGuard port</string>
<string name="wireguard_port_info_description">The automatic setting will randomly choose from the valid port ranges shown below.</string>
<string name="search_placeholder">Search for...</string>
<string name="select_location_empty_text_first_row">
<![CDATA[No result for <b>%s</b>.]]>
</string>
<string name="select_location_empty_text_second_row">Try a different search.</string>
<string name="search_location_empty_text">No result for \"%s\", please try a different search</string>
<string name="wireguard_port_info_port_range">The custom port can be any value inside the valid ranges: %s.</string>
<string name="wireguard_custon_port_title">Custom</string>
<string name="port">Port</string>
Expand Down Expand Up @@ -424,4 +421,5 @@
<string name="x_exit">%s (Exit)</string>
<string name="search_results">Search results</string>
<string name="filters">Filters</string>
<string name="search_query_empty">Type at least 2 characters to start searching.</string>
</resources>

0 comments on commit 180acb6

Please sign in to comment.