-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HW-7 Koin 적용 #580
Merged
Merged
HW-7 Koin 적용 #580
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1bdffa2
HW-7 koin gradle 추가 및 버전 업
mtjin f7c585f
HW-7 module 추가
mtjin 6a9fefa
HW-7 KoinApplication 추가
mtjin 5b3aa1a
HW-7 MyApplication - Koin 으로 대체되어 삭제
mtjin fcb326a
HW-7 MovieSearch - Koin 적용
mtjin a4e4a43
HW-7 Login - Koin 적용
mtjin f524fd1
HW-7 Splash - Koin 적용
mtjin e3a6a8c
HW-7 module - androidContext() -> get() 으로 변경
mtjin e05c1da
HW-7 KoinApplication - Logger 추가
mtjin 142fa06
HW-7 AplModule - Retrofit 통신 모듈화
mtjin 170728d
HW-7 KoinApplication - 조건문 중괄호 추가
mtjin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
37 changes: 1 addition & 36 deletions
37
...idArchitectureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/api/ApiClient.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 |
---|---|---|
@@ -1,40 +1,5 @@ | ||
package com.mtjin.androidarchitecturestudy.api | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Response | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.io.IOException | ||
|
||
object ApiClient { | ||
private const val BASE_URL = "https://openapi.naver.com/" | ||
fun getApiClient(): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(provideOkHttpClient(AppInterceptor())) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
private fun provideOkHttpClient( | ||
interceptor: AppInterceptor | ||
): OkHttpClient = OkHttpClient.Builder() | ||
.run { | ||
addInterceptor(interceptor) | ||
build() | ||
} | ||
|
||
class AppInterceptor : Interceptor { | ||
@Throws(IOException::class) | ||
override fun intercept(chain: Interceptor.Chain) | ||
: Response = with(chain) { | ||
val newRequest = request().newBuilder() | ||
.addHeader("X-Naver-Client-Id", "33chRuAiqlSn5hn8tIme") | ||
.addHeader("X-Naver-Client-Secret", "fyfwt9PCUN") | ||
.build() | ||
|
||
proceed(newRequest) | ||
} | ||
} | ||
const val BASE_URL = "https://openapi.naver.com/" | ||
} |
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 |
---|---|---|
|
@@ -72,7 +72,7 @@ class MovieRepositoryImpl( | |
fail(it) | ||
} | ||
) | ||
}else{ | ||
} else { | ||
fail(Throwable("네트워크가 연결이 되어있지 않습니다.")) | ||
} | ||
} | ||
|
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
29 changes: 29 additions & 0 deletions
29
...hitectureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/di/KoinApplication.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,29 @@ | ||
package com.mtjin.androidarchitecturestudy.di | ||
|
||
import android.app.Application | ||
import com.mtjin.androidarchitecturestudy.BuildConfig | ||
import com.mtjin.androidarchitecturestudy.module.* | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.logger.Level | ||
|
||
class KoinApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
startKoin { | ||
if (BuildConfig.DEBUG) androidLogger() | ||
else androidLogger(Level.NONE) | ||
androidContext(this@KoinApplication) | ||
modules( | ||
repositoryModule, | ||
localDataModule, | ||
remoteDataModule, | ||
networkModule, | ||
viewModelModule, | ||
apiModule | ||
) | ||
|
||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rchitectureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/ApiModule.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,45 @@ | ||
package com.mtjin.androidarchitecturestudy.module | ||
|
||
import com.mtjin.androidarchitecturestudy.api.ApiClient | ||
import com.mtjin.androidarchitecturestudy.api.ApiInterface | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
val apiModule: Module = module { | ||
|
||
single<ApiInterface> { get<Retrofit>().create(ApiInterface::class.java) } | ||
|
||
single<Retrofit> { | ||
Retrofit.Builder() | ||
.baseUrl(ApiClient.BASE_URL) | ||
.client(get()) | ||
.addConverterFactory(get<GsonConverterFactory>()) | ||
.build() | ||
} | ||
|
||
single<GsonConverterFactory> { GsonConverterFactory.create() } | ||
|
||
single<OkHttpClient> { | ||
OkHttpClient.Builder() | ||
.run { | ||
addInterceptor(get<Interceptor>()) | ||
build() | ||
} | ||
} | ||
|
||
single<Interceptor> { | ||
Interceptor { chain -> | ||
with(chain) { | ||
val newRequest = request().newBuilder() | ||
.addHeader("X-Naver-Client-Id", "33chRuAiqlSn5hn8tIme") | ||
.addHeader("X-Naver-Client-Secret", "fyfwt9PCUN") | ||
.build() | ||
proceed(newRequest) | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ctureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/LocalDataModule.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,28 @@ | ||
package com.mtjin.androidarchitecturestudy.module | ||
|
||
import androidx.room.Room | ||
import com.mtjin.androidarchitecturestudy.data.login.source.local.LoginLocalDataSource | ||
import com.mtjin.androidarchitecturestudy.data.login.source.local.LoginLocalDataSourceImpl | ||
import com.mtjin.androidarchitecturestudy.data.search.source.local.MovieDao | ||
import com.mtjin.androidarchitecturestudy.data.search.source.local.MovieDatabase | ||
import com.mtjin.androidarchitecturestudy.data.search.source.local.MovieLocalDataSource | ||
import com.mtjin.androidarchitecturestudy.data.search.source.local.MovieLocalDataSourceImpl | ||
import com.mtjin.androidarchitecturestudy.utils.PreferenceManager | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
val localDataModule: Module = module { | ||
single<MovieLocalDataSource> { MovieLocalDataSourceImpl(get()) } | ||
single<LoginLocalDataSource> { LoginLocalDataSourceImpl(get()) } | ||
single<PreferenceManager> { PreferenceManager(get()) } | ||
single<MovieDao> { get<MovieDatabase>().movieDao() } | ||
single<MovieDatabase> { | ||
Room.databaseBuilder( | ||
get(), | ||
MovieDatabase::class.java, "Movie.db" | ||
) | ||
.allowMainThreadQueries() | ||
.build() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...tectureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/NetworkModule.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.mtjin.androidarchitecturestudy.module | ||
|
||
import com.mtjin.androidarchitecturestudy.utils.NetworkManager | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
val networkModule: Module = module { | ||
single { NetworkManager(get()) } | ||
} |
10 changes: 10 additions & 0 deletions
10
...tureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/RemoteDataModule.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.mtjin.androidarchitecturestudy.module | ||
|
||
import com.mtjin.androidarchitecturestudy.data.search.source.remote.MovieRemoteDataSource | ||
import com.mtjin.androidarchitecturestudy.data.search.source.remote.MovieRemoteDataSourceImpl | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
val remoteDataModule: Module = module { | ||
single<MovieRemoteDataSource> { MovieRemoteDataSourceImpl(get()) } | ||
} |
13 changes: 13 additions & 0 deletions
13
...tureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/RepositoryModule.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,13 @@ | ||
package com.mtjin.androidarchitecturestudy.module | ||
|
||
import com.mtjin.androidarchitecturestudy.data.login.source.LoginRepository | ||
import com.mtjin.androidarchitecturestudy.data.login.source.LoginRepositoryImpl | ||
import com.mtjin.androidarchitecturestudy.data.search.source.MovieRepository | ||
import com.mtjin.androidarchitecturestudy.data.search.source.MovieRepositoryImpl | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
val repositoryModule: Module = module { | ||
single<MovieRepository> { MovieRepositoryImpl(get(), get(), get()) } | ||
single<LoginRepository> { LoginRepositoryImpl(get()) } | ||
} |
14 changes: 14 additions & 0 deletions
14
...ctureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/module/ViewModelModule.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.mtjin.androidarchitecturestudy.module | ||
|
||
import com.mtjin.androidarchitecturestudy.ui.login.LoginViewModel | ||
import com.mtjin.androidarchitecturestudy.ui.search.MovieSearchViewModel | ||
import com.mtjin.androidarchitecturestudy.ui.splash.SplashViewModel | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
val viewModelModule: Module = module { | ||
viewModel { SplashViewModel(get()) } | ||
viewModel { LoginViewModel(get()) } | ||
viewModel { MovieSearchViewModel(get()) } | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{} 추가해주세요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
170728d
수정했습니다.