diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index be2253f..3953911 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -1,6 +1,11 @@ -name: Android Build +name: Android CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] -on: pull_request jobs: build: @@ -10,14 +15,26 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Set Up JDK + - name: ๐Ÿงฑ Set Up JDK uses: actions/setup-java@v1 with: - java-version: 1.8 - + java-version: 11 - - name: Run Tests + - name: ๐Ÿงช Run Tests run: ./gradlew test - - name: Build Project - run: ./gradlew assemble + - name: ๐Ÿ›  Build Project with Spotless Check + run: ./gradlew spotlessCheck assemble lintDebug --stacktrace + + - name: โณ Build with Gradle + run: ./gradlew build + + - name: ๐Ÿ— Build APK + run: bash ./gradlew assembleDebug --stacktrace + + - name: ๐Ÿš€ Upload APK ๐Ÿ“ฑ + uses: actions/upload-artifact@v2 + with: + name: app + path: app/build/outputs/apk/debug/app-debug.apk + retention-days: 3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 64dad7a..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: KT Lint - -on: pull_request - -jobs: - lint: - name: Lint Check ๐Ÿ•ต๐Ÿปโ€โ™‚๏ธ - runs-on: ubuntu-latest - - steps: - - name: Checkout Code ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป - uses: actions/checkout@v2 - - - name: Lint Code Base ๐Ÿงช - uses: docker://github/super-linter:v2.2.0 - env: - VALIDATE_ALL_CODEBASE: true - VALIDATE_MD: false - VALIDATE_XML: true - VALIDATE_KOTLIN: true diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..8560e44 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 1beb3fa..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * * - * * * MIT License - * * * - * * * Copyright (c) 2020 Spikey Sanju - * * * - * * * Permission is hereby granted, free of charge, to any person obtaining a copy - * * * of this software and associated documentation files (the "Software"), to deal - * * * in the Software without restriction, including without limitation the rights - * * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * * * copies of the Software, and to permit persons to whom the Software is - * * * furnished to do so, subject to the following conditions: - * * * - * * * The above copyright notice and this permission notice shall be included in all - * * * copies or substantial portions of the Software. - * * * - * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * * * SOFTWARE. - * * - * - * - */ - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'kotlin-kapt' -apply plugin: "androidx.navigation.safeargs.kotlin" -apply plugin: 'dagger.hilt.android.plugin' - - -android { - compileSdkVersion 31 - buildToolsVersion "29.0.3" - - defaultConfig { - applicationId "thecodemonks.org.nottzapp" - minSdkVersion 21 - targetSdkVersion 31 - versionCode 1 - versionName "1.3.3" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildFeatures { - viewBinding true - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - -} - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - jvmTarget = "1.8" - } - -} - -dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.6.0' - implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'androidx.constraintlayout:constraintlayout:2.1.1' - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' - - // Architectural Components - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" - - // Room - implementation "androidx.room:room-runtime:2.3.0" - kapt "androidx.room:room-compiler:2.3.0" - kapt "org.xerial:sqlite-jdbc:3.36.0.3" - - - // Kotlin Extensions and Coroutines support for Room - implementation "androidx.room:room-ktx:2.3.0" - - // Coroutines - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2-native-mt' - - // Coroutine Lifecycle Scopes - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" - implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" - - // activity & fragment ktx - implementation "androidx.fragment:fragment-ktx:1.3.6" - implementation "androidx.activity:activity-ktx:1.4.0-rc01" - implementation 'androidx.appcompat:appcompat:1.4.0-beta01' - - // Navigation Components - implementation "androidx.navigation:navigation-fragment-ktx:2.3.5" - implementation "androidx.navigation:navigation-ui-ktx:2.3.5" - - // material design - implementation 'com.google.android.material:material:1.4.0' - implementation "androidx.recyclerview:recyclerview:1.2.1" - - // Preference DataStore - implementation "androidx.datastore:datastore-preferences:1.0.0" - - // Lottie Animation Library - implementation "com.airbnb.android:lottie:4.2.0" - - // Hilt - implementation "com.google.dagger:hilt-android:2.39.1" - kapt "com.google.dagger:hilt-android-compiler:2.39.1" - annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0' - -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..d56498a --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,140 @@ +/* + * + * * + * * * MIT License + * * * + * * * Copyright (c) 2020 Spikey Sanju + * * * + * * * Permission is hereby granted, free of charge, to any person obtaining a copy + * * * of this software and associated documentation files (the "Software"), to deal + * * * in the Software without restriction, including without limitation the rights + * * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * * * copies of the Software, and to permit persons to whom the Software is + * * * furnished to do so, subject to the following conditions: + * * * + * * * The above copyright notice and this permission notice shall be included in all + * * * copies or substantial portions of the Software. + * * * + * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * * * SOFTWARE. + * * + * + * + */ + +plugins { + id("com.android.application") + id("kotlin-android") + id("kotlin-kapt") + id("androidx.navigation.safeargs.kotlin") + id("dagger.hilt.android.plugin") +} + +android { + compileSdk = 31 + buildToolsVersion = "30.0.3" + + defaultConfig { + applicationId = "thecodemonks.org.nottzapp" + minSdk = 21 + targetSdk = 31 + versionCode = 1 + versionName = "1.4.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + lint { + checkReleaseBuilds = false + abortOnError = true + } + + buildFeatures { + viewBinding = true + } + + buildTypes { + release { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.31") + implementation("androidx.core:core-ktx:1.7.0") + implementation("androidx.appcompat:appcompat:1.3.1") + implementation("com.google.android.material:material:1.4.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.1") + implementation("androidx.legacy:legacy-support-v4:1.0.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.3") + androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0") + + // Architectural Components + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1") + + // Room + implementation("androidx.room:room-runtime:2.3.0") + kapt("androidx.room:room-compiler:2.3.0") + kapt("org.xerial:sqlite-jdbc:3.36.0.3") + + // Kotlin Extensions and Coroutines support for Room + implementation("androidx.room:room-ktx:2.3.0") + + // Coroutines + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2-native-mt") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2-native-mt") + + // Coroutine Lifecycle Scopes + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1") + implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.3.1") + + // activity & fragment ktx + implementation("androidx.fragment:fragment-ktx:1.3.6") + implementation("androidx.activity:activity-ktx:1.4.0-rc01") + implementation("androidx.appcompat:appcompat:1.4.0-beta01") + + // Navigation Components + implementation("androidx.navigation:navigation-fragment-ktx:2.3.5") + implementation("androidx.navigation:navigation-ui-ktx:2.3.5") + + // material design + implementation("com.google.android.material:material:1.4.0") + implementation("androidx.recyclerview:recyclerview:1.2.1") + + // Preference DataStore + implementation("androidx.datastore:datastore-preferences:1.0.0") + + // Lottie Animation Library + implementation("com.airbnb.android:lottie:4.2.0") + + // Hilt + implementation("com.google.dagger:hilt-android:2.39.1") + kapt("com.google.dagger:hilt-android-compiler:2.39.1") + kapt("androidx.hilt:hilt-compiler:1.0.0") +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..2f9dc5a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,6 +1,6 @@ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. +# proguardFiles setting in build.gradle.kts. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html @@ -18,4 +18,4 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/java/thecodemonks/org/nottzapp/app/MainActivity.kt b/app/src/main/java/thecodemonks/org/nottzapp/app/MainActivity.kt index cac7826..252b43e 100644 --- a/app/src/main/java/thecodemonks/org/nottzapp/app/MainActivity.kt +++ b/app/src/main/java/thecodemonks/org/nottzapp/app/MainActivity.kt @@ -38,18 +38,20 @@ import androidx.navigation.ui.setupActionBarWithNavController import dagger.hilt.android.AndroidEntryPoint import thecodemonks.org.nottzapp.R import thecodemonks.org.nottzapp.databinding.ActivityMainBinding -import thecodemonks.org.nottzapp.db.NotesDatabase import thecodemonks.org.nottzapp.repo.NotesRepo import thecodemonks.org.nottzapp.ui.notes.NotesViewModel import thecodemonks.org.nottzapp.utils.factory.viewModelFactory +import javax.inject.Inject @AndroidEntryPoint class MainActivity : AppCompatActivity() { private lateinit var navHostFragment: NavHostFragment private lateinit var appBarConfiguration: AppBarConfiguration - private val newsRepository by lazy { NotesRepo(NotesDatabase(this)) } + + @Inject + lateinit var repo: NotesRepo private val viewModel: NotesViewModel by viewModels { - viewModelFactory { NotesViewModel(this.application, newsRepository) } + viewModelFactory { NotesViewModel(this.application, repo) } } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/thecodemonks/org/nottzapp/db/NotesDatabase.kt b/app/src/main/java/thecodemonks/org/nottzapp/db/NotesDatabase.kt index f30bbd7..7fc88f8 100644 --- a/app/src/main/java/thecodemonks/org/nottzapp/db/NotesDatabase.kt +++ b/app/src/main/java/thecodemonks/org/nottzapp/db/NotesDatabase.kt @@ -29,9 +29,7 @@ package thecodemonks.org.nottzapp.db -import android.content.Context import androidx.room.Database -import androidx.room.Room import androidx.room.RoomDatabase import thecodemonks.org.nottzapp.model.Notes @@ -43,23 +41,4 @@ import thecodemonks.org.nottzapp.model.Notes abstract class NotesDatabase : RoomDatabase() { abstract fun getNotesDao(): NotesDao - - companion object { - @Volatile - private var instance: NotesDatabase? = null - private val LOCK = Any() - - // Check for DB instance if not null then get or insert or else create new DB Instance - operator fun invoke(context: Context) = instance ?: synchronized(LOCK) { - - instance ?: createDatabase(context).also { instance = it } - } - - // create db instance - private fun createDatabase(context: Context) = Room.databaseBuilder( - context.applicationContext, - NotesDatabase::class.java, - "notes_db.db" - ).build() - } } diff --git a/app/src/main/java/thecodemonks/org/nottzapp/di/AppModule.kt b/app/src/main/java/thecodemonks/org/nottzapp/di/AppModule.kt index 5d390b1..281d82f 100644 --- a/app/src/main/java/thecodemonks/org/nottzapp/di/AppModule.kt +++ b/app/src/main/java/thecodemonks/org/nottzapp/di/AppModule.kt @@ -30,6 +30,7 @@ package thecodemonks.org.nottzapp.di import android.content.Context +import androidx.room.Room import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -37,6 +38,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import thecodemonks.org.nottzapp.datastore.UIModeDataStore import thecodemonks.org.nottzapp.datastore.UIModeImpl +import thecodemonks.org.nottzapp.db.NotesDao import thecodemonks.org.nottzapp.db.NotesDatabase import javax.inject.Singleton @@ -52,7 +54,14 @@ object AppModule { @Singleton @Provides - fun provideNoteDatabase(@ApplicationContext context: Context): NotesDatabase { - return NotesDatabase.invoke(context) - } + fun provideTaskDao(database: NotesDatabase): NotesDao = database.getNotesDao() + + @Singleton + @Provides + fun provideNoteDatabase(@ApplicationContext context: Context): NotesDatabase = + Room.databaseBuilder( + context, + NotesDatabase::class.java, + "notes_db.db" + ).fallbackToDestructiveMigration().build() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 401993f..6383f40 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,7 +28,7 @@ --> - Nottz App + Notes Title Type something... diff --git a/build.gradle b/build.gradle.kts similarity index 59% rename from build.gradle rename to build.gradle.kts index 70a658e..28f7c6f 100644 --- a/build.gradle +++ b/build.gradle.kts @@ -29,31 +29,56 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.5.31" + val kotlin_version by extra("1.5.31") + repositories { google() mavenCentral() } + dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5" - classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1' + classpath("com.android.tools.build:gradle:7.2.0-alpha03") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5") + classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1") } } - plugins { - id "org.jlleitschuh.gradle.ktlint" version "9.4.1" + id("com.diffplug.spotless") version ("5.14.0") } allprojects { + repositories { google() mavenCentral() } - apply plugin: "org.jlleitschuh.gradle.ktlint" + + apply { + plugin("com.diffplug.spotless") + } + + spotless { + + format("misc") { + target("**/*.gradle', '**/*.md', '**/.gitignore") + indentWithSpaces() + trimTrailingWhitespace() + endWithNewline() + } + + kotlin { + target("**/*.kt") + targetExclude("$buildDir/**/*.kt") + targetExclude("bin/**/*.kt") + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + ktlint("0.41.0").userData(mapOf("disabled_rules" to "no-wildcard-imports")) + } + } } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register(name = "type", type = Delete::class) { + delete(rootProject.buildDir) } diff --git a/gradle.properties b/gradle.properties index 4d15d01..f2634d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,32 @@ +# +# /* +# * +# * * MIT License +# * * +# * * Copyright (c) 2020 Spikey Sanju +# * * +# * * Permission is hereby granted, free of charge, to any person obtaining a copy +# * * of this software and associated documentation files (the "Software"), to deal +# * * in the Software without restriction, including without limitation the rights +# * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# * * copies of the Software, and to permit persons to whom the Software is +# * * furnished to do so, subject to the following conditions: +# * * +# * * The above copyright notice and this permission notice shall be included in all +# * * copies or substantial portions of the Software. +# * * +# * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# * * SOFTWARE. +# * +# */ +# +# + # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* @@ -18,4 +47,6 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +kotlin.daemon.jvmargs=--illegal-access=permit +kapt.use.worker.api=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e8c68df..c5e7e47 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -32,4 +32,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-rc-1-bin.zip