Skip to content

Commit

Permalink
UI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joreilly committed Sep 3, 2023
1 parent 7f81edb commit db92dd1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.johnoreilly.fantasypremierleague

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand All @@ -15,7 +14,6 @@ import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
Expand All @@ -30,11 +28,11 @@ import dev.johnoreilly.fantasypremierleague.presentation.FantasyPremierLeagueVie
import dev.johnoreilly.fantasypremierleague.presentation.Screen
import dev.johnoreilly.fantasypremierleague.presentation.bottomNavigationItems
import dev.johnoreilly.fantasypremierleague.presentation.fixtures.FixturesListView
import dev.johnoreilly.fantasypremierleague.presentation.fixtures.fixtureDetails.FixtureDetailsView
import dev.johnoreilly.fantasypremierleague.presentation.fixtures.FixtureDetails.FixtureDetailsView
import dev.johnoreilly.fantasypremierleague.presentation.global.FantasyPremierLeagueTheme
import dev.johnoreilly.fantasypremierleague.presentation.leagues.LeagueListView
import dev.johnoreilly.fantasypremierleague.presentation.players.PlayerListView
import dev.johnoreilly.fantasypremierleague.presentation.players.playerDetails.PlayerDetailsView
import dev.johnoreilly.fantasypremierleague.presentation.players.PlayerDetails.PlayerDetailsView
import dev.johnoreilly.fantasypremierleague.presentation.settings.SettingsView
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -63,10 +61,8 @@ class MainActivity : ComponentActivity() {
fun MainLayout(viewModel: FantasyPremierLeagueViewModel) {
val navController = rememberNavController()

val leagues by viewModel.leagues.collectAsState()

Scaffold(
bottomBar = { FantasyPremierLeagueBottomNavigation(navController, leagues) },
bottomBar = { FantasyPremierLeagueBottomNavigation(navController) },
contentWindowInsets = WindowInsets(0, 0, 0, 0),
) {
Column(Modifier.padding(it)) {
Expand Down Expand Up @@ -131,35 +127,29 @@ fun MainLayout(viewModel: FantasyPremierLeagueViewModel) {


@Composable
private fun FantasyPremierLeagueBottomNavigation(navController: NavHostController, leagues: List<String>) {
private fun FantasyPremierLeagueBottomNavigation(navController: NavHostController) {

NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route

bottomNavigationItems.forEach { bottomNavigationitem ->

val skipItem = bottomNavigationitem.route == Screen.LeagueStandingsListScreen.title
&& leagues.isEmpty()

if (!skipItem) {
NavigationBarItem(
icon = {
Icon(
bottomNavigationitem.icon,
contentDescription = bottomNavigationitem.iconContentDescription
)
},
selected = currentRoute == bottomNavigationitem.route,
onClick = {
navController.navigate(bottomNavigationitem.route) {
popUpTo(navController.graph.id)
launchSingleTop = true
}
NavigationBarItem(
icon = {
Icon(
bottomNavigationitem.icon,
contentDescription = bottomNavigationitem.iconContentDescription
)
},
selected = currentRoute == bottomNavigationitem.route,
onClick = {
navController.navigate(bottomNavigationitem.route) {
popUpTo(navController.graph.id)
launchSingleTop = true
}
)
}
}
)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3Api::class)

package dev.johnoreilly.fantasypremierleague.presentation.fixtures.fixtureDetails
package dev.johnoreilly.fantasypremierleague.presentation.fixtures.FixtureDetails

import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package dev.johnoreilly.fantasypremierleague.presentation.players.playerDetails
package dev.johnoreilly.fantasypremierleague.presentation.players.PlayerDetails

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
Expand All @@ -18,7 +18,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand All @@ -44,18 +43,11 @@ import com.patrykandpatryk.vico.compose.axis.vertical.startAxis
import com.patrykandpatryk.vico.compose.chart.Chart
import com.patrykandpatryk.vico.compose.chart.column.columnChart
import com.patrykandpatryk.vico.compose.component.lineComponent
import com.patrykandpatryk.vico.core.DefaultDimens
import com.patrykandpatryk.vico.core.component.shape.Shapes
import com.patrykandpatryk.vico.core.entry.ChartEntry
import com.patrykandpatryk.vico.core.entry.ChartEntryModelProducer
import com.patrykandpatryk.vico.core.entry.FloatEntry
import com.patrykandpatryk.vico.core.entry.composed.ComposedChartEntryModelProducer
import com.patrykandpatryk.vico.core.entry.entryModelOf
import dev.johnoreilly.common.domain.entities.Player
import dev.johnoreilly.common.domain.entities.PlayerPastHistory
import dev.johnoreilly.fantasypremierleague.presentation.FantasyPremierLeagueViewModel
import kotlin.random.Random
import kotlin.random.Random.Default.nextFloat


@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import dev.johnoreilly.fantasypremierleague.presentation.FantasyPremierLeagueVie
fun SettingsView(viewModel: FantasyPremierLeagueViewModel, popBackStack: () -> Unit) {

val leagueIdsString = remember {
mutableStateOf<String>(viewModel.leagues.value.joinToString())
mutableStateOf(viewModel.leagues.value.joinToString())
}

Scaffold(
Expand Down
2 changes: 1 addition & 1 deletion compose-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ group = "me.joreilly"
version = "1.0-SNAPSHOT"

dependencies {
//implementation("io.github.koalaplot:koalaplot-core:0.1.0-SNAPSHOT")
implementation("io.github.koalaplot:koalaplot-core:0.4.0-dev1")
implementation(compose.desktop.currentOs)
implementation(project(":common"))
}
Expand Down
105 changes: 47 additions & 58 deletions compose-desktop/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalCoroutinesApi::class)

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -34,25 +36,24 @@ import dev.johnoreilly.common.data.repository.FantasyPremierLeagueRepository
import dev.johnoreilly.common.di.initKoin
import dev.johnoreilly.common.domain.entities.Player
import dev.johnoreilly.common.domain.entities.PlayerPastHistory
//import io.github.koalaplot.core.ChartLayout
//import io.github.koalaplot.core.bar.BarChartEntry
//import io.github.koalaplot.core.bar.DefaultBarChartEntry
//import io.github.koalaplot.core.bar.DefaultVerticalBar
//import io.github.koalaplot.core.bar.VerticalBarChart
//import io.github.koalaplot.core.util.ExperimentalKoalaPlotApi
//import io.github.koalaplot.core.util.VerticalRotation
//import io.github.koalaplot.core.util.generateHueColorPalette
//import io.github.koalaplot.core.util.rotateVertically
//import io.github.koalaplot.core.util.toString
//import io.github.koalaplot.core.xychart.CategoryAxisModel
//import io.github.koalaplot.core.xychart.LinearAxisModel
//import io.github.koalaplot.core.xychart.TickPosition
//import io.github.koalaplot.core.xychart.XYChart
//import io.github.koalaplot.core.xychart.rememberAxisStyle
import io.github.koalaplot.core.ChartLayout
import io.github.koalaplot.core.bar.BarChartEntry
import io.github.koalaplot.core.bar.DefaultBarChartEntry
import io.github.koalaplot.core.bar.DefaultVerticalBar
import io.github.koalaplot.core.bar.VerticalBarChart
import io.github.koalaplot.core.util.ExperimentalKoalaPlotApi
import io.github.koalaplot.core.util.VerticalRotation
import io.github.koalaplot.core.util.rotateVertically
import io.github.koalaplot.core.util.toString
import io.github.koalaplot.core.xychart.CategoryAxisModel
import io.github.koalaplot.core.xychart.LinearAxisModel
import io.github.koalaplot.core.xychart.TickPosition
import io.github.koalaplot.core.xychart.XYChart
import io.github.koalaplot.core.xychart.rememberAxisStyle
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import presentation.players.PlayerView
import presentation.players.fetchImage
import kotlin.math.ceil


private val koin = initKoin(enableNetworkLogs = true).koin
Expand All @@ -68,7 +69,6 @@ val lightThemeColors = lightColors(
fun main() = application {
val windowState = rememberWindowState()


Window(
onCloseRequest = ::exitApplication,
state = windowState,
Expand All @@ -84,7 +84,7 @@ fun main() = application {

@Composable
fun MainLayout() {
val selectedPlayer by remember { mutableStateOf("") }
val selectedPlayer = remember { mutableStateOf<Player?>(null) }
val repository = koin.get<FantasyPremierLeagueRepository>()

val searchQuery = MutableStateFlow("")
Expand All @@ -98,66 +98,61 @@ fun MainLayout() {

BoxWithConstraints {
if (maxWidth.value > 700) {
TwoColumnsLayout(playerList, repository)
TwoColumnsLayout(playerList, selectedPlayer, repository)
} else {
PlayerListView(playerList, {})
PlayerListView(playerList, selectedPlayer.value) {}
}
}
}


@Composable
fun TwoColumnsLayout(playerList: List<Player>, repository: FantasyPremierLeagueRepository) {

val currentPlayer: MutableState<Player?> = remember { mutableStateOf(null) }
fun TwoColumnsLayout(playerList: List<Player>, selectedPlayer: MutableState<Player?>, repository: FantasyPremierLeagueRepository) {

Row(Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxWidth(0.3f), contentAlignment = Alignment.Center) {
PlayerListView(playerList) {
currentPlayer.value = it
PlayerListView(playerList, selectedPlayer.value) {
selectedPlayer.value = it
}
}
PlayerDetailsView(currentPlayer.value, repository)
PlayerDetailsView(selectedPlayer.value, repository)
}
}


@Composable
fun PlayerListView(playerList: List<Player>, playerSelected: (player: Player) -> Unit) {
fun PlayerListView(playerList: List<Player>, selectedPlayer: Player?, playerSelected: (player: Player) -> Unit) {
Box(modifier = Modifier
.padding(3.dp)
.background(color = Color.White)
.clip(shape = RoundedCornerShape(3.dp))
) {
LazyColumn {
items(items = playerList, itemContent = { player ->
PlayerView(player, playerSelected)
PlayerView(player, selectedPlayer, playerSelected)
})
}
}
}





//@OptIn(ExperimentalKoalaPlotApi::class)
@Composable
fun PlayerDetailsView(player: Player?, repository: FantasyPremierLeagueRepository) {

player?.let {
// var tickPositionState by remember {
// mutableStateOf(
// TickPositionState(
// TickPosition.Outside,
// TickPosition.Outside
// )
// )
// }
val tickPositionState by remember {
mutableStateOf(
TickPositionState(
TickPosition.Outside,
TickPosition.Outside
)
)
}

var playerHistory by remember { mutableStateOf(emptyList<PlayerPastHistory>()) }

LaunchedEffect(true) {
LaunchedEffect(player) {
playerHistory = repository.getPlayerHistoryData(player.id)
println(playerHistory)
}
Expand Down Expand Up @@ -196,12 +191,11 @@ fun PlayerDetailsView(player: Player?, repository: FantasyPremierLeagueRepositor
PlayerStatView("Goals Scored", player.goalsScored.toString())
PlayerStatView("Assists", player.assists.toString())

// Spacer(modifier = Modifier.size(8.dp))
//
// if (playerHistory.isNotEmpty()) {
// BarSamplePlot(playerHistory, tickPositionState, "Points by Season")
// }
Spacer(modifier = Modifier.size(8.dp))

if (playerHistory.isNotEmpty()) {
BarPlot(playerHistory, tickPositionState, "Points by Season")
}
}
}

Expand Down Expand Up @@ -235,7 +229,6 @@ fun PlayerStatView(statName: String, statValue: String) {
}
}

/*

private data class TickPositionState(
val verticalAxis: TickPosition,
Expand Down Expand Up @@ -290,14 +283,8 @@ fun AxisLabel(label: String, modifier: Modifier = Modifier) {
)
}

private val YAxisRange = 0f..25f
internal val padding = 8.dp
internal val paddingMod = Modifier.padding(padding)
internal val fibonacci = mutableStateListOf(1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 8.0f, 13.0f, 21.0f)
private val colors = generateHueColorPalette(fibonacci.size)
private const val BarWidth = 0.8f

@Composable
Expand All @@ -317,12 +304,14 @@ fun HoverSurface(modifier: Modifier = Modifier, content: @Composable () -> Unit)

@OptIn(ExperimentalKoalaPlotApi::class)
@Composable
private fun BarSamplePlot(
private fun BarPlot(
playerHistory: List<PlayerPastHistory>,
tickPositionState: TickPositionState,
title: String
) {
val barChartEntries = remember() { barChartEntries(playerHistory) }
val barChartEntries = produceState<List<BarChartEntry<String, Float>>>(emptyList(), playerHistory) {
value = barChartEntries(playerHistory)
}

ChartLayout(
modifier = paddingMod,
Expand Down Expand Up @@ -357,19 +346,19 @@ private fun BarSamplePlot(
},
verticalMajorGridLineStyle = null
) {

VerticalBarChart(
series = listOf(barChartEntries),
series = listOf(barChartEntries.value),
bar = { series, _, value ->
DefaultVerticalBar(
brush = SolidColor(colors[series]),
brush = SolidColor(Color.Red),
modifier = Modifier.fillMaxWidth(BarWidth),
) {
HoverSurface { Text(value.yMax.toString()) }
}
}
)
}
}
}
*/

Loading

0 comments on commit db92dd1

Please sign in to comment.