generated from AdamMc331/AndroidAppTemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
386 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("com.android.library") | ||
} | ||
|
||
kotlin { | ||
android() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = "team-api" | ||
} | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
api(project(":core-models")) | ||
api(project(":core-data")) | ||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
val androidMain by getting | ||
val androidTest by getting | ||
val iosX64Main by getting | ||
val iosArm64Main by getting | ||
val iosSimulatorArm64Main by getting | ||
val iosMain by creating { | ||
dependsOn(commonMain) | ||
iosX64Main.dependsOn(this) | ||
iosArm64Main.dependsOn(this) | ||
iosSimulatorArm64Main.dependsOn(this) | ||
} | ||
val iosX64Test by getting | ||
val iosArm64Test by getting | ||
val iosSimulatorArm64Test by getting | ||
val iosTest by creating { | ||
dependsOn(commonTest) | ||
iosX64Test.dependsOn(this) | ||
iosArm64Test.dependsOn(this) | ||
iosSimulatorArm64Test.dependsOn(this) | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdk = AndroidConfig.compileSDK | ||
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") | ||
defaultConfig { | ||
minSdk = AndroidConfig.minSDK | ||
targetSdk = AndroidConfig.targetSDK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.adammcneilly.pocketleague.team.api" /> |
17 changes: 17 additions & 0 deletions
17
team-api/src/commonMain/kotlin/com/adammcneilly/pocketleague/team/api/TeamRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.adammcneilly.pocketleague.team.api | ||
|
||
import com.adammcneilly.pocketleague.core.data.DataResult | ||
import com.adammcneilly.pocketleague.core.models.Team | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* An interface defining the data contract for all requests within the | ||
* team domain. | ||
*/ | ||
interface TeamRepository { | ||
|
||
/** | ||
* Requests a list of [Team] entities for all of the active teams within RLCS. | ||
*/ | ||
fun fetchActiveTeams(): Flow<DataResult<List<Team>>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("plugin.serialization") | ||
id("com.android.library") | ||
} | ||
|
||
kotlin { | ||
android() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = "team-implementation" | ||
} | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(project(":team-api")) | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") | ||
implementation("io.ktor:ktor-client-core:${Versions.ktor}") | ||
implementation("io.ktor:ktor-client-json:${Versions.ktor}") | ||
implementation("io.ktor:ktor-client-logging:${Versions.ktor}") | ||
implementation("io.ktor:ktor-client-serialization:${Versions.ktor}") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
val androidMain by getting { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-android:${Versions.ktor}") | ||
} | ||
} | ||
val androidTest by getting | ||
val iosX64Main by getting | ||
val iosArm64Main by getting | ||
val iosSimulatorArm64Main by getting | ||
val iosMain by creating { | ||
dependsOn(commonMain) | ||
iosX64Main.dependsOn(this) | ||
iosArm64Main.dependsOn(this) | ||
iosSimulatorArm64Main.dependsOn(this) | ||
|
||
dependencies { | ||
implementation("io.ktor:ktor-client-ios:${Versions.ktor}") | ||
} | ||
} | ||
val iosX64Test by getting | ||
val iosArm64Test by getting | ||
val iosSimulatorArm64Test by getting | ||
val iosTest by creating { | ||
dependsOn(commonTest) | ||
iosX64Test.dependsOn(this) | ||
iosArm64Test.dependsOn(this) | ||
iosSimulatorArm64Test.dependsOn(this) | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdk = AndroidConfig.compileSDK | ||
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") | ||
defaultConfig { | ||
minSdk = AndroidConfig.minSDK | ||
targetSdk = AndroidConfig.targetSDK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.adammcneilly.pocketleague.team.implementation" /> |
46 changes: 46 additions & 0 deletions
46
...in/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGAPIClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.adammcneilly.pocketleague.team.implementation.octanegg | ||
|
||
import com.adammcneilly.pocketleague.core.data.DataResult | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.features.json.JsonFeature | ||
import io.ktor.client.features.json.serializer.KotlinxSerializer | ||
import io.ktor.client.request.HttpRequestBuilder | ||
import io.ktor.client.request.get | ||
import io.ktor.http.ContentType | ||
import kotlinx.serialization.json.Json | ||
|
||
/** | ||
* Defines the API client information for communicating with the octane.gg API. | ||
*/ | ||
internal class OctaneGGAPIClient { | ||
val baseURL = "https://zsr.octane.gg/" | ||
|
||
val httpClient = HttpClient { | ||
install(JsonFeature) { | ||
serializer = KotlinxSerializer( | ||
Json { | ||
ignoreUnknownKeys = true | ||
acceptContentTypes = acceptContentTypes + ContentType.Any | ||
} | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* A helper function to wrap all of our API requests in a try/catch and return a [DataResult] | ||
* object. | ||
*/ | ||
suspend inline fun <reified T : Any> getResponse( | ||
endpoint: String, | ||
requestBuilder: HttpRequestBuilder.() -> Unit = {}, | ||
): DataResult<T> { | ||
val url = "$baseURL$endpoint" | ||
|
||
return try { | ||
// KTOR will switch to a different dispatcher, so we don't need to. | ||
DataResult.Success(httpClient.get(url, requestBuilder)) | ||
} catch (e: Exception) { | ||
DataResult.Error(e) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGTeamService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.adammcneilly.pocketleague.team.implementation.octanegg | ||
|
||
import com.adammcneilly.pocketleague.core.data.DataResult | ||
import com.adammcneilly.pocketleague.core.models.Team | ||
import com.adammcneilly.pocketleague.team.api.TeamRepository | ||
import com.adammcneilly.pocketleague.team.implementation.octanegg.dtos.TeamDTO | ||
import com.adammcneilly.pocketleague.team.implementation.octanegg.dtos.TeamListResponseDTO | ||
import com.adammcneilly.pocketleague.team.implementation.octanegg.mappers.toTeam | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
/** | ||
* A concrete implementation of [TeamRepository] to request information from the octane.gg API. | ||
*/ | ||
class OctaneGGTeamService : TeamRepository { | ||
|
||
private val apiClient = OctaneGGAPIClient() | ||
|
||
override fun fetchActiveTeams(): Flow<DataResult<List<Team>>> { | ||
return flow { | ||
val apiResult = apiClient.getResponse<TeamListResponseDTO>("teams/active") | ||
|
||
val mappedResult: DataResult<List<Team>> = when (apiResult) { | ||
is DataResult.Success -> { | ||
val mappedTeams = apiResult.data.teams?.map(TeamDTO::toTeam).orEmpty() | ||
|
||
DataResult.Success(mappedTeams) | ||
} | ||
is DataResult.Error -> { | ||
DataResult.Error(apiResult.error) | ||
} | ||
} | ||
|
||
emit(mappedResult) | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...Main/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/dtos/AccountDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.adammcneilly.pocketleague.team.implementation.octanegg.dtos | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Represents a [PlayerDTO] account within the octane.gg API. | ||
*/ | ||
@Serializable | ||
internal data class AccountDTO( | ||
@SerialName("id") | ||
val id: String? = null, | ||
@SerialName("platform") | ||
val platform: String? = null, | ||
) |
31 changes: 31 additions & 0 deletions
31
...nMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/dtos/PlayerDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.adammcneilly.pocketleague.team.implementation.octanegg.dtos | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Represents a person who is a player for a [TeamDTO] in the octane.gg API. | ||
*/ | ||
@Serializable | ||
internal data class PlayerDTO( | ||
@SerialName("accounts") | ||
val accounts: List<AccountDTO>? = null, | ||
@SerialName("coach") | ||
val coach: Boolean? = null, | ||
@SerialName("country") | ||
val country: String? = null, | ||
@SerialName("_id") | ||
val id: String? = null, | ||
@SerialName("name") | ||
val name: String? = null, | ||
@SerialName("relevant") | ||
val relevant: Boolean? = null, | ||
@SerialName("slug") | ||
val slug: String? = null, | ||
@SerialName("substitute") | ||
val substitute: Boolean? = null, | ||
@SerialName("tag") | ||
val tag: String? = null, | ||
@SerialName("team") | ||
val team: TeamOverviewDTO? = null, | ||
) |
15 changes: 15 additions & 0 deletions
15
...monMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/dtos/TeamDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.adammcneilly.pocketleague.team.implementation.octanegg.dtos | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Represents a team within the octane.gg API domain. | ||
*/ | ||
@Serializable | ||
internal data class TeamDTO( | ||
@SerialName("players") | ||
val players: List<PlayerDTO>? = null, | ||
@SerialName("team") | ||
val team: TeamOverviewDTO? = null, | ||
) |
Oops, something went wrong.