-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ttoklip/feat/#15_첫화면로그인_구현
Feat/#15 첫화면로그인 구현
- Loading branch information
Showing
264 changed files
with
12,320 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ captures | |
.cxx | ||
local.properties | ||
.idea | ||
strings.xml | ||
constant.xml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
package com.umc.ttoklip | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import android.content.Context | ||
import androidx.annotation.StringRes | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import com.umc.ttoklip.module.NetworkConnectionChecker | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class TtoklipApplication : Application() { | ||
class TtoklipApplication : Application(), DefaultLifecycleObserver { | ||
override fun onCreate() { | ||
super<Application>.onCreate() | ||
context = applicationContext | ||
networkConnectionChecker = NetworkConnectionChecker(context) | ||
} | ||
|
||
override fun onStop(owner: LifecycleOwner) { | ||
networkConnectionChecker.unregister() | ||
super.onStop(owner) | ||
} | ||
|
||
override fun onStart(owner: LifecycleOwner) { | ||
networkConnectionChecker.register() | ||
super.onStart(owner) | ||
} | ||
|
||
companion object { | ||
@SuppressLint("StaticFieldLeak") | ||
private lateinit var context: Context | ||
|
||
fun getString(@StringRes stringResId: Int): String { | ||
return context.getString(stringResId) | ||
} | ||
|
||
private lateinit var networkConnectionChecker: NetworkConnectionChecker | ||
fun isOnline() = networkConnectionChecker.isOnline() | ||
} | ||
} |
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,11 @@ | ||
package com.umc.ttoklip.data.api | ||
|
||
import com.umc.ttoklip.data.model.TestResponse | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
|
||
//테스트용 api | ||
interface TestApi { | ||
@GET("/") | ||
suspend fun testGet(): Response<TestResponse> | ||
} |
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,9 @@ | ||
package com.umc.ttoklip.data.model | ||
|
||
|
||
//테스트용 response | ||
data class TestResponse( | ||
val time: String, | ||
val milliseconds_since_epoch: Long, | ||
val date: String | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/umc/ttoklip/data/repository/TestRepository.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,10 @@ | ||
package com.umc.ttoklip.data.repository | ||
|
||
import com.umc.ttoklip.data.model.TestResponse | ||
import retrofit2.Response | ||
|
||
//테스트용 repository | ||
interface TestRepository { | ||
|
||
suspend fun test(): Response<TestResponse> | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/umc/ttoklip/data/repository/TestRepositoryImpl.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,18 @@ | ||
package com.umc.ttoklip.data.repository | ||
|
||
import com.umc.ttoklip.data.api.TestApi | ||
import com.umc.ttoklip.data.model.TestResponse | ||
import retrofit2.Response | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
|
||
//테스트용 repositoryimpl | ||
@Singleton | ||
class TestRepositoryImpl @Inject constructor( | ||
private val api: TestApi | ||
) : TestRepository { | ||
override suspend fun test(): Response<TestResponse> { | ||
return api.testGet() | ||
} | ||
} |
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,52 @@ | ||
package com.umc.ttoklip.di | ||
|
||
import com.umc.ttoklip.R | ||
import com.umc.ttoklip.TtoklipApplication | ||
import com.umc.ttoklip.data.api.TestApi | ||
import com.umc.ttoklip.module.HttpRequestInterceptor | ||
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 | ||
import retrofit2.converter.scalars.ScalarsConverterFactory | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
const val NETWORK_EXCEPTION_OFFLINE_CASE = "network status is offline" | ||
const val NETWORK_EXCEPTION_BODY_IS_NULL = "result body is null" | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOKHttpClient(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.addInterceptor(HttpRequestInterceptor()) | ||
.retryOnConnectionFailure(false) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(TtoklipApplication.getString(R.string.base_url)) | ||
.addConverterFactory(ScalarsConverterFactory.create()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideTestApi(retrofit: Retrofit): TestApi { | ||
return retrofit.buildService() | ||
} | ||
|
||
private inline fun <reified T> Retrofit.buildService(): T { | ||
return this.create(T::class.java) | ||
} | ||
} |
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,5 @@ | ||
package com.umc.ttoklip.module | ||
|
||
object AppConfig { | ||
const val TAG_DEBUG = "TAG_DEBUG" | ||
} |
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,37 @@ | ||
package com.umc.ttoklip.module | ||
|
||
import com.umc.ttoklip.TtoklipApplication | ||
import com.umc.ttoklip.di.NetworkModule | ||
import retrofit2.Response | ||
|
||
suspend fun <T : Any, R : Any> handleApi( | ||
execute: suspend () -> Response<T>, | ||
mapper: (T) -> R | ||
): NetworkResult<R> { | ||
if (TtoklipApplication.isOnline().not()) { | ||
return NetworkResult.Error(Exception(NetworkModule.NETWORK_EXCEPTION_OFFLINE_CASE)) | ||
} | ||
|
||
return try { | ||
val response = execute() | ||
val body = response.body() | ||
if (response.isSuccessful) { | ||
body?.let { | ||
NetworkResult.Success(mapper(it)) | ||
} ?: run { | ||
throw NullPointerException(NetworkModule.NETWORK_EXCEPTION_BODY_IS_NULL) | ||
} | ||
} else { | ||
getFailDataResult(body, response) | ||
} | ||
} catch (e: Exception) { | ||
NetworkResult.Error(e) | ||
} | ||
} | ||
|
||
|
||
private fun <T : Any> getFailDataResult(body: T?, response: Response<T>) = body?.let { | ||
NetworkResult.Fail(statusCode = response.code(), message = it.toString()) | ||
} ?: run { | ||
NetworkResult.Fail(statusCode = response.code(), message = response.message()) | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/umc/ttoklip/module/HttpRequestInterceptor.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,19 @@ | ||
package com.umc.ttoklip.module | ||
|
||
import android.util.Log | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
class HttpRequestInterceptor : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
try { | ||
val originRequest = chain.request() | ||
Log.d(AppConfig.TAG_DEBUG, "HttpRequestInterceptor: ${originRequest.url}") | ||
|
||
return chain.proceed(originRequest) | ||
} catch (e: Exception) { | ||
Log.d(AppConfig.TAG_DEBUG, "HttpRequestInterceptor error: ${e.message}") | ||
throw e | ||
} | ||
} | ||
} |
Oops, something went wrong.