diff --git a/android-design-system/.gitignore b/android-design-system/.gitignore deleted file mode 100644 index 42afabfd2..000000000 --- a/android-design-system/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/android-design-system/build.gradle.kts b/android-design-system/build.gradle.kts deleted file mode 100644 index b7b6880de..000000000 --- a/android-design-system/build.gradle.kts +++ /dev/null @@ -1,54 +0,0 @@ -plugins { - id("com.android.library") - id("org.jetbrains.kotlin.android") -} - -android { - compileSdk = AndroidConfig.compileSDK - - defaultConfig { - minSdk = AndroidConfig.minSDK - targetSdk = AndroidConfig.targetSDK - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = "1.8" - } - - buildFeatures { - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = Versions.compose - } -} - -dependencies { - - implementation("androidx.compose.ui:ui:${Versions.compose}") - implementation("androidx.compose.material:material:${Versions.compose}") - implementation("androidx.compose.ui:ui-tooling-preview:${Versions.compose}") - androidTestImplementation("androidx.compose.ui:ui-test-junit4:${Versions.compose}") - debugImplementation("androidx.compose.ui:ui-tooling:${Versions.compose}") - debugImplementation("androidx.compose.ui:ui-test-manifest:${Versions.compose}") - testImplementation("junit:junit:${Versions.junit}") - androidTestImplementation("androidx.test.ext:junit:${Versions.androidxTest}") - androidTestImplementation("androidx.test.espresso:espresso-core:${Versions.espresso}") -} diff --git a/android-design-system/consumer-rules.pro b/android-design-system/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/android-design-system/proguard-rules.pro b/android-design-system/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/android-design-system/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android-design-system/src/androidTest/java/com/adammcneilly/pocketleague/android/design/ExampleInstrumentedTest.kt b/android-design-system/src/androidTest/java/com/adammcneilly/pocketleague/android/design/ExampleInstrumentedTest.kt deleted file mode 100644 index 258d87fd4..000000000 --- a/android-design-system/src/androidTest/java/com/adammcneilly/pocketleague/android/design/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.adammcneilly.pocketleague.android.design - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.adammcneilly.pocketleague.android.design.test", appContext.packageName) - } -} diff --git a/android-design-system/src/main/AndroidManifest.xml b/android-design-system/src/main/AndroidManifest.xml deleted file mode 100644 index a77e0c9f8..000000000 --- a/android-design-system/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/AdaptiveWidthModifier.kt b/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/AdaptiveWidthModifier.kt deleted file mode 100644 index 0cda25065..000000000 --- a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/AdaptiveWidthModifier.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.adammcneilly.pocketleague.android.design - -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.layout -import androidx.compose.ui.unit.dp - -private const val COMPACT_WIDTH_RATIO = 1F -private const val MEDIUM_WIDTH_RATIO = 0.75F -private const val EXPANDED_WIDTH_RATIO = 0.5F - -private const val MIN_MEDIUM_WIDTH_DP = 600 -private const val MIN_EXPANDED_WIDTH_DP = 840 - -/** - * This is a custom modifier, that will change the width of a Composable, based on the amount of space - * available to it. Centering the Composable within that available space as well. - * - * If the available space is within the COMPACT bucket, we will fill the maximum width. - * If the available space is within the MEDIUM bucket, we will 75% of the maximum width. - * If the available space is within the EXPANDED bucket, we will fill 50% of the maximum width. - */ -fun Modifier.adaptiveWidth( - compactWidthRatio: Float = COMPACT_WIDTH_RATIO, - mediumWidthRatio: Float = MEDIUM_WIDTH_RATIO, - expandedWidthRatio: Float = EXPANDED_WIDTH_RATIO, -) = this - .layout { measurable, constraints -> - val widthRatio = when { - constraints.maxWidth < MIN_MEDIUM_WIDTH_DP.dp.toPx() -> compactWidthRatio - constraints.maxWidth < MIN_EXPANDED_WIDTH_DP.dp.toPx() -> mediumWidthRatio - else -> expandedWidthRatio - } - - val widthToUse = constraints.maxWidth * widthRatio - - val newConstraints = constraints.copy( - minWidth = widthToUse.toInt(), - maxWidth = widthToUse.toInt(), - ) - - val placeable = measurable.measure(newConstraints) - - val x = Alignment.CenterHorizontally.align( - size = placeable.width, - space = constraints.maxWidth, - layoutDirection = layoutDirection, - ) - - layout(constraints.maxWidth, placeable.height) { - placeable.place(x = x, y = 0) - } - } diff --git a/android-design-system/src/main/res/values/dimens.xml b/android-design-system/src/main/res/values/dimens.xml deleted file mode 100644 index 351a48740..000000000 --- a/android-design-system/src/main/res/values/dimens.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 16dp - \ No newline at end of file diff --git a/android-design-system/src/test/java/com/adammcneilly/pocketleague/android/design/ExampleUnitTest.kt b/android-design-system/src/test/java/com/adammcneilly/pocketleague/android/design/ExampleUnitTest.kt deleted file mode 100644 index 54a47ee7a..000000000 --- a/android-design-system/src/test/java/com/adammcneilly/pocketleague/android/design/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.adammcneilly.pocketleague.android.design - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bb000b4b1..9e5ffdaea 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -80,11 +80,11 @@ android { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } + namespace = "com.adammcneilly.pocketleague" } dependencies { - implementation(project(":android-design-system")) implementation(project(":shared")) implementation("org.jetbrains.kotlinx:kotlinx-datetime:${Versions.kotlinxDatetime}") implementation("androidx.core:core-ktx:${Versions.ktxCore}") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a7f2e15b..21075ccc0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/app/src/main/java/com/adammcneilly/pocketleague/MainActivity.kt b/app/src/main/java/com/adammcneilly/pocketleague/MainActivity.kt index c26196e5d..754c0ad95 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/MainActivity.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/MainActivity.kt @@ -8,8 +8,8 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.ui.graphics.Color import androidx.core.view.WindowCompat -import com.adammcneilly.pocketleague.android.design.theme.PocketLeagueTheme import com.adammcneilly.pocketleague.ui.MainComposable +import com.adammcneilly.pocketleague.ui.theme.PocketLeagueTheme import com.google.accompanist.insets.ProvideWindowInsets import com.google.accompanist.systemuicontroller.rememberSystemUiController import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt new file mode 100644 index 000000000..b6139f494 --- /dev/null +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt @@ -0,0 +1,127 @@ +package com.adammcneilly.pocketleague.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import com.adammcneilly.pocketleague.shared.models.CoreStats +import com.adammcneilly.pocketleague.ui.theme.rlcsBlue +import com.adammcneilly.pocketleague.ui.theme.rlcsOrange + +/** + * A composable to compare the [CoreStats] between two teams. + */ +@Composable +fun CoreStatsComparison( + blueTeamStats: CoreStats, + orangeTeamStats: CoreStats, + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier + .fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + StatComparisonRow( + title = "Goals", + blueValue = blueTeamStats.goals.toFloat(), + orangeValue = orangeTeamStats.goals.toFloat(), + ) + + StatComparisonRow( + title = "Saves", + blueValue = blueTeamStats.saves.toFloat(), + orangeValue = orangeTeamStats.saves.toFloat(), + ) + + StatComparisonRow( + title = "Shots", + blueValue = blueTeamStats.shots.toFloat(), + orangeValue = orangeTeamStats.shots.toFloat(), + ) + } +} + +@Composable +private fun StatComparisonRow( + title: String, + blueValue: Float, + orangeValue: Float, +) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text( + text = title, + ) + + BoxWithConstraints { + val total = blueValue + orangeValue + val blueWeight = blueValue / total + val orangeWeight = orangeValue / total + + val statBarHeight = 4.dp + val dividerHeight = 12.dp + val dividerWidth = 4.dp + + val availableWidth = this.maxWidth - dividerWidth + val blueWidth = availableWidth * blueWeight + val orangeWidth = availableWidth * orangeWeight + + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + Box( + modifier = Modifier + .background( + color = rlcsBlue, + shape = RoundedCornerShape( + topStartPercent = 50, + bottomStartPercent = 50, + ), + ) + .size( + width = blueWidth, + height = statBarHeight, + ) + ) + + Box( + modifier = Modifier + .background(color = Color.White) + .size( + width = dividerWidth, + height = dividerHeight, + ), + ) + + Box( + modifier = Modifier + .background( + color = rlcsOrange, + shape = RoundedCornerShape( + topEndPercent = 50, + bottomEndPercent = 50, + ), + ) + .height(statBarHeight) + .width(orangeWidth) + ) + } + } + } +} diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt index c911595a0..41b312d13 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt @@ -1,11 +1,20 @@ package com.adammcneilly.pocketleague.ui +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.Icon import androidx.compose.material.Text +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowCircleDown +import androidx.compose.material.icons.filled.ArrowCircleUp import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign @@ -20,11 +29,57 @@ import com.google.accompanist.placeholder.material.placeholder fun GameListItem( game: Game, ) { + val showDetailedStats = remember { + mutableStateOf(false) + } + + Column( + modifier = Modifier + .clickable { + showDetailedStats.value = !showDetailedStats.value + } + .padding(16.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + GameOverviewRow(game) + + val iconToUse = if (showDetailedStats.value) { + Icons.Default.ArrowCircleUp + } else { + Icons.Default.ArrowCircleDown + } + + val contentDescriptionToUse = if (showDetailedStats.value) { + "Click To Expand Game Details" + } else { + "Click To Collapse Game Details" + } + + Icon( + imageVector = iconToUse, + contentDescription = contentDescriptionToUse, + modifier = Modifier + .padding(top = 16.dp), + ) + + AnimatedVisibility(visible = showDetailedStats.value) { + CoreStatsComparison( + blueTeamStats = game.blue.teamStats.core, + orangeTeamStats = game.orange.teamStats.core, + modifier = Modifier + .padding(16.dp), + ) + } + } +} + +@Composable +private fun GameOverviewRow(game: Game) { Row( + verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .padding(16.dp), - verticalAlignment = Alignment.CenterVertically, ) { Text( text = game.blue.goals.toString(), diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/MatchDetailContent.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/MatchDetailContent.kt index c5a914b1a..2fd98bca0 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/MatchDetailContent.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/MatchDetailContent.kt @@ -10,20 +10,20 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.Divider +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import coil.request.ImageRequest import com.adammcneilly.pocketleague.shared.models.Team import com.adammcneilly.pocketleague.shared.screens.matchdetail.MatchDetailViewState -import com.google.accompanist.placeholder.material.placeholder /** * The UI content of the match detail screen. @@ -72,7 +72,11 @@ private fun RowScope.TeamNameLogo( modifier = Modifier .weight(1F), ) { - Text(text = team.name) + Text( + text = team.name, + textAlign = TextAlign.Center, + style = MaterialTheme.typography.h6, + ) AsyncImage( model = ImageRequest.Builder(LocalContext.current) @@ -81,11 +85,7 @@ private fun RowScope.TeamNameLogo( .build(), contentDescription = "Event Image", modifier = Modifier - .size(48.dp) - .placeholder( - visible = team.imageUrl == null, - shape = CircleShape, - ), + .size(48.dp), ) } } diff --git a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Color.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt similarity index 96% rename from android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Color.kt rename to app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt index f4d0cf785..fb47ceb30 100644 --- a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Color.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt @@ -1,6 +1,6 @@ @file:Suppress("MagicNumber") -package com.adammcneilly.pocketleague.android.design.theme +package com.adammcneilly.pocketleague.ui.theme import androidx.compose.ui.graphics.Color @@ -60,5 +60,8 @@ val md_theme_dark_inverseSurface = Color(0xFFe3e1e6) val md_theme_dark_inversePrimary = Color(0xFF3d5ba9) val md_theme_dark_shadow = Color(0xFF000000) +val rlcsBlue = Color(0xFF0069c1) +val rlcsOrange = Color(0xFFee7d13) + val seed = Color(0xFF3d5ba9) val error = Color(0xFFba1b1b) diff --git a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Theme.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Theme.kt similarity index 96% rename from android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Theme.kt rename to app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Theme.kt index 980d1176e..dd16f8392 100644 --- a/android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/theme/Theme.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Theme.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.android.design.theme +package com.adammcneilly.pocketleague.ui.theme import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material.MaterialTheme diff --git a/build.gradle.kts b/build.gradle.kts index 0e2d240e5..eeefe857c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:7.1.2") + classpath("com.android.tools.build:gradle:7.2.0-rc01") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") classpath("org.jlleitschuh.gradle:ktlint-gradle:10.0.0") classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0") diff --git a/settings.gradle b/settings.gradle index 6945a5f6b..e4892e894 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,4 @@ rootProject.name = "PocketLeague" include ':app' -include ':android-design-system' include ':shared' diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 19f948685..4d9049883 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -77,4 +77,5 @@ android { targetCompatibility(JavaVersion.VERSION_1_8) isCoreLibraryDesugaringEnabled = true } + namespace = "com.adammcneilly.pocketleague.shared" } diff --git a/shared/src/androidMain/AndroidManifest.xml b/shared/src/androidMain/AndroidManifest.xml index df7238178..568741e54 100644 --- a/shared/src/androidMain/AndroidManifest.xml +++ b/shared/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/OctaneGGAPIClient.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/OctaneGGAPIClient.kt index 9c2e4f504..84dd4ee5e 100644 --- a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/OctaneGGAPIClient.kt +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/OctaneGGAPIClient.kt @@ -4,6 +4,10 @@ import com.adammcneilly.pocketleague.shared.data.DataState import io.ktor.client.HttpClient import io.ktor.client.features.json.JsonFeature import io.ktor.client.features.json.serializer.KotlinxSerializer +import io.ktor.client.features.logging.LogLevel +import io.ktor.client.features.logging.Logger +import io.ktor.client.features.logging.Logging +import io.ktor.client.features.logging.SIMPLE import io.ktor.client.request.HttpRequestBuilder import io.ktor.client.request.get import io.ktor.http.ContentType @@ -24,6 +28,10 @@ class OctaneGGAPIClient { } ) } + install(Logging) { + logger = Logger.SIMPLE + level = LogLevel.ALL + } } /** diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGCoreStatsMapper.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGCoreStatsMapper.kt new file mode 100644 index 000000000..fa528cb5e --- /dev/null +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGCoreStatsMapper.kt @@ -0,0 +1,18 @@ +package com.adammcneilly.pocketleague.shared.data.remote.octanegg.mappers + +import com.adammcneilly.pocketleague.shared.data.remote.octanegg.models.OctaneGGCoreStats +import com.adammcneilly.pocketleague.shared.models.CoreStats + +/** + * Converts an [OctaneGGCoreStats] entity to a [CoreStats] entity. + */ +fun OctaneGGCoreStats.toCoreStats(): CoreStats { + return CoreStats( + shots = this.shots ?: 0, + goals = this.goals ?: 0, + saves = this.saves ?: 0, + assists = this.assists ?: 0, + score = this.score ?: 0, + shootingPercentage = this.shootingPercentage ?: 0F, + ) +} diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGGameTeamResultMapper.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGGameTeamResultMapper.kt index 2afe5287c..bad88d146 100644 --- a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGGameTeamResultMapper.kt +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGGameTeamResultMapper.kt @@ -2,6 +2,7 @@ package com.adammcneilly.pocketleague.shared.data.remote.octanegg.mappers import com.adammcneilly.pocketleague.shared.data.remote.octanegg.models.OctaneGGGameTeamResult import com.adammcneilly.pocketleague.shared.models.GameTeamResult +import com.adammcneilly.pocketleague.shared.models.Stats import com.adammcneilly.pocketleague.shared.models.Team /** @@ -12,5 +13,7 @@ fun OctaneGGGameTeamResult.toGameTeamResult(): GameTeamResult { goals = this.team?.stats?.core?.goals ?: 0, winner = this.gameWinner == true, team = this.team?.team?.toTeam() ?: Team(), + matchWinner = this.matchWinner == true, + teamStats = this.team?.stats?.toStats() ?: Stats(), ) } diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGStatsMapper.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGStatsMapper.kt new file mode 100644 index 000000000..083712f02 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGStatsMapper.kt @@ -0,0 +1,14 @@ +package com.adammcneilly.pocketleague.shared.data.remote.octanegg.mappers + +import com.adammcneilly.pocketleague.shared.data.remote.octanegg.models.OctaneGGStats +import com.adammcneilly.pocketleague.shared.models.CoreStats +import com.adammcneilly.pocketleague.shared.models.Stats + +/** + * Converts an [OctaneGGStats] entity to a [Stats] entity. + */ +fun OctaneGGStats.toStats(): Stats { + return Stats( + core = this.core?.toCoreStats() ?: CoreStats(), + ) +} diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/services/OctaneGGMatchService.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/services/OctaneGGMatchService.kt index 6369d465f..cf393287e 100644 --- a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/services/OctaneGGMatchService.kt +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/services/OctaneGGMatchService.kt @@ -38,8 +38,7 @@ class OctaneGGMatchService( val mappedMatches = apiResult.data.matches?.mapNotNull(OctaneGGMatch::toMatch).orEmpty() -// val sortedMatches = mappedMatches.sortedByDescending(Match::date) - val sortedMatches = mappedMatches.sortedBy(Match::date) + val sortedMatches = mappedMatches.sortedByDescending(Match::date) DataState.Success(sortedMatches) } diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/CoreStats.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/CoreStats.kt new file mode 100644 index 000000000..3a9250db3 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/CoreStats.kt @@ -0,0 +1,13 @@ +package com.adammcneilly.pocketleague.shared.models + +/** + * The core statistics for a player or team within a match or game. + */ +data class CoreStats( + val shots: Int = 0, + val goals: Int = 0, + val saves: Int = 0, + val assists: Int = 0, + val score: Int = 0, + val shootingPercentage: Float = 0F, +) diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/GameTeamResult.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/GameTeamResult.kt index 22db5fe06..cffbb0e82 100644 --- a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/GameTeamResult.kt +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/GameTeamResult.kt @@ -7,10 +7,12 @@ package com.adammcneilly.pocketleague.shared.models * @property[winner] True if this team won the specific game. * @property[matchWinner] True if this team won the match between both teams. * @property[team] Detailed information about the [Team] playing in the match. + * @property[teamStats] The detailed [Stats] for this [team] in the game. */ data class GameTeamResult( val goals: Int = -1, val winner: Boolean = false, val matchWinner: Boolean = false, val team: Team = Team(), + val teamStats: Stats = Stats(), ) diff --git a/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/Stats.kt b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/Stats.kt new file mode 100644 index 000000000..edf2c5a7c --- /dev/null +++ b/shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/Stats.kt @@ -0,0 +1,8 @@ +package com.adammcneilly.pocketleague.shared.models + +/** + * A collection of different types of statistics for a player or team. + */ +data class Stats( + val core: CoreStats = CoreStats(), +)