├── .github └── workflows │ └── android.yml ├── .gitignore ├── LICENSE-2.0.txt ├── README.md ├── app ├── .editorconfig ├── .gitignore ├── build.gradle.kts ├── ktlint.gradle.kts ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── ic_app_logo-playstore.png │ ├── java │ │ └── com │ │ │ └── okanaydin │ │ │ └── assignment │ │ │ ├── Application.kt │ │ │ ├── data │ │ │ ├── di │ │ │ │ └── RemoteDataModule.kt │ │ │ └── remote │ │ │ │ ├── api │ │ │ │ ├── PhotoService.kt │ │ │ │ └── PostService.kt │ │ │ │ └── datasource │ │ │ │ ├── model │ │ │ │ ├── CommentModel.kt │ │ │ │ ├── PhotoModel.kt │ │ │ │ ├── PostAndPhotoModel.kt │ │ │ │ └── PostModel.kt │ │ │ │ ├── photos │ │ │ │ ├── PhotoRemoteDataSource.kt │ │ │ │ └── PhotoRemoteDataSourceImp.kt │ │ │ │ └── posts │ │ │ │ ├── PostRemoteDataSource.kt │ │ │ │ └── PostRemoteDataSourceImp.kt │ │ │ └── features │ │ │ ├── MainActivity.kt │ │ │ ├── core │ │ │ ├── BaseFragment.kt │ │ │ ├── LayoutViewState.kt │ │ │ └── Resource.kt │ │ │ ├── details │ │ │ ├── repository │ │ │ │ └── PostDetailRepository.kt │ │ │ ├── ui │ │ │ │ ├── CommentsAdapter.kt │ │ │ │ ├── CommentsDiffUtil.kt │ │ │ │ ├── PostDetailFragment.kt │ │ │ │ ├── PostDetailViewModel.kt │ │ │ │ └── PostDetailViewState.kt │ │ │ └── usecase │ │ │ │ └── PostDetailUseCase.kt │ │ │ ├── posts │ │ │ ├── di │ │ │ │ └── PostModule.kt │ │ │ ├── repository │ │ │ │ └── PostRepository.kt │ │ │ ├── ui │ │ │ │ ├── PostAdapter.kt │ │ │ │ ├── PostListDiffUtil.kt │ │ │ │ ├── PostListFragment.kt │ │ │ │ ├── PostViewModel.kt │ │ │ │ └── PostViewState.kt │ │ │ └── usecase │ │ │ │ └── PostListUseCase.kt │ │ │ └── splash │ │ │ └── SplashFragment.kt │ └── res │ │ ├── anim │ │ └── fade_in.xml │ │ ├── drawable-mdpi │ │ ├── app_icon.png │ │ └── art_whoops.png │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_discuss.png │ │ └── ic_launcher_background.xml │ │ ├── font │ │ ├── proxima_nova_soft_bold.otf │ │ ├── proxima_nova_soft_regular.ttf │ │ └── proxima_nova_soft_semibold.otf │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_failed.xml │ │ ├── content_loading.xml │ │ ├── fragment_post_detail.xml │ │ ├── fragment_post_list.xml │ │ ├── fragment_splash.xml │ │ ├── item_comment.xml │ │ └── item_post.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── nav_graph.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ic_app_logo_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── okanaydin │ └── assignment │ ├── data │ └── remote │ │ └── datasource │ │ ├── model │ │ ├── CommentModelFactory.kt │ │ ├── PhotoModelFactory.kt │ │ ├── PostAndPhotoModelFactory.kt │ │ └── PostModelFactory.kt │ │ ├── photo │ │ └── PhotoRemoteDataSourceImpTest.kt │ │ └── post │ │ └── PostRemoteDataSourceImpTest.kt │ ├── features │ ├── core │ │ └── LayoutViewStateTest.kt │ ├── details │ │ ├── PostDetailRepositoryTest.kt │ │ ├── PostDetailUseCaseTest.kt │ │ └── PostDetailViewModelTest.kt │ └── posts │ │ ├── PostListUseCaseTest.kt │ │ ├── PostRepositoryTest.kt │ │ └── PostViewModelTest.kt │ └── util │ ├── ListExtensions.kt │ └── MainCoroutineRule.kt ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── java │ ├── ClassPaths.kt │ ├── Configs.kt │ ├── Dependencies.kt │ └── Versions.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── results ├── action.png ├── board.png ├── screenshot_1.png ├── screenshot_2.png ├── screenshot_3.png ├── screenshot_4.png └── screenshot_5.png └── settings.gradle.kts /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: 4 | push: 5 | branches: [ dev ] 6 | pull_request: 7 | branches: [ dev ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: set up JDK 11 17 | uses: actions/setup-java@v2 18 | with: 19 | java-version: '11' 20 | distribution: 'adopt' 21 | 22 | - name: Grant execute permission for gradlew 23 | run: chmod +x gradlew 24 | - name: Build with Gradle 25 | run: ./gradlew build 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | /.idea 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/sonarlint 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Assignment 2 | 3 | ## :scroll: Description 4 | This assignment gives you basically a post list and its detail with comments. 5 | 6 | ## :iphone: Features 7 | 8 | - [x] Users can see random post list. 9 | - [x] Users can see the comments of the post. 10 | 11 | ## :camera_flash: Screenshots 12 | 13 | Splash Screen | Post List Screen | Post Detail Screen 14 | :-------------------------:|:-------------------------:|:-------------------------: 15 | | | | 16 | Error Screen | Missing Data Screen | 17 | | 18 | 19 | ## :rocket: What the project uses ? 20 | * [Architecture Components](https://developer.android.com/topic/libraries/architecture/) 21 | * [Android X](https://developer.android.com/jetpack/androidx) 22 | * [Android KTX](https://developer.android.com/kotlin/ktx.html) 23 | * [Dagger Hilt](https://developer.android.com/training/dependency-injection/hilt-android) 24 | * [Retrofit2](https://square.github.io/retrofit/) 25 | * [OkHttp3](https://github.com/square/okhttp) 26 | * [Kotlin Coroutines](https://developer.android.com/kotlin/coroutines) 27 | * [Kotlin Flow](https://developer.android.com/kotlin/flow) 28 | * [ViewBinding](https://developer.android.com/topic/libraries/view-binding) 29 | * [Navigation Component](https://developer.android.com/guide/navigation/navigation-getting-started) 30 | * [Moshi](https://github.com/square/moshi) 31 | * [Coil](https://github.com/coil-kt/coil) 32 | * [ktlint](https://ktlint.github.io/) 33 | * [MockK](https://mockk.io/) 34 | * [Truth](https://truth.dev//) 35 | 36 | ## :file_folder: Package Structure 37 | 38 | com.okanaydin.assignment # root package 39 | . 40 | | 41 | ├── data 42 | │ ── remote # api calls 43 | │ └── models # response model 44 | │ └── remote data source # data source 45 | | 46 | ├── features 47 | │ └── core # resource handling 48 | │ 49 | │ └── feature1 # post list 50 | │ └── di # dependency Injection 51 | │ └── repository # repository 52 | │ └── ui # fragments, viewModel, viewState, adapters 53 | │ └── usecase # use case 54 | . 55 | 56 | ## :writing_hand: GitHub Projects 57 | I have created issues for the defined requirements such as features, improvements, and bugs to assign myself and track those issues on the board. Basically, there are three columns which are In-Progress, To-Do, and Done. 58 | 59 | 60 | ## :running_man: GitHub Action 61 | I have implemented GitHub Action for this project and when you create a new pull request it goes to build the project automatically if there is a problem in your build time you can easily see the issue. 62 | 63 | 64 | ## License 65 | ``` 66 | Copyright 2021 The Android Open Source Project 67 | 68 | Licensed under the Apache License, Version 2.0 (the "License"); 69 | you may not use this file except in compliance with the License. 70 | You may obtain a copy of the License at 71 | 72 | https://www.apache.org/licenses/LICENSE-2.0 73 | 74 | Unless required by applicable law or agreed to in writing, software 75 | distributed under the License is distributed on an "AS IS" BASIS, 76 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 77 | See the License for the specific language governing permissions and 78 | limitations under the License. 79 | ``` 80 | -------------------------------------------------------------------------------- /app/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{kt,kts}] 2 | # possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely) 3 | indent_size=4 4 | # true (recommended) / false 5 | insert_final_newline=true 6 | # possible values: number (e.g. 120) (package name, imports & comments are ignored), "off" 7 | # it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide) 8 | max_line_length=off 9 | disabled_rules=import-ordering,final-newline -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | id("kotlin-kapt") 5 | id("kotlin-parcelize") 6 | id("androidx.navigation.safeargs") 7 | id("dagger.hilt.android.plugin") 8 | id("de.mannodermaus.android-junit5") 9 | } 10 | 11 | android { 12 | 13 | compileSdkVersion(Configs.compileSdkVersion) 14 | defaultConfig { 15 | applicationId(Configs.applicationId) 16 | minSdkVersion(Configs.minSdkVersion) 17 | targetSdkVersion(Configs.targetSdkVersion) 18 | versionCode(Configs.versionCode) 19 | versionName(Configs.versionName) 20 | testInstrumentationRunner(Configs.testInstrumentationRunner) 21 | } 22 | 23 | buildTypes { 24 | getByName("release") { 25 | isMinifyEnabled = false 26 | proguardFiles( 27 | getDefaultProguardFile("proguard-android-optimize.txt"), 28 | "proguard-rules.pro" 29 | ) 30 | } 31 | } 32 | 33 | compileOptions { 34 | sourceCompatibility = JavaVersion.VERSION_1_8 35 | targetCompatibility = JavaVersion.VERSION_1_8 36 | } 37 | 38 | kotlinOptions { 39 | jvmTarget = JavaVersion.VERSION_1_8.toString() 40 | } 41 | 42 | viewBinding { 43 | android.buildFeatures.viewBinding = true 44 | } 45 | 46 | testOptions { 47 | unitTests.isReturnDefaultValues = true 48 | unitTests.isIncludeAndroidResources = true 49 | } 50 | } 51 | 52 | dependencies { 53 | 54 | implementation(Dependencies.appCompat) 55 | implementation(Dependencies.androidMaterial) 56 | implementation(Dependencies.coil) 57 | implementation(Dependencies.constraintLayout) 58 | implementation(Dependencies.coreKtx) 59 | implementation(Dependencies.coroutinesAndroid) 60 | implementation(Dependencies.coroutinesCore) 61 | implementation(Dependencies.cardView) 62 | implementation(Dependencies.daggerHilt) 63 | implementation(Dependencies.fragmentKtx) 64 | implementation(Dependencies.liveDataKtx) 65 | implementation(Dependencies.moshi) 66 | implementation(Dependencies.navigationFragment) 67 | implementation(Dependencies.navigationUi) 68 | implementation(Dependencies.okhttp3) 69 | implementation(Dependencies.okhttp3Interceptor) 70 | implementation(Dependencies.retrofit2) 71 | implementation(Dependencies.retrofit2MoshiConvertor) 72 | implementation(Dependencies.swipeRefreshLayout) 73 | implementation(Dependencies.viewModelKtx) 74 | 75 | kapt(Dependencies.daggerHiltCompiler) 76 | kapt(Dependencies.moshiCodegen) 77 | 78 | testImplementation(Dependencies.archTest) 79 | testImplementation(Dependencies.coroutinesTest) 80 | testImplementation(Dependencies.jUnit) 81 | testImplementation(Dependencies.truth) 82 | testImplementation(Dependencies.truthExtensions) 83 | testImplementation(Dependencies.mockk) 84 | testImplementation(Dependencies.robolectric) 85 | 86 | testImplementation(Dependencies.jupiterApi) 87 | testRuntimeOnly(Dependencies.jupiterEngine) 88 | testImplementation(Dependencies.jupiterParams) 89 | testRuntimeOnly(Dependencies.jupiterVintageEngine) 90 | 91 | androidTestImplementation(Dependencies.jUnitExt) 92 | androidTestImplementation(Dependencies.espresso) 93 | } 94 | -------------------------------------------------------------------------------- /app/ktlint.gradle.kts: -------------------------------------------------------------------------------- 1 | val ktlint by configurations.creating 2 | 3 | dependencies { 4 | ktlint(Dependencies.ktlint) 5 | } 6 | 7 | val outputDir = "${project.buildDir}/reports/ktlint/" 8 | val inputFiles = project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt")) 9 | 10 | val ktlintCheck by tasks.creating(JavaExec::class) { 11 | inputs.files(inputFiles) 12 | outputs.dir(outputDir) 13 | 14 | description = "Check Kotlin code style." 15 | classpath = ktlint 16 | main = "com.pinterest.ktlint.Main" 17 | args = listOf("src/**/*.kt") 18 | } 19 | 20 | val ktlintFormat by tasks.creating(JavaExec::class) { 21 | inputs.files(inputFiles) 22 | outputs.dir(outputDir) 23 | 24 | description = "Fix Kotlin code style deviations." 25 | classpath = ktlint 26 | main = "com.pinterest.ktlint.Main" 27 | args = listOf("-F", "src/**/*.kt") 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle.kts. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/ic_app_logo-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/ic_app_logo-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/Application.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | /** 7 | * @HiltAndroidApp triggers Hilt's code generation, including a base class for your application that serves as the application-level dependency container. 8 | * ref: https://developer.android.com/training/dependency-injection/hilt-android#application-class 9 | */ 10 | @HiltAndroidApp 11 | class Application : Application() 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/di/RemoteDataModule.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.di 2 | 3 | import com.okanaydin.assignment.com.BuildConfig 4 | import com.okanaydin.assignment.data.remote.api.PhotoService 5 | import com.okanaydin.assignment.data.remote.api.PostService 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.components.SingletonComponent 10 | import okhttp3.OkHttpClient 11 | import okhttp3.logging.HttpLoggingInterceptor 12 | import retrofit2.Retrofit 13 | import retrofit2.converter.moshi.MoshiConverterFactory 14 | import retrofit2.create 15 | import javax.inject.Singleton 16 | 17 | /** 18 | * A Hilt module is a class that is annotated with @Module. Like a Dagger module, it informs Hilt how to provide instances of certain types. 19 | * Unlike Dagger modules, you must annotate Hilt modules with @InstallIn to tell Hilt which Android class each module will be used or installed in. 20 | * ref: https://developer.android.com/training/dependency-injection/hilt-android#hilt-modules 21 | */ 22 | 23 | @Module 24 | @InstallIn(SingletonComponent::class) 25 | object RemoteDataModule { 26 | 27 | private const val BASE_API_URL = "https://jsonplaceholder.typicode.com/" 28 | 29 | /** 30 | * @Provides annotation would be accessed across the application. 31 | * @Singleton annotation helps the instance to be created and used once across the application. 32 | */ 33 | @Provides 34 | @Singleton 35 | fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor = 36 | HttpLoggingInterceptor().apply { 37 | level = if (BuildConfig.DEBUG) { 38 | // development build 39 | HttpLoggingInterceptor.Level.BODY 40 | } else { 41 | // production build 42 | HttpLoggingInterceptor.Level.NONE 43 | } 44 | } 45 | 46 | @Provides 47 | @Singleton 48 | fun provideOkHttpClient(httpLoggingInterceptor: HttpLoggingInterceptor): OkHttpClient = 49 | OkHttpClient.Builder() 50 | .addInterceptor(httpLoggingInterceptor) 51 | .build() 52 | 53 | @Provides 54 | @Singleton 55 | fun provideRetrofit( 56 | okHttpClient: OkHttpClient, 57 | moshiConverterFactory: MoshiConverterFactory 58 | ): Retrofit = 59 | Retrofit.Builder() 60 | .client(okHttpClient) 61 | .baseUrl(BASE_API_URL) 62 | .addConverterFactory(moshiConverterFactory) 63 | .build() 64 | 65 | @Provides 66 | @Singleton 67 | fun provideMoshiConverterFactory(): MoshiConverterFactory = MoshiConverterFactory.create() 68 | 69 | @Provides 70 | @Singleton 71 | fun providePostService(retrofit: Retrofit): PostService { 72 | return retrofit.create() 73 | } 74 | 75 | @Provides 76 | @Singleton 77 | fun providePhotoService(retrofit: Retrofit): PhotoService { 78 | return retrofit.create() 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/api/PhotoService.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.api 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModel 4 | import retrofit2.http.GET 5 | 6 | interface PhotoService { 7 | 8 | @GET("/photos") 9 | suspend fun fetchPhotos(): List 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/api/PostService.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.api 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 4 | import com.okanaydin.assignment.data.remote.datasource.model.PostModel 5 | import retrofit2.http.GET 6 | import retrofit2.http.Path 7 | 8 | interface PostService { 9 | 10 | @GET("/posts") 11 | suspend fun fetchPosts(): List 12 | 13 | @GET("/posts/{id}/comments") 14 | suspend fun fetchComments(@Path("id") id: Int): List 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/model/CommentModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | import com.squareup.moshi.Json 4 | import com.squareup.moshi.JsonClass 5 | 6 | @JsonClass(generateAdapter = true) 7 | data class CommentModel( 8 | @Json(name = "postId") 9 | val postId: Int?, 10 | @Json(name = "id") 11 | val id: Int?, 12 | @Json(name = "name") 13 | val name: String?, 14 | @Json(name = "email") 15 | val email: String?, 16 | @Json(name = "body") 17 | val body: String? 18 | ) 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/model/PhotoModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | import com.squareup.moshi.Json 4 | import com.squareup.moshi.JsonClass 5 | 6 | @JsonClass(generateAdapter = true) 7 | data class PhotoModel( 8 | @Json(name = "albumId") 9 | val albumId: Int?, 10 | @Json(name = "id") 11 | val id: Int?, 12 | @Json(name = "title") 13 | val title: String?, 14 | @Json(name = "url") 15 | val url: String?, 16 | @Json(name = "thumbnailUrl") 17 | val thumbnailUrl: String? 18 | ) 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/model/PostAndPhotoModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | import android.os.Parcelable 4 | import com.squareup.moshi.JsonClass 5 | import kotlinx.parcelize.Parcelize 6 | 7 | @Parcelize 8 | @JsonClass(generateAdapter = true) 9 | data class PostAndPhotoModel( 10 | val postItem: PostModel?, 11 | val thumbnailUrl: String?, 12 | val imageUrl: String? 13 | ) : Parcelable 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/model/PostModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | import android.os.Parcelable 4 | import com.squareup.moshi.Json 5 | import com.squareup.moshi.JsonClass 6 | import kotlinx.parcelize.Parcelize 7 | 8 | @Parcelize 9 | @JsonClass(generateAdapter = true) 10 | data class PostModel( 11 | @Json(name = "userId") 12 | val userId: Int?, 13 | @Json(name = "id") 14 | val id: Int?, 15 | @Json(name = "title") 16 | val title: String?, 17 | @Json(name = "body") 18 | val body: String? 19 | ) : Parcelable 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/photos/PhotoRemoteDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.photos 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModel 4 | 5 | interface PhotoRemoteDataSource { 6 | 7 | suspend fun getPhotos(): List 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/photos/PhotoRemoteDataSourceImp.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.photos 2 | 3 | import com.okanaydin.assignment.data.remote.api.PhotoService 4 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModel 5 | import javax.inject.Inject 6 | 7 | class PhotoRemoteDataSourceImp @Inject constructor( 8 | private val photoService: PhotoService 9 | ) : PhotoRemoteDataSource { 10 | 11 | override suspend fun getPhotos(): List = photoService.fetchPhotos() 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/posts/PostRemoteDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.posts 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 4 | import com.okanaydin.assignment.data.remote.datasource.model.PostModel 5 | 6 | interface PostRemoteDataSource { 7 | 8 | suspend fun getPosts(): List 9 | 10 | suspend fun getComments(id: Int): List 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/data/remote/datasource/posts/PostRemoteDataSourceImp.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.posts 2 | 3 | import com.okanaydin.assignment.data.remote.api.PostService 4 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 5 | import com.okanaydin.assignment.data.remote.datasource.model.PostModel 6 | import javax.inject.Inject 7 | 8 | /** 9 | * you do not have to create a new instance of PostService 10 | * use @Inject in the constructor to have only one instance 11 | */ 12 | class PostRemoteDataSourceImp @Inject constructor( 13 | private val postService: PostService 14 | ) : PostRemoteDataSource { 15 | 16 | override suspend fun getPosts(): List = postService.fetchPosts() 17 | 18 | override suspend fun getComments(id: Int): List = postService.fetchComments(id) 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.okanaydin.assignment.com.databinding.ActivityMainBinding 6 | import dagger.hilt.android.AndroidEntryPoint 7 | 8 | @AndroidEntryPoint 9 | class MainActivity : AppCompatActivity() { 10 | 11 | lateinit var binding: ActivityMainBinding 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | binding = ActivityMainBinding.inflate(layoutInflater) 16 | setContentView(binding.root) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/core/BaseFragment.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.core 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.fragment.app.Fragment 8 | import androidx.viewbinding.ViewBinding 9 | 10 | abstract class BaseFragment : Fragment() { 11 | 12 | lateinit var binding: VB 13 | 14 | override fun onCreateView( 15 | inflater: LayoutInflater, 16 | container: ViewGroup?, 17 | savedInstanceState: Bundle? 18 | ): View? { 19 | super.onCreateView(inflater, container, savedInstanceState) 20 | binding = getViewBinding() 21 | return binding.root 22 | } 23 | 24 | abstract fun getViewBinding(): VB 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/core/LayoutViewState.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.core 2 | 3 | /** 4 | * Layout View State is a class that contains status about the data for tracking on the UI. 5 | */ 6 | class LayoutViewState(private val resource: Resource<*>) { 7 | 8 | fun isLoading() = resource is Resource.Loading 9 | 10 | fun isSuccess() = resource is Resource.Success 11 | 12 | fun isFailed() = resource is Resource.Failed 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/core/Resource.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.core 2 | 3 | /** 4 | * Resource is a generic class that contains data and status about loading this data. 5 | * ref: https://developer.android.com/jetpack/guide#addendum 6 | */ 7 | 8 | sealed class Resource { 9 | class Loading : Resource() 10 | class Success(val data: T) : Resource() 11 | class Failed(val throwable: Throwable) : Resource() 12 | 13 | companion object { 14 | fun loading() = Loading() 15 | fun success(data: T) = Success(data) 16 | fun failed(throwable: Throwable) = Failed(throwable) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/repository/PostDetailRepository.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.repository 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSource 4 | import javax.inject.Inject 5 | 6 | class PostDetailRepository @Inject constructor( 7 | private val postRemoteDataSource: PostRemoteDataSource 8 | ) { 9 | suspend fun getComments(id: Int) = postRemoteDataSource.getComments(id) 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/ui/CommentsAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.ui 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.ListAdapter 6 | import androidx.recyclerview.widget.RecyclerView 7 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 8 | import com.okanaydin.assignment.com.databinding.ItemCommentBinding 9 | import javax.inject.Inject 10 | 11 | /** 12 | * ListAdapter is a convenience wrapper around AsyncListDiffer that implements 13 | * Adapter common default behavior for item access and counting. 14 | * ref: https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter 15 | */ 16 | 17 | class CommentsAdapter @Inject constructor() : 18 | ListAdapter(CommentsDiffUtil()) { 19 | 20 | override fun onCreateViewHolder( 21 | parent: ViewGroup, 22 | viewType: Int 23 | ): CommentViewHolder { 24 | val view = ItemCommentBinding.inflate(LayoutInflater.from(parent.context), parent, false) 25 | return CommentViewHolder(view) 26 | } 27 | 28 | override fun onBindViewHolder(holder: CommentViewHolder, position: Int) { 29 | holder.bind(getItem(position)) 30 | } 31 | 32 | inner class CommentViewHolder(private val binding: ItemCommentBinding) : 33 | RecyclerView.ViewHolder(binding.root) { 34 | 35 | fun bind(comment: CommentModel) { 36 | with(binding) { 37 | textViewCommentTitle.text = comment.name 38 | textViewCommentDescription.text = comment.body 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/ui/CommentsDiffUtil.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.ui 2 | 3 | import androidx.recyclerview.widget.DiffUtil 4 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 5 | 6 | /** 7 | * DiffUtil is a utility class that calculates the difference between two lists 8 | * and outputs a list of update operations that converts the first list into the second one. 9 | * ref: https://developer.android.com/reference/androidx/recyclerview/widget/DiffUtil 10 | */ 11 | class CommentsDiffUtil : DiffUtil.ItemCallback() { 12 | override fun areItemsTheSame(oldItem: CommentModel, newItem: CommentModel): Boolean { 13 | return oldItem == newItem 14 | } 15 | 16 | override fun areContentsTheSame(oldItem: CommentModel, newItem: CommentModel): Boolean { 17 | return oldItem == newItem 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/ui/PostDetailFragment.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.ui 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.core.view.isVisible 6 | import androidx.fragment.app.viewModels 7 | import androidx.navigation.fragment.navArgs 8 | import coil.load 9 | import com.okanaydin.assignment.com.databinding.FragmentPostDetailBinding 10 | import com.okanaydin.assignment.features.core.BaseFragment 11 | import dagger.hilt.android.AndroidEntryPoint 12 | import javax.inject.Inject 13 | 14 | @AndroidEntryPoint 15 | class PostDetailFragment : BaseFragment() { 16 | 17 | @Inject 18 | lateinit var commentAdapter: CommentsAdapter 19 | private val postDetailViewModel: PostDetailViewModel by viewModels() 20 | private val postArg by navArgs() 21 | private lateinit var viewState: PostDetailViewState 22 | 23 | override fun getViewBinding(): FragmentPostDetailBinding = 24 | FragmentPostDetailBinding.inflate(layoutInflater) 25 | 26 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 27 | super.onViewCreated(view, savedInstanceState) 28 | setUpUi() 29 | observeCommentList() 30 | } 31 | 32 | private fun setUpUi() { 33 | viewState = PostDetailViewState(postArg.post) 34 | observeLayoutViewState() 35 | with(binding) { 36 | toolbar.title = viewState.getPostTitle() 37 | imageViewBanner.load(viewState.getImageUrl()) 38 | recyclerViewComments.adapter = commentAdapter 39 | contentFailed.buttonTryAgain.setOnClickListener { 40 | postDetailViewModel.getCommentList(viewState.getPostId()) 41 | } 42 | } 43 | } 44 | 45 | private fun observeLayoutViewState() { 46 | postDetailViewModel.layoutViewState.observe(viewLifecycleOwner) { state -> 47 | with(binding) { 48 | contentLoading.progressBar.isVisible = state.isLoading() 49 | recyclerViewComments.isVisible = state.isSuccess() 50 | contentFailed.layout.isVisible = state.isFailed() 51 | } 52 | } 53 | } 54 | 55 | private fun observeCommentList() { 56 | postDetailViewModel.getCommentList(viewState.getPostId()) 57 | postDetailViewModel.commentList.observe(viewLifecycleOwner) { commentList -> 58 | commentAdapter.submitList(commentList) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/ui/PostDetailViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.ui 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 8 | import com.okanaydin.assignment.features.core.LayoutViewState 9 | import com.okanaydin.assignment.features.core.Resource 10 | import com.okanaydin.assignment.features.details.usecase.PostDetailUseCase 11 | import dagger.hilt.android.lifecycle.HiltViewModel 12 | import kotlinx.coroutines.flow.collect 13 | import kotlinx.coroutines.launch 14 | import javax.inject.Inject 15 | 16 | @HiltViewModel 17 | class PostDetailViewModel @Inject constructor( 18 | private val postDetailUseCase: PostDetailUseCase 19 | ) : ViewModel() { 20 | 21 | private val _commentList = MutableLiveData>() 22 | val commentList: LiveData> = _commentList 23 | 24 | private val _layoutViewState = MutableLiveData() 25 | val layoutViewState: LiveData = _layoutViewState 26 | 27 | fun getCommentList(id: Int) { 28 | viewModelScope.launch { 29 | postDetailUseCase.getComments(id).collect { state -> 30 | _layoutViewState.value = LayoutViewState(state) 31 | if (state is Resource.Success) { 32 | _commentList.value = state.data 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/ui/PostDetailViewState.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.ui 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 4 | import java.util.Locale 5 | 6 | data class PostDetailViewState(private var postDetail: PostAndPhotoModel) { 7 | 8 | fun getImageUrl() = postDetail.imageUrl ?: "" 9 | 10 | fun getPostId() = postDetail.postItem?.id ?: 0 11 | 12 | fun getPostTitle() = postDetail.postItem?.title?.capitalize(Locale.ROOT) ?: "Unknown post" 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/details/usecase/PostDetailUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details.usecase 2 | 3 | import com.okanaydin.assignment.features.core.Resource 4 | import com.okanaydin.assignment.features.details.repository.PostDetailRepository 5 | import kotlinx.coroutines.Dispatchers 6 | import kotlinx.coroutines.flow.catch 7 | import kotlinx.coroutines.flow.flow 8 | import kotlinx.coroutines.flow.flowOn 9 | import javax.inject.Inject 10 | 11 | class PostDetailUseCase @Inject constructor( 12 | private val postDetailRepository: PostDetailRepository 13 | ) { 14 | fun getComments(id: Int) = flow { 15 | emit(Resource.loading()) 16 | emit(Resource.success(getComment(id))) 17 | }.catch { exception -> 18 | emit(Resource.failed(exception)) 19 | }.flowOn(Dispatchers.IO) 20 | 21 | private suspend fun getComment(id: Int) = postDetailRepository.getComments(id) 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/di/PostModule.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.di 2 | 3 | import com.okanaydin.assignment.data.remote.api.PhotoService 4 | import com.okanaydin.assignment.data.remote.api.PostService 5 | import com.okanaydin.assignment.data.remote.datasource.photos.PhotoRemoteDataSource 6 | import com.okanaydin.assignment.data.remote.datasource.photos.PhotoRemoteDataSourceImp 7 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSource 8 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSourceImp 9 | import dagger.Module 10 | import dagger.Provides 11 | import dagger.hilt.InstallIn 12 | import dagger.hilt.components.SingletonComponent 13 | import javax.inject.Singleton 14 | 15 | /** 16 | * A Hilt module is a class that is annotated with @Module. Like a Dagger module, it informs Hilt how to provide instances of certain types. 17 | * Unlike Dagger modules, you must annotate Hilt modules with @InstallIn to tell Hilt which Android class each module will be used or installed in. 18 | * ref: https://developer.android.com/training/dependency-injection/hilt-android#hilt-modules 19 | */ 20 | 21 | @Module 22 | @InstallIn(SingletonComponent::class) 23 | object PostModule { 24 | 25 | /** 26 | * @Provides annotation would be accessed across the application. 27 | * @Singleton annotation helps the instance to be created and used once across the application. 28 | */ 29 | @Provides 30 | @Singleton 31 | fun providePostDataSource(postService: PostService): PostRemoteDataSource { 32 | return PostRemoteDataSourceImp(postService) 33 | } 34 | 35 | @Provides 36 | @Singleton 37 | fun providePhotoDataSource(photoService: PhotoService): PhotoRemoteDataSource { 38 | return PhotoRemoteDataSourceImp(photoService) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/repository/PostRepository.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.repository 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.photos.PhotoRemoteDataSource 4 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSource 5 | import javax.inject.Inject 6 | 7 | /** 8 | * Repository modules handle data operations. They provide a clean API so that the rest of the app can retrieve this data easily. 9 | * They know where to get the data from and what API calls to make when data is updated. 10 | * You can consider repositories to be mediators between different data sources, such as persistent models, web services, and caches. 11 | * ref: https://developer.android.com/jetpack/guide#fetch-data 12 | */ 13 | class PostRepository @Inject constructor( 14 | private val postRemoteDataSource: PostRemoteDataSource, 15 | private val photoRemoteDataSource: PhotoRemoteDataSource 16 | ) { 17 | 18 | suspend fun getPosts() = postRemoteDataSource.getPosts() 19 | 20 | suspend fun getPhotos() = photoRemoteDataSource.getPhotos() 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/ui/PostAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.ui 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.ListAdapter 6 | import androidx.recyclerview.widget.RecyclerView 7 | import coil.load 8 | import com.okanaydin.assignment.com.databinding.ItemPostBinding 9 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 10 | import javax.inject.Inject 11 | 12 | /** 13 | * ListAdapter is a convenience wrapper around AsyncListDiffer that implements 14 | * Adapter common default behavior for item access and counting. 15 | * ref: https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter 16 | */ 17 | class PostAdapter @Inject constructor() : 18 | ListAdapter(PostListDiffUtil()) { 19 | 20 | private lateinit var viewState: PostViewState 21 | 22 | var postItemClickListener: ((postItem: PostAndPhotoModel) -> Unit)? = null 23 | 24 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostViewHolder { 25 | val view = ItemPostBinding.inflate(LayoutInflater.from(parent.context), parent, false) 26 | return PostViewHolder(view, postItemClickListener) 27 | } 28 | 29 | override fun onBindViewHolder(holder: PostViewHolder, position: Int) { 30 | holder.bind(getItem(position)) 31 | } 32 | 33 | inner class PostViewHolder( 34 | private val binding: ItemPostBinding, 35 | private val postItemClickListener: ((postItem: PostAndPhotoModel) -> Unit)? 36 | ) : RecyclerView.ViewHolder(binding.root) { 37 | 38 | fun bind(post: PostAndPhotoModel) { 39 | viewState = PostViewState(post) 40 | with(binding) { 41 | root.setOnClickListener { postItemClickListener?.invoke(post) } 42 | textViewPostTitle.text = viewState.getPostTitle() 43 | textViewPostBody.text = viewState.getPostBody() 44 | imageViewPostItem.load(viewState.getImageUrl()) 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/ui/PostListDiffUtil.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.ui 2 | 3 | import androidx.recyclerview.widget.DiffUtil 4 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 5 | 6 | /** 7 | * DiffUtil is a utility class that calculates the difference between two lists 8 | * and outputs a list of update operations that converts the first list into the second one. 9 | * ref: https://developer.android.com/reference/androidx/recyclerview/widget/DiffUtil 10 | */ 11 | class PostListDiffUtil : DiffUtil.ItemCallback() { 12 | 13 | override fun areItemsTheSame( 14 | oldItem: PostAndPhotoModel, 15 | newItem: PostAndPhotoModel 16 | ): Boolean { 17 | return oldItem == newItem 18 | } 19 | 20 | override fun areContentsTheSame( 21 | oldItem: PostAndPhotoModel, 22 | newItem: PostAndPhotoModel 23 | ): Boolean { 24 | return oldItem == newItem 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/ui/PostListFragment.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.ui 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.core.view.isVisible 6 | import androidx.fragment.app.viewModels 7 | import androidx.navigation.fragment.findNavController 8 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout 9 | import com.okanaydin.assignment.com.R 10 | import com.okanaydin.assignment.com.databinding.FragmentPostListBinding 11 | import com.okanaydin.assignment.features.core.BaseFragment 12 | import dagger.hilt.android.AndroidEntryPoint 13 | import javax.inject.Inject 14 | 15 | /** 16 | * A fragment that is annotated with @AndroidEntryPoint can get the ViewModel instance as normal using ViewModelProvider or the by viewModels() using KTX 17 | * ref: https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels 18 | */ 19 | @AndroidEntryPoint 20 | class PostListFragment : BaseFragment() { 21 | 22 | @Inject 23 | lateinit var postAdapter: PostAdapter 24 | 25 | private val postViewModel: PostViewModel by viewModels() 26 | 27 | override fun getViewBinding(): FragmentPostListBinding = 28 | FragmentPostListBinding.inflate(layoutInflater) 29 | 30 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 31 | super.onViewCreated(view, savedInstanceState) 32 | setUpUi() 33 | setUpViewModel() 34 | } 35 | 36 | private fun setUpUi() { 37 | with(binding) { 38 | observeLayoutViewState() 39 | 40 | toolbar.title = getString(R.string.app_name) 41 | 42 | swipeRefreshLayout.setOnRefreshListener(onRefreshListener()) 43 | 44 | contentFailed.buttonTryAgain.setOnClickListener { 45 | postViewModel.getPostList() 46 | } 47 | 48 | binding.recyclerViewPostList.adapter = postAdapter 49 | postAdapter.postItemClickListener = { postItem -> 50 | val direction = PostListFragmentDirections 51 | .actionPostListFragmentToPostDetailFragment(postItem) 52 | findNavController().navigate(direction) 53 | } 54 | } 55 | } 56 | 57 | private fun observeLayoutViewState() { 58 | postViewModel.layoutViewState.observe(viewLifecycleOwner) { state -> 59 | with(binding) { 60 | contentLoading.progressBar.isVisible = state.isLoading() 61 | recyclerViewPostList.isVisible = state.isSuccess() 62 | contentFailed.layout.isVisible = state.isFailed() 63 | } 64 | } 65 | } 66 | 67 | private fun setUpViewModel() { 68 | postViewModel.postList.observe(viewLifecycleOwner) { postAndPhotoList -> 69 | postAdapter.submitList(postAndPhotoList) 70 | } 71 | postViewModel.getPostList() 72 | } 73 | 74 | private fun onRefreshListener(): SwipeRefreshLayout.OnRefreshListener { 75 | return SwipeRefreshLayout.OnRefreshListener { 76 | postViewModel.getPostList() 77 | binding.swipeRefreshLayout.isRefreshing = false 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/ui/PostViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.ui 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 8 | import com.okanaydin.assignment.features.core.LayoutViewState 9 | import com.okanaydin.assignment.features.core.Resource 10 | import com.okanaydin.assignment.features.posts.usecase.PostListUseCase 11 | import dagger.hilt.android.lifecycle.HiltViewModel 12 | import kotlinx.coroutines.flow.collect 13 | import kotlinx.coroutines.launch 14 | import javax.inject.Inject 15 | 16 | /** 17 | * A ViewModel object provides the data for a specific UI component, such as a fragment or activity, and contains data-handling business logic to communicate with the model. 18 | * Provide a ViewModel by annotating it with @HiltViewModel and using the @Inject annotation in the ViewModel object's constructor. 19 | * ref: https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels 20 | */ 21 | @HiltViewModel 22 | class PostViewModel @Inject constructor( 23 | private val postListUseCase: PostListUseCase 24 | ) : ViewModel() { 25 | 26 | private val _postList = MutableLiveData>() 27 | val postList: LiveData> = _postList 28 | 29 | private val _layoutViewState = MutableLiveData() 30 | val layoutViewState: LiveData = _layoutViewState 31 | 32 | fun getPostList() { 33 | viewModelScope.launch { 34 | // Coroutine that will be canceled when the ViewModel is cleared. 35 | postListUseCase.getCombinedPostsAndPhotos().collect { state -> 36 | _layoutViewState.value = LayoutViewState(state) 37 | if (state is Resource.Success) { 38 | _postList.value = state.data 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/ui/PostViewState.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.ui 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 4 | import java.util.Locale 5 | 6 | data class PostViewState(var postDetail: PostAndPhotoModel) { 7 | 8 | fun getImageUrl() = postDetail.thumbnailUrl ?: "" 9 | 10 | fun getPostTitle() = 11 | postDetail.postItem?.title?.capitalize(Locale.ROOT) ?: "Unknown post title" 12 | 13 | fun getPostBody() = postDetail.postItem?.body?.capitalize(Locale.ROOT) ?: "Unknown post body" 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/posts/usecase/PostListUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts.usecase 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModel 4 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 5 | import com.okanaydin.assignment.data.remote.datasource.model.PostModel 6 | import com.okanaydin.assignment.features.core.Resource 7 | import com.okanaydin.assignment.features.posts.repository.PostRepository 8 | import kotlinx.coroutines.Dispatchers 9 | import kotlinx.coroutines.async 10 | import kotlinx.coroutines.coroutineScope 11 | import kotlinx.coroutines.flow.catch 12 | import kotlinx.coroutines.flow.flow 13 | import kotlinx.coroutines.flow.flowOn 14 | import javax.inject.Inject 15 | 16 | class PostListUseCase @Inject constructor( 17 | private val postRepository: PostRepository 18 | ) { 19 | /** 20 | * In coroutines, a flow is a type that can emit multiple values sequentially, as opposed to suspend functions that return only a single value. 21 | * ref: https://developer.android.com/kotlin/flow 22 | */ 23 | fun getCombinedPostsAndPhotos() = flow { 24 | emit(Resource.loading()) 25 | emit(Resource.success(getPostsAndPhotos())) 26 | }.catch { exception -> 27 | emit(Resource.failed(exception)) 28 | }.flowOn(Dispatchers.IO) 29 | 30 | /** 31 | * In parallel, fetch posts and photos and return when both requests 32 | * ref: https://developer.android.com/kotlin/coroutines/coroutines-best-practices#create-coroutines-data-layer 33 | */ 34 | private suspend fun getPostsAndPhotos() = coroutineScope { 35 | 36 | val deferredPhotos = async { postRepository.getPhotos() } 37 | val deferredPosts = async { postRepository.getPosts() } 38 | val photos = try { 39 | deferredPhotos.await() 40 | } catch (e: Exception) { 41 | listOf() 42 | } 43 | 44 | val post = try { 45 | deferredPosts.await() 46 | } catch (e: Exception) { 47 | listOf() 48 | } 49 | combinePostsAndPhotos(post, photos) 50 | } 51 | 52 | private fun combinePostsAndPhotos( 53 | postList: List, 54 | photoList: List 55 | ): List { 56 | var selectedPhoto: PhotoModel? 57 | return postList.map { postResponse -> 58 | selectedPhoto = if (photoList.isEmpty()) { 59 | null 60 | } else { 61 | photoList.random() 62 | } 63 | PostAndPhotoModel( 64 | postItem = postResponse, 65 | thumbnailUrl = selectedPhoto?.thumbnailUrl, 66 | imageUrl = selectedPhoto?.url 67 | ) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/okanaydin/assignment/features/splash/SplashFragment.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.splash 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.view.animation.Animation 6 | import android.view.animation.AnimationUtils 7 | import androidx.navigation.fragment.findNavController 8 | import com.okanaydin.assignment.com.R 9 | import com.okanaydin.assignment.com.databinding.FragmentSplashBinding 10 | import com.okanaydin.assignment.features.core.BaseFragment 11 | import dagger.hilt.android.AndroidEntryPoint 12 | 13 | @AndroidEntryPoint 14 | class SplashFragment : BaseFragment() { 15 | 16 | override fun getViewBinding(): FragmentSplashBinding = 17 | FragmentSplashBinding.inflate(layoutInflater) 18 | 19 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 20 | super.onViewCreated(view, savedInstanceState) 21 | startViewAnimation() 22 | } 23 | 24 | private fun startViewAnimation() { 25 | 26 | val slideAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in) 27 | binding.imageViewAppIcon.startAnimation(slideAnimation) 28 | 29 | slideAnimation.setAnimationListener(object : Animation.AnimationListener { 30 | override fun onAnimationStart(animation: Animation?) = Unit 31 | 32 | override fun onAnimationEnd(animation: Animation?) { 33 | navigateToPostListFragment() 34 | } 35 | 36 | override fun onAnimationRepeat(animation: Animation?) = Unit 37 | }) 38 | } 39 | 40 | private fun navigateToPostListFragment() { 41 | findNavController().navigate(com.okanaydin.assignment.features.splash.SplashFragmentDirections.actionSplashFragmentToPostListFragment()) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/drawable-mdpi/app_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/art_whoops.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/drawable-mdpi/art_whoops.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_discuss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/drawable/ic_discuss.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/font/proxima_nova_soft_bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/font/proxima_nova_soft_bold.otf -------------------------------------------------------------------------------- /app/src/main/res/font/proxima_nova_soft_regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/font/proxima_nova_soft_regular.ttf -------------------------------------------------------------------------------- /app/src/main/res/font/proxima_nova_soft_semibold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/font/proxima_nova_soft_semibold.otf -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_failed.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 21 | 22 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_post_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 25 | 26 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 55 | 56 | 63 | 64 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | 86 | 87 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_post_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 42 | 43 | 53 | 54 | 55 | 58 | 59 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_comment.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_post.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 22 | 23 | 33 | 34 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 19 | 20 | 21 | 26 | 29 | 30 | 31 | 36 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF451B 4 | #56001E 5 | #FF4081 6 | #090b15 7 | #989898 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 180dp 3 | 16dp 4 | 16dp 5 | 256dp 6 | 16dp 7 | 4dp 8 | 12dp 9 | 12dp 10 | 24dp 11 | 24dp 12 | 16sp 13 | 32sp 14 | 12sp 15 | 8dp 16 | 16dp 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/ic_app_logo_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Post List 3 | Details 4 | Comments 5 | Whoops! 6 | Try Again! 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 14 | 15 | 26 | 27 | 32 | 33 | 38 | 39 | 48 | 49 | 60 | 61 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/model/CommentModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | object CommentModelFactory { 4 | 5 | fun getComment() = CommentModel(1001, 1001, "name", "email", "body") 6 | } 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/model/PhotoModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | object PhotoModelFactory { 4 | 5 | fun getPhoto() = PhotoModel(1000, 1001, "title", "imageUrl", "thumbnailUrl") 6 | } 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/model/PostAndPhotoModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PostModelFactory.getPost 4 | 5 | object PostAndPhotoModelFactory { 6 | 7 | fun getPostAndPhoto() = 8 | PostAndPhotoModel( 9 | postItem = getPost(), 10 | thumbnailUrl = "thumbnailUrl", 11 | imageUrl = "imageUrl" 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/model/PostModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.model 2 | 3 | object PostModelFactory { 4 | 5 | fun getPost() = PostModel(1000, 1001, "title", "body") 6 | } 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/photo/PhotoRemoteDataSourceImpTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.photo 2 | 3 | import com.okanaydin.assignment.data.remote.api.PhotoService 4 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModelFactory.getPhoto 5 | import com.okanaydin.assignment.data.remote.datasource.photos.PhotoRemoteDataSourceImp 6 | import com.okanaydin.assignment.util.MainCoroutineRule 7 | import io.mockk.MockKAnnotations 8 | import io.mockk.coEvery 9 | import io.mockk.coVerify 10 | import io.mockk.impl.annotations.MockK 11 | import kotlinx.coroutines.ExperimentalCoroutinesApi 12 | import kotlinx.coroutines.runBlocking 13 | import org.junit.Assert.assertEquals 14 | import org.junit.Before 15 | import org.junit.Rule 16 | import org.junit.Test 17 | 18 | @ExperimentalCoroutinesApi 19 | class PhotoRemoteDataSourceImpTest { 20 | 21 | @get:Rule 22 | var mainCoroutineRule = MainCoroutineRule() 23 | 24 | @MockK 25 | lateinit var photoService: PhotoService 26 | 27 | private lateinit var photoRemoteDataSourceImp: PhotoRemoteDataSourceImp 28 | 29 | @Before 30 | fun setUp() { 31 | MockKAnnotations.init(this) 32 | photoRemoteDataSourceImp = PhotoRemoteDataSourceImp(photoService) 33 | } 34 | 35 | @Test 36 | fun `check getPhotos()`() = runBlocking { 37 | // given 38 | coEvery { photoService.fetchPhotos() } returns listOf(getPhoto()) 39 | 40 | // when 41 | val result = photoRemoteDataSourceImp.getPhotos() 42 | 43 | // then 44 | coVerify { photoService.fetchPhotos() } 45 | assertEquals(result, listOf(getPhoto())) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/data/remote/datasource/post/PostRemoteDataSourceImpTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.data.remote.datasource.post 2 | 3 | import com.okanaydin.assignment.data.remote.api.PostService 4 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModelFactory.getComment 5 | import com.okanaydin.assignment.data.remote.datasource.model.PostModelFactory.getPost 6 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSourceImp 7 | import com.okanaydin.assignment.util.MainCoroutineRule 8 | import io.mockk.MockKAnnotations 9 | import io.mockk.coEvery 10 | import io.mockk.coVerify 11 | import io.mockk.impl.annotations.MockK 12 | import kotlinx.coroutines.ExperimentalCoroutinesApi 13 | import kotlinx.coroutines.runBlocking 14 | import org.junit.Assert.assertEquals 15 | import org.junit.Before 16 | import org.junit.Rule 17 | import org.junit.Test 18 | 19 | @ExperimentalCoroutinesApi 20 | class PostRemoteDataSourceImpTest { 21 | 22 | @get:Rule 23 | var mainCoroutineRule = MainCoroutineRule() 24 | 25 | @MockK 26 | lateinit var postService: PostService 27 | 28 | private lateinit var postRemoteDataSourceImp: PostRemoteDataSourceImp 29 | 30 | @Before 31 | fun setUp() { 32 | MockKAnnotations.init(this) 33 | postRemoteDataSourceImp = PostRemoteDataSourceImp(postService) 34 | } 35 | 36 | @Test 37 | fun `check getPosts`() = runBlocking { 38 | // given 39 | coEvery { postService.fetchPosts() } returns listOf(getPost()) 40 | 41 | // when 42 | val postResult = postRemoteDataSourceImp.getPosts() 43 | 44 | // then 45 | coVerify { postService.fetchPosts() } 46 | assertEquals(postResult, listOf(getPost())) 47 | } 48 | 49 | @Test 50 | fun `check getComment`() = runBlocking { 51 | // given 52 | val id = 1 53 | coEvery { postService.fetchComments(id) } returns listOf(getComment()) 54 | 55 | // when 56 | val commentResult = postRemoteDataSourceImp.getComments(id) 57 | 58 | // then 59 | coVerify { postService.fetchComments(id) } 60 | assertEquals(commentResult, listOf(getComment())) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/core/LayoutViewStateTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.core 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import org.junit.jupiter.params.ParameterizedTest 5 | import org.junit.jupiter.params.provider.Arguments 6 | import org.junit.jupiter.params.provider.MethodSource 7 | import java.util.stream.Stream 8 | 9 | class LayoutViewStateTest { 10 | 11 | private lateinit var layoutViewState: LayoutViewState 12 | 13 | @ParameterizedTest(name = "when state is {0}, then isLoading returns {1}") 14 | @MethodSource("isLoadingProvider") 15 | fun `check isLoading`(resource: Resource<*>, expected: Boolean) { 16 | // given 17 | layoutViewState = LayoutViewState(resource) 18 | 19 | // when 20 | val result = layoutViewState.isLoading() 21 | 22 | // then 23 | assertThat(result).isEqualTo(expected) 24 | } 25 | 26 | @ParameterizedTest 27 | @MethodSource("isSuccessProvider") 28 | fun `check isSuccess`(resource: Resource<*>, expected: Boolean) { 29 | // given 30 | layoutViewState = LayoutViewState(resource) 31 | 32 | // when 33 | val result = layoutViewState.isSuccess() 34 | 35 | // then 36 | assertThat(result).isEqualTo(expected) 37 | } 38 | 39 | @ParameterizedTest 40 | @MethodSource("isFailedProvider") 41 | fun `check isFailed`(resource: Resource<*>, expected: Boolean) { 42 | // given 43 | layoutViewState = LayoutViewState(resource) 44 | 45 | // when 46 | val result = layoutViewState.isFailed() 47 | 48 | // then 49 | assertThat(result).isEqualTo(expected) 50 | } 51 | 52 | companion object { 53 | @JvmStatic 54 | fun isLoadingProvider(): Stream { 55 | return Stream.of( 56 | Arguments.of(Resource.Loading(), true), 57 | Arguments.of(Resource.Success(Any()), false), 58 | Arguments.of(Resource.Failed(Throwable()), false) 59 | ) 60 | } 61 | 62 | @JvmStatic 63 | fun isSuccessProvider(): Stream { 64 | return Stream.of( 65 | Arguments.of(Resource.Loading(), false), 66 | Arguments.of(Resource.Success(Any()), true), 67 | Arguments.of(Resource.Failed(Throwable()), false) 68 | ) 69 | } 70 | 71 | @JvmStatic 72 | fun isFailedProvider(): Stream { 73 | return Stream.of( 74 | Arguments.of(Resource.Loading(), false), 75 | Arguments.of(Resource.Success(Any()), false), 76 | Arguments.of(Resource.Failed(Throwable()), true) 77 | ) 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/details/PostDetailRepositoryTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModelFactory.getComment 4 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSource 5 | import com.okanaydin.assignment.features.details.repository.PostDetailRepository 6 | import com.okanaydin.assignment.util.MainCoroutineRule 7 | import io.mockk.MockKAnnotations 8 | import io.mockk.coEvery 9 | import io.mockk.coVerify 10 | import io.mockk.impl.annotations.MockK 11 | import junit.framework.Assert.assertEquals 12 | import kotlinx.coroutines.ExperimentalCoroutinesApi 13 | import kotlinx.coroutines.runBlocking 14 | import org.junit.Before 15 | import org.junit.Rule 16 | import org.junit.Test 17 | 18 | @ExperimentalCoroutinesApi 19 | class PostDetailRepositoryTest { 20 | 21 | @get:Rule 22 | var mainCoroutineRule = MainCoroutineRule() 23 | 24 | @MockK 25 | lateinit var postRemoteDataSource: PostRemoteDataSource 26 | 27 | private lateinit var postDetailRepository: PostDetailRepository 28 | 29 | @Before 30 | fun setUp() { 31 | MockKAnnotations.init(this) 32 | postDetailRepository = PostDetailRepository(postRemoteDataSource) 33 | } 34 | 35 | @Test 36 | fun `check getComments`() = runBlocking { 37 | // given 38 | val id = 1 39 | coEvery { postRemoteDataSource.getComments(id) } returns listOf(getComment()) 40 | 41 | // when 42 | val result = postDetailRepository.getComments(id) 43 | 44 | // then 45 | coVerify { postRemoteDataSource.getComments(id) } 46 | assertEquals(result, listOf(getComment())) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/details/PostDetailUseCaseTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModelFactory.getComment 5 | import com.okanaydin.assignment.features.core.Resource 6 | import com.okanaydin.assignment.features.details.repository.PostDetailRepository 7 | import com.okanaydin.assignment.features.details.usecase.PostDetailUseCase 8 | import com.okanaydin.assignment.util.MainCoroutineRule 9 | import com.okanaydin.assignment.util.second 10 | import io.mockk.MockKAnnotations 11 | import io.mockk.coEvery 12 | import io.mockk.coVerify 13 | import io.mockk.impl.annotations.MockK 14 | import io.mockk.mockk 15 | import kotlinx.coroutines.ExperimentalCoroutinesApi 16 | import kotlinx.coroutines.flow.first 17 | import kotlinx.coroutines.flow.toList 18 | import kotlinx.coroutines.runBlocking 19 | import org.junit.Before 20 | import org.junit.Rule 21 | import org.junit.Test 22 | 23 | @ExperimentalCoroutinesApi 24 | class PostDetailUseCaseTest { 25 | 26 | @get:Rule 27 | var mainCoroutineRule = MainCoroutineRule() 28 | 29 | @MockK 30 | lateinit var postDetailRepository: PostDetailRepository 31 | 32 | private lateinit var postDetailUseCase: PostDetailUseCase 33 | 34 | @Before 35 | fun setUp() { 36 | MockKAnnotations.init(this) 37 | postDetailUseCase = PostDetailUseCase(postDetailRepository) 38 | } 39 | 40 | @Test 41 | fun `when state is loading, then getComments returns loading`() = runBlocking { 42 | // given 43 | val id = 1 44 | coEvery { postDetailRepository.getComments(id) } 45 | 46 | // when 47 | val flow = postDetailUseCase.getComments(id).first() 48 | 49 | // then 50 | assertThat(flow).isInstanceOf(Resource.Loading::class.java) 51 | } 52 | 53 | @Test 54 | fun `when state is success, then getComments returns comments of the post`() = 55 | runBlocking { 56 | // given 57 | val id = 1 58 | coEvery { postDetailRepository.getComments(id) } returns listOf(getComment()) 59 | 60 | // when 61 | val result = postDetailUseCase.getComments(id).toList() 62 | 63 | // then 64 | coVerify { postDetailRepository.getComments(id) } 65 | 66 | assertThat(result).hasSize(2) 67 | assertThat(result.first()).isInstanceOf(Resource.Loading::class.java) 68 | assertThat((result.second() as Resource.Success<*>).data).isEqualTo(listOf(getComment())) 69 | } 70 | 71 | @Test 72 | fun `when state is failed, then getComments returns error`() = 73 | runBlocking { 74 | // given 75 | val id = 1 76 | val throwable = mockk() 77 | coEvery { postDetailRepository.getComments(id) } throws throwable 78 | 79 | // when 80 | val result = postDetailUseCase.getComments(id).toList() 81 | 82 | // then 83 | assertThat(result).hasSize(2) 84 | assertThat(result.first()).isInstanceOf(Resource.Loading::class.java) 85 | assertThat((result.second() as Resource.Failed<*>).throwable).isEqualTo(throwable) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/details/PostDetailViewModelTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.details 2 | 3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule 4 | import androidx.lifecycle.Observer 5 | import com.google.common.truth.Truth.assertThat 6 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModel 7 | import com.okanaydin.assignment.data.remote.datasource.model.CommentModelFactory.getComment 8 | import com.okanaydin.assignment.features.core.LayoutViewState 9 | import com.okanaydin.assignment.features.core.Resource 10 | import com.okanaydin.assignment.features.details.ui.PostDetailViewModel 11 | import com.okanaydin.assignment.features.details.usecase.PostDetailUseCase 12 | import com.okanaydin.assignment.util.MainCoroutineRule 13 | import com.okanaydin.assignment.util.second 14 | import io.mockk.MockKAnnotations 15 | import io.mockk.coEvery 16 | import io.mockk.coVerify 17 | import io.mockk.every 18 | import io.mockk.impl.annotations.MockK 19 | import io.mockk.mockk 20 | import io.mockk.slot 21 | import kotlinx.coroutines.ExperimentalCoroutinesApi 22 | import kotlinx.coroutines.flow.flow 23 | import kotlinx.coroutines.test.runBlockingTest 24 | import org.junit.Before 25 | import org.junit.Rule 26 | import org.junit.Test 27 | 28 | @ExperimentalCoroutinesApi 29 | class PostDetailViewModelTest { 30 | 31 | @get:Rule 32 | var mainCoroutineRule = MainCoroutineRule() 33 | 34 | @get:Rule 35 | var instantTaskExecutorRule = InstantTaskExecutorRule() 36 | 37 | @MockK 38 | private lateinit var postDetailUseCase: PostDetailUseCase 39 | 40 | @MockK 41 | private lateinit var layoutViewStateObserver: Observer 42 | 43 | @MockK 44 | private lateinit var commentListStateObserver: Observer> 45 | 46 | private lateinit var postDetailViewModel: PostDetailViewModel 47 | 48 | private val layoutViewStateValues = arrayListOf() 49 | private val commentListValues = arrayListOf>() 50 | 51 | private val layoutViewStateSlot = slot() 52 | private val commentListSlot = slot>() 53 | 54 | @Before 55 | fun setUp() { 56 | MockKAnnotations.init(this) 57 | postDetailViewModel = PostDetailViewModel(postDetailUseCase) 58 | } 59 | 60 | @Test 61 | fun `check getCommentList success`() = runBlockingTest { 62 | // given 63 | postDetailViewModel.layoutViewState.observeForever(layoutViewStateObserver) 64 | postDetailViewModel.commentList.observeForever(commentListStateObserver) 65 | 66 | every { layoutViewStateObserver.onChanged(capture(layoutViewStateSlot)) } answers { 67 | layoutViewStateValues.add( 68 | layoutViewStateSlot.captured 69 | ) 70 | } 71 | 72 | every { commentListStateObserver.onChanged(capture(commentListSlot)) } answers { 73 | commentListValues.add( 74 | commentListSlot.captured 75 | ) 76 | } 77 | 78 | coEvery { postDetailUseCase.getComments(1) } returns flow { 79 | emit(Resource.loading()) 80 | emit(Resource.success(listOf(getComment()))) 81 | } 82 | 83 | // when 84 | postDetailViewModel.getCommentList(1) 85 | 86 | // then 87 | coVerify(exactly = 1) { postDetailUseCase.getComments(1) } 88 | assertThat(layoutViewStateValues).hasSize(2) 89 | assertThat(layoutViewStateValues.first().isLoading()).isTrue() 90 | assertThat(layoutViewStateValues.second().isSuccess()).isTrue() 91 | assertThat(commentListValues).hasSize(1) 92 | assertThat(commentListValues.first()).isEqualTo(listOf(getComment())) 93 | } 94 | 95 | @Test 96 | fun `check getCommentList fail`() = runBlockingTest { 97 | // given 98 | val throwable = mockk() 99 | postDetailViewModel.layoutViewState.observeForever(layoutViewStateObserver) 100 | postDetailViewModel.commentList.observeForever(commentListStateObserver) 101 | 102 | every { layoutViewStateObserver.onChanged(capture(layoutViewStateSlot)) } answers { 103 | layoutViewStateValues.add( 104 | layoutViewStateSlot.captured 105 | ) 106 | } 107 | 108 | every { commentListStateObserver.onChanged(capture(commentListSlot)) } answers { 109 | commentListValues.add( 110 | commentListSlot.captured 111 | ) 112 | } 113 | 114 | coEvery { postDetailUseCase.getComments(1) } returns flow>> { 115 | emit(Resource.loading()) 116 | emit(Resource.failed(throwable)) 117 | } 118 | 119 | // when 120 | postDetailViewModel.getCommentList(1) 121 | 122 | // then 123 | coVerify(exactly = 1) { postDetailUseCase.getComments(1) } 124 | assertThat(layoutViewStateValues).hasSize(2) 125 | assertThat(layoutViewStateValues.first().isLoading()).isTrue() 126 | assertThat(layoutViewStateValues.second().isFailed()).isTrue() 127 | assertThat(commentListValues).hasSize(0) 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/posts/PostListUseCaseTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModelFactory.getPhoto 5 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModelFactory.getPostAndPhoto 6 | import com.okanaydin.assignment.data.remote.datasource.model.PostModelFactory.getPost 7 | import com.okanaydin.assignment.features.core.Resource 8 | import com.okanaydin.assignment.features.core.Resource.Success 9 | import com.okanaydin.assignment.features.posts.repository.PostRepository 10 | import com.okanaydin.assignment.features.posts.usecase.PostListUseCase 11 | import com.okanaydin.assignment.util.MainCoroutineRule 12 | import com.okanaydin.assignment.util.second 13 | import io.mockk.MockKAnnotations 14 | import io.mockk.coEvery 15 | import io.mockk.coVerify 16 | import io.mockk.impl.annotations.MockK 17 | import kotlinx.coroutines.ExperimentalCoroutinesApi 18 | import kotlinx.coroutines.flow.first 19 | import kotlinx.coroutines.flow.toList 20 | import kotlinx.coroutines.runBlocking 21 | import org.junit.Before 22 | import org.junit.Rule 23 | import org.junit.Test 24 | 25 | @ExperimentalCoroutinesApi 26 | class PostListUseCaseTest { 27 | 28 | @get:Rule 29 | var mainCoroutineRule = MainCoroutineRule() 30 | 31 | @MockK 32 | private lateinit var postRepository: PostRepository 33 | 34 | private lateinit var postListUseCase: PostListUseCase 35 | 36 | @Before 37 | fun setUp() { 38 | MockKAnnotations.init(this) 39 | postListUseCase = PostListUseCase(postRepository) 40 | } 41 | 42 | @Test 43 | fun `when state is loading, then getCombinedPostsAndPhotos returns loading`() = runBlocking { 44 | // given 45 | coEvery { postRepository.getPosts() } 46 | 47 | // when 48 | val result = postListUseCase.getCombinedPostsAndPhotos().first() 49 | 50 | // then 51 | assertThat(result).isInstanceOf(Resource.Loading::class.java) 52 | } 53 | 54 | @Test 55 | fun `when state is success, then getCombinedPostsAndPhotos returns post and photo`() = 56 | runBlocking { 57 | // given 58 | coEvery { postRepository.getPosts() } returns listOf(getPost()) 59 | coEvery { postRepository.getPhotos() } returns listOf(getPhoto()) 60 | 61 | // when 62 | val result = postListUseCase.getCombinedPostsAndPhotos().toList() 63 | 64 | // then 65 | coVerify { postRepository.getPhotos() } 66 | coVerify { postRepository.getPosts() } 67 | 68 | assertThat(result).hasSize(2) 69 | assertThat(result.first()).isInstanceOf(Resource.Loading::class.java) 70 | assertThat((result.second() as Success<*>).data).isEqualTo(listOf(getPostAndPhoto())) 71 | } 72 | 73 | @Test 74 | fun `when state is failed, then getCombinedPostsAndPhotos returns error`() = 75 | runBlocking { 76 | // given 77 | val errorMessage = "ERROR_MESSAGE" 78 | val throwable = Throwable(errorMessage) 79 | coEvery { postRepository.getPosts() } throws throwable 80 | coEvery { postRepository.getPhotos() } throws throwable 81 | 82 | // when 83 | val result = postListUseCase.getCombinedPostsAndPhotos().toList() 84 | 85 | // then 86 | assertThat(result).hasSize(2) 87 | assertThat(result.first()).isInstanceOf(Resource.Loading::class.java) 88 | assertThat((result.second() as Resource.Failed<*>).throwable.message).isEqualTo( 89 | errorMessage 90 | ) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/posts/PostRepositoryTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts 2 | 3 | import com.okanaydin.assignment.data.remote.datasource.model.PhotoModelFactory.getPhoto 4 | import com.okanaydin.assignment.data.remote.datasource.model.PostModelFactory.getPost 5 | import com.okanaydin.assignment.data.remote.datasource.photos.PhotoRemoteDataSource 6 | import com.okanaydin.assignment.data.remote.datasource.posts.PostRemoteDataSource 7 | import com.okanaydin.assignment.features.posts.repository.PostRepository 8 | import com.okanaydin.assignment.util.MainCoroutineRule 9 | import io.mockk.MockKAnnotations 10 | import io.mockk.coEvery 11 | import io.mockk.coVerify 12 | import io.mockk.impl.annotations.MockK 13 | import junit.framework.Assert.assertEquals 14 | import kotlinx.coroutines.ExperimentalCoroutinesApi 15 | import kotlinx.coroutines.runBlocking 16 | import org.junit.Before 17 | import org.junit.Rule 18 | import org.junit.Test 19 | 20 | @ExperimentalCoroutinesApi 21 | class PostRepositoryTest { 22 | 23 | @get:Rule 24 | var mainCoroutineRule = MainCoroutineRule() 25 | 26 | @MockK 27 | private lateinit var postRemoteDataSource: PostRemoteDataSource 28 | 29 | @MockK 30 | private lateinit var photoRemoteDataSource: PhotoRemoteDataSource 31 | 32 | private lateinit var postRepository: PostRepository 33 | 34 | @Before 35 | fun setUp() { 36 | MockKAnnotations.init(this) 37 | postRepository = PostRepository(postRemoteDataSource, photoRemoteDataSource) 38 | } 39 | 40 | @Test 41 | fun `check getPosts`() = runBlocking { 42 | // given 43 | coEvery { postRemoteDataSource.getPosts() } returns listOf(getPost()) 44 | 45 | // when 46 | val result = postRepository.getPosts() 47 | 48 | // then 49 | coVerify { postRemoteDataSource.getPosts() } 50 | assertEquals(result, listOf(getPost())) 51 | } 52 | 53 | @Test 54 | fun `check getPhotos`() = runBlocking { 55 | // given 56 | coEvery { photoRemoteDataSource.getPhotos() } returns listOf(getPhoto()) 57 | 58 | // when 59 | val result = postRepository.getPhotos() 60 | 61 | // then 62 | coVerify { photoRemoteDataSource.getPhotos() } 63 | assertEquals(result, listOf(getPhoto())) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/features/posts/PostViewModelTest.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.features.posts 2 | 3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule 4 | import androidx.lifecycle.Observer 5 | import com.google.common.truth.Truth.assertThat 6 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModel 7 | import com.okanaydin.assignment.data.remote.datasource.model.PostAndPhotoModelFactory.getPostAndPhoto 8 | import com.okanaydin.assignment.features.core.LayoutViewState 9 | import com.okanaydin.assignment.features.core.Resource 10 | import com.okanaydin.assignment.features.posts.ui.PostViewModel 11 | import com.okanaydin.assignment.features.posts.usecase.PostListUseCase 12 | import com.okanaydin.assignment.util.MainCoroutineRule 13 | import com.okanaydin.assignment.util.second 14 | import io.mockk.MockKAnnotations 15 | import io.mockk.coEvery 16 | import io.mockk.coVerify 17 | import io.mockk.every 18 | import io.mockk.impl.annotations.MockK 19 | import io.mockk.mockk 20 | import io.mockk.slot 21 | import kotlinx.coroutines.ExperimentalCoroutinesApi 22 | import kotlinx.coroutines.flow.flow 23 | import kotlinx.coroutines.test.runBlockingTest 24 | import org.junit.Before 25 | import org.junit.Rule 26 | import org.junit.Test 27 | 28 | @ExperimentalCoroutinesApi 29 | class PostViewModelTest { 30 | 31 | @get:Rule 32 | var mainCoroutineRule = MainCoroutineRule() 33 | 34 | @get:Rule 35 | var instantTaskExecutorRule = InstantTaskExecutorRule() 36 | 37 | @MockK 38 | private lateinit var postListUseCase: PostListUseCase 39 | 40 | @MockK 41 | private lateinit var layoutViewStateObserver: Observer 42 | 43 | @MockK 44 | private lateinit var postListStateObserver: Observer> 45 | 46 | private lateinit var postViewModel: PostViewModel 47 | 48 | private val layoutViewStateValues = arrayListOf() 49 | private val postListValues = arrayListOf>() 50 | 51 | private val layoutViewStateSlot = slot() 52 | private val postListSlot = slot>() 53 | 54 | @Before 55 | fun setUp() { 56 | MockKAnnotations.init(this) 57 | postViewModel = PostViewModel(postListUseCase) 58 | } 59 | 60 | @Test 61 | fun `check getPostList success`() = runBlockingTest { 62 | // given 63 | postViewModel.layoutViewState.observeForever(layoutViewStateObserver) 64 | postViewModel.postList.observeForever(postListStateObserver) 65 | 66 | every { layoutViewStateObserver.onChanged(capture(layoutViewStateSlot)) } answers { 67 | layoutViewStateValues.add( 68 | layoutViewStateSlot.captured 69 | ) 70 | } 71 | 72 | every { postListStateObserver.onChanged(capture(postListSlot)) } answers { 73 | postListValues.add( 74 | postListSlot.captured 75 | ) 76 | } 77 | 78 | coEvery { postListUseCase.getCombinedPostsAndPhotos() } returns flow { 79 | emit(Resource.loading()) 80 | emit(Resource.success(listOf(getPostAndPhoto()))) 81 | } 82 | 83 | // when 84 | postViewModel.getPostList() 85 | 86 | // then 87 | coVerify(exactly = 1) { postListUseCase.getCombinedPostsAndPhotos() } 88 | assertThat(layoutViewStateValues).hasSize(2) 89 | assertThat(layoutViewStateValues.first().isLoading()).isTrue() 90 | assertThat(layoutViewStateValues.second().isSuccess()).isTrue() 91 | assertThat(postListValues).hasSize(1) 92 | assertThat(postListValues.first()).isEqualTo(listOf(getPostAndPhoto())) 93 | } 94 | 95 | @Test 96 | fun `check getPostList fail`() = runBlockingTest { 97 | // given 98 | val throwable = mockk() 99 | postViewModel.layoutViewState.observeForever(layoutViewStateObserver) 100 | postViewModel.postList.observeForever(postListStateObserver) 101 | 102 | every { layoutViewStateObserver.onChanged(capture(layoutViewStateSlot)) } answers { 103 | layoutViewStateValues.add( 104 | layoutViewStateSlot.captured 105 | ) 106 | } 107 | 108 | every { postListStateObserver.onChanged(capture(postListSlot)) } answers { 109 | postListValues.add( 110 | postListSlot.captured 111 | ) 112 | } 113 | 114 | coEvery { postListUseCase.getCombinedPostsAndPhotos() } returns flow>> { 115 | emit(Resource.loading()) 116 | emit(Resource.failed(throwable)) 117 | } 118 | 119 | // when 120 | postViewModel.getPostList() 121 | 122 | // then 123 | coVerify(exactly = 1) { postListUseCase.getCombinedPostsAndPhotos() } 124 | assertThat(layoutViewStateValues).hasSize(2) 125 | assertThat(layoutViewStateValues.first().isLoading()).isTrue() 126 | assertThat(layoutViewStateValues.second().isFailed()).isTrue() 127 | assertThat(postListValues).hasSize(0) 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/util/ListExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.util 2 | 3 | fun List.second() = this[1] 4 | -------------------------------------------------------------------------------- /app/src/test/java/com/okanaydin/assignment/util/MainCoroutineRule.kt: -------------------------------------------------------------------------------- 1 | package com.okanaydin.assignment.util 2 | 3 | import kotlinx.coroutines.Dispatchers 4 | import kotlinx.coroutines.ExperimentalCoroutinesApi 5 | import kotlinx.coroutines.test.TestCoroutineDispatcher 6 | import kotlinx.coroutines.test.TestCoroutineScope 7 | import kotlinx.coroutines.test.resetMain 8 | import kotlinx.coroutines.test.setMain 9 | import org.junit.rules.TestWatcher 10 | import org.junit.runner.Description 11 | 12 | @ExperimentalCoroutinesApi 13 | class MainCoroutineRule(val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : 14 | TestWatcher(), 15 | TestCoroutineScope by TestCoroutineScope(dispatcher) { 16 | override fun starting(description: Description?) { 17 | super.starting(description) 18 | Dispatchers.setMain(dispatcher) 19 | } 20 | 21 | override fun finished(description: Description?) { 22 | super.finished(description) 23 | cleanupTestCoroutines() 24 | Dispatchers.resetMain() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | buildscript { 2 | /** 3 | * Bintray's JCenter repository for dependencies is deprecated. 4 | * JFrog announced JCenter's shutdown in February 2021. Use mavenCentral() instead. 5 | * ref: https://blog.gradle.org/jcenter-shutdown 6 | */ 7 | repositories { 8 | google() 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | classpath(ClassPaths.daggerHilt) 14 | classpath(ClassPaths.gradle) 15 | classpath(ClassPaths.kotlinGradlePlugin) 16 | classpath(ClassPaths.navigationSafeArgPlugin) 17 | classpath("de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1") 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | google() 24 | mavenCentral() 25 | } 26 | } 27 | 28 | tasks.register("clean", Delete::class.java) { 29 | delete(rootProject.buildDir) 30 | } 31 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/ClassPaths.kt: -------------------------------------------------------------------------------- 1 | object ClassPaths { 2 | 3 | const val daggerHilt = 4 | "com.google.dagger:hilt-android-gradle-plugin:${Versions.daggerHiltVersion}" 5 | const val gradle = "com.android.tools.build:gradle:${Versions.gradleVersion}" 6 | const val kotlinGradlePlugin = 7 | "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}" 8 | const val navigationSafeArgPlugin = 9 | "androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.navigationVersion}" 10 | } 11 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/Configs.kt: -------------------------------------------------------------------------------- 1 | object Configs { 2 | 3 | const val applicationId = "com.okanaydin.assignment" 4 | const val compileSdkVersion = 30 5 | const val minSdkVersion = 17 6 | const val targetSdkVersion = 30 7 | const val testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 8 | const val versionCode = 1 9 | const val versionName = "1.0" 10 | } 11 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/Dependencies.kt: -------------------------------------------------------------------------------- 1 | object Dependencies { 2 | 3 | const val androidMaterial = 4 | "com.google.android.material:material:${Versions.androidMaterialVersion}" 5 | const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompatVersion}" 6 | const val archTest = "androidx.arch.core:core-testing:${Versions.archTestVersion}" 7 | const val cardView = "androidx.cardview:cardview:${Versions.cardViewVersion}" 8 | const val coil = "io.coil-kt:coil:${Versions.coilVersion}" 9 | const val constraintLayout = 10 | "androidx.constraintlayout:constraintlayout:${Versions.constraintLayoutVersion}" 11 | const val coreKtx = "androidx.core:core-ktx:${Versions.coreKtxVersion}" 12 | const val coroutinesAndroid = 13 | "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutinesVersion}" 14 | const val coroutinesCore = 15 | "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutinesVersion}" 16 | const val coroutinesTest = 17 | "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutinesVersion}" 18 | const val daggerHilt = "com.google.dagger:hilt-android:${Versions.daggerHiltVersion}" 19 | const val daggerHiltCompiler = "com.google.dagger:hilt-compiler:${Versions.daggerHiltVersion}" 20 | const val espresso = "androidx.test.espresso:espresso-core:${Versions.espressoVersion}" 21 | const val fragmentKtx = "androidx.fragment:fragment-ktx:${Versions.fragmentKtxVersion}" 22 | const val jUnit = "junit:junit:${Versions.junitVersion}" 23 | const val jUnitExt = "androidx.test.ext:junit:${Versions.junitExtensionsVersion}" 24 | const val jupiterApi = "org.junit.jupiter:junit-jupiter-api:${Versions.jupiterVersion}" 25 | const val jupiterEngine = "org.junit.jupiter:junit-jupiter-engine:${Versions.jupiterVersion}" 26 | const val jupiterParams = "org.junit.jupiter:junit-jupiter-params:${Versions.jupiterVersion}" 27 | const val jupiterVintageEngine = 28 | "org.junit.vintage:junit-vintage-engine:${Versions.jupiterVersion}" 29 | const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlinVersion}" 30 | const val ktlint = "com.pinterest:ktlint:${Versions.ktlintVersion}" 31 | const val liveDataKtx = 32 | "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.liveDataKtxVersion}" 33 | const val mockk = "io.mockk:mockk:${Versions.mockkVersion}" 34 | const val moshi = "com.squareup.moshi:moshi:${Versions.moshiVersion}" 35 | const val moshiCodegen = "com.squareup.moshi:moshi-kotlin-codegen:${Versions.moshiVersion}" 36 | const val navigationFragment = 37 | "androidx.navigation:navigation-fragment-ktx:${Versions.navigationVersion}" 38 | const val navigationUi = "androidx.navigation:navigation-ui-ktx:${Versions.navigationVersion}" 39 | const val okhttp3 = "com.squareup.okhttp3:okhttp:${Versions.okhttp3Version}" 40 | const val okhttp3Interceptor = 41 | "com.squareup.okhttp3:logging-interceptor:${Versions.okhttp3Version}" 42 | const val retrofit2 = "com.squareup.retrofit2:retrofit:${Versions.retrofit2Version}" 43 | const val retrofit2MoshiConvertor = 44 | "com.squareup.retrofit2:converter-moshi:${Versions.retrofit2MoshiConvertorVersion}" 45 | const val robolectric = "org.robolectric:robolectric:${Versions.robolectricVersion}" 46 | const val swipeRefreshLayout = 47 | "androidx.swiperefreshlayout:swiperefreshlayout:${Versions.swipeRefreshLayoutVersion}" 48 | const val truth = "com.google.truth:truth:${Versions.truthVersion}" 49 | const val truthExtensions = 50 | "com.google.truth.extensions:truth-java8-extension:${Versions.truthVersion}" 51 | const val viewModelKtx = 52 | "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.viewModelKtxVersion}" 53 | } 54 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/Versions.kt: -------------------------------------------------------------------------------- 1 | object Versions { 2 | 3 | const val androidMaterialVersion = "1.3.0" 4 | const val appCompatVersion = "1.2.0" 5 | const val archTestVersion = "2.1.0" 6 | const val cardViewVersion = "1.0.0" 7 | const val coilVersion = "1.2.0" 8 | const val constraintLayoutVersion = "1.3.2" 9 | const val coroutinesVersion = "1.5.0" 10 | const val coreKtxVersion = "1.3.2" 11 | const val daggerHiltVersion = "2.33-beta" 12 | const val espressoVersion = "3.3.0" 13 | const val fragmentKtxVersion = "1.3.2" 14 | const val gradleVersion = "4.1.3" 15 | const val junitExtensionsVersion = "1.1.2" 16 | const val junitVersion = "4.13.2" 17 | const val jupiterVersion = "5.7.1" 18 | const val kotlinVersion = "1.4.31" 19 | const val ktlintVersion = "0.41.0" 20 | const val liveDataKtxVersion = "2.3.1" 21 | const val mockkVersion = "1.11.0" 22 | const val moshiVersion = "1.12.0" 23 | const val navigationVersion = "2.3.5" 24 | const val okhttp3Version = "5.0.0-alpha.2" 25 | const val retrofit2MoshiConvertorVersion = "2.4.0" 26 | const val retrofit2Version = "2.9.0" 27 | const val robolectricVersion = "4.5.1" 28 | const val swipeRefreshLayoutVersion = "1.1.0" 29 | const val truthVersion = "1.1.2" 30 | const val viewModelKtxVersion = "2.3.1" 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 15 23:57:42 EET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /results/action.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/action.png -------------------------------------------------------------------------------- /results/board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/board.png -------------------------------------------------------------------------------- /results/screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/screenshot_1.png -------------------------------------------------------------------------------- /results/screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/screenshot_2.png -------------------------------------------------------------------------------- /results/screenshot_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/screenshot_3.png -------------------------------------------------------------------------------- /results/screenshot_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/screenshot_4.png -------------------------------------------------------------------------------- /results/screenshot_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okanaydin/Android-Assignment/59e04e539678e3bce7516e4f3c501be921932ef4/results/screenshot_5.png -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | include(":app") 2 | --------------------------------------------------------------------------------