Formatting
This commit is contained in:
parent
a9fb0a1e17
commit
76f7b84f5f
7 changed files with 68 additions and 91 deletions
|
|
@ -86,22 +86,16 @@ class HomeScreen : Screen {
|
|||
"fairy"
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(color = orange),
|
||||
modifier = Modifier.fillMaxSize().background(color = orange),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = searchQuery,
|
||||
OutlinedTextField(value = searchQuery,
|
||||
onValueChange = { newName -> searchQuery = newName; placeholder = "" },
|
||||
modifier = Modifier.fillMaxWidth(0.8f)
|
||||
.padding(horizontal = 16.dp)
|
||||
.padding(top = 16.dp)
|
||||
.background(color = Color.White),
|
||||
modifier = Modifier.fillMaxWidth(0.8f).padding(horizontal = 16.dp)
|
||||
.padding(top = 16.dp).background(color = Color.White),
|
||||
trailingIcon = {
|
||||
Row() {
|
||||
IconButton(
|
||||
onClick = {
|
||||
IconButton(onClick = {
|
||||
if (searchQuery.length >= 3 && PokemonNames.names.any { name ->
|
||||
name.contains(
|
||||
searchQuery.lowercase(
|
||||
|
|
@ -146,18 +140,14 @@ class HomeScreen : Screen {
|
|||
}
|
||||
} else {
|
||||
searchQuery = ""
|
||||
placeholder =
|
||||
"No results, make sure to use more than 2 letters."
|
||||
placeholder = "No results, make sure to use more than 2 letters."
|
||||
}
|
||||
}
|
||||
) {
|
||||
}) {
|
||||
Icon(Icons.Default.Search, contentDescription = "Search")
|
||||
}
|
||||
IconButton(
|
||||
onClick = {
|
||||
IconButton(onClick = {
|
||||
isFilterOpen = !isFilterOpen
|
||||
}
|
||||
) {
|
||||
}) {
|
||||
Icon(Icons.Default.Settings, contentDescription = "Filter")
|
||||
}
|
||||
}
|
||||
|
|
@ -170,8 +160,7 @@ class HomeScreen : Screen {
|
|||
focusedLabelColor = orange,
|
||||
unfocusedLabelColor = orange,
|
||||
),
|
||||
placeholder = { Text(placeholder) }
|
||||
)
|
||||
placeholder = { Text(placeholder) })
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
//Grid
|
||||
LazyVerticalGrid(
|
||||
|
|
@ -179,8 +168,7 @@ class HomeScreen : Screen {
|
|||
) {
|
||||
items(pokemap.size) { index ->
|
||||
Box(modifier = Modifier.size(256.dp).padding(5.dp)) {
|
||||
Canvas(
|
||||
modifier = Modifier.matchParentSize()
|
||||
Canvas(modifier = Modifier.matchParentSize()
|
||||
.clickable { navigator.push(DetailScreen(pokemap[index])) }) {
|
||||
drawRoundRect(
|
||||
color = Color.White,
|
||||
|
|
@ -225,9 +213,7 @@ class HomeScreen : Screen {
|
|||
}
|
||||
}
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = isFilterOpen,
|
||||
onDismissRequest = { isFilterOpen = false }) {
|
||||
DropdownMenu(expanded = isFilterOpen, onDismissRequest = { isFilterOpen = false }) {
|
||||
filterOptions.forEach { option ->
|
||||
DropdownMenuItem(onClick = { currentFilter = option; isFilterOpen = false }) {
|
||||
Text(option)
|
||||
|
|
|
|||
|
|
@ -98,7 +98,8 @@ suspend fun loadPokemonData(startId: Int, endId: Int): List<Pokemon> {
|
|||
val json = JSONObject(URL(apiString + i).readText());
|
||||
val sprites = json.optJSONObject("sprites")
|
||||
val type: String =
|
||||
json.getJSONArray("types").optJSONObject(0).optJSONObject("type")?.optString("name") ?: "null"
|
||||
json.getJSONArray("types").optJSONObject(0).optJSONObject("type")?.optString("name")
|
||||
?: "null"
|
||||
val name: String = json.optString("name")
|
||||
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
|
||||
|
|
@ -124,7 +125,8 @@ suspend fun loadPokemonDataFromName(name: String): Pokemon? {
|
|||
}
|
||||
val sprites = json.optJSONObject("sprites")
|
||||
val type: String =
|
||||
json.getJSONArray("types").optJSONObject(0).optJSONObject("type")?.optString("name") ?: "null"
|
||||
json.getJSONArray("types").optJSONObject(0).optJSONObject("type")?.optString("name")
|
||||
?: "null"
|
||||
val name: String = json.optString("name")
|
||||
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ class LoadingScreen : Screen {
|
|||
Box(modifier = Modifier.background(color = orange).fillMaxSize()) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(128.dp),
|
||||
color = Color.White
|
||||
modifier = Modifier.size(128.dp), color = Color.White
|
||||
)
|
||||
Text(
|
||||
"Fetching data from API...",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
import java.net.URL
|
||||
|
||||
data class Pokemon (
|
||||
val name: String,
|
||||
val imageUrl: URL,
|
||||
val type: String,
|
||||
val id: Int
|
||||
data class Pokemon(
|
||||
val name: String, val imageUrl: URL, val type: String, val id: Int
|
||||
)
|
||||
|
|
@ -5,8 +5,8 @@ data class PokemonData(
|
|||
val name: String,
|
||||
val type: String,
|
||||
val baseExperience: Int,
|
||||
val height: Int, // Height in decimetres
|
||||
val weight: Int, // Weight in hectograms
|
||||
val height: Int,
|
||||
val weight: Int,
|
||||
val hp: Int,
|
||||
val attack: Int,
|
||||
val defense: Int,
|
||||
|
|
@ -18,8 +18,8 @@ data class PokemonData(
|
|||
fun fromJson(json: JSONObject): PokemonData {
|
||||
val name = json.optString("name")
|
||||
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
val type = json.getJSONArray("types").optJSONObject(0).optJSONObject("type")
|
||||
.optString("name")
|
||||
val type =
|
||||
json.getJSONArray("types").optJSONObject(0).optJSONObject("type").optString("name")
|
||||
val baseExperience = json.optInt("base_experience")
|
||||
val height = json.optInt("height")
|
||||
val weight = json.optInt("weight")
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -21,16 +20,10 @@ import androidx.compose.ui.unit.dp
|
|||
|
||||
@Composable
|
||||
fun PokemonStatCard(
|
||||
hp: Int,
|
||||
attack: Int,
|
||||
defense: Int,
|
||||
specialAttack: Int,
|
||||
specialDefense: Int,
|
||||
speed: Int
|
||||
hp: Int, attack: Int, defense: Int, specialAttack: Int, specialDefense: Int, speed: Int
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.background(color = Color.White, shape = RoundedCornerShape(8.dp))
|
||||
modifier = Modifier.background(color = Color.White, shape = RoundedCornerShape(8.dp))
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Bottom,
|
||||
) {
|
||||
|
|
@ -46,8 +39,7 @@ fun PokemonStatCard(
|
|||
@Composable
|
||||
private fun StatRow(statName: String, progress: Int, color: Color) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = "$statName: $progress",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue