Skip to content

Commit

Permalink
Merge pull request #25 from Yoon-Chan/login-feature
Browse files Browse the repository at this point in the history
Login feature
  • Loading branch information
Yoon-Chan authored Apr 18, 2024
2 parents 13c24a4 + 1ee64ee commit 64b1407
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
cache: gradle

- name: Run tests
run: ./gradlew test
run: |
echo sdk.dir=~/Android/Sdk >> local.properties
echo api_key=\"${{ secrets.API_KEY }}\" >> local.properties
./gradlew test
- name: Upload test report
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -110,6 +113,7 @@ jobs:
- name: Grant execute permission for gradlew
run: |
echo sdk.dir=~/Android/Sdk >> local.properties
echo api_key=\"${{ secrets.API_KEY }}\" >> local.properties
chmod +x gradlew
- name: Build with Gradle
run: |
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ android {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
lintOptions.disable("Instantiatable")
lintOptions.isAbortOnError = false
}

dependencies {
Expand All @@ -75,6 +77,8 @@ dependencies {
implementation(libs.converter.gson)
implementation(libs.hilt.android)
ksp(libs.hilt.android.compiler)
ksp(libs.dagger.compiler) // Dagger compiler
ksp(libs.hilt.compiler) // Hilt compiler
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.orbit.viewmodel)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<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:name="com.example.app.App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.SnsProject"
tools:targetApi="31">

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com.example.app/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.app

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class App : Application()
21 changes: 21 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import java.util.Properties

plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
alias(libs.plugins.kotlin.serialization)
id("com.google.devtools.ksp")
}

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())

android {
namespace = "com.example.data"
compileSdk = 34
Expand All @@ -14,6 +19,9 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

buildConfigField("String", "api_key", properties["api_key"] as String)
manifestPlaceholders["api_key"] = properties["api_key"] as String
}

buildTypes {
Expand All @@ -32,6 +40,11 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
}
lintOptions.disable("Instantiatable")
lintOptions.isAbortOnError = false
}

dependencies {
Expand All @@ -48,4 +61,12 @@ dependencies {
ksp(libs.hilt.android.compiler)

implementation(project(":domain"))

//retrofit
implementation(libs.retrofit)
implementation(libs.converter.gson)

//okhttp
implementation(libs.okhttp)
implementation(libs.logging.interceptor)
}
40 changes: 40 additions & 0 deletions data/src/main/java/com/example/data/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.data.di

import com.example.data.BuildConfig
import com.example.data.retrofit.UserService
import com.google.gson.GsonBuilder
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

@Module
@InstallIn(SingletonComponent::class)
class RetrofitModule {

@Provides
fun provideOkHttp(): OkHttpClient {
return OkHttpClient
.Builder()
.build()
}

@Provides
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
val gson = GsonBuilder()
.setLenient()
.create();
return Retrofit.Builder()
.baseUrl("${BuildConfig.api_key}/api/")
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient)
.build()
}

@Provides
fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::class.java)

}
16 changes: 16 additions & 0 deletions data/src/main/java/com/example/data/di/UserModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.data.di

import com.example.data.usecase.LoginUseCaseImpl
import com.example.domain.usecase.login.LoginUseCase
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
abstract class UserModule {

@Binds
abstract fun bindLoginUseCase(loginUseCase: LoginUseCaseImpl) : LoginUseCase
}
8 changes: 8 additions & 0 deletions data/src/main/java/com/example/data/model/CommonResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.data.model

data class CommonResponse<T>(
val result: String,
val data: T,
val errorCode: String,
val errorMessage: String,
)
17 changes: 17 additions & 0 deletions data/src/main/java/com/example/data/model/LoginParam.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.data.model

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

data class LoginParam(
@SerializedName("loginId")
val loginId: String,
@SerializedName("password")
val password: String,
) {
fun toRequestBody(): RequestBody {
return Gson().toJson(this).toRequestBody()
}
}
15 changes: 15 additions & 0 deletions data/src/main/java/com/example/data/retrofit/UserService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.data.retrofit

import com.example.data.model.CommonResponse
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST

interface UserService {
@POST("users/login")
@Headers("Content-Type:application/json; charset=UTF-8")
suspend fun login(
@Body requestBody: RequestBody
) : CommonResponse<String>
}
16 changes: 16 additions & 0 deletions data/src/main/java/com/example/data/usecase/LoginUseCaseImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.data.usecase

import com.example.data.model.LoginParam
import com.example.data.retrofit.UserService
import com.example.domain.usecase.login.LoginUseCase
import javax.inject.Inject
import okhttp3.RequestBody

class LoginUseCaseImpl @Inject constructor(
private val userService: UserService
): LoginUseCase {
override suspend fun invoke(id: String, password: String): Result<String> = runCatching {
val requestBody = LoginParam(id, password).toRequestBody()
userService.login(requestBody).data
}
}
15 changes: 14 additions & 1 deletion domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import java.util.Properties

plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())

android {
namespace = "com.example.domain"
compileSdk = 34
Expand All @@ -12,6 +17,9 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

buildConfigField("String", "api_key", properties["api_key"] as String)
manifestPlaceholders["api_key"] = properties["api_key"] as String
}

buildTypes {
Expand All @@ -30,6 +38,11 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
}
lintOptions.disable("Instantiatable")
lintOptions.isAbortOnError = false
}

dependencies {
Expand All @@ -41,4 +54,4 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

}
}
11 changes: 11 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ lifecycle-runtime-ktx = "2.7.0"
material = "1.11.0"

navigation-compose = "2.7.7"
okhttp = "4.12.0"
orbit-compose = "7.0.1"
orbit-core = "7.0.1"
orbit-test = "7.0.1"
orbit-viewmodel = "7.0.1"
paging-compose = "3.3.0-beta01"
paging-runtime = "3.2.1"
Expand Down Expand Up @@ -47,11 +51,14 @@ androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref =
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room-runtime" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "converter-gson" }
dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "hilt-android" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt-android" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt-android" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt-android" }
junit = { module = "junit:junit", version.ref = "junit" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }
material = { module = "com.google.android.material:material", version.ref = "material" }
logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }

androidx-compose-ui= { group = "androidx.compose.ui", name= "ui" }
androidx-compose-ui-graphics= { group = "androidx.compose.ui", name= "ui-graphics" }
Expand All @@ -61,6 +68,10 @@ androidx-compose-compose-bom = {group= "androidx.compose", name = "compose-bom",
androidx-compose-ui-ui-test-junit4 = {group="androidx.compose.ui", name="ui-test-junit4"}
androidx-compose-ui-ui-tooling = {group="androidx.compose.ui", name="ui-tooling"}
androidx-compose-ui-ui-test-manifest = {group="androidx.compose.ui", name="ui-test-manifest"}
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
orbit-compose = { module = "org.orbit-mvi:orbit-compose", version.ref = "orbit-compose" }
orbit-core = { module = "org.orbit-mvi:orbit-core", version.ref = "orbit-core" }
orbit-test = { module = "org.orbit-mvi:orbit-test", version.ref = "orbit-test" }
orbit-viewmodel = { module = "org.orbit-mvi:orbit-viewmodel", version.ref = "orbit-viewmodel" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }

Expand Down
9 changes: 9 additions & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.google.devtools.ksp")
alias(libs.plugins.ktlint)
alias(libs.plugins.kotlin.serialization)
id("com.google.dagger.hilt.android")
}

android {
Expand Down Expand Up @@ -41,6 +42,8 @@ android {
composeOptions {
kotlinCompilerExtensionVersion = "1.5.0"
}
lintOptions.disable("Instantiatable")
lintOptions.isAbortOnError = false
}

dependencies {
Expand All @@ -67,5 +70,11 @@ dependencies {
ksp(libs.hilt.android.compiler)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
ksp(libs.dagger.compiler) // Dagger compiler
ksp(libs.hilt.compiler) // Hilt compiler
implementation(project(":domain"))
implementation(libs.orbit.core)
implementation(libs.orbit.viewmodel)
implementation(libs.orbit.compose)
testImplementation(libs.orbit.test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp

@Composable
fun LoginTextField(
modifier: Modifier,
value: String,
visualTransformation: VisualTransformation = VisualTransformation.None,
onValueString: (String) -> Unit,
) {
TextField(
Expand All @@ -27,5 +29,6 @@ fun LoginTextField(
disabledIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(8.dp),
visualTransformation = visualTransformation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.example.presentation.ui.theme.SnsProjectTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Loading

0 comments on commit 64b1407

Please sign in to comment.