From efaa85cb49536eef6b4e53de97309c578cc6ad76 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sun, 4 Sep 2022 21:36:19 +0530 Subject: [PATCH] Improve modular (#221) * Improving module * refactor: modules * refactor: modules * bump sdk v * minor fixes * fix spotless --- app/build.gradle | 27 ++---------- .../keypass/ui/home/HomeFragment.kt | 4 +- .../keypass/ui/nav/NavigationModelItem.kt | 2 +- .../keypass}/utils/AnimationUtils.kt | 0 .../keypass/utils}/StringDiffUtil.kt | 2 +- common/build.gradle | 43 ++++++++++--------- keypasscompose/build.gradle | 12 ++---- .../keypasscompose/ExampleUnitTest.kt | 16 ------- 8 files changed, 33 insertions(+), 73 deletions(-) rename {common/src/main/java/com/yogeshpaliyal/common => app/src/main/java/com/yogeshpaliyal/keypass}/utils/AnimationUtils.kt (100%) rename {common/src/main/java/com/yogeshpaliyal/common/data => app/src/main/java/com/yogeshpaliyal/keypass/utils}/StringDiffUtil.kt (90%) delete mode 100644 keypasscompose/src/test/java/com/yogeshpaliyal/keypasscompose/ExampleUnitTest.kt diff --git a/app/build.gradle b/app/build.gradle index 0c66726a..7579db26 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,13 +13,12 @@ def appPackageId = 'com.yogeshpaliyal.keypass' android { - compileSdkVersion 31 - buildToolsVersion "30.0.3" + compileSdkVersion 32 defaultConfig { applicationId appPackageId minSdkVersion 22 - targetSdkVersion 31 + targetSdkVersion 32 versionCode 1407 versionName "1.4.7" @@ -74,25 +73,14 @@ android { dependencies { - implementation project(":common") + api project(":common") implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}" - implementation 'androidx.core:core-ktx:1.8.0' - implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'com.google.android.material:material:1.7.0-alpha02' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.preference:preference-ktx:1.2.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test:core-ktx:1.4.0' - androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - implementation ('androidx.appcompat:appcompat:1.4.1') - implementation "androidx.documentfile:documentfile:1.0.1" - // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // LiveData @@ -103,17 +91,12 @@ dependencies { implementation "androidx.navigation:navigation-ui-ktx:$navigation_version" - implementation "androidx.room:room-runtime:$room_version" - androidTestImplementation 'androidx.test:rules:1.4.0' kapt "androidx.room:room-compiler:$room_version" - implementation "androidx.room:room-ktx:$room_version" implementation 'com.yogeshpaliyal:universal-adapter:3.0.1' - implementation "androidx.biometric:biometric:1.1.0" - // dependency injection implementation("com.google.dagger:hilt-android:$hilt_version") kapt("com.google.dagger:hilt-android-compiler:$hilt_version") @@ -137,9 +120,5 @@ dependencies { // ...with Kotlin. kaptTest("com.google.dagger:hilt-android-compiler:$hilt_version") - implementation 'com.google.code.gson:gson:2.9.1' - - implementation "androidx.datastore:datastore-preferences:1.0.0" - } diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/ui/home/HomeFragment.kt b/app/src/main/java/com/yogeshpaliyal/keypass/ui/home/HomeFragment.kt index 3db4cce2..e3bc7018 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/ui/home/HomeFragment.kt @@ -7,9 +7,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.activity.viewModels import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.lifecycle.Observer import com.yogeshpaliyal.common.constants.AccountType import com.yogeshpaliyal.common.data.AccountModel @@ -35,7 +35,7 @@ class HomeFragment : Fragment() { private lateinit var binding: FragmentHomeBinding private val mViewModel by lazy { - requireActivity().viewModels().value + activityViewModels().value } private val mAdapter by lazy { diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/NavigationModelItem.kt b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/NavigationModelItem.kt index 4d52db3b..d794c76d 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/NavigationModelItem.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/NavigationModelItem.kt @@ -3,7 +3,7 @@ package com.yogeshpaliyal.keypass.ui.nav import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.recyclerview.widget.DiffUtil -import com.yogeshpaliyal.common.data.StringDiffUtil +import com.yogeshpaliyal.keypass.utils.StringDiffUtil /** * A sealed class which encapsulates all objects [NavigationAdapter] is able to display. diff --git a/common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt b/app/src/main/java/com/yogeshpaliyal/keypass/utils/AnimationUtils.kt similarity index 100% rename from common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt rename to app/src/main/java/com/yogeshpaliyal/keypass/utils/AnimationUtils.kt diff --git a/common/src/main/java/com/yogeshpaliyal/common/data/StringDiffUtil.kt b/app/src/main/java/com/yogeshpaliyal/keypass/utils/StringDiffUtil.kt similarity index 90% rename from common/src/main/java/com/yogeshpaliyal/common/data/StringDiffUtil.kt rename to app/src/main/java/com/yogeshpaliyal/keypass/utils/StringDiffUtil.kt index 5f153222..fa6dd23f 100644 --- a/common/src/main/java/com/yogeshpaliyal/common/data/StringDiffUtil.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/utils/StringDiffUtil.kt @@ -1,4 +1,4 @@ -package com.yogeshpaliyal.common.data +package com.yogeshpaliyal.keypass.utils import androidx.recyclerview.widget.DiffUtil diff --git a/common/build.gradle b/common/build.gradle index 1c398c4f..61074c77 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -7,11 +7,11 @@ plugins { } android { - compileSdk 31 + compileSdk 32 defaultConfig { minSdk 21 - targetSdk 31 + targetSdk 32 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -35,41 +35,44 @@ android { dependencies { - implementation 'androidx.core:core-ktx:1.8.0' - implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'com.google.android.material:material:1.7.0-alpha02' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - + api 'androidx.core:core-ktx:1.8.0' + api 'androidx.appcompat:appcompat:1.5.0' + testApi 'junit:junit:4.13.2' + androidTestApi 'androidx.test.ext:junit:1.1.3' + androidTestApi 'androidx.test.espresso:espresso-core:3.4.0' + androidTestApi 'androidx.test:core-ktx:1.4.0' + androidTestApi 'androidx.test.ext:junit-ktx:1.1.3' // apache common codec implementation "commons-codec:commons-codec:1.15" //Androidx Security implementation "androidx.security:security-crypto:1.1.0-alpha03" + api "androidx.documentfile:documentfile:1.0.1" - implementation "androidx.room:room-runtime:$room_version" - androidTestImplementation 'androidx.test:rules:1.4.0' + api "androidx.room:room-runtime:$room_version" + androidTestApi 'androidx.test:rules:1.4.0' kapt "androidx.room:room-compiler:$room_version" - implementation "androidx.room:room-ktx:$room_version" + api "androidx.room:room-ktx:$room_version" + + api 'com.google.android.material:material:1.7.0-rc01' // dependency injection - implementation("com.google.dagger:hilt-android:$hilt_version") + api("com.google.dagger:hilt-android:$hilt_version") kapt("com.google.dagger:hilt-android-compiler:$hilt_version") - implementation("androidx.hilt:hilt-work:1.0.0") + api("androidx.hilt:hilt-work:1.0.0") // When using Kotlin. kapt("androidx.hilt:hilt-compiler:1.0.0") - implementation "androidx.work:work-runtime-ktx:2.7.1" + api "androidx.work:work-runtime-ktx:2.7.1" + implementation 'com.google.code.gson:gson:2.9.0' - implementation 'com.google.code.gson:gson:2.9.1' + api 'com.google.code.gson:gson:2.9.0' - implementation "androidx.datastore:datastore-preferences:1.0.0" + api "androidx.datastore:datastore-preferences:1.0.0" + api "androidx.biometric:biometric:1.1.0" - -} \ No newline at end of file +} diff --git a/keypasscompose/build.gradle b/keypasscompose/build.gradle index 92f7ca1b..27ad6d21 100644 --- a/keypasscompose/build.gradle +++ b/keypasscompose/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdk 31 + compileSdk 32 defaultConfig { applicationId "com.yogeshpaliyal.keypasscompose" minSdk 21 - targetSdk 31 + targetSdk 32 versionCode 1 versionName "1.0" @@ -57,19 +57,13 @@ android { } dependencies { - implementation project(":common") + api project(":common") - implementation 'androidx.core:core-ktx:1.8.0' - implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'com.google.android.material:material:1.7.0-alpha02' implementation "androidx.compose.ui:ui:1.1.1" implementation "androidx.compose.material:material:1.1.1" implementation "androidx.compose.ui:ui-tooling-preview:1.1.1" implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' implementation 'androidx.activity:activity-compose:1.5.1' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.2.1" debugImplementation "androidx.compose.ui:ui-tooling:1.1.1" diff --git a/keypasscompose/src/test/java/com/yogeshpaliyal/keypasscompose/ExampleUnitTest.kt b/keypasscompose/src/test/java/com/yogeshpaliyal/keypasscompose/ExampleUnitTest.kt deleted file mode 100644 index 59cb9b28..00000000 --- a/keypasscompose/src/test/java/com/yogeshpaliyal/keypasscompose/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.yogeshpaliyal.keypasscompose - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -}