From 038589f36ced4831b6c194e476d93060b614a50d Mon Sep 17 00:00:00 2001 From: adammc331 Date: Sun, 24 Apr 2022 21:46:17 -0400 Subject: [PATCH 1/8] Android updates. --- android-design-system/build.gradle.kts | 1 + android-design-system/src/main/AndroidManifest.xml | 2 +- app/build.gradle.kts | 1 + app/src/main/AndroidManifest.xml | 3 +-- build.gradle.kts | 2 +- shared/build.gradle.kts | 1 + shared/src/androidMain/AndroidManifest.xml | 2 +- 7 files changed, 7 insertions(+), 5 deletions(-) diff --git a/android-design-system/build.gradle.kts b/android-design-system/build.gradle.kts index b7b6880de..299f09d9a 100644 --- a/android-design-system/build.gradle.kts +++ b/android-design-system/build.gradle.kts @@ -38,6 +38,7 @@ android { composeOptions { kotlinCompilerExtensionVersion = Versions.compose } + namespace = "com.adammcneilly.pocketleague.android.design" } dependencies { diff --git a/android-design-system/src/main/AndroidManifest.xml b/android-design-system/src/main/AndroidManifest.xml index a77e0c9f8..8072ee00d 100644 --- a/android-design-system/src/main/AndroidManifest.xml +++ b/android-design-system/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ - + diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bb000b4b1..7ccc88e5b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -80,6 +80,7 @@ android { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } + namespace = "com.adammcneilly.pocketleague" } dependencies { 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/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/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 From 5743be77389d5ce32cde0155520ba2d198e5ebf1 Mon Sep 17 00:00:00 2001 From: adammc331 Date: Sun, 24 Apr 2022 21:53:57 -0400 Subject: [PATCH 2/8] Removing design system module. --- android-design-system/.gitignore | 1 - android-design-system/build.gradle.kts | 55 ------------------- android-design-system/consumer-rules.pro | 0 android-design-system/proguard-rules.pro | 21 ------- .../android/design/ExampleInstrumentedTest.kt | 22 -------- .../src/main/AndroidManifest.xml | 2 - .../android/design/AdaptiveWidthModifier.kt | 53 ------------------ .../src/main/res/values/dimens.xml | 4 -- .../android/design/ExampleUnitTest.kt | 16 ------ app/build.gradle.kts | 1 - .../adammcneilly/pocketleague/MainActivity.kt | 2 +- .../pocketleague/ui}/theme/Color.kt | 2 +- .../pocketleague/ui}/theme/Theme.kt | 2 +- settings.gradle | 1 - 14 files changed, 3 insertions(+), 179 deletions(-) delete mode 100644 android-design-system/.gitignore delete mode 100644 android-design-system/build.gradle.kts delete mode 100644 android-design-system/consumer-rules.pro delete mode 100644 android-design-system/proguard-rules.pro delete mode 100644 android-design-system/src/androidTest/java/com/adammcneilly/pocketleague/android/design/ExampleInstrumentedTest.kt delete mode 100644 android-design-system/src/main/AndroidManifest.xml delete mode 100644 android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design/AdaptiveWidthModifier.kt delete mode 100644 android-design-system/src/main/res/values/dimens.xml delete mode 100644 android-design-system/src/test/java/com/adammcneilly/pocketleague/android/design/ExampleUnitTest.kt rename {android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design => app/src/main/java/com/adammcneilly/pocketleague/ui}/theme/Color.kt (98%) rename {android-design-system/src/main/java/com/adammcneilly/pocketleague/android/design => app/src/main/java/com/adammcneilly/pocketleague/ui}/theme/Theme.kt (96%) 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 299f09d9a..000000000 --- a/android-design-system/build.gradle.kts +++ /dev/null @@ -1,55 +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 - } - namespace = "com.adammcneilly.pocketleague.android.design" -} - -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 8072ee00d..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 7ccc88e5b..9e5ffdaea 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -85,7 +85,6 @@ android { 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/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/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 98% 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..f45ebc6b9 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 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/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' From 1d18f416b5ced0184f71c42363511d9ec3f63e24 Mon Sep 17 00:00:00 2001 From: adammc331 Date: Sun, 24 Apr 2022 22:06:45 -0400 Subject: [PATCH 3/8] Adding ktor logging. --- .../pocketleague/ui/MatchDetailContent.kt | 16 ++++++++-------- .../data/remote/octanegg/OctaneGGAPIClient.kt | 8 ++++++++ .../octanegg/services/OctaneGGMatchService.kt | 3 +-- 3 files changed, 17 insertions(+), 10 deletions(-) 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/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/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) } From 1c4a4de2c954b262ca5169e4117842fc14e6fc90 Mon Sep 17 00:00:00 2001 From: adammc331 Date: Sun, 24 Apr 2022 22:14:46 -0400 Subject: [PATCH 4/8] Tracking stats for game. --- .../pocketleague/ui/GameListItem.kt | 67 +++++++++++-------- .../mappers/OctaneGGCoreStatsMapper.kt | 18 +++++ .../mappers/OctaneGGGameTeamResultMapper.kt | 3 + .../octanegg/mappers/OctaneGGStatsMapper.kt | 14 ++++ .../pocketleague/shared/models/CoreStats.kt | 13 ++++ .../shared/models/GameTeamResult.kt | 1 + .../pocketleague/shared/models/Stats.kt | 8 +++ 7 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGCoreStatsMapper.kt create mode 100644 shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/data/remote/octanegg/mappers/OctaneGGStatsMapper.kt create mode 100644 shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/CoreStats.kt create mode 100644 shared/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/models/Stats.kt 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..edce87ae0 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt @@ -1,5 +1,6 @@ package com.adammcneilly.pocketleague.ui +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -20,40 +21,50 @@ import com.google.accompanist.placeholder.material.placeholder fun GameListItem( game: Game, ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = game.blue.goals.toString(), + Column { + Row( modifier = Modifier - .placeholder( - visible = game.blue.goals == -1, - shape = CircleShape, - ), - ) + .fillMaxWidth() + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = game.blue.goals.toString(), + modifier = Modifier + .placeholder( + visible = game.blue.goals == -1, + shape = CircleShape, + ), + ) + + Text( + text = "Game ${game.number}\n${game.map}", + modifier = Modifier + .weight(1F) + .padding(horizontal = 16.dp) + .placeholder( + visible = game.map.isEmpty(), + shape = CircleShape, + ), + textAlign = TextAlign.Center, + ) + + Text( + text = game.orange.goals.toString(), + modifier = Modifier + .placeholder( + visible = game.orange.goals == -1, + shape = CircleShape, + ), + ) + } Text( - text = "Game ${game.number}\n${game.map}", - modifier = Modifier - .weight(1F) - .padding(horizontal = 16.dp) - .placeholder( - visible = game.map.isEmpty(), - shape = CircleShape, - ), - textAlign = TextAlign.Center, + text = "Blue stats: ${game.blue.teamStats}", ) Text( - text = game.orange.goals.toString(), - modifier = Modifier - .placeholder( - visible = game.orange.goals == -1, - shape = CircleShape, - ), + text = "Orange stats: ${game.orange.teamStats}", ) } } 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/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..521b5164e 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 @@ -13,4 +13,5 @@ data class GameTeamResult( 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(), +) From 35502fdb48d082a4eafaeb54550a04898673dfcd Mon Sep 17 00:00:00 2001 From: adammc331 Date: Sun, 24 Apr 2022 22:26:55 -0400 Subject: [PATCH 5/8] Showing core stats comparison. --- .../pocketleague/ui/CoreStatsComparison.kt | 101 ++++++++++++++++++ .../pocketleague/ui/GameListItem.kt | 9 +- 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt 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..b31509af7 --- /dev/null +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt @@ -0,0 +1,101 @@ +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.width +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 + +/** + * A composable to compare the [CoreStats] between two teams. + */ +@Composable +fun CoreStatsComparison( + blueTeamStats: CoreStats, + orangeTeamStats: CoreStats, +) { + Column( + modifier = Modifier + .fillMaxWidth(), + ) { + 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 availableWidth = this.maxWidth - 2.dp + val blueWidth = availableWidth * blueWeight + val orangeWidth = availableWidth * orangeWeight + + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + Box( + modifier = Modifier + .background(color = Color.Blue) + .height(1.dp) + .width(blueWidth) + ) + + Box( + modifier = Modifier + .background(color = Color.White) + .height(4.dp) + .width(2.dp) + ) + + Box( + modifier = Modifier + .background(color = Color.Red) + .height(1.dp) + .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 edce87ae0..57d9bf166 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt @@ -59,12 +59,9 @@ fun GameListItem( ) } - Text( - text = "Blue stats: ${game.blue.teamStats}", - ) - - Text( - text = "Orange stats: ${game.orange.teamStats}", + CoreStatsComparison( + blueTeamStats = game.blue.teamStats.core, + orangeTeamStats = game.orange.teamStats.core, ) } } From 1256937d4972e1d74d730380f348abe4f59295e4 Mon Sep 17 00:00:00 2001 From: adammc331 Date: Wed, 27 Apr 2022 13:28:12 -0400 Subject: [PATCH 6/8] Working on stat comparison. --- .../pocketleague/ui/CoreStatsComparison.kt | 42 +++++++++++---- .../pocketleague/ui/GameListItem.kt | 54 ++++++++++++++++--- 2 files changed, 81 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt index b31509af7..90b5d865f 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt @@ -8,7 +8,9 @@ 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 @@ -24,10 +26,12 @@ import com.adammcneilly.pocketleague.shared.models.CoreStats fun CoreStatsComparison( blueTeamStats: CoreStats, orangeTeamStats: CoreStats, + modifier: Modifier = Modifier, ) { Column( - modifier = Modifier + modifier = modifier .fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(8.dp), ) { StatComparisonRow( title = "Goals", @@ -68,7 +72,11 @@ private fun StatComparisonRow( val blueWeight = blueValue / total val orangeWeight = orangeValue / total - val availableWidth = this.maxWidth - 2.dp + 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 @@ -77,22 +85,38 @@ private fun StatComparisonRow( ) { Box( modifier = Modifier - .background(color = Color.Blue) - .height(1.dp) - .width(blueWidth) + .background( + color = Color(0xFF0069c1), + shape = RoundedCornerShape( + topStartPercent = 50, + bottomStartPercent = 50, + ), + ) + .size( + width = blueWidth, + height = statBarHeight, + ) ) Box( modifier = Modifier .background(color = Color.White) - .height(4.dp) - .width(2.dp) + .size( + width = dividerWidth, + height = dividerHeight, + ), ) Box( modifier = Modifier - .background(color = Color.Red) - .height(1.dp) + .background( + color = Color(0xFFee7d13), + 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 57d9bf166..230ee4f11 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt @@ -1,12 +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 @@ -21,12 +29,23 @@ import com.google.accompanist.placeholder.material.placeholder fun GameListItem( game: Game, ) { - Column { + val showDetailedStats = remember { + mutableStateOf(false) + } + + Column( + modifier = Modifier + .clickable { + showDetailedStats.value = !showDetailedStats.value + } + .padding(16.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { Row( + verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .padding(16.dp), - verticalAlignment = Alignment.CenterVertically, ) { Text( text = game.blue.goals.toString(), @@ -59,9 +78,32 @@ fun GameListItem( ) } - CoreStatsComparison( - blueTeamStats = game.blue.teamStats.core, - orangeTeamStats = game.orange.teamStats.core, + 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), + ) + } } } From 2e8fcb9e97ff8963cafb5d28c5ab5b3010384b8a Mon Sep 17 00:00:00 2001 From: adammc331 Date: Wed, 27 Apr 2022 13:31:40 -0400 Subject: [PATCH 7/8] static analysis fixes. --- .../pocketleague/ui/CoreStatsComparison.kt | 6 +- .../pocketleague/ui/GameListItem.kt | 75 ++++++++++--------- .../pocketleague/ui/theme/Color.kt | 3 + 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt index 90b5d865f..b6139f494 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/CoreStatsComparison.kt @@ -18,6 +18,8 @@ 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. @@ -86,7 +88,7 @@ private fun StatComparisonRow( Box( modifier = Modifier .background( - color = Color(0xFF0069c1), + color = rlcsBlue, shape = RoundedCornerShape( topStartPercent = 50, bottomStartPercent = 50, @@ -110,7 +112,7 @@ private fun StatComparisonRow( Box( modifier = Modifier .background( - color = Color(0xFFee7d13), + color = rlcsOrange, shape = RoundedCornerShape( topEndPercent = 50, bottomEndPercent = 50, 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 230ee4f11..41b312d13 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/GameListItem.kt @@ -42,41 +42,7 @@ fun GameListItem( .fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, ) { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - ) { - Text( - text = game.blue.goals.toString(), - modifier = Modifier - .placeholder( - visible = game.blue.goals == -1, - shape = CircleShape, - ), - ) - - Text( - text = "Game ${game.number}\n${game.map}", - modifier = Modifier - .weight(1F) - .padding(horizontal = 16.dp) - .placeholder( - visible = game.map.isEmpty(), - shape = CircleShape, - ), - textAlign = TextAlign.Center, - ) - - Text( - text = game.orange.goals.toString(), - modifier = Modifier - .placeholder( - visible = game.orange.goals == -1, - shape = CircleShape, - ), - ) - } + GameOverviewRow(game) val iconToUse = if (showDetailedStats.value) { Icons.Default.ArrowCircleUp @@ -107,3 +73,42 @@ fun GameListItem( } } } + +@Composable +private fun GameOverviewRow(game: Game) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + ) { + Text( + text = game.blue.goals.toString(), + modifier = Modifier + .placeholder( + visible = game.blue.goals == -1, + shape = CircleShape, + ), + ) + + Text( + text = "Game ${game.number}\n${game.map}", + modifier = Modifier + .weight(1F) + .padding(horizontal = 16.dp) + .placeholder( + visible = game.map.isEmpty(), + shape = CircleShape, + ), + textAlign = TextAlign.Center, + ) + + Text( + text = game.orange.goals.toString(), + modifier = Modifier + .placeholder( + visible = game.orange.goals == -1, + shape = CircleShape, + ), + ) + } +} diff --git a/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt index f45ebc6b9..fb47ceb30 100644 --- a/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt +++ b/app/src/main/java/com/adammcneilly/pocketleague/ui/theme/Color.kt @@ -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) From 8b50f20da96e9d1e67ca4f15fda1c2abf7d61991 Mon Sep 17 00:00:00 2001 From: adammc331 Date: Wed, 27 Apr 2022 13:32:45 -0400 Subject: [PATCH 8/8] Doc fixes. --- .../adammcneilly/pocketleague/shared/models/GameTeamResult.kt | 1 + 1 file changed, 1 insertion(+) 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 521b5164e..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,6 +7,7 @@ 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,