Skip to content

Commit

Permalink
Add data logic (#11)
Browse files Browse the repository at this point in the history
* chore: remove .idea/*

* chore: add libraries

* chore: add Internet permission

* feat: implement ApiFactory
  • Loading branch information
giovannijunseokim authored Mar 29, 2024
1 parent cbb2d80 commit 486e37e
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 75 deletions.
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/migrations.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

11 changes: 9 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.ktlint)
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

android {
Expand All @@ -13,7 +14,7 @@ android {
minSdk = 28
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = "1.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -39,9 +40,10 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
kotlinCompilerExtensionVersion = "1.5.11"
}
packaging {
resources {
Expand Down Expand Up @@ -70,6 +72,11 @@ dependencies {
implementation(libs.coil.compose)
implementation(libs.grid)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.retrofit2)
implementation(libs.okhttp)
implementation(libs.kotlinx.serialization.json)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.retrofit2.kotlinx.serialization.converter)
}

ktlint {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/univ/earthbreaker/namu/data/ApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package univ.earthbreaker.namu.data

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import univ.earthbreaker.namu.BuildConfig

object ApiFactory {
private val client: OkHttpClient by lazy {
OkHttpClient.Builder().addInterceptor(
HttpLoggingInterceptor().apply {
level =
if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
},
).build()
}

val retrofitForGrowTreeServer: Retrofit by lazy {
Retrofit.Builder().baseUrl(BuildConfig.GROW_TREE_BASE_URL).client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())).build()
}

val retrofitForChatGPT: Retrofit by lazy {
Retrofit.Builder().baseUrl(BuildConfig.CHAT_GPT_BASE_URL).client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())).build()
}

inline fun <reified T> create(forWhichServer: Server): T =
when (forWhichServer) {
Server.GrowTreeServer -> retrofitForGrowTreeServer.create(T::class.java)
Server.ChatGPT -> retrofitForChatGPT.create(T::class.java)
}
}

enum class Server {
GrowTreeServer,
ChatGPT,
}

object ServicePool
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.ktlint) apply false

kotlin("jvm") version "1.9.23"
kotlin("plugin.serialization") version "1.9.23"
}

buildscript {
dependencies {
classpath(libs.secrets.gradle.plugin)
}
}
18 changes: 15 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
[versions]
agp = "8.3.0"
agp = "8.3.1"
coilCompose = "2.6.0"
grid = "1.0.0"
kotlin = "1.9.0"
kotlin = "1.9.23"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
kotlinxSerializationJson = "1.6.3"
lifecycleRuntimeKtx = "2.7.0"
activityCompose = "1.8.2"
composeBom = "2023.08.00"
composeBom = "2024.03.00"
ktlint = "12.1.0"
loggingInterceptor = "4.12.0"
okhttp = "4.12.0"
retrofit = "2.11.0"
retrofit2KotlinxSerializationConverter = "1.0.0"
secretsGradlePlugin = "2.0.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -30,6 +36,12 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
okhttp-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "loggingInterceptor" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
retrofit2 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit2-kotlinx-serialization-converter = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter", version.ref = "retrofit2KotlinxSerializationConverter" }
secrets-gradle-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
Expand Down

0 comments on commit 486e37e

Please sign in to comment.