From 5c378e96059781cf219bbb0b2c464765030a5647 Mon Sep 17 00:00:00 2001 From: OYJ <89826723+oyj7677@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:04:25 +0900 Subject: [PATCH 1/9] Create README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..f7b3fad1 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# android-github + +## 1 단계 - GitHub(모듈 분리) +### 프로그래밍 요구 사항 +- 순수 코틀린 모듈인 domain 모듈을 만든다. +- 순수 코틀린 모듈인 data 모듈을 만든다. +- data 모듈은 domain 모듈에 의존해야 한다. +- app 모듈은 domain 모듈에 의존해야 한다. From 678ced4659788c372704813e834b66745ee10565 Mon Sep 17 00:00:00 2001 From: OYJ Date: Mon, 4 Sep 2023 01:15:03 +0900 Subject: [PATCH 2/9] =?UTF-8?q?step2=20-=20GitHub(HTTP)=20=20-=20GitHub=20?= =?UTF-8?q?Repository=20=EB=AA=A9=EB=A1=9D=20=EC=88=98=EC=8B=A0=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84=20=20-=20MockWebServer=EB=A5=BC?= =?UTF-8?q?=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 23 +- app/src/main/AndroidManifest.xml | 2 + .../nextstep/edu/github/GitHubViewModel.kt | 14 + .../edu/github/GithubViewModelFactory.kt | 15 + .../camp/nextstep/edu/github/MainActivity.kt | 34 ++- app/src/main/res/layout/activity_main.xml | 42 +-- .../edu/github/GitHubViewModelTest.kt | 54 ++++ app/src/test/resources/githubRepo.json | 270 ++++++++++++++++++ github-data/.gitignore | 1 + github-data/build.gradle.kts | 47 +++ .../java/com/example/github_data/GitHubApi.kt | 10 + .../github_data/GitHubRepositoryImpl.kt | 28 ++ .../com/example/github_data/GitHubService.kt | 16 ++ .../example/github_data/room/GithubRepoDao.kt | 25 ++ .../github_data/room/GithubRepoDatabase.kt | 32 +++ .../github_data/room/GithubRepoEntity.kt | 18 ++ .../com/example/github_data/room/Injector.kt | 10 + github-domain/.gitignore | 1 + github-domain/build.gradle.kts | 10 + .../example/github_domain/GitHubRepository.kt | 7 + .../com/example/github_domain/GithubDomain.kt | 4 + .../example/github_domain/GithubRepoData.kt | 7 + settings.gradle.kts | 2 + 23 files changed, 646 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/camp/nextstep/edu/github/GitHubViewModel.kt create mode 100644 app/src/main/java/camp/nextstep/edu/github/GithubViewModelFactory.kt create mode 100644 app/src/test/java/camp/nextstep/edu/github/GitHubViewModelTest.kt create mode 100644 app/src/test/resources/githubRepo.json create mode 100644 github-data/.gitignore create mode 100644 github-data/build.gradle.kts create mode 100644 github-data/src/main/java/com/example/github_data/GitHubApi.kt create mode 100644 github-data/src/main/java/com/example/github_data/GitHubRepositoryImpl.kt create mode 100644 github-data/src/main/java/com/example/github_data/GitHubService.kt create mode 100644 github-data/src/main/java/com/example/github_data/room/GithubRepoDao.kt create mode 100644 github-data/src/main/java/com/example/github_data/room/GithubRepoDatabase.kt create mode 100644 github-data/src/main/java/com/example/github_data/room/GithubRepoEntity.kt create mode 100644 github-data/src/main/java/com/example/github_data/room/Injector.kt create mode 100644 github-domain/.gitignore create mode 100644 github-domain/build.gradle.kts create mode 100644 github-domain/src/main/java/com/example/github_domain/GitHubRepository.kt create mode 100644 github-domain/src/main/java/com/example/github_domain/GithubDomain.kt create mode 100644 github-domain/src/main/java/com/example/github_domain/GithubRepoData.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0245d0f8..da8b0673 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,3 @@ -@file:Suppress("UnstableApiUsage") - plugins { id("com.android.application") id("kotlin-android") @@ -10,7 +8,7 @@ android { compileSdk = Version.compileSdk defaultConfig { - applicationId = "edu.nextstep.camp.calculator" + applicationId = "camp.nextstep.edu.github" minSdk = Version.minSdk targetSdk = Version.targetSdk versionCode = 1 @@ -42,15 +40,26 @@ android { } dependencies { + implementation(project(":github-data")) + implementation(project(":github-domain")) + implementation("org.jetbrains.kotlin:kotlin-stdlib:${Version.kotlin}") - implementation("androidx.core:core-ktx:1.9.0") - implementation("androidx.appcompat:appcompat:1.6.0") - implementation("com.google.android.material:material:1.7.0") + implementation("androidx.core:core-ktx:1.10.1") + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("com.google.android.material:material:1.9.0") implementation("androidx.constraintlayout:constraintlayout:2.1.4") - implementation("androidx.fragment:fragment-ktx:1.5.5") + implementation("androidx.fragment:fragment-ktx:1.6.1") + implementation("com.squareup.retrofit2:retrofit:2.9.0") + implementation ("com.squareup.retrofit2:converter-gson:2.9.0") + implementation ("com.google.code.gson:gson:2.10.1") + implementation("androidx.room:room-runtime:2.5.2") + annotationProcessor("androidx.room:room-compiler:2.5.2") testImplementation("junit:junit:4.13.2") testImplementation("com.google.truth:truth:1.1.3") + testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") + implementation("com.squareup.okhttp3:mockwebserver:4.11.0") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") } + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a9b73270..d5da6292 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + create(modelClass: Class): T { + if (modelClass.isAssignableFrom(GitHubViewModel::class.java)) { + return GitHubViewModel(Injector.providesGithubRepoRepository(githubRepoDao)) as T + } + throw IllegalArgumentException("Unknown ViewModel class") + } +} diff --git a/app/src/main/java/camp/nextstep/edu/github/MainActivity.kt b/app/src/main/java/camp/nextstep/edu/github/MainActivity.kt index 23a363ce..60716b42 100644 --- a/app/src/main/java/camp/nextstep/edu/github/MainActivity.kt +++ b/app/src/main/java/camp/nextstep/edu/github/MainActivity.kt @@ -2,10 +2,42 @@ package camp.nextstep.edu.github import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log +import androidx.activity.viewModels +import androidx.lifecycle.ViewModelProvider +import camp.nextstep.edu.github.databinding.ActivityMainBinding +import com.example.github_data.room.GithubRepoDao +import com.example.github_data.room.GithubRepoDatabase +import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class MainActivity : AppCompatActivity() { + + private lateinit var binding: ActivityMainBinding + private lateinit var viewModel: GitHubViewModel + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + + initBinding() + initViewModel() + + setContentView(binding.root) + } + + private fun initViewModel() { + val githubRepoDao = GithubRepoDatabase.getInstance(this)!!.GithubRepoDao() + val githubViewModelFactory = GithubViewModelFactory(githubRepoDao) + viewModel = ViewModelProvider(this, githubViewModelFactory)[GitHubViewModel::class.java] + binding.viewModel = viewModel + } + + private fun initBinding() { + binding = ActivityMainBinding.inflate(layoutInflater) + binding.lifecycleOwner = this } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a628662c..f7eff280 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,21 +1,27 @@ - + + + + - + - +