Skip to content

Commit

Permalink
[BUD-21] build : hilt build 세팅 (#9)
Browse files Browse the repository at this point in the history
KDW03 committed Feb 1, 2023
1 parent 9d4ad83 commit 45dedb6
Showing 24 changed files with 353 additions and 8 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {
namespace 'com.nocapstone.buddyvet'
@@ -13,7 +15,7 @@ android {
targetSdk 33
versionCode 1
versionName "1.0"

manifestPlaceholders["NATIVE_APP_KEY"] = "d48bcd0a6e882bce9b756ab78c9acd6e"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

@@ -40,7 +42,10 @@ dependencies {
api project(path: ':home')
api project(path: ':onboarding')
api project(path: ':common-ui')
api project(path: ':common')

implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
31 changes: 29 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nocapstone.buddyvet"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="com.nocapstone.buddyvet">

<application
android:name=".BuddyVetApplication"
@@ -14,18 +14,45 @@
android:supportsRtl="true"
android:theme="@style/Theme.Buddyvet"
tools:targetApi="33">

<activity
android:name=".SplashActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="oauth"
android:scheme="kakao${NATIVE_APP_KEY}" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@ package com.nocapstone.buddyvet
import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import com.nocapstone.common.util.NATIVE_APP_KEY
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class BuddyVetApplication : Application(){

override fun onCreate() {
57 changes: 57 additions & 0 deletions app/src/main/java/com/nocapstone/buddyvet/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.nocapstone.buddyvet

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.nocapstone.buddyvet.databinding.ActivitySplashBinding
import com.nocapstone.onboarding.LoginUtil
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch


class SplashActivity : AppCompatActivity() {

private lateinit var binding: ActivitySplashBinding
private val viewModel: SplashViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
}


private fun tryAutoLogin() {
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
// 하나라도 실패했을 경우
viewModel.failure.collectLatest {
if (it >= 1){} // Todo Login 실패 로직
}
}
launch {
viewModel.success.collectLatest {
if (it == 2){} // Todo Login 성공 로직
}
}
}
}

viewModel.with

}


//LoginUtil에 Login로직 시행
private fun loginWithKakao() {
LoginUtil.loginWithKaKao(this, { _, _ ->
viewModel.addSuccess()
}, { _, _ ->
viewModel.addFailure()
})
}

}
31 changes: 31 additions & 0 deletions app/src/main/java/com/nocapstone/buddyvet/SplashViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nocapstone.buddyvet

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

class SplashViewModel : ViewModel() {

private val _success = MutableStateFlow(0)
val success : StateFlow<Int> = _success

private val _failure = MutableStateFlow(0)
val failure: StateFlow<Int> = _failure

fun addSuccess() {
_success.value++
}

fun addFailure() {
_failure.value++
}

fun withRefreshToken(callback: (String?) -> Unit) {
viewModelScope.launch {
callback.invoke()
}
}

}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashActivity">

</androidx.constraintlayout.widget.ConstraintLayout>


</layout>
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -14,9 +14,17 @@ buildscript {
fragment_version = '1.5.5'
activity_version = '1.6.1'
kakao_version = '2.12.1'
dataStorePreferences_version = '1.0.0'

retrofit2Version = '2.9.0'
okHttpVersion = '4.10.0'

hiltVersion = '2.44'

}

dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$hiltVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}

8 changes: 7 additions & 1 deletion common-ui/build.gradle
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'


android {
@@ -37,10 +38,15 @@ android {

dependencies {

api project(path: ':foundation')


api "androidx.navigation:navigation-fragment-ktx:$rootProject.nav_version"
api "androidx.navigation:navigation-ui-ktx:$rootProject.nav_version"
implementation "androidx.activity:activity-ktx:$rootProject.activity_version"

implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
12 changes: 11 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {
namespace 'com.nocapstone.common'
@@ -32,9 +34,17 @@ android {

dependencies {

api "com.kakao.sdk:v2-all:$rootProject.kakao_version"
api project(path: ':foundation')


// Preferences DataStore
implementation("androidx.datastore:datastore-preferences:$rootProject.dataStorePreferences_version")


api "com.kakao.sdk:v2-all:$rootProject.kakao_version"

implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nocapstone.common.util

import androidx.datastore.core.DataStore
import kotlinx.coroutines.flow.Flow
import java.util.prefs.Preferences

@Singletone
class DataStoreUseCase(private val dataStore: DataStore<Preferences>) {

val refreshToken: Flow<String?> =
dataStore.data.map { preferences -> preferences[refreshTokenKey] }


}
1 change: 1 addition & 0 deletions foundation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions foundation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'


android {
namespace 'com.example.foundation'
compileSdk 33

defaultConfig {
minSdk 23
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled 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'
}
}

dependencies {
// Retrofit2
api "com.squareup.okhttp3:okhttp:$rootProject.okHttpVersion"
api "com.squareup.okhttp3:logging-interceptor:$rootProject.okHttpVersion"
api "com.squareup.retrofit2:retrofit:$rootProject.retrofit2Version"
api "com.squareup.retrofit2:converter-gson:$rootProject.retrofit2Version"

// Hilt
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"
}
Empty file added foundation/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions foundation/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.foundation

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* 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.example.foundation.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions foundation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
17 changes: 17 additions & 0 deletions foundation/src/test/java/com/example/foundation/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.foundation

import org.junit.Test

import org.junit.Assert.*

/**
* 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)
}
}
1 change: 1 addition & 0 deletions onboarding/build.gradle
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
4 changes: 1 addition & 3 deletions onboarding/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.nocapstone.onboarding

import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.navigation.fragment.findNavController
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient
import com.nocapstone.onboarding.databinding.FragmentLoginBinding


50 changes: 50 additions & 0 deletions onboarding/src/main/java/com/nocapstone/onboarding/LoginUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.nocapstone.onboarding

import android.content.Context
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient

class LoginUtil {

companion object {

fun loginWithKaKao(
context: Context,
onLoginSuccess: (OAuthToken?, Throwable?) -> Unit,
onLoginFailure: (OAuthToken?, Throwable?) -> Unit
) {
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
// 에러가 비어있지 않다면 즉 에러가 존재한다면
if (error != null) onLoginFailure(token, error)
// 토큰이 비어있지 않다면 즉 토근이 존재한다면
else if (token != null) onLoginSuccess(token, error)
}

// 카카오톡이 설치되어 있다면 카카오톡으로 로그인, 아니면 카카오계정으로 로그인
if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) {
UserApiClient.instance.loginWithKakaoTalk(context) { token, error ->
// 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도한다.
if (error != null) {
onLoginFailure(token, error)

// 단, 사용자가 의독적로 로그인을 취소한 경우는 제외
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
onLoginFailure(token, error)
return@loginWithKakaoTalk
}
//카카오 계정으로 로그인
UserApiClient.instance.loginWithKakaoAccount(context, callback = callback)
} else if (token != null) onLoginSuccess(token, error)
}
}
// 카카오톡이 설치되어 있지 않다면 카카오 계정으로 로그인
else {
UserApiClient.instance.loginWithKakaoAccount(context, callback = callback)
}

}
}

}
1 change: 1 addition & 0 deletions onboarding/src/main/res/layout/fragment_on_boarding1.xml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
android:layout_height="match_parent"
tools:context=".OnBoarding1Fragment">


<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -19,3 +19,4 @@ include ':home'
include ':common'
include ':common-ui'
include ':onboarding'
include ':foundation'

0 comments on commit 45dedb6

Please sign in to comment.