Skip to content

Commit

Permalink
Merge pull request #1 from hyeonhh/feature/code-refactor
Browse files Browse the repository at this point in the history
refactor : 코드 구조 개선
  • Loading branch information
hyeonhh authored Nov 24, 2024
2 parents a1680ad + ab26234 commit df6847b
Show file tree
Hide file tree
Showing 112 changed files with 2,137 additions and 789 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
kotlin("plugin.serialization") version "2.0.10"
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
}

android {
Expand Down Expand Up @@ -54,6 +56,9 @@ android {

dependencies {

implementation("com.google.dagger:hilt-android:2.51.1")
ksp("com.google.dagger:hilt-android-compiler:2.51.1")

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
Expand All @@ -64,12 +69,12 @@ dependencies {
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("androidx.activity:activity-compose:1.9.1")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation(platform("androidx.compose:compose-bom:2024.11.00"))
implementation("androidx.compose.ui:ui-graphics")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2024.11.00"))

val composeBom = platform("androidx.compose:compose-bom:2024.06.00")
implementation(composeBom)
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".base.Application"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:networkSecurityConfig="@xml/network_security_config"
Expand All @@ -15,35 +16,40 @@
android:supportsRtl="true"
android:theme="@style/Theme.Comus"
tools:targetApi="31">
<activity android:name=".ui.login.LoginActivity"
android:exported="true">

</activity>
<activity
android:name=".ui.question.QuestionPreviousAnswerActivity"
android:name=".ui.question.previous.PreviousAnswerActivity"
android:exported="false" />
<activity
android:name=".ui.question.QuestionCollectBlockActivity"
android:name=".ui.question.block.CollectBlockActivity"
android:exported="false" />
<activity
android:name=".ui.question.QuestionResultActivity"
android:name=".ui.question.result.ResultAfterSignActivity"
android:exported="false" />
<activity
android:name=".ui.question.QuestionCheckAnswerActivity"
android:name=".ui.question.result.ResultBeforeSignActivity"
android:exported="true">
</activity>
<activity
android:name=".ui.question.QuestionDetailActivity"
android:name=".ui.question.select.SelectAnswerActivity"
android:exported="false" />
<activity
android:name=".ui.home.HomeThemeQuestionListActivity"
android:name=".ui.question.theme.ThemeQuestionListActivity"
android:exported="true" />
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name" >

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

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


</activity>
</application>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/example/com_us/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.example.com_us.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/example/com_us/base/AppInterceptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.com_us.base

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class AppInterceptor(private val accessToken: String) : Interceptor {
private val contentType = "application/json"
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain) : Response = with(chain) {
val newRequest = request().newBuilder()
.addHeader("Content-Type", contentType)
.addHeader("Authorization", accessToken)
.build()

val response = proceed(newRequest)
when (response.code) {
401, 404 -> {
Log.d("API FAILURE", response.toString())
}
500 -> {
Log.d("API FAILURE 500", response.toString())
}
}
response
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/com_us/base/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.com_us.base

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class Application : Application() {
}
26 changes: 26 additions & 0 deletions app/src/main/java/com/example/com_us/base/data/BaseResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.com_us.base.data

import kotlinx.serialization.Serializable

@Serializable
data class BaseResponse<T>(
val status: Int,
val message: String,
val data: T? = null,
)

@Serializable
data class BaseResponseNoData(
val status: Int,
val message: String,
)

fun <T> BaseResponse<T>.toResult(): Result<T> {
return when{
status == 200 && data != null -> Result.success(data)
status == 200 && data == null -> Result.failure(NetworkError.NullDataError())
status == 400 or 401 -> Result.failure(NetworkError.ApiError(status, message))
status == 500 -> Result.failure(NetworkError.ApiError(status, message))
else -> Result.failure(NetworkError.ApiError(status, message))
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/example/com_us/base/data/NetworkError.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.com_us.base.data

sealed class NetworkError : Exception(){
data class ApiError(
val statusCode : Int,
override val message : String
) : NetworkError()

data class NetworkException(
override val cause : Throwable,
) : NetworkError()

data class NullDataError(
override val message : String = "Data is null"
) : NetworkError()

}
22 changes: 22 additions & 0 deletions app/src/main/java/com/example/com_us/base/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.com_us.base.di

import android.content.Context
import com.example.com_us.R
import com.example.com_us.data.di.BaseUrl
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import dagger.Provides
import dagger.hilt.android.qualifiers.ApplicationContext

@Module
@InstallIn(SingletonComponent::class)
object ServiceModule {

@Provides
@BaseUrl
fun provideBaseUrl(
@ApplicationContext context: Context
) : String = context.getString(R.string.baseUrl)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.com_us.data.default_repository

import com.example.com_us.base.data.NetworkError
import com.example.com_us.data.model.home.ResponseHomeDataDto
import com.example.com_us.data.repository.HomeRepository
import com.example.com_us.data.default_source.DefaultHomeDataSource
import com.example.com_us.base.data.toResult
import javax.inject.Inject



class DefaultHomeRepository @Inject constructor(
private val defaultHomeDataSource: DefaultHomeDataSource
) : HomeRepository {
override suspend fun getHomeData(): Result<ResponseHomeDataDto> {
return try {
defaultHomeDataSource.getHomeData().toResult()
} catch (e: Exception) {
Result.failure(NetworkError.NetworkException(e))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.com_us.data.default_repository

import com.example.com_us.base.data.NetworkError
import com.example.com_us.data.model.question.response.question.ResponseProfileDto
import com.example.com_us.data.repository.ProfileRepository
import com.example.com_us.data.default_source.DefaultProfileDataSource
import com.example.com_us.base.data.toResult
import javax.inject.Inject

class DefaultProfileRepository @Inject constructor(
private val profileRemoteDataSource: DefaultProfileDataSource
) : ProfileRepository {
override suspend fun getProfileData(): Result<ResponseProfileDto> {
return try {
profileRemoteDataSource.getProfileData().toResult()
}catch (e: Exception){
Result.failure(NetworkError.NetworkException(e))
}
}
}
Loading

0 comments on commit df6847b

Please sign in to comment.