-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
353 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/nocapstone/buddyvet/SplashActivity.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,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
31
app/src/main/java/com/nocapstone/buddyvet/SplashViewModel.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.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() | ||
} | ||
} | ||
|
||
} |
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 @@ | ||
<?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> |
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
14 changes: 14 additions & 0 deletions
14
common/src/main/java/com/nocapstone/common/util/DataStoreUseCase.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,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] } | ||
|
||
|
||
} |
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 @@ | ||
/build |
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 @@ | ||
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.
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,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 |
24 changes: 24 additions & 0 deletions
24
foundation/src/androidTest/java/com/example/foundation/ExampleInstrumentedTest.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,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) | ||
} | ||
} |
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,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
17
foundation/src/test/java/com/example/foundation/ExampleUnitTest.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.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) | ||
} | ||
} |
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 |
---|---|---|
@@ -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" /> |
5 changes: 5 additions & 0 deletions
5
onboarding/src/main/java/com/nocapstone/onboarding/LoginFragment.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
50 changes: 50 additions & 0 deletions
50
onboarding/src/main/java/com/nocapstone/onboarding/LoginUtil.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,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) | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ include ':home' | |
include ':common' | ||
include ':common-ui' | ||
include ':onboarding' | ||
include ':foundation' |