Skip to content

Commit

Permalink
Merge pull request #19 from ttoklip/feat/#15_첫화면로그인_구현
Browse files Browse the repository at this point in the history
Feat/#15 첫화면로그인 구현
  • Loading branch information
40food authored Jan 23, 2024
2 parents 4551899 + 135c75a commit a86b51a
Show file tree
Hide file tree
Showing 264 changed files with 12,320 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ captures
.cxx
local.properties
.idea
strings.xml
constant.xml
27 changes: 22 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ plugins {
id 'dagger.hilt.android.plugin'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'com.umc.ttoklip'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.umc.ttoklip"
minSdk 24
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -33,11 +36,11 @@ android {
kotlinOptions {
jvmTarget = '17'
}
dataBinding{
dataBinding {
enabled = true
}
viewBinding{
enabled =true
viewBinding {
enabled = true
}
}

Expand Down Expand Up @@ -66,6 +69,7 @@ dependencies {
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
implementation "androidx.lifecycle:lifecycle-runtime:2.6.2"
implementation "androidx.activity:activity-ktx:1.7.2"


//lifecycle
Expand All @@ -74,6 +78,7 @@ dependencies {
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "com.squareup.retrofit2:converter-scalars:2.9.0"

// https://github.com/square/okhttp
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
Expand All @@ -88,6 +93,18 @@ dependencies {
implementation "com.google.dagger:hilt-android:2.47"
kapt "com.google.dagger:hilt-compiler:2.47"

//indicator : https://github.com/tommybuonomo/dotsindicator?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=7127
implementation "com.tbuonomo:dotsindicator:5.0"

//circleViwe: https://github.com/hdodenhof/CircleImageView
implementation 'de.hdodenhof:circleimageview:3.1.0'


implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.6'

//naver map
//implementation "com.naver.maps:map-sdk:3.16.2"
}
kapt {
correctErrorTypes true
Expand Down
53 changes: 50 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name=".TtoklipApplication"
Expand All @@ -18,6 +19,35 @@
android:supportsRtl="true"
android:theme="@style/Theme.Ttoklip"
tools:targetApi="31">

<activity
android:name=".presentation.mypage.ManageMyInfoActivity"
android:exported="false" />
<activity
android:name=".presentation.honeytip.read.ReadActivity"
android:exported="false" />
<activity
android:name=".presentation.honeytip.write.WriteHoneyTipActivity"
android:exported="false"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".presentation.alarm.AlarmActivity"
android:exported="false" />
<activity
android:name=".presentation.news.detail.ArticleActivity"
android:exported="false" />
<activity
android:name=".presentation.mypage.SetAnnouncementActivity"
android:exported="false" />
<activity
android:name=".presentation.mypage.ManageUsageActivity"
android:exported="false" />
<activity
android:name=".presentation.mypage.MyHometownAddressActivity"
android:exported="false" />
<activity
android:name=".presentation.mypage.ManageAccountActivity"
android:exported="false" />
<activity
android:name=".presentation.MainActivity"
android:exported="true">
Expand All @@ -27,6 +57,23 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name="com.google.android.gms.metadata.ModuleDependencies"
android:enabled="false"
android:exported="false"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
</intent-filter>

<meta-data
android:name="photopicker_activity:0:required"
android:value="" />
</service>
<activity
android:name=".presentation.search.SearchActivity"
android:exported="false" />
</application>

</manifest>
35 changes: 34 additions & 1 deletion app/src/main/java/com/umc/ttoklip/TtoklipApplication.kt
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()
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/api/TestApi.kt
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>
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/model/TestResponse.kt
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
)
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>
}
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()
}
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt
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)
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/umc/ttoklip/module/AppConfig.kt
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"
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/umc/ttoklip/module/HandleApi.kt
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 app/src/main/java/com/umc/ttoklip/module/HttpRequestInterceptor.kt
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
}
}
}
Loading

0 comments on commit a86b51a

Please sign in to comment.