-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ef1810
commit 4856ad8
Showing
48 changed files
with
755 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
/build |
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,66 @@ | ||
import dependencies.Deps | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
apply plugin: 'dagger.hilt.android.plugin' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "dohun.kim.kinda.hilt_retrofit_test" | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(path: ':kinda-core') | ||
implementation project(path: ':kinda-dsl') | ||
implementation project(path: ':kinda-android') | ||
|
||
implementation Deps.Glide.glide | ||
|
||
implementation Deps.Kotlin.kotlin | ||
|
||
implementation Deps.AndroidX.activityKtx | ||
implementation Deps.AndroidX.appCompat | ||
implementation Deps.AndroidX.constraintLayout | ||
implementation Deps.AndroidX.recyclerView | ||
|
||
implementation Deps.AndroidX.Hilt.lifecycleViewModel | ||
kapt Deps.AndroidX.Hilt.compiler | ||
|
||
implementation Deps.Hilt.android | ||
kapt Deps.Hilt.compiler | ||
|
||
implementation Deps.Retrofit.retrofit | ||
implementation Deps.Retrofit.gson | ||
|
||
testImplementation project(path: ':kinda-android-test') | ||
testImplementation Deps.Test.junit4 | ||
testImplementation Deps.Test.mockitoCore | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dohun.kim.kinda.hilt_retrofit_test"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
android:name=".ExampleApplication"> | ||
<activity android:name=".github.GithubActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
7 changes: 7 additions & 0 deletions
7
...hilt-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/ExampleApplication.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,7 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class ExampleApplication : Application() |
10 changes: 10 additions & 0 deletions
10
...ple/hilt-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/data/GithubApi.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 dohun.kim.kinda.hilt_retrofit_test.data | ||
|
||
import dohun.kim.kinda.hilt_retrofit_test.model.UserModel | ||
import retrofit2.http.GET | ||
|
||
interface GithubApi { | ||
|
||
@GET("users") | ||
suspend fun getUsers(): List<UserModel> | ||
} |
22 changes: 22 additions & 0 deletions
22
...t-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/data/GithubRepository.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,22 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.data | ||
|
||
import dohun.kim.kinda.hilt_retrofit_test.data.exception.getCustomHttpException | ||
import dohun.kim.kinda.hilt_retrofit_test.model.UserModel | ||
import javax.inject.Inject | ||
|
||
interface GithubRepository { | ||
|
||
suspend fun getUsers(): List<UserModel> | ||
} | ||
|
||
class DefaultGithubRepository @Inject constructor( | ||
private val githubApi: GithubApi | ||
) : GithubRepository { | ||
|
||
override suspend fun getUsers(): List<UserModel> = | ||
try { | ||
githubApi.getUsers() | ||
} catch (e: Exception) { | ||
throw e.getCustomHttpException() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../main/java/dohun/kim/kinda/hilt_retrofit_test/data/exception/CustomExceptionExtensions.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,15 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.data.exception | ||
|
||
import retrofit2.HttpException | ||
|
||
fun Exception.getCustomHttpException(): Exception = | ||
when (this) { | ||
is HttpException -> { | ||
when (code()) { | ||
403 -> ForbiddenException() | ||
500 -> InternalErrorException() | ||
else -> InternalErrorException() | ||
} | ||
} | ||
else -> InternalErrorException() | ||
} |
3 changes: 3 additions & 0 deletions
3
...est/src/main/java/dohun/kim/kinda/hilt_retrofit_test/data/exception/ForbiddenException.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,3 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.data.exception | ||
|
||
class ForbiddenException : RuntimeException() |
3 changes: 3 additions & 0 deletions
3
...src/main/java/dohun/kim/kinda/hilt_retrofit_test/data/exception/InternalErrorException.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,3 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.data.exception | ||
|
||
class InternalErrorException : RuntimeException() |
24 changes: 24 additions & 0 deletions
24
...e/hilt-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/di/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,24 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ApplicationComponent | ||
import dohun.kim.kinda.hilt_retrofit_test.data.GithubApi | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(ApplicationComponent::class) | ||
class NetworkModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideGithubApi(): GithubApi = | ||
Retrofit.Builder() | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.baseUrl("https://api.github.com/") | ||
.build() | ||
.create(GithubApi::class.java) | ||
} |
18 changes: 18 additions & 0 deletions
18
...ilt-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/di/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,18 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityRetainedComponent | ||
import dagger.hilt.android.scopes.ActivityRetainedScoped | ||
import dohun.kim.kinda.hilt_retrofit_test.data.DefaultGithubRepository | ||
import dohun.kim.kinda.hilt_retrofit_test.data.GithubRepository | ||
|
||
@Module | ||
@InstallIn(ActivityRetainedComponent::class) | ||
abstract class RepositoryModule { | ||
|
||
@Binds | ||
@ActivityRetainedScoped | ||
abstract fun bindGithubRepository(githubRepository: DefaultGithubRepository): GithubRepository | ||
} |
35 changes: 35 additions & 0 deletions
35
...t-retrofit-test/src/main/java/dohun/kim/kinda/hilt_retrofit_test/github/GithubActivity.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,35 @@ | ||
package dohun.kim.kinda.hilt_retrofit_test.github | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.activity.viewModels | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import dohun.kim.kinda.hilt_retrofit_test.R | ||
import dohun.kim.kinda.kinda_android.KindaActivity | ||
import kotlinx.android.synthetic.main.activity_github.* | ||
|
||
@AndroidEntryPoint | ||
class GithubActivity : KindaActivity<GithubState, GithubEvent, GithubSideEffect>() { | ||
|
||
override val viewModel: GithubViewModel by viewModels() | ||
|
||
private val userListAdapter = UserListAdapter() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_github) | ||
|
||
rv_user.adapter = userListAdapter | ||
} | ||
|
||
override fun render(state: GithubState) { | ||
pb_loading.visibility = if (state.isLoading) View.VISIBLE else View.INVISIBLE | ||
|
||
userListAdapter.submitList(state.users) | ||
|
||
state.toastEvent.getData()?.let { strRes -> | ||
Toast.makeText(this, strRes, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} |
Oops, something went wrong.