Skip to content

Commit

Permalink
Merge pull request #36 from EAT-SSU/34-add-splash-screen
Browse files Browse the repository at this point in the history
34 add splash screen
  • Loading branch information
Amepistheo authored Jul 28, 2023
2 parents 241c0f3 + f28e35a commit 37c9d91
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 109 deletions.
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ dependencies {
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.4'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'com.google.android.datatransport:transport-runtime:3.1.2'
implementation 'com.google.android.gms:play-services-base:18.0.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down Expand Up @@ -108,4 +110,10 @@ dependencies {
// implementation group: 'com.kakao.sdk', name: 'kakaolink', version: '1.30.5'

implementation "com.kakao.sdk:v2-user:2.5.0" // ์นด์นด์˜ค ๋กœ๊ทธ์ธ

implementation 'com.google.dagger:hilt-android:2.47'
annotationProcessor 'com.google.dagger:hilt-compiler:2.47'

// implementation "androidx.security:security-crypto:1.0.0"

}
30 changes: 16 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,41 @@
<uses-feature
android:name="android.hardware.camera"
android:required="true" />

<application
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/image_logo_none"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/image_logo_none"
android:supportsRtl="true"
android:theme="@style/Theme.EatSSUAndroid"
android:usesCleartextTraffic="true"
tools:replace="android:usesCleartextTraffic"
tools:targetApi="31">
<activity
android:name="com.eatssu.android.ui.login.SocialLoginActivity"
android:name=".ui.login.SocialLoginActivity"
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>

<meta-data
android:name="com.kakao.sdk.AppKey"
android:value="$kakao_native_app_key" />
<!-- <meta-data-->
<!-- android:name="com.kakao.sdk.AppKey"-->
<!-- android:value="${APP_KEY}" />-->

android:value="$kakao_native_app_key" /> <!-- <meta-data -->
<!-- android:name="com.kakao.sdk.AppKey" -->
<!-- android:value="${APP_KEY}" /> -->
<activity
android:name=".ui.login.LoginActivity"
android:exported="true">
Expand All @@ -58,11 +59,11 @@

<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"
Expand All @@ -79,7 +80,6 @@
android:scheme="@string/kakao_redirection_scheme" />
</intent-filter>
</activity>

<activity
android:name=".ui.BaseActivity"
android:exported="false">
Expand All @@ -89,13 +89,14 @@
</activity>
<activity
android:name=".ui.login.SignUpActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
android:exported="true"
android:windowSoftInputMode="adjustResize">
<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="" />
Expand All @@ -109,6 +110,7 @@

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

<meta-data
android:name="android.app.lib_name"
android:value="" />
Expand All @@ -122,11 +124,11 @@

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

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>

<activity
android:name=".ui.mypage.MyReviewListActivity"
android:exported="true">
Expand Down Expand Up @@ -179,11 +181,11 @@
android:exported="true"
android:windowSoftInputMode="adjustResize">
<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="" />
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/eatssu/android/data/RefreshTokenService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.eatssu.android.data

import RetrofitImpl.retrofit
import com.eatssu.android.App
import com.eatssu.android.data.service.UserService

object RefreshTokenService {

private val userService = retrofit.create(UserService::class.java)

fun refreshToken(): String {
val res = userService.getNewToken().execute()
if (res.isSuccessful) {
val newAccessToken = res.body()?.accessToken ?: ""
val newRefreshToken = res.body()?.refreshToken ?: ""
if (newAccessToken.isNotBlank()) {
App.token_prefs.accessToken = newAccessToken
App.token_prefs.refreshToken = newRefreshToken
return newAccessToken
}
}
throw IllegalStateException("ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ์‹คํŒจ")
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/eatssu/android/data/RetrofitImpl.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.eatssu.android.App
import com.eatssu.android.BuildConfig
import com.eatssu.android.data.TokenAuthenticator
import okhttp3.*
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
Expand Down Expand Up @@ -48,6 +49,7 @@ object RetrofitImpl {
OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(AppInterceptor())
.authenticator(TokenAuthenticator())
.build()
}

Expand Down
113 changes: 18 additions & 95 deletions app/src/main/java/com/eatssu/android/data/TokenAuthenticator.kt
Original file line number Diff line number Diff line change
@@ -1,102 +1,25 @@
package com.eatssu.android.data

import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import android.util.Log
import okhttp3.Authenticator
import okhttp3.Request
import okhttp3.Response
import okhttp3.Route
import retrofit2.Retrofit

//class TokenAuthenticator constructor(
// val context: Context,
// private val refreshToken: String,
//) : Authenticator {
//
// companion object {
// private val TAG = TokenAuthenticator::class.java.simpleName
// }
//
// override fun authenticate(route: Route?, response: Response): Request? {
//
// if (response.code == 401) {
//
// val refreshToken = CommonHelper.getRefreshToken(sharedPref)
// val getNewDeviceToken = GlobalScope.async(Dispatchers.Default) {
// getNewDeviceToken(refreshToken)
// }
//
// val token = runBlocking {
// getNewDeviceToken.await()
// }
// if(token != null) {
// return getRequest(response, token)
// }
// }
// return null
// }
//
// private suspend inline fun getNewDeviceToken(token: String): String? {
// return GlobalScope.async(Dispatchers.Default) {
// callApiNewDeviceToken(token)
// }.await()
// }
//
//
// private suspend inline fun callApiNewDeviceToken(token: String) : String? = suspendCoroutine { continuation ->
// createWebService<Api>()
// .refreshToken(RefreshToken(token))
// .with(rx)
// .response(object : ApiCallback<Token>{
// override fun success(data: Token?) {
// if(data != null) {
// CommonHelper.saveTokenInfo(sharedPref, data)
// continuation.resume(data.accessToken)
// } else {
// continuation.resume(null)
// }
// }
//
// override fun error(statusCode: Int, message: String?) {
// continuation.resume(null)
// }
// })
//
// return@suspendCoroutine
// }
//
// private val okHttp = OkHttpClient.Builder()
// .connectTimeout(TIMEOUT_LIMIT, TimeUnit.SECONDS)
// .readTimeout(TIMEOUT_LIMIT, TimeUnit.SECONDS)
// .writeTimeout(TIMEOUT_LIMIT, TimeUnit.SECONDS)
// .addInterceptor(HttpLoggingInterceptor().apply {
// level = if (BuildConfig.DEBUG) {
// HttpLoggingInterceptor.Level.BODY
// } else {
// HttpLoggingInterceptor.Level.NONE
// }
// })
// .build()
//
// private inline fun <reified T> createWebService(): T {
// val retrofit = Retrofit.Builder()
// .baseUrl(BuildConfig.SERVER_URL)
// .client(okHttp)
// .addConverterFactory(GsonConverterFactory.create(
// GsonBuilder().serializeNulls().create()
// ))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build()
// return retrofit.create(T::class.java)
// }
//
// private fun getRequest(response: Response, token: String): Request {
// return response.request
// .newBuilder()
// .removeHeader("Authorization")
// .addHeader("Authorization", "Bearer $token")
// .build()
// }
//}
class TokenAuthenticator: Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
Log.i("Authenticator", response.toString())
Log.i("Authenticator", "ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ์‹œ๋„")
return try {
val newAccessToken = RefreshTokenService.refreshToken()
Log.i("Authenticator", "ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ์„ฑ๊ณต : $newAccessToken")
response.request.newBuilder()
.removeHeader("Bearer").apply {
addHeader("Bearer", newAccessToken)
}.build() // ํ† ํฐ ์žฌ๋ฐœ๊ธ‰์ด ์„ฑ๊ณตํ–ˆ๋‹ค๋ฉด, ๊ธฐ์กด ํ—ค๋”๋ฅผ ์ง€์šฐ๊ณ , ์ƒˆ๋กœ์šด ํ•ด๋”๋ฅผ ๋‹จ๋‹ค.
} catch (e: Exception) {
e.printStackTrace()
null // ๋งŒ์•ฝ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰์ด ์‹คํŒจํ–ˆ๋‹ค๋ฉด ํ—ค๋”์— ์•„๋ฌด๊ฒƒ๋„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.eatssu.android.App
import com.eatssu.android.data.MySharedPreferences
import com.eatssu.android.data.model.request.loginWithKakaoRequest
import com.eatssu.android.data.model.response.TokenResponse
import com.eatssu.android.data.service.OauthService
Expand Down Expand Up @@ -69,6 +70,31 @@ class SocialLoginActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivitySocialLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

//์นด์นด์˜ค ๋กœ๊ทธ์ธ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ž๋™๋กœ๊ทธ์ธ ๋ฉ”์†Œ๋“œ
// UserApiClient.instance.accessTokenInfo { tokenInfo, error ->
// if (error != null) {
// Toast.makeText(this, "์ž๋™ ๋กœ๊ทธ์ธ ์‹คํŒจ", Toast.LENGTH_SHORT).show()
// }
// else if (tokenInfo != null) {
// Toast.makeText(this, "์ž๋™ ๋กœ๊ทธ์ธ ์„ฑ๊ณต", Toast.LENGTH_SHORT).show()
// val intent = Intent(this, MainActivity::class.java)
// startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
// }
// }

// SharedPreferences ์•ˆ์— ๊ฐ’์ด ์ €์žฅ๋˜์–ด ์žˆ์„ ๋•Œ-> Login ํŒจ์Šคํ•˜๊ธฐ
if (App.token_prefs.accessToken?.isNotBlank() == true){ // SharedPreferences ์•ˆ์— ๊ฐ’์ด ์ €์žฅ๋˜์–ด ์žˆ์„ ๋•Œ -> MainActivity๋กœ ์ด๋™
Toast.makeText(
this,
"์ž๋™ ๋กœ๊ทธ์ธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",
Toast.LENGTH_SHORT
).show()
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}

val context = this
binding.imbKakao.setOnClickListener {
lifecycleScope.launch {
Expand Down

0 comments on commit 37c9d91

Please sign in to comment.