Refactor: Update DiscoverServersList and related files
- Updated `DiscoverServersList` to refine UI elements:
- Removed background modifier and lazy list state.
- Adjusted padding, spacing, and image resources for server items.
- Replaced `UserAvatar` with a generic `Image` for server icons.
- Added an `IconButton` for server selection.
- Added extra space at the bottom of list.
- Simplified `DiscoverViewModel` by removing filtering logic, selected category, search query, and server acknowledgement functionality.
- Streamlined `ServerData` in `ServerDataRepository.kt` by removing several fields: `iconUrl`, `bannerUrl`, `memberCount`, `category`, `tags`, `isVerified`, and `isOfficial`.
- Added a new drawable resource `three_person.xml`.
- Updated `ChannelSideDrawer.kt` to use `safeDrawingPadding()` for better handling of system UI elements.
This commit is contained in:
parent
6fbdac17fe
commit
cfb68f0ed6
|
|
@ -24,13 +24,6 @@ class ServerDataRepository {
|
|||
id = rowData["id"] ?: "",
|
||||
name = rowData["name"] ?: "",
|
||||
description = rowData["description"] ?: "",
|
||||
iconUrl = rowData["iconUrl"] ?: "",
|
||||
bannerUrl = rowData["bannerUrl"] ?: "",
|
||||
memberCount = rowData["memberCount"]?.toIntOrNull() ?: 0,
|
||||
category = rowData["category"] ?: "",
|
||||
tags = rowData["tags"]?.split(",")?.map { it.trim() } ?: emptyList(),
|
||||
isVerified = rowData["isVerified"]?.toBoolean() ?: false,
|
||||
isOfficial = rowData["isOfficial"]?.toBoolean() ?: false
|
||||
)
|
||||
}
|
||||
emit(servers)
|
||||
|
|
@ -65,13 +58,6 @@ data class ServerData(
|
|||
val id: String,
|
||||
val name: String,
|
||||
val description: String,
|
||||
val iconUrl: String,
|
||||
val bannerUrl: String,
|
||||
val memberCount: Int,
|
||||
val category: String,
|
||||
val tags: List<String>,
|
||||
val isVerified: Boolean,
|
||||
val isOfficial: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
@ -84,4 +70,4 @@ data class ServerCategory(
|
|||
val description: String,
|
||||
val iconName: String,
|
||||
val sortOrder: Int
|
||||
)
|
||||
)
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package chat.revolt.composables.screens.chat.discover
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -11,14 +10,12 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -26,18 +23,15 @@ import androidx.compose.runtime.collectAsState
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
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
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import chat.revolt.R
|
||||
import chat.revolt.api.routes.googlesheets.ServerData
|
||||
import chat.revolt.composables.generic.NonIdealState
|
||||
import chat.revolt.composables.generic.UserAvatar
|
||||
|
||||
@Composable
|
||||
fun DiscoverServersList() {
|
||||
|
|
@ -57,22 +51,22 @@ fun DiscoverServersList() {
|
|||
painter = painterResource(R.drawable.discover_character_image),
|
||||
contentDescription = null,
|
||||
)
|
||||
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.discover_servers),
|
||||
style = MaterialTheme.typography.headlineMedium
|
||||
)
|
||||
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.discover_servers_description),
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
|
||||
when {
|
||||
isLoading -> {
|
||||
CircularProgressIndicator(
|
||||
|
|
@ -89,7 +83,6 @@ fun DiscoverServersList() {
|
|||
}
|
||||
else -> {
|
||||
LazyColumn(
|
||||
state = rememberLazyListState(),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.weight(1f)
|
||||
|
|
@ -100,6 +93,9 @@ fun DiscoverServersList() {
|
|||
onClick = { /* Handle server selection */ }
|
||||
)
|
||||
}
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(96.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -120,11 +116,15 @@ fun ServerItem(
|
|||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
.padding(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Image(
|
||||
painter = painterResource(R.drawable.three_person),
|
||||
contentDescription = "",
|
||||
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onBackground)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
|
|
@ -132,7 +132,6 @@ fun ServerItem(
|
|||
Text(
|
||||
text = server.name,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
|
@ -140,17 +139,28 @@ fun ServerItem(
|
|||
Text(
|
||||
text = server.description,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onBackground.copy(
|
||||
alpha = 0.7f,
|
||||
),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Text(
|
||||
text = "${server.memberCount} members",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
IconButton(
|
||||
onClick = onClick,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.icn_arrow_forward_24dp),
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import androidx.compose.foundation.layout.navigationBars
|
|||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.safeContentPadding
|
||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.layout.width
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import androidx.lifecycle.viewModelScope
|
|||
import chat.revolt.api.routes.googlesheets.ServerCategory
|
||||
import chat.revolt.api.routes.googlesheets.ServerData
|
||||
import chat.revolt.api.routes.googlesheets.ServerDataRepository
|
||||
import chat.revolt.api.routes.server.ackServer
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -27,14 +26,6 @@ class DiscoverViewModel @Inject constructor(
|
|||
var uiState by mutableStateOf<DiscoverUiState>(DiscoverUiState.Loading)
|
||||
private set
|
||||
|
||||
// Selected category for filtering
|
||||
var selectedCategory by mutableStateOf<String?>(null)
|
||||
private set
|
||||
|
||||
// Search query for filtering
|
||||
var searchQuery by mutableStateOf("")
|
||||
private set
|
||||
|
||||
// Initialize the ViewModel
|
||||
init {
|
||||
loadServerData()
|
||||
|
|
@ -68,56 +59,6 @@ class DiscoverViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected category for filtering
|
||||
* @param categoryId The ID of the category to select, or null to clear selection
|
||||
*/
|
||||
fun selectCategory(categoryId: String?) {
|
||||
selectedCategory = categoryId
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the search query for filtering
|
||||
* @param query The search query
|
||||
*/
|
||||
fun updateSearchQuery(query: String) {
|
||||
searchQuery = query
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filtered list of servers based on selected category and search query
|
||||
*/
|
||||
fun getFilteredServers(): List<ServerData> {
|
||||
val currentState = uiState
|
||||
if (currentState !is DiscoverUiState.Success) return emptyList()
|
||||
|
||||
return currentState.servers.filter { server ->
|
||||
val matchesCategory = selectedCategory == null || server.category == selectedCategory
|
||||
val matchesSearch = searchQuery.isEmpty() ||
|
||||
server.name.contains(searchQuery, ignoreCase = true) ||
|
||||
server.description.contains(searchQuery, ignoreCase = true) ||
|
||||
server.tags.any { it.contains(searchQuery, ignoreCase = true) }
|
||||
|
||||
matchesCategory && matchesSearch
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acknowledges a server selection
|
||||
* This can be used for analytics or to mark a server as viewed
|
||||
* @param serverId The ID of the selected server
|
||||
*/
|
||||
fun acknowledgeServerSelection(serverId: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
ackServer(serverId)
|
||||
} catch (e: Exception) {
|
||||
// Log but don't change UI state as this is not critical
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="40dp"
|
||||
android:height="40dp"
|
||||
android:viewportWidth="40"
|
||||
android:viewportHeight="40">
|
||||
<path
|
||||
android:pathData="M14.01,21.857C14.012,21.908 14.005,21.958 13.987,22.006C13.969,22.054 13.942,22.097 13.907,22.134C13.872,22.171 13.83,22.2 13.783,22.22C13.736,22.24 13.686,22.251 13.635,22.251H9.499C9.329,22.251 9.165,22.194 9.032,22.089C8.899,21.984 8.806,21.837 8.767,21.672C8.743,21.559 8.744,21.443 8.771,21.33C8.797,21.218 8.848,21.113 8.919,21.022C9.581,20.145 10.459,19.454 11.467,19.017C11.024,18.614 10.685,18.11 10.477,17.548C10.269,16.986 10.199,16.382 10.272,15.788C10.345,15.193 10.56,14.624 10.898,14.13C11.236,13.635 11.688,13.229 12.215,12.945C12.743,12.66 13.331,12.507 13.93,12.497C14.529,12.486 15.122,12.62 15.659,12.886C16.196,13.152 16.661,13.543 17.016,14.026C17.371,14.508 17.604,15.069 17.698,15.661C17.71,15.741 17.696,15.822 17.657,15.893C17.619,15.963 17.558,16.02 17.485,16.053C16.445,16.534 15.564,17.302 14.946,18.267C14.328,19.233 14,20.355 13.998,21.501C13.998,21.621 13.998,21.739 14.01,21.857ZM31.072,21.022C30.412,20.145 29.536,19.455 28.53,19.017C28.972,18.614 29.312,18.11 29.52,17.548C29.728,16.986 29.798,16.382 29.725,15.788C29.652,15.193 29.437,14.624 29.099,14.13C28.761,13.635 28.309,13.229 27.782,12.945C27.254,12.66 26.666,12.507 26.067,12.497C25.468,12.486 24.875,12.62 24.338,12.886C23.802,13.152 23.336,13.543 22.981,14.026C22.627,14.508 22.393,15.069 22.299,15.661C22.287,15.741 22.301,15.822 22.34,15.893C22.378,15.963 22.439,16.02 22.512,16.053C23.552,16.534 24.433,17.302 25.051,18.267C25.669,19.233 25.998,20.355 25.999,21.501C25.999,21.621 25.999,21.739 25.987,21.857C25.985,21.908 25.993,21.958 26.01,22.006C26.028,22.054 26.055,22.097 26.09,22.134C26.125,22.171 26.168,22.2 26.214,22.22C26.261,22.24 26.311,22.251 26.362,22.251H30.499C30.668,22.251 30.832,22.194 30.965,22.089C31.098,21.984 31.191,21.837 31.23,21.672C31.254,21.559 31.253,21.442 31.226,21.33C31.2,21.217 31.149,21.112 31.077,21.022H31.072ZM22.729,25.07C23.475,24.498 24.024,23.706 24.298,22.806C24.571,21.906 24.556,20.943 24.254,20.053C23.952,19.162 23.379,18.388 22.615,17.84C21.85,17.292 20.933,16.997 19.993,16.997C19.052,16.997 18.135,17.292 17.37,17.84C16.606,18.388 16.032,19.162 15.731,20.053C15.429,20.943 15.413,21.906 15.687,22.806C15.961,23.706 16.51,24.498 17.256,25.07C15.931,25.644 14.825,26.627 14.099,27.876C14.033,27.99 13.998,28.119 13.998,28.251C13.998,28.382 14.033,28.512 14.099,28.626C14.165,28.74 14.259,28.834 14.373,28.9C14.488,28.966 14.617,29.001 14.748,29.001H25.249C25.38,29.001 25.51,28.966 25.624,28.9C25.738,28.834 25.832,28.74 25.898,28.626C25.964,28.512 25.999,28.382 25.999,28.251C25.999,28.119 25.964,27.99 25.898,27.876C25.171,26.626 24.062,25.643 22.735,25.07H22.729Z"
|
||||
android:fillColor="#FFFFFD"/>
|
||||
</vector>
|
||||
Loading…
Reference in New Issue