├── .github └── workflows │ └── build.yaml ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ragvax │ │ └── dictionary │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-playstore.png │ ├── java │ │ └── com │ │ │ └── ragvax │ │ │ ├── DictionaryApp.kt │ │ │ └── dictionary │ │ │ ├── MainActivity.kt │ │ │ ├── data │ │ │ ├── DefinitionRepository.kt │ │ │ ├── RecentQueryRepository.kt │ │ │ └── source │ │ │ │ ├── local │ │ │ │ ├── DictionaryDatabase.kt │ │ │ │ ├── LocalDataSource.kt │ │ │ │ ├── RecentQueryDao.kt │ │ │ │ ├── RecentQueryEntity.kt │ │ │ │ └── RecentQueryMapper.kt │ │ │ │ └── remote │ │ │ │ ├── DefinitionMapper.kt │ │ │ │ ├── DefinitionService.kt │ │ │ │ ├── RemoteDataSource.kt │ │ │ │ ├── WordDefinitionDTO.kt │ │ │ │ └── WordDefinitionEntity.kt │ │ │ ├── di │ │ │ ├── DatabaseModule.kt │ │ │ ├── NetworkModule.kt │ │ │ ├── RepositoryModule.kt │ │ │ └── UseCaseModule.kt │ │ │ ├── domain │ │ │ ├── model │ │ │ │ ├── RecentQuery.kt │ │ │ │ └── WordDefinition.kt │ │ │ ├── repository │ │ │ │ ├── IDefinitionRepository.kt │ │ │ │ └── IRecentQueryRepository.kt │ │ │ └── usecase │ │ │ │ ├── DeleteRecentQuery.kt │ │ │ │ ├── GetRecentQueries.kt │ │ │ │ ├── GetWordDefinitions.kt │ │ │ │ └── InsertRecentQuery.kt │ │ │ ├── ui │ │ │ ├── definition │ │ │ │ ├── DefinitionFragment.kt │ │ │ │ ├── DefinitionState.kt │ │ │ │ ├── DefinitionViewModel.kt │ │ │ │ └── adapters │ │ │ │ │ ├── DefinitionAdapter.kt │ │ │ │ │ └── MeaningAdapter.kt │ │ │ └── home │ │ │ │ ├── HomeEvent.kt │ │ │ │ ├── HomeFragment.kt │ │ │ │ ├── HomeViewModel.kt │ │ │ │ └── adapters │ │ │ │ └── RecentSearchesAdapter.kt │ │ │ └── utils │ │ │ ├── ContextExt.kt │ │ │ ├── FlowObserverExt.kt │ │ │ ├── Mapper.kt │ │ │ ├── Resource.kt │ │ │ └── ViewExt.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_baseline_search_24.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_foreground.xml │ │ └── text_input_layout_background.xml │ │ ├── font │ │ └── playfair_display_bold.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_main.xml │ │ ├── fragment_definition.xml │ │ ├── fragment_home.xml │ │ ├── item_definition.xml │ │ ├── item_meaning.xml │ │ └── item_recent_searches.xml │ │ ├── menu │ │ └── main_menu.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-night │ │ └── themes.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── font_certs.xml │ │ ├── preloaded_fonts.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── ragvax │ └── dictionary │ └── ExampleUnitTest.kt ├── assets ├── DictionaryHeader.jpg ├── definition_day.png ├── definition_night.png ├── home_day.png └── home_night.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout the code 14 | uses: actions/checkout@v2 15 | 16 | - name: Set up JDK 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: 11 20 | 21 | - name: Make gradlew executable 22 | run: chmod +x ./gradlew 23 | 24 | - name: Build with Gradle 25 | run: ./gradlew build -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/discord.xml 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | /.idea/navEditor.xml 10 | /.idea/assetWizardSettings.xml 11 | .DS_Store 12 | /build 13 | /captures 14 | .externalNativeBuild 15 | .cxx 16 | local.properties -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Dictionary -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 119 | 120 | 122 | 123 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Rizki Fajar Maulian 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Github Header](https://github.com/ragvax/Dictionary/blob/master/assets/DictionaryHeader.jpg?raw=true) 2 | 3 | # Dictionary 📖 4 | [![build](https://github.com/ragvax/Dictionary/actions/workflows/build.yaml/badge.svg)](https://github.com/ragvax/Dictionary/actions) 5 | [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?labelColor=373e45&logo=android&style=flat)](https://android-arsenal.com/api?level=21) 6 | [![github profile](https://img.shields.io/badge/Github-ragvax-4a88ea?labelColor=373e45&style=flat&logo=github)](https://github.com/ragvax) 7 | 8 | Dictionary is a small online dictionary application to look up the meanings and definitions of words entered by users. It simply fetches data from the remote API created by [Meet Developer](https://github.com/meetDeveloper) and displays it to the users. This application is built based on modern Android development tech-stacks recommended by the Android team with MVVM and Single Activity Architecture. Currently, this app only supports English. 9 | 10 | ## Screenshots 📷 11 | 12 | 13 | ## Built With 🛠 14 | * Minimum SDK level 21 15 | * Kotlin 16 | * [Foundation][0] - Components for core system capabilities, Kotlin extensions and support for 17 | multidex and automated testing. 18 | * [AppCompat][1] - Degrade gracefully on older versions of Android. 19 | * [Android KTX][2] - Write more concise, idiomatic Kotlin code. 20 | * [Architecture][3] - A collection of libraries that help you design robust, testable, and 21 | maintainable apps. Start with classes for managing your UI component lifecycle and handling data 22 | persistence. 23 | * [Lifecycles][4] - Create a UI that automatically responds to lifecycle events. 24 | * [Navigation][5] - Handle everything needed for in-app navigation. 25 | * [Room][5] - Access your app's SQLite database with in-app objects and compile-time checks. 26 | * [ViewModel][6] - Store UI-related data that isn't destroyed on app rotations. Easily schedule 27 | asynchronous tasks for optimal execution. 28 | * Third party and miscellaneous libraries 29 | * [Hilt][7]: for [dependency injection][8] 30 | * [Kotlin Coroutines][9] for managing background threads with simplified code and reducing needs for callbacks 31 | 32 | [0]: https://developer.android.com/jetpack/components 33 | [1]: https://developer.android.com/topic/libraries/support-library/packages#v7-appcompat 34 | [2]: https://developer.android.com/kotlin/ktx 35 | [3]: https://developer.android.com/jetpack/arch/ 36 | [4]: https://developer.android.com/topic/libraries/architecture/lifecycle 37 | [5]: https://developer.android.com/topic/libraries/architecture/navigation/ 38 | [5]: https://developer.android.com/topic/libraries/architecture/room 39 | [6]: https://developer.android.com/topic/libraries/architecture/viewmodel 40 | [7]: https://developer.android.com/training/dependency-injection/hilt-android 41 | [8]: https://developer.android.com/training/dependency-injection 42 | [9]: https://kotlinlang.org/docs/reference/coroutines-overview.html 43 | 44 | ## License 🔖 45 | ``` 46 | Copyright 2021 Rizki Fajar Maulian 47 | 48 | Licensed under the Apache License, Version 2.0 (the "License"); 49 | you may not use this file except in compliance with the License. 50 | You may obtain a copy of the License at 51 | 52 | http://www.apache.org/licenses/LICENSE-2.0 53 | 54 | Unless required by applicable law or agreed to in writing, software 55 | distributed under the License is distributed on an "AS IS" BASIS, 56 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 57 | See the License for the specific language governing permissions and 58 | limitations under the License. 59 | ``` -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-parcelize' 5 | id 'kotlin-kapt' 6 | id "androidx.navigation.safeargs.kotlin" 7 | id 'dagger.hilt.android.plugin' 8 | } 9 | 10 | android { 11 | compileSdkVersion 31 12 | buildToolsVersion "30.0.2" 13 | 14 | defaultConfig { 15 | applicationId "com.ragvax.dictionary" 16 | minSdkVersion 21 17 | targetSdkVersion 31 18 | versionCode 1 19 | versionName "1.0" 20 | 21 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled true 27 | shrinkResources true 28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | 32 | buildFeatures { 33 | viewBinding true 34 | } 35 | 36 | compileOptions { 37 | sourceCompatibility JavaVersion.VERSION_11 38 | targetCompatibility JavaVersion.VERSION_11 39 | } 40 | 41 | kotlinOptions { 42 | jvmTarget = '11' 43 | } 44 | } 45 | 46 | dependencies { 47 | 48 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 49 | implementation 'androidx.core:core-ktx:1.6.0' 50 | implementation 'androidx.appcompat:appcompat:1.3.1' 51 | implementation 'androidx.constraintlayout:constraintlayout:2.1.1' 52 | implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' 53 | 54 | // Material Design Components 55 | implementation 'com.google.android.material:material:1.4.0' 56 | 57 | // Coroutines 58 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1' 59 | 60 | // Lifecycle 61 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0" 62 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0" 63 | implementation "androidx.lifecycle:lifecycle-common-java8:2.4.0" 64 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0" 65 | 66 | // Retrofit + GSON Converter 67 | implementation "com.squareup.retrofit2:retrofit:2.9.0" 68 | implementation "com.squareup.retrofit2:converter-gson:2.9.0" 69 | implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2" 70 | implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2" 71 | 72 | // Navigation Components 73 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' 74 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' 75 | 76 | // Room Persistence Library 77 | implementation 'androidx.room:room-runtime:2.3.0' 78 | implementation "androidx.room:room-ktx:2.3.0" 79 | kapt 'androidx.room:room-compiler:2.3.0' 80 | 81 | // Dagger Hilt 82 | implementation "com.google.dagger:hilt-android:$hilt_version" 83 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03" 84 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 85 | kapt "androidx.hilt:hilt-compiler:1.0.0" 86 | 87 | // Test Dependencies 88 | testImplementation 'junit:junit:4.13.2' 89 | testImplementation "com.google.truth:truth:1.0.1" 90 | androidTestImplementation "com.google.truth:truth:1.0.1" 91 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 92 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 93 | } -------------------------------------------------------------------------------- /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. 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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ragvax/dictionary/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.ragvax.dictionary", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/DictionaryApp.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class DictionaryApp : Application() -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary 2 | 3 | import android.os.Bundle 4 | import android.view.Menu 5 | import android.view.MenuItem 6 | import androidx.appcompat.app.AppCompatActivity 7 | import androidx.appcompat.app.AppCompatDelegate 8 | import androidx.navigation.NavController 9 | import androidx.navigation.fragment.NavHostFragment 10 | import androidx.navigation.fragment.findNavController 11 | import androidx.navigation.ui.AppBarConfiguration 12 | import androidx.navigation.ui.setupActionBarWithNavController 13 | import com.ragvax.dictionary.databinding.ActivityMainBinding 14 | import dagger.hilt.android.AndroidEntryPoint 15 | 16 | @AndroidEntryPoint 17 | class MainActivity : AppCompatActivity() { 18 | private lateinit var navController: NavController 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | val binding = ActivityMainBinding.inflate(layoutInflater) 23 | setContentView(binding.root) 24 | setSupportActionBar(binding.toolbar) 25 | 26 | val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_container) as NavHostFragment 27 | navController = navHostFragment.findNavController() 28 | val appBarConfiguration = AppBarConfiguration(navController.graph) 29 | 30 | supportActionBar?.setDisplayShowTitleEnabled(true) 31 | setupActionBarWithNavController(navController, appBarConfiguration) 32 | observeNavElements(navController) 33 | } 34 | 35 | override fun onCreateOptionsMenu(menu: Menu?): Boolean { 36 | menuInflater.inflate(R.menu.main_menu, menu) 37 | val nightMode = AppCompatDelegate.getDefaultNightMode() 38 | if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) { 39 | menu?.findItem(R.id.night_mode)?.setTitle(R.string.day_mode) 40 | } else { 41 | menu?.findItem(R.id.night_mode)?.setTitle(R.string.night_mode) 42 | } 43 | return true 44 | } 45 | 46 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 47 | if (item.itemId == R.id.night_mode) { 48 | val nightMode = AppCompatDelegate.getDefaultNightMode() 49 | if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) { 50 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) 51 | } else { 52 | AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) 53 | } 54 | } 55 | // recreate() 56 | return super.onOptionsItemSelected(item) 57 | } 58 | 59 | private fun observeNavElements(navController: NavController) { 60 | navController.addOnDestinationChangedListener { _, destination, _ -> 61 | when (destination.id) { 62 | R.id.definitionFragment -> { 63 | supportActionBar!!.setDisplayShowTitleEnabled(false) 64 | } 65 | else -> { 66 | supportActionBar!!.setDisplayShowTitleEnabled(false) 67 | } 68 | } 69 | } 70 | } 71 | 72 | override fun onSupportNavigateUp(): Boolean { 73 | return navController.navigateUp() || super.onSupportNavigateUp() 74 | } 75 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/DefinitionRepository.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data 2 | 3 | import com.ragvax.dictionary.data.source.remote.DefinitionMapper 4 | import com.ragvax.dictionary.data.source.remote.RemoteDataSource 5 | import com.ragvax.dictionary.data.source.remote.WordDefinitionDTO 6 | import com.ragvax.dictionary.domain.model.WordDefinition 7 | import com.ragvax.dictionary.domain.repository.IDefinitionRepository 8 | import com.ragvax.dictionary.utils.Resource 9 | import okio.IOException 10 | import javax.inject.Inject 11 | import javax.inject.Singleton 12 | 13 | @Singleton 14 | class DefinitionRepository @Inject constructor( 15 | private val remoteDataSource: RemoteDataSource, 16 | private val definitionMapper: DefinitionMapper, 17 | ): IDefinitionRepository { 18 | 19 | override suspend fun getWordDefinitions(word: String): Resource { 20 | return try { 21 | val response = remoteDataSource.fetchWordDefinition(word) 22 | if (response.isSuccessful) { 23 | val result = response.body()?.get(0) 24 | if (result != null) { 25 | Resource.Success(mapResultToDomain(result)) 26 | } else { 27 | Resource.Error(GENERIC_ERROR, EMPTY_RESULT_MESSAGE) 28 | } 29 | } else { 30 | Resource.Error(DEFINITIONS_NOT_FOUND, DEFINITIONS_NOT_FOUND_MESSAGE) 31 | } 32 | } catch (throwable: Throwable) { 33 | when (throwable) { 34 | is Exception -> { 35 | Resource.Error(NETWORK_ERROR, EXCEPTION_ERROR_MESSAGE) 36 | } 37 | is IOException -> { 38 | Resource.Error(NETWORK_ERROR, throwable.message ?: NETWORK_ERROR) 39 | } 40 | else -> Resource.Error(ERROR, UNKNOWN_ERROR_MESSAGE) 41 | } 42 | } 43 | } 44 | 45 | private fun mapResultToDomain(result: WordDefinitionDTO): WordDefinition { 46 | return definitionMapper.mapFromDTO(result) 47 | } 48 | 49 | companion object { 50 | const val ERROR = "Error" 51 | const val GENERIC_ERROR = "Whoops" 52 | const val NETWORK_ERROR = "Network Error" 53 | const val DEFINITIONS_NOT_FOUND = "No definitions found" 54 | const val EMPTY_RESULT_MESSAGE = "Server returned an empty result" 55 | const val DEFINITIONS_NOT_FOUND_MESSAGE = "Sorry, we couldn't find definitions for the word you were looking for." 56 | const val EXCEPTION_ERROR_MESSAGE = "An error occurred while trying to fetch data from the server. Please check you internet connection." 57 | const val UNKNOWN_ERROR_MESSAGE = "Unknown error occurred" 58 | } 59 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/RecentQueryRepository.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data 2 | 3 | import com.ragvax.dictionary.data.source.local.LocalDataSource 4 | import com.ragvax.dictionary.data.source.local.RecentQueryEntity 5 | import com.ragvax.dictionary.data.source.local.RecentQueryMapper 6 | import com.ragvax.dictionary.domain.model.RecentQuery 7 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 8 | import kotlinx.coroutines.flow.Flow 9 | import kotlinx.coroutines.flow.map 10 | import javax.inject.Inject 11 | import javax.inject.Singleton 12 | 13 | @Singleton 14 | class RecentQueryRepository @Inject constructor( 15 | private val localDataSource: LocalDataSource, 16 | private val RecentQueryMapper: RecentQueryMapper, 17 | ) : IRecentQueryRepository { 18 | 19 | override fun getRecentWordQueries(): Flow> { 20 | return localDataSource.getQueriesWithLimit(10).map { recentQueryList -> 21 | RecentQueryMapper.mapFromEntities(recentQueryList) 22 | } 23 | } 24 | 25 | override suspend fun insertRecentWordQuery(word: String) { 26 | localDataSource.insertQuery(RecentQueryEntity(word)) 27 | } 28 | 29 | override suspend fun deleteRecentWordQuery(query: RecentQuery) { 30 | val recentQueryEntity = RecentQueryMapper.mapToEntity(query) 31 | localDataSource.deleteQuery(recentQueryEntity) 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/local/DictionaryDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.local 2 | 3 | import android.content.Context 4 | import androidx.room.Database 5 | import androidx.room.Room 6 | import androidx.room.RoomDatabase 7 | 8 | @Database(entities = [RecentQueryEntity::class], version = 1, exportSchema = false) 9 | abstract class DictionaryDatabase : RoomDatabase() { 10 | 11 | abstract fun recentQueryDao(): RecentQueryDao 12 | 13 | companion object { 14 | @Volatile 15 | private var INSTANCE: DictionaryDatabase? = null 16 | 17 | fun getDatabase( 18 | context: Context, 19 | ): DictionaryDatabase { 20 | return INSTANCE ?: synchronized(this) { 21 | val instance = Room.databaseBuilder( 22 | context.applicationContext, 23 | DictionaryDatabase::class.java, 24 | "dictionary_database" 25 | ) 26 | .fallbackToDestructiveMigration() 27 | .build() 28 | INSTANCE = instance 29 | instance 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/local/LocalDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.local 2 | 3 | import kotlinx.coroutines.flow.Flow 4 | import javax.inject.Inject 5 | import javax.inject.Singleton 6 | 7 | @Singleton 8 | class LocalDataSource @Inject constructor( 9 | private val recentQueryDao: RecentQueryDao, 10 | ) { 11 | 12 | suspend fun insertQuery(recentQuery: RecentQueryEntity) = recentQueryDao.insertQuery(recentQuery) 13 | 14 | suspend fun deleteQuery(recentQuery: RecentQueryEntity) = recentQueryDao.deleteQuery(recentQuery) 15 | 16 | fun getQueriesWithLimit(limit: Int): Flow> = recentQueryDao.getQueriesWithLimit(limit) 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/local/RecentQueryDao.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.local 2 | 3 | import androidx.room.* 4 | import kotlinx.coroutines.flow.Flow 5 | 6 | @Dao 7 | interface RecentQueryDao { 8 | 9 | @Insert(onConflict = OnConflictStrategy.REPLACE) 10 | suspend fun insertQuery(recentQuery: RecentQueryEntity) 11 | 12 | @Delete 13 | suspend fun deleteQuery(recentQuery: RecentQueryEntity) 14 | 15 | @Query("SELECT * FROM recent_query ORDER BY time_date DESC LIMIT :limit") 16 | fun getQueriesWithLimit(limit: Int): Flow> 17 | 18 | @Query("DELETE FROM recent_query") 19 | suspend fun clear() 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/local/RecentQueryEntity.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.local 2 | 3 | import androidx.room.ColumnInfo 4 | import androidx.room.Entity 5 | import androidx.room.PrimaryKey 6 | 7 | @Entity(tableName = "recent_query") 8 | data class RecentQueryEntity( 9 | 10 | @PrimaryKey 11 | @ColumnInfo(name = "query_text") 12 | val queryText: String, 13 | 14 | @ColumnInfo(name = "time_date") 15 | val timeDate: Long = System.currentTimeMillis() 16 | ) 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/local/RecentQueryMapper.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.local 2 | 3 | import com.ragvax.dictionary.domain.model.RecentQuery 4 | import com.ragvax.dictionary.utils.Mapper 5 | import javax.inject.Inject 6 | 7 | class RecentQueryMapper @Inject constructor() : Mapper { 8 | fun mapFromEntity(input: RecentQueryEntity): RecentQuery { 9 | return RecentQuery( 10 | queryText = input.queryText, 11 | timeDate = input.timeDate 12 | ) 13 | } 14 | 15 | fun mapFromEntities(input: List): List { 16 | return input.map { 17 | mapFromEntity(it) 18 | } 19 | } 20 | 21 | fun mapToEntity(input: RecentQuery): RecentQueryEntity { 22 | return RecentQueryEntity( 23 | queryText = input.queryText, 24 | timeDate = input.timeDate 25 | ) 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/remote/DefinitionMapper.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.remote 2 | 3 | import com.ragvax.dictionary.domain.model.WordDefinition 4 | import com.ragvax.dictionary.utils.Mapper 5 | import javax.inject.Inject 6 | 7 | class DefinitionMapper @Inject constructor() : Mapper { 8 | 9 | fun mapFromDTO(input: WordDefinitionDTO): WordDefinition { 10 | return WordDefinition( 11 | word = input.word, 12 | phonetics = input.phonetics?.mapPhonetics() ?: emptyList(), 13 | meanings = input.meanings?.mapMeanings() ?: emptyList(), 14 | isFavorite = false, 15 | ) 16 | } 17 | 18 | private fun List.mapPhonetics(): List { 19 | return this.map { 20 | WordDefinition.Phonetics( 21 | text = it.text ?: "", 22 | audio = it.audio ?: "", 23 | ) 24 | } 25 | } 26 | 27 | private fun List.mapMeanings(): List { 28 | return this.map { 29 | WordDefinition.Meaning( 30 | definitions = it.definitions?.mapDefinitions() ?: emptyList(), 31 | partOfSpeech = it.partOfSpeech ?: "", 32 | ) 33 | } 34 | } 35 | 36 | private fun List.mapDefinitions(): List { 37 | return this.map { 38 | WordDefinition.Meaning.Definition( 39 | definition = it.definition ?: "", 40 | example = it.example ?: "", 41 | ) 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/remote/DefinitionService.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.remote 2 | 3 | import retrofit2.Response 4 | import retrofit2.http.GET 5 | import retrofit2.http.Path 6 | 7 | interface DefinitionService { 8 | 9 | @GET("entries/en_US/{word}") 10 | suspend fun fetchWordDefinition(@Path("word") word: String): Response> 11 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/remote/RemoteDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.remote 2 | 3 | import retrofit2.Response 4 | import javax.inject.Inject 5 | import javax.inject.Singleton 6 | 7 | @Singleton 8 | class RemoteDataSource @Inject constructor( 9 | private val apiService: DefinitionService, 10 | ) { 11 | suspend fun fetchWordDefinition(word: String): Response> { 12 | return apiService.fetchWordDefinition(word) 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/remote/WordDefinitionDTO.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.remote 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class WordDefinitionDTO( 8 | val word: String, 9 | val origin: String?, 10 | val phonetics: List?, 11 | val meanings: List? 12 | ) : Parcelable 13 | 14 | @Parcelize 15 | data class PhoneticDTO( 16 | val text: String?, 17 | val audio: String? 18 | ) : Parcelable 19 | 20 | @Parcelize 21 | data class MeaningDTO( 22 | val definitions: List?, 23 | val partOfSpeech: String? 24 | ) : Parcelable 25 | 26 | @Parcelize 27 | data class DefinitionDTO( 28 | val definition: String?, 29 | val example: String?, 30 | val synonyms: List?, 31 | val antonyms: List? 32 | ) : Parcelable -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/data/source/remote/WordDefinitionEntity.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.data.source.remote 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class WordDefinitionEntity( 8 | val word: String, 9 | val phonetics: List?, 10 | val meanings: List? 11 | ) : Parcelable 12 | 13 | @Parcelize 14 | data class Phonetic( 15 | val text: String?, 16 | val audio: String? 17 | ) : Parcelable 18 | 19 | @Parcelize 20 | data class Meaning( 21 | val definitions: List?, 22 | val partOfSpeech: String? 23 | ) : Parcelable 24 | 25 | @Parcelize 26 | data class Definition( 27 | val definition: String?, 28 | val example: String?, 29 | val synonyms: List? 30 | ) : Parcelable -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/di/DatabaseModule.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.di 2 | 3 | import android.content.Context 4 | import com.ragvax.dictionary.data.source.local.DictionaryDatabase 5 | import com.ragvax.dictionary.data.source.local.RecentQueryDao 6 | import dagger.Module 7 | import dagger.Provides 8 | import dagger.hilt.InstallIn 9 | import dagger.hilt.android.qualifiers.ApplicationContext 10 | import dagger.hilt.components.SingletonComponent 11 | import javax.inject.Singleton 12 | 13 | @InstallIn(SingletonComponent::class) 14 | @Module 15 | object DatabaseModule { 16 | 17 | @Singleton 18 | @Provides 19 | fun provideDatabase(@ApplicationContext context: Context): DictionaryDatabase { 20 | return DictionaryDatabase.getDatabase(context) 21 | } 22 | 23 | @Provides 24 | fun provideRecentQueryDao(dictionaryDatabase: DictionaryDatabase): RecentQueryDao { 25 | return dictionaryDatabase.recentQueryDao() 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/di/NetworkModule.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.di 2 | 3 | import com.ragvax.dictionary.data.source.remote.DefinitionService 4 | import com.ragvax.dictionary.data.source.remote.DefinitionMapper 5 | import dagger.Module 6 | import dagger.Provides 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.components.SingletonComponent 9 | import okhttp3.Interceptor 10 | import okhttp3.OkHttpClient 11 | import okhttp3.logging.HttpLoggingInterceptor 12 | import retrofit2.Retrofit 13 | import retrofit2.converter.gson.GsonConverterFactory 14 | import java.util.concurrent.TimeUnit 15 | import javax.inject.Singleton 16 | 17 | private const val BASE_URL = "https://api.dictionaryapi.dev/api/v2/" 18 | 19 | @InstallIn(SingletonComponent::class) 20 | @Module 21 | object NetworkModule { 22 | 23 | @Provides 24 | @Singleton 25 | fun provideHttpLoggingInterceptor() : Interceptor { 26 | return HttpLoggingInterceptor().apply { 27 | level = HttpLoggingInterceptor.Level.BODY 28 | } 29 | } 30 | @Provides 31 | @Singleton 32 | fun provideHttpClient(HttpLoggingInterceptor: Interceptor): OkHttpClient { 33 | return OkHttpClient.Builder() 34 | .connectTimeout(120, TimeUnit.SECONDS) 35 | .readTimeout(120, TimeUnit.SECONDS) 36 | .addInterceptor(HttpLoggingInterceptor) 37 | .addNetworkInterceptor(HttpLoggingInterceptor) 38 | .build() 39 | } 40 | @Provides 41 | @Singleton 42 | fun provideRetrofit(client: OkHttpClient): Retrofit = 43 | Retrofit.Builder() 44 | .baseUrl(BASE_URL) 45 | .client(client) 46 | .addConverterFactory(GsonConverterFactory.create()) 47 | .build() 48 | 49 | @Provides 50 | @Singleton 51 | fun provideDefinitionService(retrofit: Retrofit): DefinitionService = 52 | retrofit.create(DefinitionService::class.java) 53 | 54 | @Provides 55 | @Singleton 56 | fun provideNetworkMapper(): DefinitionMapper = DefinitionMapper() 57 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/di/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.di 2 | 3 | import com.ragvax.dictionary.data.DefinitionRepository 4 | import com.ragvax.dictionary.data.RecentQueryRepository 5 | import com.ragvax.dictionary.domain.repository.IDefinitionRepository 6 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 7 | import dagger.Binds 8 | import dagger.Module 9 | import dagger.hilt.InstallIn 10 | import dagger.hilt.components.SingletonComponent 11 | 12 | @Module(includes = [NetworkModule::class, DatabaseModule::class]) 13 | @InstallIn(SingletonComponent::class) 14 | abstract class RepositoryModule { 15 | 16 | @Binds 17 | abstract fun provideDefinitionRepository(definitionRepository: DefinitionRepository): IDefinitionRepository 18 | 19 | @Binds 20 | abstract fun provideRecentQueryRepository(definitionRepository: RecentQueryRepository): IRecentQueryRepository 21 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/di/UseCaseModule.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.di 2 | 3 | import com.ragvax.dictionary.domain.repository.IDefinitionRepository 4 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 5 | import com.ragvax.dictionary.domain.usecase.DeleteRecentQuery 6 | import com.ragvax.dictionary.domain.usecase.GetRecentQueries 7 | import com.ragvax.dictionary.domain.usecase.GetWordDefinitions 8 | import com.ragvax.dictionary.domain.usecase.InsertRecentQuery 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 | @Module 16 | @InstallIn(SingletonComponent::class) 17 | object UseCaseModule { 18 | 19 | @Provides 20 | @Singleton 21 | fun provideGetWordDefinitions(repository: IDefinitionRepository): GetWordDefinitions { 22 | return GetWordDefinitions(repository) 23 | } 24 | 25 | @Provides 26 | @Singleton 27 | fun provideGetRecentQuery(repository: IRecentQueryRepository): GetRecentQueries { 28 | return GetRecentQueries(repository) 29 | } 30 | 31 | @Provides 32 | @Singleton 33 | fun provideInsertRecentQuery(repository: IRecentQueryRepository): InsertRecentQuery { 34 | return InsertRecentQuery(repository) 35 | } 36 | 37 | @Provides 38 | @Singleton 39 | fun provideDeleteRecentQuery(repository: IRecentQueryRepository): DeleteRecentQuery { 40 | return DeleteRecentQuery(repository) 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/model/RecentQuery.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.model 2 | 3 | data class RecentQuery( 4 | val queryText: String, 5 | val timeDate: Long = System.currentTimeMillis() 6 | ) { 7 | companion object { 8 | val empty = RecentQuery("",0) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/model/WordDefinition.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.model 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | 6 | @Parcelize 7 | data class WordDefinition( 8 | val word: String, 9 | val phonetics: List, 10 | val meanings: List, 11 | val isFavorite: Boolean, 12 | ) : Parcelable { 13 | 14 | @Parcelize 15 | data class Phonetics( 16 | val text: String, 17 | val audio: String, 18 | ) : Parcelable 19 | 20 | @Parcelize 21 | data class Meaning( 22 | val definitions: List, 23 | val partOfSpeech: String, 24 | ) : Parcelable { 25 | 26 | @Parcelize 27 | data class Definition( 28 | val definition: String, 29 | val example: String, 30 | ) : Parcelable 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/repository/IDefinitionRepository.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.repository 2 | 3 | import com.ragvax.dictionary.domain.model.WordDefinition 4 | import com.ragvax.dictionary.utils.Resource 5 | 6 | interface IDefinitionRepository { 7 | 8 | suspend fun getWordDefinitions(word: String): Resource 9 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/repository/IRecentQueryRepository.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.repository 2 | 3 | import com.ragvax.dictionary.data.source.local.RecentQueryEntity 4 | import com.ragvax.dictionary.domain.model.RecentQuery 5 | import kotlinx.coroutines.flow.Flow 6 | 7 | interface IRecentQueryRepository { 8 | 9 | fun getRecentWordQueries(): Flow> 10 | 11 | suspend fun insertRecentWordQuery(word: String) 12 | 13 | suspend fun deleteRecentWordQuery(query: RecentQuery) 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/usecase/DeleteRecentQuery.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.usecase 2 | 3 | import com.ragvax.dictionary.domain.model.RecentQuery 4 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 5 | import javax.inject.Inject 6 | 7 | class DeleteRecentQuery @Inject constructor( 8 | private val repository: IRecentQueryRepository, 9 | ) { 10 | suspend operator fun invoke(query: RecentQuery) { 11 | repository.deleteRecentWordQuery(query) 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/usecase/GetRecentQueries.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.usecase 2 | 3 | import com.ragvax.dictionary.domain.model.RecentQuery 4 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 5 | import kotlinx.coroutines.flow.Flow 6 | import javax.inject.Inject 7 | 8 | class GetRecentQueries @Inject constructor( 9 | private val repository: IRecentQueryRepository, 10 | ) { 11 | operator fun invoke(): Flow> { 12 | return repository.getRecentWordQueries() 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/usecase/GetWordDefinitions.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.usecase 2 | 3 | import com.ragvax.dictionary.domain.model.WordDefinition 4 | import com.ragvax.dictionary.domain.repository.IDefinitionRepository 5 | import com.ragvax.dictionary.utils.Resource 6 | import javax.inject.Inject 7 | 8 | class GetWordDefinitions @Inject constructor( 9 | private val repository: IDefinitionRepository, 10 | ) { 11 | suspend operator fun invoke(word: String): Resource { 12 | return repository.getWordDefinitions(word) 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/domain/usecase/InsertRecentQuery.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.domain.usecase 2 | 3 | import com.ragvax.dictionary.domain.repository.IDefinitionRepository 4 | import com.ragvax.dictionary.domain.repository.IRecentQueryRepository 5 | import javax.inject.Inject 6 | 7 | class InsertRecentQuery @Inject constructor( 8 | private val repository: IRecentQueryRepository, 9 | ) { 10 | suspend operator fun invoke(word: String) { 11 | repository.insertRecentWordQuery(word) 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/definition/DefinitionFragment.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.definition 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.fragment.app.Fragment 6 | import androidx.fragment.app.viewModels 7 | import androidx.navigation.fragment.navArgs 8 | import androidx.recyclerview.widget.LinearLayoutManager 9 | import com.ragvax.dictionary.R 10 | import com.ragvax.dictionary.databinding.FragmentDefinitionBinding 11 | import com.ragvax.dictionary.domain.model.WordDefinition 12 | import com.ragvax.dictionary.ui.definition.adapters.MeaningAdapter 13 | import com.ragvax.dictionary.utils.* 14 | import dagger.hilt.android.AndroidEntryPoint 15 | 16 | @AndroidEntryPoint 17 | class DefinitionFragment : Fragment(R.layout.fragment_definition) { 18 | private val viewModel: DefinitionViewModel by viewModels() 19 | private val args: DefinitionFragmentArgs by navArgs() 20 | private var _binding: FragmentDefinitionBinding? = null 21 | private val binding get() = _binding!! 22 | 23 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 24 | super.onViewCreated(view, savedInstanceState) 25 | _binding = FragmentDefinitionBinding.bind(view) 26 | val queryStr = args.query 27 | getWordDefinitions(queryStr) 28 | 29 | observeViewModel() 30 | } 31 | 32 | private fun getWordDefinitions(query: String) { 33 | viewModel.getDefinitions(query) 34 | } 35 | 36 | private fun setupAdapter(meanings: List) { 37 | binding.apply { 38 | rvMeaning.adapter = MeaningAdapter(meanings, requireContext()) 39 | rvMeaning.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) 40 | rvMeaning.isNestedScrollingEnabled = false 41 | rvMeaning.setHasFixedSize(false) 42 | } 43 | } 44 | 45 | private fun observeViewModel() { 46 | viewModel.definitionFlow.observeWithLifecycle(viewLifecycleOwner) { state -> 47 | when (state) { 48 | is DefinitionState.Success -> bindOnSuccess(state.definition) 49 | is DefinitionState.Failure -> bindOnFailure(state.errorTitle, state.errorMsg) 50 | is DefinitionState.Empty -> bindEmpty() 51 | is DefinitionState.Loading -> bindEmpty() 52 | } 53 | } 54 | } 55 | 56 | private fun bindOnSuccess(result: WordDefinition) { 57 | binding.apply { 58 | requireContext().also { 59 | it.hideViews(progressBar, tvErrorTitle, tvErrorMessage) 60 | it.showViews(tvWordTitle, tvPhonetic, tvDefinitionTitle) 61 | } 62 | tvWordTitle.text = result.word 63 | tvPhonetic.text = result.phonetics.joinToString { it -> it.text } 64 | if (result.meanings.isNotEmpty()) { 65 | rvMeaning.show() 66 | setupAdapter(result.meanings) 67 | } else rvMeaning.hide() 68 | } 69 | } 70 | 71 | private fun bindOnFailure(errorTitle: String, errorMsg: String) { 72 | binding.apply { 73 | requireContext().also { 74 | it.hideViews(progressBar, tvWordTitle, tvPhonetic, tvDefinitionTitle, rvMeaning) 75 | it.showViews(tvErrorTitle, tvErrorMessage) 76 | } 77 | if (errorTitle.isNotBlank()) tvErrorTitle.text = errorTitle 78 | if (errorMsg.isNotBlank()) tvErrorMessage.text = errorMsg 79 | } 80 | } 81 | 82 | private fun bindEmpty(){ 83 | binding.apply { 84 | requireContext().hideViews(tvWordTitle, tvPhonetic, tvDefinitionTitle, rvMeaning, tvErrorTitle, tvErrorMessage) 85 | progressBar.show() 86 | } 87 | } 88 | 89 | override fun onDestroyView() { 90 | _binding = null 91 | super.onDestroyView() 92 | } 93 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/definition/DefinitionState.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.definition 2 | 3 | import com.ragvax.dictionary.domain.model.WordDefinition 4 | 5 | sealed class DefinitionState { 6 | data class Success(val definition: WordDefinition) : DefinitionState() 7 | data class Failure(val errorTitle: String, val errorMsg: String) : DefinitionState() 8 | object Loading : DefinitionState() 9 | object Empty : DefinitionState() 10 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/definition/DefinitionViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.definition 2 | 3 | import androidx.lifecycle.SavedStateHandle 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.viewModelScope 6 | import com.ragvax.dictionary.domain.model.WordDefinition 7 | import com.ragvax.dictionary.domain.usecase.GetWordDefinitions 8 | import com.ragvax.dictionary.domain.usecase.InsertRecentQuery 9 | import com.ragvax.dictionary.utils.Resource 10 | import dagger.hilt.android.lifecycle.HiltViewModel 11 | import kotlinx.coroutines.Dispatchers 12 | import kotlinx.coroutines.flow.MutableStateFlow 13 | import kotlinx.coroutines.flow.StateFlow 14 | import kotlinx.coroutines.launch 15 | import javax.inject.Inject 16 | 17 | @HiltViewModel 18 | class DefinitionViewModel @Inject constructor( 19 | private val getWordDefinitions: GetWordDefinitions, 20 | private val insertRecentQuery: InsertRecentQuery, 21 | private val state: SavedStateHandle, 22 | ) : ViewModel() { 23 | 24 | private val _definitionFlow = MutableStateFlow(DefinitionState.Empty) 25 | val definitionFlow: StateFlow = _definitionFlow 26 | 27 | fun getDefinitions(word: String) = viewModelScope.launch(Dispatchers.IO) { 28 | _definitionFlow.value = DefinitionState.Loading 29 | when(val result = getResult(word)) { 30 | is Resource.Success -> { 31 | _definitionFlow.value = DefinitionState.Success(result.data) 32 | state.set("state", result.data) 33 | insertRecent(word) 34 | } 35 | is Resource.Error -> _definitionFlow.value = DefinitionState.Failure(result.title,result.message) 36 | } 37 | } 38 | 39 | private suspend fun getResult(word: String): Resource = if (state.get("state") != null) { 40 | Resource.Success(state.get("state")!!) 41 | } else { 42 | getWordDefinitions(word) 43 | } 44 | 45 | private fun insertRecent(word: String) = viewModelScope.launch(Dispatchers.IO) { 46 | insertRecentQuery(word) 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/definition/adapters/DefinitionAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.definition.adapters 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.ragvax.dictionary.databinding.ItemDefinitionBinding 7 | import com.ragvax.dictionary.domain.model.WordDefinition 8 | import com.ragvax.dictionary.utils.hide 9 | 10 | class DefinitionAdapter( 11 | private val definitions: List, 12 | ) : RecyclerView.Adapter() { 13 | 14 | inner class ViewHolder(private val binding: ItemDefinitionBinding) : 15 | RecyclerView.ViewHolder(binding.root) { 16 | 17 | fun bind(definition: WordDefinition.Meaning.Definition, position: Int) { 18 | binding.tvDefinition.text = "$position. ${definition.definition}" 19 | if (definition.example.isNotBlank()) { 20 | binding.tvDefinitionExample.text = definition.example 21 | } else { 22 | binding.tvDefinitionExample.hide() 23 | } 24 | } 25 | } 26 | 27 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 28 | return ViewHolder( 29 | ItemDefinitionBinding.inflate( 30 | LayoutInflater.from(parent.context), 31 | parent, 32 | false 33 | ) 34 | ) 35 | } 36 | 37 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 38 | holder.bind(definitions[position], position + 1) 39 | } 40 | 41 | override fun getItemCount(): Int = definitions.size 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/definition/adapters/MeaningAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.definition.adapters 2 | 3 | import android.content.Context 4 | import android.view.LayoutInflater 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.DiffUtil 7 | import androidx.recyclerview.widget.LinearLayoutManager 8 | import androidx.recyclerview.widget.ListAdapter 9 | import androidx.recyclerview.widget.RecyclerView 10 | import com.ragvax.dictionary.databinding.ItemMeaningBinding 11 | import com.ragvax.dictionary.domain.model.WordDefinition 12 | import com.ragvax.dictionary.utils.hide 13 | 14 | class MeaningAdapter( 15 | private val meanings: List, 16 | private val context: Context, 17 | ) : ListAdapter(MeaningDiffCallback()) { 18 | 19 | inner class ViewHolder(private val binding: ItemMeaningBinding) : 20 | RecyclerView.ViewHolder(binding.root) { 21 | 22 | fun bind(meaning: WordDefinition.Meaning) { 23 | binding.tvPartOfSpeech.text = meaning.partOfSpeech 24 | if (meaning.definitions.isNotEmpty()) { 25 | binding.rvDefinition.adapter = DefinitionAdapter(meaning.definitions) 26 | binding.rvDefinition.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 27 | } else { 28 | binding.rvDefinition.hide() 29 | } 30 | } 31 | } 32 | 33 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 34 | return ViewHolder( 35 | ItemMeaningBinding.inflate( 36 | LayoutInflater.from(parent.context), 37 | parent, 38 | false 39 | ) 40 | ) 41 | } 42 | 43 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 44 | holder.bind(meanings[position]) 45 | } 46 | 47 | override fun getItemCount(): Int = meanings.size 48 | 49 | class MeaningDiffCallback : DiffUtil.ItemCallback() { 50 | override fun areItemsTheSame(oldItem: WordDefinition.Meaning, newItem: WordDefinition.Meaning): Boolean = 51 | oldItem.partOfSpeech == newItem.partOfSpeech 52 | 53 | override fun areContentsTheSame(oldItem: WordDefinition.Meaning, newItem: WordDefinition.Meaning): Boolean = 54 | oldItem == newItem 55 | } 56 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/home/HomeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.home 2 | 3 | sealed class HomeEvent { 4 | data class NavigateToDefinition(val query: String) : HomeEvent() 5 | object ShowDeleteNotificationToast : HomeEvent() 6 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/home/HomeFragment.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.home 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import android.view.inputmethod.EditorInfo 6 | import android.widget.Toast 7 | import androidx.fragment.app.Fragment 8 | import androidx.fragment.app.viewModels 9 | import androidx.lifecycle.lifecycleScope 10 | import androidx.navigation.fragment.findNavController 11 | import androidx.recyclerview.widget.ItemTouchHelper 12 | import androidx.recyclerview.widget.LinearLayoutManager 13 | import androidx.recyclerview.widget.RecyclerView 14 | import com.ragvax.dictionary.R 15 | import com.ragvax.dictionary.databinding.FragmentHomeBinding 16 | import com.ragvax.dictionary.ui.home.adapters.RecentSearchesAdapter 17 | import com.ragvax.dictionary.utils.observeWithLifecycle 18 | import com.ragvax.dictionary.utils.hideKeyboard 19 | import dagger.hilt.android.AndroidEntryPoint 20 | import kotlinx.coroutines.flow.collect 21 | 22 | @AndroidEntryPoint 23 | class HomeFragment : Fragment(R.layout.fragment_home), 24 | RecentSearchesAdapter.OnRecentSearchesItemClickListener { 25 | private val viewModel: HomeViewModel by viewModels() 26 | private var _binding: FragmentHomeBinding? = null 27 | private val binding get() = _binding!! 28 | 29 | private lateinit var recentSearchesAdapter: RecentSearchesAdapter 30 | 31 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 32 | super.onViewCreated(view, savedInstanceState) 33 | _binding = FragmentHomeBinding.bind(view) 34 | recentSearchesAdapter = RecentSearchesAdapter(this) 35 | 36 | initView() 37 | observeViewModel() 38 | } 39 | 40 | private fun initView() { 41 | binding.apply { 42 | tvSearch.setOnEditorActionListener { textView, i, _ -> 43 | if (i == EditorInfo.IME_ACTION_SEARCH && textView.text.toString().isNotEmpty()) { 44 | onSearchAction(textView.text.toString()) 45 | true 46 | } else { 47 | false 48 | } 49 | } 50 | 51 | rvRecentSearches.adapter = recentSearchesAdapter 52 | rvRecentSearches.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false) 53 | 54 | ItemTouchHelper(object : ItemTouchHelper.SimpleCallback( 55 | 0, 56 | ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT 57 | ) { 58 | override fun onMove( 59 | recyclerView: RecyclerView, 60 | viewHolder: RecyclerView.ViewHolder, 61 | target: RecyclerView.ViewHolder 62 | ): Boolean { 63 | return false 64 | } 65 | 66 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { 67 | val query = recentSearchesAdapter.currentList[viewHolder.adapterPosition] 68 | viewModel.onQuerySwiped(query) 69 | } 70 | }).attachToRecyclerView(rvRecentSearches) 71 | } 72 | } 73 | 74 | private fun observeViewModel() { 75 | viewModel.homeEvent.observeWithLifecycle(viewLifecycleOwner) { event -> 76 | when (event) { 77 | is HomeEvent.NavigateToDefinition -> { 78 | val action = HomeFragmentDirections.actionHomeFragmentToDefinitionFragment(event.query) 79 | findNavController().navigate(action) 80 | hideKeyboard() 81 | } 82 | is HomeEvent.ShowDeleteNotificationToast -> { 83 | Toast.makeText(context, "Recent query deleted", Toast.LENGTH_SHORT).show() 84 | } 85 | } 86 | } 87 | 88 | viewLifecycleOwner.lifecycleScope.launchWhenStarted { 89 | viewModel.recentQueries.collect { recentQueries -> 90 | recentSearchesAdapter.submitList(recentQueries) 91 | } 92 | } 93 | } 94 | 95 | override fun onRecentSearchesItemClick(query: String) { 96 | viewModel.onButtonClick(query) 97 | } 98 | 99 | private fun onSearchAction(query: String) { 100 | viewModel.onButtonClick(query) 101 | } 102 | 103 | override fun onDestroyView() { 104 | _binding = null 105 | super.onDestroyView() 106 | } 107 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/home/HomeViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.home 2 | 3 | import androidx.lifecycle.ViewModel 4 | import androidx.lifecycle.viewModelScope 5 | import com.ragvax.dictionary.domain.model.RecentQuery 6 | import com.ragvax.dictionary.domain.usecase.DeleteRecentQuery 7 | import com.ragvax.dictionary.domain.usecase.GetRecentQueries 8 | import dagger.hilt.android.lifecycle.HiltViewModel 9 | import kotlinx.coroutines.channels.Channel 10 | import kotlinx.coroutines.flow.receiveAsFlow 11 | import kotlinx.coroutines.launch 12 | import javax.inject.Inject 13 | 14 | @HiltViewModel 15 | class HomeViewModel @Inject constructor( 16 | getRecentQueries: GetRecentQueries, 17 | private val deleteRecentQuery: DeleteRecentQuery, 18 | ) : ViewModel() { 19 | 20 | private val homeEventChannel = Channel(Channel.CONFLATED) 21 | val homeEvent = homeEventChannel.receiveAsFlow() 22 | 23 | fun onButtonClick(query: String) = viewModelScope.launch { 24 | homeEventChannel.send(HomeEvent.NavigateToDefinition(query)) 25 | } 26 | 27 | fun onQuerySwiped(query: RecentQuery) = viewModelScope.launch { 28 | deleteRecentQuery(query) 29 | homeEventChannel.send(HomeEvent.ShowDeleteNotificationToast) 30 | } 31 | 32 | val recentQueries = getRecentQueries() 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/ui/home/adapters/RecentSearchesAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.ui.home.adapters 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.DiffUtil 6 | import androidx.recyclerview.widget.ListAdapter 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.ragvax.dictionary.databinding.ItemRecentSearchesBinding 9 | import com.ragvax.dictionary.domain.model.RecentQuery 10 | import java.util.* 11 | 12 | class RecentSearchesAdapter( 13 | private val listener: OnRecentSearchesItemClickListener, 14 | ) : ListAdapter(RecentSearchesDiffCallback()) { 15 | 16 | inner class ViewHolder( 17 | private val binding: ItemRecentSearchesBinding 18 | ) : RecyclerView.ViewHolder(binding.root) { 19 | 20 | init { 21 | binding.root.setOnClickListener { 22 | val position = adapterPosition 23 | if (position != RecyclerView.NO_POSITION) { 24 | val searchQuery = getItem(position) 25 | listener.onRecentSearchesItemClick(searchQuery.queryText) 26 | } 27 | } 28 | } 29 | fun bind(recentQuery: RecentQuery) { 30 | binding.tvSearchQuery.text = recentQuery.queryText.capitalize(Locale.ROOT) 31 | } 32 | } 33 | 34 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 35 | return ViewHolder( 36 | ItemRecentSearchesBinding.inflate( 37 | LayoutInflater.from(parent.context), 38 | parent, 39 | false 40 | ) 41 | ) 42 | } 43 | 44 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 45 | holder.bind(getItem(position)) 46 | } 47 | 48 | private class RecentSearchesDiffCallback : DiffUtil.ItemCallback() { 49 | override fun areItemsTheSame(oldItem: RecentQuery, newItem: RecentQuery): Boolean = 50 | oldItem.queryText == newItem.queryText 51 | 52 | override fun areContentsTheSame(oldItem: RecentQuery, newItem: RecentQuery): Boolean = 53 | oldItem == newItem 54 | } 55 | 56 | interface OnRecentSearchesItemClickListener { 57 | fun onRecentSearchesItemClick(query: String) 58 | } 59 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/utils/ContextExt.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.utils 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import android.view.View 6 | import android.view.inputmethod.InputMethodManager 7 | import androidx.fragment.app.Fragment 8 | 9 | fun Fragment.hideKeyboard() { 10 | view?.let { activity?.hideKeyboard(it) } 11 | } 12 | 13 | fun Activity.hideKeyboard() { 14 | hideKeyboard(currentFocus ?: View(this)) 15 | } 16 | 17 | fun Context.hideKeyboard(view: View) { 18 | val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager 19 | inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/utils/FlowObserverExt.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.utils 2 | 3 | import androidx.lifecycle.* 4 | import kotlinx.coroutines.Job 5 | import kotlinx.coroutines.flow.Flow 6 | import kotlinx.coroutines.flow.collect 7 | import kotlinx.coroutines.launch 8 | 9 | inline fun Flow.observeWithLifecycle( 10 | lifecycleOwner: LifecycleOwner, 11 | minActiveState: Lifecycle.State = Lifecycle.State.STARTED, 12 | noinline action: suspend (T) -> Unit 13 | ): Job { 14 | return lifecycleOwner.lifecycleScope.launch { 15 | flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState).collect(action) 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/utils/Mapper.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.utils 2 | 3 | interface Mapper -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/utils/Resource.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.utils 2 | 3 | sealed class Resource { 4 | data class Success(val data: T): Resource() 5 | data class Error(val title: String, val message: String): Resource() 6 | object Loading: Resource() 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/ragvax/dictionary/utils/ViewExt.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary.utils 2 | 3 | import android.content.Context 4 | import android.view.View 5 | 6 | fun View.show() { visibility = View.VISIBLE} 7 | 8 | fun View.hide() { visibility = View.GONE } 9 | 10 | fun Context.hideViews(vararg views: View) = views.forEach { it.visibility = View.GONE } 11 | 12 | fun Context.showViews(vararg views: View) = views.forEach { it.visibility = View.VISIBLE } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_search_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/text_input_layout_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/font/playfair_display_bold.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_definition.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 24 | 25 | 34 | 35 | 44 | 45 | 53 | 54 | 58 | 59 | 70 | 71 | 84 | 85 | 97 | 98 | 104 | 105 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 37 | 38 | 46 | 47 | 48 | 49 | 59 | 60 | 71 | 72 | 78 | 79 | 85 | 86 | 92 | 93 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_definition.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_meaning.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_recent_searches.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /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/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 16 | 17 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 29 | 30 | 34 | 35 | 42 | 43 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 61 | 62 | 67 | 68 | 69 | 74 | 75 | 80 | 81 | 82 | 88 | 89 | 94 | 95 | 96 | 101 | 102 | 107 | 108 | 109 | 115 | 116 | 121 | 122 | 123 | 128 | 129 | 134 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | 11 | 12 | #37383B 13 | #8E8E93 14 | #007AFF 15 | #FFFFFF 16 | #EFEFF4 17 | 18 | 19 | #FFFFFF 20 | #838389 21 | #0A84FF 22 | #000000 23 | #1c1c1f 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/font_certs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @array/com_google_android_gms_fonts_certs_dev 5 | @array/com_google_android_gms_fonts_certs_prod 6 | 7 | 8 | 9 | MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs= 10 | 11 | 12 | 13 | 14 | MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEzMzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtWLgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/preloaded_fonts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @font/playfair_display_bold 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Dictionary 3 | DEFINITIONS 4 | Oops! 5 | Something went wrong 6 | No definitions found 7 | Recent Searches 8 | Search for a word 9 | Night Mode 10 | Day Mode 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 29 | 30 | 34 | 35 | 42 | 43 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 61 | 62 | 67 | 68 | 69 | 74 | 75 | 78 | 79 | 80 | 85 | 86 | 91 | 92 | 93 | 99 | 100 | 105 | 106 | 107 | 112 | 113 | 118 | 119 | 120 | 126 | 127 | 132 | 133 | 134 | 139 | 140 | 145 | -------------------------------------------------------------------------------- /app/src/test/java/com/ragvax/dictionary/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.ragvax.dictionary 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /assets/DictionaryHeader.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/assets/DictionaryHeader.jpg -------------------------------------------------------------------------------- /assets/definition_day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/assets/definition_day.png -------------------------------------------------------------------------------- /assets/definition_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/assets/definition_night.png -------------------------------------------------------------------------------- /assets/home_day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/assets/home_day.png -------------------------------------------------------------------------------- /assets/home_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/assets/home_night.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext{ 4 | kotlin_version = "1.5.30" 5 | navigation_version = "2.3.4" 6 | hilt_version = "2.38.1" 7 | } 8 | repositories { 9 | google() 10 | mavenCentral() 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:7.0.2' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | 16 | classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version" 17 | classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" 18 | 19 | // NOTE: Do not place your application dependencies here; they belong 20 | // in the individual module build.gradle files 21 | } 22 | } 23 | 24 | allprojects { 25 | repositories { 26 | google() 27 | mavenCentral() 28 | } 29 | } 30 | 31 | task clean(type: Delete) { 32 | delete rootProject.buildDir 33 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ragvax/Dictionary/5be2903a40786f9899f9c7d730da69128421d024/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 07 18:39:46 SGT 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.2-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "Dictionary" --------------------------------------------------------------------------------