From 6f052609b82c64c68a873e5de93135a61e77863a Mon Sep 17 00:00:00 2001 From: Rajesh Hadiya Date: Fri, 9 Sep 2022 22:32:32 +0530 Subject: [PATCH 01/47] Test PR (#51) * Added database schema, functions and paging data UI handling (#15) * Adding CONTRIBUTING.md * Added CONTRIBUTING.md and squashed commits * Updated branch naming convention Updated branch naming convention with github-username * 1. Added database schema (entity) 2. Added database functions (dao) 3. Added how to fetch paging data 4. Added LazyColumn UI with paging data with different states like loading, success, error Signed-off-by: Rajesh Hadiya Signed-off-by: Rajesh Hadiya Co-authored-by: Hritik Kumar Singh * Added CODEOWNERS files (#33) * Adding CONTRIBUTING.md * Added CONTRIBUTING.md and squashed commits * Updated branch naming convention Updated branch naming convention with github-username * 1. Added database schema (entity) 2. Added database functions (dao) 3. Added how to fetch paging data 4. Added LazyColumn UI with paging data with different states like loading, success, error Signed-off-by: Rajesh Hadiya * Added CODEOWNERS files. (#19) * Adding CODEOWNERS files. Still needed to add the Default reviewer for the two teams. * Update CODEOWNERS * fix the validation issues on GitHub. * updated owners for all the branches. * updated the Wrong branch combinations. Signed-off-by: Rajesh Hadiya Co-authored-by: Hritik Kumar Singh Co-authored-by: Abhinav Suman * Create main.yml * Update main.yml * Update main.yml * Added PR template + Updated .gitignore files (#42) Added the PR Templates + .gitignore Signed-off-by: Rajesh Hadiya Co-authored-by: Hritik Kumar Singh Co-authored-by: Abhinav Suman --- .github/workflows/main.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c0299dc --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,40 @@ +# This is a workflow to verify that Android build is successful. + +name: Android Build test + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master", "dev", "branch_hadiyarajesh", "branch_loveleen", "branch_geet", "branch_siddu"] + pull_request: + branches: [ "master", "dev", "branch_hadiyarajesh", "branch_loveleen", "branch_geet", "branch_siddu"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build_project" + build_project: + name: Build NoteX Android project + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + - name: set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 11 + + # Provide required permission to gradle + - name: Change gradle wrapper permissions + run: chmod +x ./gradlew + + # Build Android project + - name: Build Project + run: ./gradlew assemble From e7cde5967ca014ff90a6a2a9240f651acc75dc28 Mon Sep 17 00:00:00 2001 From: Rajesh Hadiya Date: Fri, 9 Sep 2022 22:48:46 +0530 Subject: [PATCH 02/47] Revert "Test PR (#51)" (#53) This reverts commit 6f052609b82c64c68a873e5de93135a61e77863a. --- .github/workflows/main.yml | 40 -------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index c0299dc..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This is a workflow to verify that Android build is successful. - -name: Android Build test - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the "master" branch - push: - branches: [ "master", "dev", "branch_hadiyarajesh", "branch_loveleen", "branch_geet", "branch_siddu"] - pull_request: - branches: [ "master", "dev", "branch_hadiyarajesh", "branch_loveleen", "branch_geet", "branch_siddu"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build_project" - build_project: - name: Build NoteX Android project - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - name: set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 11 - - # Provide required permission to gradle - - name: Change gradle wrapper permissions - run: chmod +x ./gradlew - - # Build Android project - - name: Build Project - run: ./gradlew assemble From 2017fe12f1052c12fa1d9fd801625087387a136a Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Sat, 10 Sep 2022 13:57:24 +0530 Subject: [PATCH 03/47] Revert "Test PR (#51)" (#53) (#54) This reverts commit 6f052609b82c64c68a873e5de93135a61e77863a. Co-authored-by: Rajesh Hadiya From 7d3e5fdb452c71372537f01a5f7c5f143edffa67 Mon Sep 17 00:00:00 2001 From: Rajesh Hadiya Date: Sat, 10 Sep 2022 17:02:11 +0530 Subject: [PATCH 04/47] Branch hadiyarajesh (#55) * Added new line in Constants.kt * Note card ui component added which will be inflated in lazy column to show all notes (#35) * Added CODEOWNERS files (#33) * Adding CONTRIBUTING.md * Added CONTRIBUTING.md and squashed commits * Updated branch naming convention Updated branch naming convention with github-username * 1. Added database schema (entity) 2. Added database functions (dao) 3. Added how to fetch paging data 4. Added LazyColumn UI with paging data with different states like loading, success, error Signed-off-by: Rajesh Hadiya * Added CODEOWNERS files. (#19) * Adding CODEOWNERS files. Still needed to add the Default reviewer for the two teams. * Update CODEOWNERS * fix the validation issues on GitHub. * updated owners for all the branches. * updated the Wrong branch combinations. Signed-off-by: Rajesh Hadiya Co-authored-by: Hritik Kumar Singh Co-authored-by: Abhinav Suman * NoteCardView for all notes ui made * Create main.yml * Update main.yml * Update main.yml * Some improvements done generalised the code * Some ui improvements and code to inflate all card views added Signed-off-by: Rajesh Hadiya Co-authored-by: Rajesh Hadiya Co-authored-by: Hritik Kumar Singh Co-authored-by: Abhinav Suman Co-authored-by: Rajesh Hadiya Signed-off-by: Rajesh Hadiya Co-authored-by: Swapnil bhojwani <53923373+swapnil20711@users.noreply.github.com> Co-authored-by: Hritik Kumar Singh Co-authored-by: Abhinav Suman --- .idea/.gitignore | 3 - .../database/converter/InstantConverter.kt | 14 +++ .../notex/ui/component/AllNotesComponents.kt | 88 +++++++++++++++++++ .../notex/ui/component/TextComposables.kt | 24 +++++ .../hadiyarajesh/notex/ui/note/NotesScreen.kt | 11 +-- .../hadiyarajesh/notex/utility/Constants.kt | 2 +- 6 files changed, 133 insertions(+), 9 deletions(-) delete mode 100644 .idea/.gitignore create mode 100644 app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt create mode 100644 app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt b/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt index a2aa463..36bdc44 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt @@ -2,6 +2,10 @@ package com.hadiyarajesh.notex.database.converter import androidx.room.TypeConverter import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter object InstantConverter { @JvmStatic @@ -11,4 +15,14 @@ object InstantConverter { @JvmStatic @TypeConverter fun toInstant(value: String?): Instant? = value?.let { Instant.parse(value) } + + + @JvmStatic + @TypeConverter + fun getLocalDate(instant: Instant): LocalDate { + val localDateTime: LocalDateTime = + LocalDateTime.ofInstant(instant, ZoneOffset.systemDefault()) + val formatter = DateTimeFormatter.ofPattern("yyyyMMdd") + return LocalDate.parse(localDateTime.format(formatter), formatter) + } } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt new file mode 100644 index 0000000..a175825 --- /dev/null +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt @@ -0,0 +1,88 @@ +package com.hadiyarajesh.notex.ui.component + +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Divider +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.hadiyarajesh.notex.database.converter.InstantConverter +import com.hadiyarajesh.notex.database.entity.Note +import java.time.Instant + +@Composable +fun NoteCard(note: Note) { + Card( + elevation = CardDefaults.cardElevation(), + modifier = Modifier + .fillMaxWidth() + .padding(start = 16.dp, end = 16.dp, top = 16.dp), + shape = RoundedCornerShape(16.dp) + ) { + Column( + verticalArrangement = Arrangement.Center, + modifier = Modifier.padding(16.dp) + ) { + note.title?.let { + TextSemiBold( + content = it, + null, + MaterialTheme.typography.titleLarge, Color.Black + ) + } + Row( + Modifier + .fillMaxWidth() + .padding(top = 16.dp) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(IntrinsicSize.Min) + .weight(1f) + ) { + TextSemiBold( + content = "Succeed", Modifier.padding(end = 8.dp) + ) + Divider( + color = Color.Gray, modifier = Modifier + .fillMaxHeight() + .width(1.dp) + ) + TextSemiBold(content = "Goal", Modifier.padding(start = 8.dp)) + } + Row( + Modifier + .fillMaxWidth() + .weight(1f), horizontalArrangement = Arrangement.End + ) { + TextSemiBold( + content = InstantConverter.getLocalDate(note.createdOn).toString() + ) + } + + } + } + } + +} + +@Preview +@Composable +fun NoteCardPrev() { + NoteCard( + Note( + noteId = 12345, + title = "Note title", + content = "Note content", + archived = false, + createdOn = Instant.now(), + updatedOn = Instant.now() + ) + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt new file mode 100644 index 0000000..82a9c45 --- /dev/null +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt @@ -0,0 +1,24 @@ +package com.hadiyarajesh.notex.ui.component + +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight + + +@Composable +fun TextSemiBold( + content: String, + modifier: Modifier? = Modifier, + textStyle: TextStyle? = null, + color: Color? = null +) { + Text( + text = content, fontWeight = FontWeight.SemiBold, + color = color ?: Color.Gray, + modifier = modifier ?: Modifier, + style = textStyle ?: TextStyle.Default + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt index f85f375..2f67bf1 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt @@ -24,6 +24,7 @@ import com.hadiyarajesh.notex.R import com.hadiyarajesh.notex.database.entity.Note import com.hadiyarajesh.notex.ui.component.EmptyView import com.hadiyarajesh.notex.ui.component.LoadingProgressBar +import com.hadiyarajesh.notex.ui.component.NoteCard import com.hadiyarajesh.notex.ui.component.RetryItem import java.time.Instant @@ -43,7 +44,10 @@ fun NotesScreen( .fillMaxSize() .padding(innerPadding), horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center + verticalArrangement = if (notesViewModel.notes == null) { + Arrangement.Center + } else + Arrangement.Top ) { AllNotesView( notes = notes, @@ -64,10 +68,7 @@ private fun AllNotesView( LazyColumn(modifier = modifier) { items(notes) { item -> item?.let { note -> - NoteItem( - note = note, - onClick = onClick - ) + NoteCard(note = note) } } diff --git a/app/src/main/java/com/hadiyarajesh/notex/utility/Constants.kt b/app/src/main/java/com/hadiyarajesh/notex/utility/Constants.kt index 3513199..501e093 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/utility/Constants.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/utility/Constants.kt @@ -6,4 +6,4 @@ object Constants { } } -const val TAG = Constants.App.APP_NAME \ No newline at end of file +const val TAG = Constants.App.APP_NAME From 33c4fe02f304e49c229fff257897060d032e7c4e Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Sun, 2 Oct 2022 02:03:42 +0530 Subject: [PATCH 05/47] Base Integration of Detekt Analytics tool done. --- .../notex/ExampleInstrumentedTest.kt | 4 +- build.gradle.kts | 56 +- config/detekt/detekt-baseline.xml | 67 ++ config/detekt/detekt.yml | 733 ++++++++++++++++++ gradlew | 0 5 files changed, 857 insertions(+), 3 deletions(-) create mode 100644 config/detekt/detekt-baseline.xml create mode 100644 config/detekt/detekt.yml mode change 100644 => 100755 gradlew diff --git a/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt index 4824663..90e2355 100644 --- a/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt @@ -6,7 +6,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* +import org.junit.Assert.assertEquals /** * Instrumented test, which will execute on an Android device. @@ -21,4 +21,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.hadiyarajesh.notex", appContext.packageName) } -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index 1c1e440..3c765aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,70 @@ +import io.gitlab.arturbosch.detekt.Detekt + buildscript { val hiltVersion by extra("2.42") dependencies { classpath("com.google.dagger:hilt-android-gradle-plugin:$hiltVersion") + classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.22.0-RC1") } -}// Top-level build file where you can add configuration options common to all sub-projects/modules. +} + +// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "7.2.2" apply false id("com.android.library") version "7.2.2" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false + id("io.gitlab.arturbosch.detekt") version "1.22.0-RC1" +// id("org.jlleitschuh.gradle.ktlint") version "10.2.1" +} + +allprojects { +// apply(plugin = "org.jlleitschuh.gradle.ktlint") + apply(plugin = "io.gitlab.arturbosch.detekt") + configureDetekt() +} + +configureDetekt() +fun Project.configureDetekt() { + tasks.withType { + jvmTarget = JavaVersion.VERSION_1_8.toString() + setSource(files(projectDir)) + parallel = true + baseline.set(file(path = "${rootProject.projectDir}/config/detekt/detekt-baseline.xml")) + autoCorrect = true + reports { + xml.required.set(true) + html.required.set(false) + txt.required.set(false) + sarif.required.set(false) + } + } } tasks.register("clean", Delete::class) { delete(rootProject.buildDir) } + +/*fun Project.configureKtLint() { + this.configure { + version.set("0.45.2") + android.set(true) + outputToConsole.set(true) + ignoreFailures.set(true) + enableExperimentalRules.set(true) + disabledRules.set(ktlintDisabledChecks) + reporters { + reporter(ReporterType.CHECKSTYLE) + } + } +} + +val ktlintDisabledChecks = setOf( + "unused-imports", + "final-newline", + "max-line-length", + "experimental:argument-list-wrapping", + "no-wildcard-imports", + "experimental:trailing-comma", + "experimental:comment-wrapping" +)*/ diff --git a/config/detekt/detekt-baseline.xml b/config/detekt/detekt-baseline.xml new file mode 100644 index 0000000..3dfaf4a --- /dev/null +++ b/config/detekt/detekt-baseline.xml @@ -0,0 +1,67 @@ + + + + + EmptyClassBlock:NoteApi.kt$NoteApi${ } + FunctionNaming:AddNoteScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun AddNoteScreen( navController: NavController ) + FunctionNaming:AllNotesComponents.kt$@Composable fun NoteCard(note: Note) + FunctionNaming:AllNotesComponents.kt$@Preview @Composable fun NoteCardPrev() + FunctionNaming:NoteXApp.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun NoteXApp() + FunctionNaming:NoteXNavigation.kt$@Composable fun MainBottomBar( navController: NavController, items: List<Screens>, onFABClick: () -> Unit ) + FunctionNaming:NoteXNavigation.kt$@Composable fun NoteXNavigation( modifier: Modifier = Modifier, navController: NavHostController, bottomBarState: MutableState<Boolean> ) + FunctionNaming:NotesScreen.kt$@Composable private fun AllNotesView( modifier: Modifier = Modifier, notes: LazyPagingItems<Note>, onClick: (Note) -> Unit, ) + FunctionNaming:NotesScreen.kt$@Composable private fun NoteItem( modifier: Modifier = Modifier, note: Note, onClick: (Note) -> Unit, ) + FunctionNaming:NotesScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun NotesScreen( navController: NavController, notesViewModel: NotesViewModel ) + FunctionNaming:NotesScreen.kt$@Preview @Composable fun NoteItemPreview() + FunctionNaming:Other.kt$@Composable fun EmptyView( modifier: Modifier = Modifier, text: String ) + FunctionNaming:Other.kt$@Composable fun ErrorText( modifier: Modifier = Modifier, text: String, color: Color = MaterialTheme.colorScheme.error, style: TextStyle = MaterialTheme.typography.labelMedium ) + FunctionNaming:Other.kt$@Composable fun HorizontalSpacer(size: Int) + FunctionNaming:Other.kt$@Composable fun ImageItem( modifier: Modifier = Modifier, data: Any?, crossfadeValue: Int = 300, contentDescription: String? = null, contentScale: ContentScale = ContentScale.Crop, transformation: Transformation? = null, ) + FunctionNaming:Other.kt$@Composable fun LoadingProgressBar( modifier: Modifier = Modifier, size: Dp = 40.dp, color: Color = MaterialTheme.colorScheme.primary, strokeWidth: Dp = 4.dp ) + FunctionNaming:Other.kt$@Composable fun RetryItem( modifier: Modifier = Modifier, onRetryClick: () -> Unit ) + FunctionNaming:Other.kt$@Composable fun SubComposeImageItem( modifier: Modifier = Modifier, data: Any?, crossfadeValue: Int = 300, contentDescription: String? = null, contentScale: ContentScale = ContentScale.Crop, transformation: Transformation? = null, ) + FunctionNaming:Other.kt$@Composable fun VerticalSpacer(size: Int) + FunctionNaming:RemindersScreen.kt$@Composable private fun AllRemindersView( modifier: Modifier = Modifier, reminders: LazyPagingItems<Reminder>, onClick: (Reminder) -> Unit, ) + FunctionNaming:RemindersScreen.kt$@Composable private fun ReminderItem( modifier: Modifier = Modifier, reminder: Reminder, onClick: (Reminder) -> Unit, ) + FunctionNaming:RemindersScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun RemindersScreen( navController: NavController, remindersViewModel: RemindersViewModel ) + FunctionNaming:TextComposables.kt$@Composable fun TextSemiBold( content: String, modifier: Modifier? = Modifier, textStyle: TextStyle? = null, color: Color? = null ) + FunctionNaming:Theme.kt$@Composable fun NoteXTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit ) + LongParameterList:Other.kt$( modifier: Modifier = Modifier, data: Any?, crossfadeValue: Int = 300, contentDescription: String? = null, contentScale: ContentScale = ContentScale.Crop, transformation: Transformation? = null, ) + MagicNumber:Color.kt$0xFF625b71 + MagicNumber:Color.kt$0xFF6650a4 + MagicNumber:Color.kt$0xFF7D5260 + MagicNumber:Color.kt$0xFFCCC2DC + MagicNumber:Color.kt$0xFFD0BCFF + MagicNumber:Color.kt$0xFFEFB8C8 + MatchingDeclarationName:Scope.kt$ApplicationScope + MaxLineLength:FolderDao.kt$FolderDao$* This method requires Room to run two queries, so add the @Transaction annotation to this method to ensure that the whole operation is performed atomically. + MaxLineLength:NotesScreen.kt$loadState.refresh is LoadState.NotLoading && loadState.append.endOfPaginationReached && notes.itemCount < 1 + MaxLineLength:RemindersScreen.kt$loadState.refresh is LoadState.NotLoading && loadState.append.endOfPaginationReached && reminders.itemCount < 1 + NewLineAtEndOfFile:AllNotesComponents.kt$com.hadiyarajesh.notex.ui.component.AllNotesComponents.kt + NewLineAtEndOfFile:Color.kt$com.hadiyarajesh.notex.ui.theme.Color.kt + NewLineAtEndOfFile:ExampleUnitTest.kt$com.hadiyarajesh.notex.ExampleUnitTest.kt + NewLineAtEndOfFile:Screens.kt$com.hadiyarajesh.notex.ui.navigation.Screens.kt + NewLineAtEndOfFile:TextComposables.kt$com.hadiyarajesh.notex.ui.component.TextComposables.kt + NewLineAtEndOfFile:Type.kt$com.hadiyarajesh.notex.ui.theme.Type.kt + TooManyFunctions:NoteDao.kt$NoteDao + UnusedPrivateMember:AddNoteScreen.kt$navController: NavController + UnusedPrivateMember:NotesScreen.kt$navController: NavController + UnusedPrivateMember:NotesScreen.kt$onClick: (Note) -> Unit + UnusedPrivateMember:NotesScreen.kt$val context = LocalContext.current + UnusedPrivateMember:NotesScreen.kt$val scope = rememberCoroutineScope() + UnusedPrivateMember:RemindersScreen.kt$navController: NavController + UnusedPrivateMember:RemindersScreen.kt$onClick: (Reminder) -> Unit + UnusedPrivateMember:RemindersScreen.kt$val context = LocalContext.current + UnusedPrivateMember:RemindersScreen.kt$val scope = rememberCoroutineScope() + WildcardImport:AllNotesComponents.kt$import androidx.compose.foundation.layout.* + WildcardImport:ExampleUnitTest.kt$import org.junit.Assert.* + WildcardImport:FolderDao.kt$import androidx.room.* + WildcardImport:InstantAdapter.kt$import com.squareup.moshi.* + WildcardImport:NoteDao.kt$import androidx.room.* + WildcardImport:NotesScreen.kt$import androidx.compose.foundation.layout.* + WildcardImport:Other.kt$import androidx.compose.foundation.layout.* + WildcardImport:ReminderDao.kt$import androidx.room.* + WildcardImport:RemindersScreen.kt$import androidx.compose.foundation.layout.* + WildcardImport:Theme.kt$import androidx.compose.material3.* + + diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml new file mode 100644 index 0000000..764ba81 --- /dev/null +++ b/config/detekt/detekt.yml @@ -0,0 +1,733 @@ +build: + maxIssues: 0 + excludeCorrectable: false + weights: + # complexity: 2 + # LongParameterList: 1 + # style: 1 + # comments: 1 + +config: + validation: true + warningsAsErrors: false + checkExhaustiveness: false + # when writing own rules with new properties, exclude the property path e.g.: 'my_rule_set,.*>.*>[my_property]' + excludes: '' + +processors: + active: true + exclude: + - 'DetektProgressListener' + # - 'KtFileCountProcessor' + # - 'PackageCountProcessor' + # - 'ClassCountProcessor' + # - 'FunctionCountProcessor' + # - 'PropertyCountProcessor' + # - 'ProjectComplexityProcessor' + # - 'ProjectCognitiveComplexityProcessor' + # - 'ProjectLLOCProcessor' + # - 'ProjectCLOCProcessor' + # - 'ProjectLOCProcessor' + # - 'ProjectSLOCProcessor' + # - 'LicenseHeaderLoaderExtension' + +console-reports: + active: true + exclude: + - 'ProjectStatisticsReport' + - 'ComplexityReport' + - 'NotificationReport' + - 'FindingsReport' + - 'FileBasedFindingsReport' + # - 'LiteFindingsReport' + +output-reports: + active: true + exclude: + # - 'TxtOutputReport' + # - 'XmlOutputReport' + # - 'HtmlOutputReport' + # - 'MdOutputReport' + +comments: + active: true + AbsentOrWrongFileLicense: + active: false + licenseTemplateFile: 'license.template' + licenseTemplateIsRegex: false + CommentOverPrivateFunction: + active: false + CommentOverPrivateProperty: + active: false + DeprecatedBlockTag: + active: false + EndOfSentenceFormat: + active: false + endOfSentenceFormat: '([.?!][ \t\n\r\f<])|([.?!:]$)' + KDocReferencesNonPublicProperty: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + OutdatedDocumentation: + active: false + matchTypeParameters: true + matchDeclarationsOrder: true + allowParamOnConstructorProperties: false + UndocumentedPublicClass: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + searchInNestedClass: true + searchInInnerClass: true + searchInInnerObject: true + searchInInnerInterface: true + searchInProtectedClass: false + UndocumentedPublicFunction: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedFunction: false + UndocumentedPublicProperty: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedProperty: false + +complexity: + active: true + ComplexCondition: + active: true + threshold: 4 + ComplexInterface: + active: false + threshold: 10 + includeStaticDeclarations: false + includePrivateDeclarations: false + ignoreOverloaded: false + ComplexMethod: + active: true + threshold: 15 + ignoreSingleWhenExpression: false + ignoreSimpleWhenEntries: false + ignoreNestingFunctions: false + nestingFunctions: + - 'also' + - 'apply' + - 'forEach' + - 'isNotNull' + - 'ifNull' + - 'let' + - 'run' + - 'use' + - 'with' + LabeledExpression: + active: false + ignoredLabels: [] + LargeClass: + active: true + threshold: 600 + LongMethod: + active: true + threshold: 60 + LongParameterList: + active: true + functionThreshold: 6 + constructorThreshold: 7 + ignoreDefaultParameters: false + ignoreDataClasses: true + ignoreAnnotatedParameter: [] + MethodOverloading: + active: false + threshold: 6 + NamedArguments: + active: false + threshold: 3 + ignoreArgumentsMatchingNames: false + NestedBlockDepth: + active: true + threshold: 4 + NestedScopeFunctions: + active: false + threshold: 1 + functions: + - 'kotlin.apply' + - 'kotlin.run' + - 'kotlin.with' + - 'kotlin.let' + - 'kotlin.also' + ReplaceSafeCallChainWithRun: + active: false + StringLiteralDuplication: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + threshold: 3 + ignoreAnnotation: true + excludeStringsWithLessThan5Characters: true + ignoreStringsRegex: '$^' + TooManyFunctions: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + thresholdInFiles: 11 + thresholdInClasses: 11 + thresholdInInterfaces: 11 + thresholdInObjects: 11 + thresholdInEnums: 11 + ignoreDeprecated: false + ignorePrivate: false + ignoreOverridden: false + +coroutines: + active: true + GlobalCoroutineUsage: + active: false + InjectDispatcher: + active: true + dispatcherNames: + - 'IO' + - 'Default' + - 'Unconfined' + RedundantSuspendModifier: + active: true + SleepInsteadOfDelay: + active: true + SuspendFunWithCoroutineScopeReceiver: + active: false + SuspendFunWithFlowReturnType: + active: true + +empty-blocks: + active: true + EmptyCatchBlock: + active: true + allowedExceptionNameRegex: '_|(ignore|expected).*' + EmptyClassBlock: + active: true + EmptyDefaultConstructor: + active: true + EmptyDoWhileBlock: + active: true + EmptyElseBlock: + active: true + EmptyFinallyBlock: + active: true + EmptyForBlock: + active: true + EmptyFunctionBlock: + active: true + ignoreOverridden: false + EmptyIfBlock: + active: true + EmptyInitBlock: + active: true + EmptyKtFile: + active: true + EmptySecondaryConstructor: + active: true + EmptyTryBlock: + active: true + EmptyWhenBlock: + active: true + EmptyWhileBlock: + active: true + +exceptions: + active: true + ExceptionRaisedInUnexpectedLocation: + active: true + methodNames: + - 'equals' + - 'finalize' + - 'hashCode' + - 'toString' + InstanceOfCheckForException: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + NotImplementedDeclaration: + active: false + ObjectExtendsThrowable: + active: false + PrintStackTrace: + active: true + RethrowCaughtException: + active: true + ReturnFromFinally: + active: true + ignoreLabeled: false + SwallowedException: + active: true + ignoredExceptionTypes: + - 'InterruptedException' + - 'MalformedURLException' + - 'NumberFormatException' + - 'ParseException' + allowedExceptionNameRegex: '_|(ignore|expected).*' + ThrowingExceptionFromFinally: + active: true + ThrowingExceptionInMain: + active: false + ThrowingExceptionsWithoutMessageOrCause: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + exceptions: + - 'ArrayIndexOutOfBoundsException' + - 'Exception' + - 'IllegalArgumentException' + - 'IllegalMonitorStateException' + - 'IllegalStateException' + - 'IndexOutOfBoundsException' + - 'NullPointerException' + - 'RuntimeException' + - 'Throwable' + ThrowingNewInstanceOfSameException: + active: true + TooGenericExceptionCaught: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + exceptionNames: + - 'ArrayIndexOutOfBoundsException' + - 'Error' + - 'Exception' + - 'IllegalMonitorStateException' + - 'IndexOutOfBoundsException' + - 'NullPointerException' + - 'RuntimeException' + - 'Throwable' + allowedExceptionNameRegex: '_|(ignore|expected).*' + TooGenericExceptionThrown: + active: true + exceptionNames: + - 'Error' + - 'Exception' + - 'RuntimeException' + - 'Throwable' + +naming: + active: true + BooleanPropertyNaming: + active: false + allowedPattern: '^(is|has|are)' + ignoreOverridden: true + ClassNaming: + active: true + classPattern: '[A-Z][a-zA-Z0-9]*' + ConstructorParameterNaming: + active: true + parameterPattern: '[a-z][A-Za-z0-9]*' + privateParameterPattern: '[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + EnumNaming: + active: true + enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' + ForbiddenClassName: + active: false + forbiddenName: [] + FunctionMaxLength: + active: false + maximumFunctionNameLength: 30 + FunctionMinLength: + active: false + minimumFunctionNameLength: 3 + FunctionNaming: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + functionPattern: '[a-z][a-zA-Z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + FunctionParameterNaming: + active: true + parameterPattern: '[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + InvalidPackageDeclaration: + active: true + rootPackage: '' + requireRootInDeclaration: false + LambdaParameterNaming: + active: false + parameterPattern: '[a-z][A-Za-z0-9]*|_' + MatchingDeclarationName: + active: true + mustBeFirst: true + MemberNameEqualsClassName: + active: true + ignoreOverridden: true + NoNameShadowing: + active: true + NonBooleanPropertyPrefixedWithIs: + active: false + ObjectPropertyNaming: + active: true + constantPattern: '[A-Za-z][_A-Za-z0-9]*' + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*' + PackageNaming: + active: true + packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' + TopLevelPropertyNaming: + active: true + constantPattern: '[A-Z][_A-Z0-9]*' + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' + VariableMaxLength: + active: false + maximumVariableNameLength: 64 + VariableMinLength: + active: false + minimumVariableNameLength: 1 + VariableNaming: + active: true + variablePattern: '[a-z][A-Za-z0-9]*' + privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + ignoreOverridden: true + +performance: + active: true + ArrayPrimitive: + active: true + CouldBeSequence: + active: false + threshold: 3 + ForEachOnRange: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + SpreadOperator: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + UnnecessaryPartOfBinaryExpression: + active: false + UnnecessaryTemporaryInstantiation: + active: true + +potential-bugs: + active: true + AvoidReferentialEquality: + active: true + forbiddenTypePatterns: + - 'kotlin.String' + CastToNullableType: + active: false + Deprecation: + active: false + DontDowncastCollectionTypes: + active: false + DoubleMutabilityForCollection: + active: true + mutableTypes: + - 'kotlin.collections.MutableList' + - 'kotlin.collections.MutableMap' + - 'kotlin.collections.MutableSet' + - 'java.util.ArrayList' + - 'java.util.LinkedHashSet' + - 'java.util.HashSet' + - 'java.util.LinkedHashMap' + - 'java.util.HashMap' + DuplicateCaseInWhenExpression: + active: true + ElseCaseInsteadOfExhaustiveWhen: + active: false + EqualsAlwaysReturnsTrueOrFalse: + active: true + EqualsWithHashCodeExist: + active: true + ExitOutsideMain: + active: false + ExplicitGarbageCollectionCall: + active: true + HasPlatformType: + active: true + IgnoredReturnValue: + active: true + restrictToConfig: true + returnValueAnnotations: + - '*.CheckResult' + - '*.CheckReturnValue' + ignoreReturnValueAnnotations: + - '*.CanIgnoreReturnValue' + returnValueTypes: + - 'kotlin.sequences.Sequence' + - 'kotlinx.coroutines.flow.*Flow' + - 'java.util.stream.*Stream' + ignoreFunctionCall: [] + ImplicitDefaultLocale: + active: true + ImplicitUnitReturnType: + active: false + allowExplicitReturnType: true + InvalidRange: + active: true + IteratorHasNextCallsNextMethod: + active: true + IteratorNotThrowingNoSuchElementException: + active: true + LateinitUsage: + active: false + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + ignoreOnClassesPattern: '' + MapGetWithNotNullAssertionOperator: + active: true + MissingPackageDeclaration: + active: false + excludes: ['**/*.kts'] + MissingWhenCase: + active: true + allowElseExpression: true + NullCheckOnMutableProperty: + active: false + NullableToStringCall: + active: false + RedundantElseInWhen: + active: true + UnconditionalJumpStatementInLoop: + active: false + UnnecessaryNotNullOperator: + active: true + UnnecessarySafeCall: + active: true + UnreachableCatchBlock: + active: true + UnreachableCode: + active: true + UnsafeCallOnNullableType: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + UnsafeCast: + active: true + UnusedUnaryOperator: + active: true + UselessPostfixExpression: + active: true + WrongEqualsTypeParameter: + active: true + +style: + active: true + CanBeNonNullable: + active: false + CascadingCallWrapping: + active: false + includeElvis: true + ClassOrdering: + active: false + CollapsibleIfStatements: + active: false + DataClassContainsFunctions: + active: false + conversionFunctionPrefix: + - 'to' + DataClassShouldBeImmutable: + active: false + DestructuringDeclarationWithTooManyEntries: + active: true + maxDestructuringEntries: 3 + EqualsNullCall: + active: true + EqualsOnSignatureLine: + active: false + ExplicitCollectionElementAccessMethod: + active: false + ExplicitItLambdaParameter: + active: true + ExpressionBodySyntax: + active: false + includeLineWrapping: false + ForbiddenComment: + active: true + values: + - 'FIXME:' + - 'STOPSHIP:' + - 'TODO:' + allowedPatterns: '' + customMessage: '' + ForbiddenImport: + active: false + imports: [] + forbiddenPatterns: '' + ForbiddenMethodCall: + active: false + methods: + - reason: 'print does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.print' + - reason: 'println does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.println' + ForbiddenPublicDataClass: + active: true + excludes: ['**'] + ignorePackages: + - '*.internal' + - '*.internal.*' + ForbiddenSuppress: + active: false + rules: [] + ForbiddenVoid: + active: true + ignoreOverridden: false + ignoreUsageInGenerics: false + FunctionOnlyReturningConstant: + active: true + ignoreOverridableFunction: true + ignoreActualFunction: true + excludedFunctions: [] + LibraryCodeMustSpecifyReturnType: + active: true + excludes: ['**'] + LibraryEntitiesShouldNotBePublic: + active: true + excludes: ['**'] + LoopWithTooManyJumpStatements: + active: true + maxJumpCount: 1 + MagicNumber: + active: true + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts'] + ignoreNumbers: + - '-1' + - '0' + - '1' + - '2' + ignoreHashCodeFunction: true + ignorePropertyDeclaration: false + ignoreLocalVariableDeclaration: false + ignoreConstantDeclaration: true + ignoreCompanionObjectPropertyDeclaration: true + ignoreAnnotation: false + ignoreNamedArgument: true + ignoreEnums: false + ignoreRanges: false + ignoreExtensionFunctions: true + MandatoryBracesIfStatements: + active: false + MandatoryBracesLoops: + active: false + MaxChainedCallsOnSameLine: + active: false + maxChainedCalls: 5 + MaxLineLength: + active: true + maxLineLength: 120 + excludePackageStatements: true + excludeImportStatements: true + excludeCommentStatements: false + excludeRawStrings: true + MayBeConst: + active: true + ModifierOrder: + active: true + MultilineLambdaItParameter: + active: false + MultilineRawStringIndentation: + active: false + indentSize: 4 + NestedClassesVisibility: + active: true + NewLineAtEndOfFile: + active: true + NoTabs: + active: false + NullableBooleanCheck: + active: false + ObjectLiteralToLambda: + active: true + OptionalAbstractKeyword: + active: true + OptionalUnit: + active: false + OptionalWhenBraces: + active: false + PreferToOverPairSyntax: + active: false + ProtectedMemberInFinalClass: + active: true + RedundantExplicitType: + active: false + RedundantHigherOrderMapUsage: + active: true + RedundantVisibilityModifierRule: + active: false + ReturnCount: + active: true + max: 2 + excludedFunctions: + - 'equals' + excludeLabeled: false + excludeReturnFromLambda: true + excludeGuardClauses: false + SafeCast: + active: true + SerialVersionUIDInSerializableClass: + active: true + SpacingBetweenPackageAndImports: + active: false + ThrowsCount: + active: true + max: 2 + excludeGuardClauses: false + TrailingWhitespace: + active: false + TrimMultilineRawString: + active: false + UnderscoresInNumericLiterals: + active: false + acceptableLength: 4 + allowNonStandardGrouping: false + UnnecessaryAbstractClass: + active: true + UnnecessaryAnnotationUseSiteTarget: + active: false + UnnecessaryApply: + active: true + UnnecessaryBackticks: + active: false + UnnecessaryFilter: + active: true + UnnecessaryInheritance: + active: true + UnnecessaryInnerClass: + active: false + UnnecessaryLet: + active: false + UnnecessaryParentheses: + active: false + allowForUnclearPrecedence: false + UntilInsteadOfRangeTo: + active: false + UnusedImports: + active: false + UnusedPrivateClass: + active: true + UnusedPrivateMember: + active: true + allowedNames: '(_|ignored|expected|serialVersionUID)' + UseAnyOrNoneInsteadOfFind: + active: true + UseArrayLiteralsInAnnotations: + active: true + UseCheckNotNull: + active: true + UseCheckOrError: + active: true + UseDataClass: + active: false + allowVars: false + UseEmptyCounterpart: + active: false + UseIfEmptyOrIfBlank: + active: false + UseIfInsteadOfWhen: + active: false + UseIsNullOrEmpty: + active: true + UseOrEmpty: + active: true + UseRequire: + active: true + UseRequireNotNull: + active: true + UselessCallOnNotNull: + active: true + UtilityClassWithPublicConstructor: + active: true + VarCouldBeVal: + active: true + ignoreLateinitVar: false + WildcardImport: + active: true + excludeImports: + - 'java.util.*' diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From d9008c9bc81e6e28683e566731ec46ad00c69d91 Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Tue, 4 Oct 2022 19:58:19 +0530 Subject: [PATCH 06/47] added the detekt as pre-push git-hooks. --- app/build.gradle.kts | 6 ++++++ git-hooks/pre-push.sh | 17 +++++++++++++++++ gradle/install-git-hooks.gradle | 6 ++++++ 3 files changed, 29 insertions(+) create mode 100644 git-hooks/pre-push.sh create mode 100644 gradle/install-git-hooks.gradle diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4cac126..c9a480f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -134,3 +134,9 @@ dependencies { debugImplementation("androidx.compose.ui:ui-tooling:${LibVersion.composeVersion}") debugImplementation("androidx.compose.ui:ui-test-manifest:${LibVersion.composeVersion}") } + +//afterEvaluate { +// // We install the hooks +// tasks.getByPath(":app:clean").dependsOn installGitHooks +// tasks.getByPath(":app:preBuild").dependsOn installGitHooks +//} diff --git a/git-hooks/pre-push.sh b/git-hooks/pre-push.sh new file mode 100644 index 0000000..da13004 --- /dev/null +++ b/git-hooks/pre-push.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +echo "Running static code analysis..." + +# Run Detekt, KtLint and Checkstyle static analysis +./gradlew detekt --daemon + +status=$? + +if [ "$status" = 0 ] ; then + echo "Static analysis found no problems." + exit 0 +else + echo 1>&2 "Static analysis found violations! Fix then before pushing your code!" + echo "See generated reports above or in /mobile/build/reports folder" + exit 1 +fi \ No newline at end of file diff --git a/gradle/install-git-hooks.gradle b/gradle/install-git-hooks.gradle new file mode 100644 index 0000000..5672490 --- /dev/null +++ b/gradle/install-git-hooks.gradle @@ -0,0 +1,6 @@ +tasks.register("installGitHooks", Copy) { + from file("$rootDir/.githooks") + into file("$rootDir/.git/hooks") + fileMode = 0775 +} +tasks.getByPath(":app:preBuild").dependsOn installGitHooks \ No newline at end of file From 9ebb6358392b1974e3d1d4bb3ddc775263789338 Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Thu, 6 Oct 2022 01:47:56 +0530 Subject: [PATCH 07/47] Enabled the ktlint and also added it into the pre-push git-hooks. --- app/build.gradle.kts | 4 +- .../com/hadiyarajesh/notex/MyApplication.kt | 2 +- .../notex/database/entity/Note.kt | 2 +- .../notex/database/entity/Reminder.kt | 2 +- .../hadiyarajesh/notex/di/NetworkModule.kt | 2 +- .../com/hadiyarajesh/notex/di/ScopeModule.kt | 2 +- .../hadiyarajesh/notex/network/api/NoteApi.kt | 3 +- .../notex/repository/notes/NotesRepository.kt | 2 +- .../reminders/RemindersRepository.kt | 2 +- .../notex/ui/component/AllNotesComponents.kt | 8 +- .../hadiyarajesh/notex/ui/component/Other.kt | 1 - .../notex/ui/component/TextComposables.kt | 1 - .../hadiyarajesh/notex/ui/note/NotesScreen.kt | 4 +- .../notex/ui/note/NotesViewModel.kt | 2 +- .../notex/ui/reminders/RemindersScreen.kt | 1 - .../notex/ui/reminders/RemindersViewModel.kt | 5 +- .../com/hadiyarajesh/notex/ui/theme/Theme.kt | 2 +- .../com/hadiyarajesh/notex/ui/theme/Type.kt | 2 +- .../notex/utility/PreferenceManager.kt | 5 +- build.gradle.kts | 36 ++++-- config/detekt/detekt.yml | 120 +++++++++--------- git-hooks/pre-push.sh | 2 +- 22 files changed, 106 insertions(+), 104 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c9a480f..4afe1fe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -135,8 +135,8 @@ dependencies { debugImplementation("androidx.compose.ui:ui-test-manifest:${LibVersion.composeVersion}") } -//afterEvaluate { +// afterEvaluate { // // We install the hooks // tasks.getByPath(":app:clean").dependsOn installGitHooks // tasks.getByPath(":app:preBuild").dependsOn installGitHooks -//} +// } diff --git a/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt b/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt index e8ccd78..0ad1e04 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt @@ -4,4 +4,4 @@ import android.app.Application import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp -class MyApplication: Application() +class MyApplication : Application() diff --git a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Note.kt b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Note.kt index e829b80..582103f 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Note.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Note.kt @@ -14,7 +14,7 @@ data class Note( val content: String?, val archived: Boolean, val archivedOn: Instant? = null, - //HexCode of a color + // HexCode of a color val color: String? = null, val createdOn: Instant, val updatedOn: Instant, diff --git a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Reminder.kt b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Reminder.kt index 25c6ed1..4fd8354 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Reminder.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Reminder.kt @@ -18,7 +18,7 @@ data class Reminder( val cancelledOn: Instant? = null, val completed: Boolean, val completedOn: Instant?, - //HexCode of a color + // HexCode of a color val color: String? = null, val createdOn: Instant, val updatedOn: Instant, diff --git a/app/src/main/java/com/hadiyarajesh/notex/di/NetworkModule.kt b/app/src/main/java/com/hadiyarajesh/notex/di/NetworkModule.kt index 90a2639..ad9349e 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/di/NetworkModule.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/di/NetworkModule.kt @@ -8,11 +8,11 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory -import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt index e258925..6b3a54c 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt @@ -4,10 +4,10 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob -import javax.inject.Singleton @InstallIn(SingletonComponent::class) @Module diff --git a/app/src/main/java/com/hadiyarajesh/notex/network/api/NoteApi.kt b/app/src/main/java/com/hadiyarajesh/notex/network/api/NoteApi.kt index 7d7f3b7..27c7bce 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/network/api/NoteApi.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/network/api/NoteApi.kt @@ -1,4 +1,3 @@ package com.hadiyarajesh.notex.network.api -interface NoteApi { -} +interface NoteApi diff --git a/app/src/main/java/com/hadiyarajesh/notex/repository/notes/NotesRepository.kt b/app/src/main/java/com/hadiyarajesh/notex/repository/notes/NotesRepository.kt index 5b6a8d3..148301b 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/repository/notes/NotesRepository.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/repository/notes/NotesRepository.kt @@ -5,10 +5,10 @@ import androidx.paging.PagingConfig import androidx.paging.PagingData import com.hadiyarajesh.notex.database.dao.NoteDao import com.hadiyarajesh.notex.database.entity.Note -import kotlinx.coroutines.flow.Flow import java.time.Instant import javax.inject.Inject import javax.inject.Singleton +import kotlinx.coroutines.flow.Flow @Singleton class NotesRepository @Inject constructor( diff --git a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt index 6e0c994..903314d 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt @@ -6,10 +6,10 @@ import androidx.paging.PagingData import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.entity.Reminder import com.hadiyarajesh.notex.database.model.RepetitionStrategy -import kotlinx.coroutines.flow.Flow import java.time.Instant import javax.inject.Inject import javax.inject.Singleton +import kotlinx.coroutines.flow.Flow @Singleton class RemindersRepository @Inject constructor( diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt index a175825..697e977 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/component/AllNotesComponents.kt @@ -50,7 +50,8 @@ fun NoteCard(note: Note) { content = "Succeed", Modifier.padding(end = 8.dp) ) Divider( - color = Color.Gray, modifier = Modifier + color = Color.Gray, + modifier = Modifier .fillMaxHeight() .width(1.dp) ) @@ -59,17 +60,16 @@ fun NoteCard(note: Note) { Row( Modifier .fillMaxWidth() - .weight(1f), horizontalArrangement = Arrangement.End + .weight(1f), + horizontalArrangement = Arrangement.End ) { TextSemiBold( content = InstantConverter.getLocalDate(note.createdOn).toString() ) } - } } } - } @Preview diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/component/Other.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/component/Other.kt index c6ff11d..18dca7e 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/component/Other.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/component/Other.kt @@ -84,7 +84,6 @@ fun LoadingProgressBar( color: Color = MaterialTheme.colorScheme.primary, strokeWidth: Dp = 4.dp ) { - Box(modifier = modifier) { CircularProgressIndicator( modifier = Modifier diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt index 82a9c45..df219b4 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/component/TextComposables.kt @@ -7,7 +7,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight - @Composable fun TextSemiBold( content: String, diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt index 2f67bf1..6686782 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt @@ -46,13 +46,13 @@ fun NotesScreen( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = if (notesViewModel.notes == null) { Arrangement.Center - } else + } else { Arrangement.Top + } ) { AllNotesView( notes = notes, onClick = { note -> - } ) } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesViewModel.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesViewModel.kt index 20cd515..f6cd554 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesViewModel.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesViewModel.kt @@ -7,9 +7,9 @@ import androidx.paging.cachedIn import com.hadiyarajesh.notex.database.entity.Note import com.hadiyarajesh.notex.repository.notes.NotesRepository import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch -import javax.inject.Inject @HiltViewModel class NotesViewModel @Inject constructor( diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt index 6456400..c05988f 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt @@ -45,7 +45,6 @@ fun RemindersScreen( AllRemindersView( reminders = reminders, onClick = { reminder -> - } ) } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersViewModel.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersViewModel.kt index fd65e98..8aca915 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersViewModel.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersViewModel.kt @@ -8,10 +8,10 @@ import com.hadiyarajesh.notex.database.entity.Reminder import com.hadiyarajesh.notex.database.model.RepetitionStrategy import com.hadiyarajesh.notex.repository.reminders.RemindersRepository import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.launch import java.time.Instant import javax.inject.Inject +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.launch @HiltViewModel class RemindersViewModel @Inject constructor( @@ -32,5 +32,4 @@ class RemindersViewModel @Inject constructor( title, reminderTime, repeat ) } - } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Theme.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Theme.kt index 8b7df94..b83f61c 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Theme.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Theme.kt @@ -30,7 +30,7 @@ private val LightColorScheme = lightColorScheme( onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), - */ + */ ) @Composable diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Type.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Type.kt index 175abcd..451bdd6 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Type.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/theme/Type.kt @@ -30,5 +30,5 @@ val Typography = Typography( lineHeight = 16.sp, letterSpacing = 0.5.sp ) - */ + */ ) \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/utility/PreferenceManager.kt b/app/src/main/java/com/hadiyarajesh/notex/utility/PreferenceManager.kt index b1c5da2..f9e321b 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/utility/PreferenceManager.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/utility/PreferenceManager.kt @@ -8,11 +8,11 @@ import androidx.datastore.preferences.core.emptyPreferences import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import dagger.hilt.android.qualifiers.ApplicationContext +import java.io.IOException +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map -import java.io.IOException -import javax.inject.Inject private val Context.dataStore: DataStore by preferencesDataStore( name = "${Constants.App.APP_NAME.lowercase()}_prefs" @@ -35,7 +35,6 @@ class PreferenceManager @Inject constructor(@ApplicationContext val context: Con preferences[APP_LANGUAGE_KEY] } - suspend fun saveAppLanguage(language: String) { context.dataStore.edit { preferences -> preferences[APP_LANGUAGE_KEY] = language diff --git a/build.gradle.kts b/build.gradle.kts index 3c765aa..dcb92ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,6 @@ import io.gitlab.arturbosch.detekt.Detekt +import org.jlleitschuh.gradle.ktlint.KtlintExtension +import org.jlleitschuh.gradle.ktlint.reporter.ReporterType buildscript { val hiltVersion by extra("2.42") @@ -15,13 +17,14 @@ plugins { id("com.android.library") version "7.2.2" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false id("io.gitlab.arturbosch.detekt") version "1.22.0-RC1" -// id("org.jlleitschuh.gradle.ktlint") version "10.2.1" + id("org.jlleitschuh.gradle.ktlint") version "10.2.1" } allprojects { -// apply(plugin = "org.jlleitschuh.gradle.ktlint") + apply(plugin = "org.jlleitschuh.gradle.ktlint") apply(plugin = "io.gitlab.arturbosch.detekt") configureDetekt() + configureKtLint() } configureDetekt() @@ -29,6 +32,7 @@ fun Project.configureDetekt() { tasks.withType { jvmTarget = JavaVersion.VERSION_1_8.toString() setSource(files(projectDir)) + exclude("**/build/**") parallel = true baseline.set(file(path = "${rootProject.projectDir}/config/detekt/detekt-baseline.xml")) autoCorrect = true @@ -45,26 +49,30 @@ tasks.register("clean", Delete::class) { delete(rootProject.buildDir) } -/*fun Project.configureKtLint() { +fun Project.configureKtLint() { this.configure { version.set("0.45.2") android.set(true) outputToConsole.set(true) ignoreFailures.set(true) enableExperimentalRules.set(true) - disabledRules.set(ktlintDisabledChecks) + disabledRules.set( + setOf( + "unused-imports", + "final-newline", + "max-line-length", + "experimental:argument-list-wrapping", + "no-wildcard-imports", + "experimental:trailing-comma", + "experimental:comment-wrapping" + ) + ) reporters { reporter(ReporterType.CHECKSTYLE) } + filter { + exclude("**/generated/**") + include("**/build/**") + } } } - -val ktlintDisabledChecks = setOf( - "unused-imports", - "final-newline", - "max-line-length", - "experimental:argument-list-wrapping", - "no-wildcard-imports", - "experimental:trailing-comma", - "experimental:comment-wrapping" -)*/ diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 764ba81..d8cb181 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -9,7 +9,7 @@ build: config: validation: true - warningsAsErrors: false + warningsAsErrors: true checkExhaustiveness: false # when writing own rules with new properties, exclude the property path e.g.: 'my_rule_set,.*>.*>[my_property]' excludes: '' @@ -95,8 +95,8 @@ complexity: active: true threshold: 4 ComplexInterface: - active: false - threshold: 10 + active: true + threshold: 20 includeStaticDeclarations: false includePrivateDeclarations: false ignoreOverloaded: false @@ -127,16 +127,16 @@ complexity: threshold: 60 LongParameterList: active: true - functionThreshold: 6 - constructorThreshold: 7 - ignoreDefaultParameters: false + functionThreshold: 10 + constructorThreshold: 10 + ignoreDefaultParameters: true ignoreDataClasses: true - ignoreAnnotatedParameter: [] + ignoreAnnotatedParameter: [ 'Composable' ] MethodOverloading: - active: false + active: true threshold: 6 NamedArguments: - active: false + active: true threshold: 3 ignoreArgumentsMatchingNames: false NestedBlockDepth: @@ -175,7 +175,7 @@ complexity: coroutines: active: true GlobalCoroutineUsage: - active: false + active: true InjectDispatcher: active: true dispatcherNames: @@ -187,7 +187,7 @@ coroutines: SleepInsteadOfDelay: active: true SuspendFunWithCoroutineScopeReceiver: - active: false + active: true SuspendFunWithFlowReturnType: active: true @@ -239,9 +239,9 @@ exceptions: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] NotImplementedDeclaration: - active: false + active: true ObjectExtendsThrowable: - active: false + active: true PrintStackTrace: active: true RethrowCaughtException: @@ -260,7 +260,7 @@ exceptions: ThrowingExceptionFromFinally: active: true ThrowingExceptionInMain: - active: false + active: true ThrowingExceptionsWithoutMessageOrCause: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] @@ -300,7 +300,7 @@ exceptions: naming: active: true BooleanPropertyNaming: - active: false + active: true allowedPattern: '^(is|has|are)' ignoreOverridden: true ClassNaming: @@ -316,13 +316,13 @@ naming: active: true enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: - active: false + active: true forbiddenName: [] FunctionMaxLength: - active: false - maximumFunctionNameLength: 30 + active: true + maximumFunctionNameLength: 50 FunctionMinLength: - active: false + active: true minimumFunctionNameLength: 3 FunctionNaming: active: true @@ -340,7 +340,7 @@ naming: rootPackage: '' requireRootInDeclaration: false LambdaParameterNaming: - active: false + active: true parameterPattern: '[a-z][A-Za-z0-9]*|_' MatchingDeclarationName: active: true @@ -351,7 +351,7 @@ naming: NoNameShadowing: active: true NonBooleanPropertyPrefixedWithIs: - active: false + active: true ObjectPropertyNaming: active: true constantPattern: '[A-Za-z][_A-Za-z0-9]*' @@ -366,10 +366,10 @@ naming: propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' VariableMaxLength: - active: false + active: true maximumVariableNameLength: 64 VariableMinLength: - active: false + active: true minimumVariableNameLength: 1 VariableNaming: active: true @@ -403,11 +403,11 @@ potential-bugs: forbiddenTypePatterns: - 'kotlin.String' CastToNullableType: - active: false + active: true Deprecation: - active: false + active: true DontDowncastCollectionTypes: - active: false + active: true DoubleMutabilityForCollection: active: true mutableTypes: @@ -422,13 +422,13 @@ potential-bugs: DuplicateCaseInWhenExpression: active: true ElseCaseInsteadOfExhaustiveWhen: - active: false + active: true EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: active: true ExitOutsideMain: - active: false + active: true ExplicitGarbageCollectionCall: active: true HasPlatformType: @@ -449,7 +449,7 @@ potential-bugs: ImplicitDefaultLocale: active: true ImplicitUnitReturnType: - active: false + active: true allowExplicitReturnType: true InvalidRange: active: true @@ -470,13 +470,13 @@ potential-bugs: active: true allowElseExpression: true NullCheckOnMutableProperty: - active: false + active: true NullableToStringCall: - active: false + active: true RedundantElseInWhen: active: true UnconditionalJumpStatementInLoop: - active: false + active: true UnnecessaryNotNullOperator: active: true UnnecessarySafeCall: @@ -507,13 +507,13 @@ style: ClassOrdering: active: false CollapsibleIfStatements: - active: false + active: true DataClassContainsFunctions: active: false conversionFunctionPrefix: - 'to' DataClassShouldBeImmutable: - active: false + active: true DestructuringDeclarationWithTooManyEntries: active: true maxDestructuringEntries: 3 @@ -537,11 +537,11 @@ style: allowedPatterns: '' customMessage: '' ForbiddenImport: - active: false + active: true imports: [] forbiddenPatterns: '' ForbiddenMethodCall: - active: false + active: true methods: - reason: 'print does not allow you to configure the output stream. Use a logger instead.' value: 'kotlin.io.print' @@ -554,7 +554,7 @@ style: - '*.internal' - '*.internal.*' ForbiddenSuppress: - active: false + active: true rules: [] ForbiddenVoid: active: true @@ -569,10 +569,10 @@ style: active: true excludes: ['**'] LibraryEntitiesShouldNotBePublic: - active: true + active: false excludes: ['**'] LoopWithTooManyJumpStatements: - active: true + active: false maxJumpCount: 1 MagicNumber: active: true @@ -589,19 +589,19 @@ style: ignoreCompanionObjectPropertyDeclaration: true ignoreAnnotation: false ignoreNamedArgument: true - ignoreEnums: false + ignoreEnums: true ignoreRanges: false ignoreExtensionFunctions: true MandatoryBracesIfStatements: - active: false + active: true MandatoryBracesLoops: - active: false + active: true MaxChainedCallsOnSameLine: active: false maxChainedCalls: 5 MaxLineLength: active: true - maxLineLength: 120 + maxLineLength: 160 excludePackageStatements: true excludeImportStatements: true excludeCommentStatements: false @@ -624,26 +624,26 @@ style: NullableBooleanCheck: active: false ObjectLiteralToLambda: - active: true + active: false OptionalAbstractKeyword: active: true OptionalUnit: active: false OptionalWhenBraces: - active: false + active: true PreferToOverPairSyntax: - active: false + active: true ProtectedMemberInFinalClass: active: true RedundantExplicitType: - active: false + active: true RedundantHigherOrderMapUsage: active: true RedundantVisibilityModifierRule: - active: false + active: true ReturnCount: active: true - max: 2 + max: 5 excludedFunctions: - 'equals' excludeLabeled: false @@ -660,17 +660,17 @@ style: max: 2 excludeGuardClauses: false TrailingWhitespace: - active: false + active: true TrimMultilineRawString: active: false UnderscoresInNumericLiterals: active: false - acceptableLength: 4 + acceptableLength: 5 allowNonStandardGrouping: false UnnecessaryAbstractClass: active: true UnnecessaryAnnotationUseSiteTarget: - active: false + active: true UnnecessaryApply: active: true UnnecessaryBackticks: @@ -680,16 +680,16 @@ style: UnnecessaryInheritance: active: true UnnecessaryInnerClass: - active: false + active: true UnnecessaryLet: - active: false + active: true UnnecessaryParentheses: - active: false + active: true allowForUnclearPrecedence: false UntilInsteadOfRangeTo: - active: false + active: true UnusedImports: - active: false + active: true UnusedPrivateClass: active: true UnusedPrivateMember: @@ -704,12 +704,12 @@ style: UseCheckOrError: active: true UseDataClass: - active: false + active: true allowVars: false UseEmptyCounterpart: - active: false + active: true UseIfEmptyOrIfBlank: - active: false + active: true UseIfInsteadOfWhen: active: false UseIsNullOrEmpty: diff --git a/git-hooks/pre-push.sh b/git-hooks/pre-push.sh index da13004..18d4531 100644 --- a/git-hooks/pre-push.sh +++ b/git-hooks/pre-push.sh @@ -3,7 +3,7 @@ echo "Running static code analysis..." # Run Detekt, KtLint and Checkstyle static analysis -./gradlew detekt --daemon +./gradlew detekt ktlintCheck --daemon status=$? From 2a307a0986f5b46f4ea50617b5cc78f578701851 Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Thu, 6 Oct 2022 02:06:46 +0530 Subject: [PATCH 08/47] change order and define the taks to generate output in some dir --- build.gradle.kts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index dcb92ba..0bd41d5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ import io.gitlab.arturbosch.detekt.Detekt import org.jlleitschuh.gradle.ktlint.KtlintExtension import org.jlleitschuh.gradle.ktlint.reporter.ReporterType +import org.jlleitschuh.gradle.ktlint.tasks.GenerateReportsTask buildscript { val hiltVersion by extra("2.42") @@ -45,10 +46,6 @@ fun Project.configureDetekt() { } } -tasks.register("clean", Delete::class) { - delete(rootProject.buildDir) -} - fun Project.configureKtLint() { this.configure { version.set("0.45.2") @@ -76,3 +73,15 @@ fun Project.configureKtLint() { } } } + +tasks.withType { + reportsOutputDirectory.set( + File(project.buildDir, "reports/ktlint/merged-ktlint-results.xml") + ) +} + +tasks.register("clean", Delete::class) { + delete(rootProject.buildDir) +} + + From 0c04e39877e04fc25ebf390282877f769a910dbc Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Thu, 6 Oct 2022 03:10:23 +0530 Subject: [PATCH 09/47] change some files and tasks and testing that pre-push is working or not --- app/build.gradle.kts | 6 ------ build.gradle.kts | 7 +++++++ git-hooks/pre-push.sh | 34 ++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4afe1fe..4cac126 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -134,9 +134,3 @@ dependencies { debugImplementation("androidx.compose.ui:ui-tooling:${LibVersion.composeVersion}") debugImplementation("androidx.compose.ui:ui-test-manifest:${LibVersion.composeVersion}") } - -// afterEvaluate { -// // We install the hooks -// tasks.getByPath(":app:clean").dependsOn installGitHooks -// tasks.getByPath(":app:preBuild").dependsOn installGitHooks -// } diff --git a/build.gradle.kts b/build.gradle.kts index 0bd41d5..b112f2c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,6 +74,13 @@ fun Project.configureKtLint() { } } +tasks.register("installGitHook", Copy::class) { + from(file("$rootDir/.githooks")) + into(file("$rootDir/.git/hooks")) + fileMode = 0b0111101101 // -rwxr-xr-x +} +tasks.getByPath(":app:preBuild").dependsOn(tasks.named("installGitHook")) + tasks.withType { reportsOutputDirectory.set( File(project.buildDir, "reports/ktlint/merged-ktlint-results.xml") diff --git a/git-hooks/pre-push.sh b/git-hooks/pre-push.sh index 18d4531..17df2dd 100644 --- a/git-hooks/pre-push.sh +++ b/git-hooks/pre-push.sh @@ -1,8 +1,8 @@ #!/bin/sh +echo "*********************************************************" +echo "Running git pre-push hook. Running Static analysis... " +echo "*********************************************************" -echo "Running static code analysis..." - -# Run Detekt, KtLint and Checkstyle static analysis ./gradlew detekt ktlintCheck --daemon status=$? @@ -11,7 +11,29 @@ if [ "$status" = 0 ] ; then echo "Static analysis found no problems." exit 0 else - echo 1>&2 "Static analysis found violations! Fix then before pushing your code!" - echo "See generated reports above or in /mobile/build/reports folder" + echo "*********************************************************" + echo " ******************************************** " + echo 1>&2 "Static analysis found violations it could not fix." + echo "Run ./gradlew ktlintFormat to fix formatting related issues." + echo " ******************************************** " + echo "*********************************************************" exit 1 -fi \ No newline at end of file +fi + + + +#echo "Running static code analysis..." +# +## Run Detekt, KtLint and Checkstyle static analysis +#./gradlew detekt ktlintCheck --daemon +# +#status=$? +# +#if [ "$status" = 0 ] ; then +# echo "Static analysis found no problems." +# exit 0 +#else +# echo 1>&2 "Static analysis found violations! Fix then before pushing your code!" +# echo "See generated reports above or in /app/build/reports folder" +# exit 1 +#fi From 9a8b9208580df62f1e76573099533abae4ac692c Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Thu, 6 Oct 2022 03:30:28 +0530 Subject: [PATCH 10/47] manually it is running but while push it is not working --- build.gradle.kts | 21 +++++++++++++++++++++ gradle/install-git-hooks.gradle | 6 ------ 2 files changed, 21 insertions(+), 6 deletions(-) delete mode 100644 gradle/install-git-hooks.gradle diff --git a/build.gradle.kts b/build.gradle.kts index b112f2c..aa42b40 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,6 +74,27 @@ fun Project.configureKtLint() { } } +//val deletePreviousGitHOok by tasks.registering(Delete::class) { +// group = "utils" +// description = "Deleting previous githook" +// +//// val preCommit = "${rootProject.rootDir}/.git/hooks/pre-commit" +// val prePush = "${rootProject.rootDir}/.git/hooks/pre-push" +// if (file(prePush).exists()) { +// delete(prePush) +// } +//} +// +//val installGitHook by tasks.registering(Copy::class) { +// group = "utils" +// description = "Adding githook to local working copy, this must be run manually" +// +// dependsOn(deletePreviousGitHOok) +// from("${rootProject.rootDir}/.githooks/pre-push") +// into("${rootProject.rootDir}/.git/hooks") +// fileMode = 0b0111101101 +//} + tasks.register("installGitHook", Copy::class) { from(file("$rootDir/.githooks")) into(file("$rootDir/.git/hooks")) diff --git a/gradle/install-git-hooks.gradle b/gradle/install-git-hooks.gradle deleted file mode 100644 index 5672490..0000000 --- a/gradle/install-git-hooks.gradle +++ /dev/null @@ -1,6 +0,0 @@ -tasks.register("installGitHooks", Copy) { - from file("$rootDir/.githooks") - into file("$rootDir/.git/hooks") - fileMode = 0775 -} -tasks.getByPath(":app:preBuild").dependsOn installGitHooks \ No newline at end of file From 229668cf85a60898569de3a794a4d8c28440f36f Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Thu, 6 Oct 2022 03:58:00 +0530 Subject: [PATCH 11/47] code cleanup. --- build.gradle.kts | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa42b40..985f0ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,27 +74,14 @@ fun Project.configureKtLint() { } } -//val deletePreviousGitHOok by tasks.registering(Delete::class) { -// group = "utils" -// description = "Deleting previous githook" -// -//// val preCommit = "${rootProject.rootDir}/.git/hooks/pre-commit" -// val prePush = "${rootProject.rootDir}/.git/hooks/pre-push" -// if (file(prePush).exists()) { -// delete(prePush) -// } -//} -// -//val installGitHook by tasks.registering(Copy::class) { -// group = "utils" -// description = "Adding githook to local working copy, this must be run manually" -// -// dependsOn(deletePreviousGitHOok) -// from("${rootProject.rootDir}/.githooks/pre-push") -// into("${rootProject.rootDir}/.git/hooks") -// fileMode = 0b0111101101 -//} +// Tasks for providing dir for generated reports from detekt and ktlint +tasks.withType { + reportsOutputDirectory.set( + File(project.buildDir, "reports/ktlint/merged-ktlint-results.xml") + ) +} +// Tasks for automatically installing git-hooks and making it executable also. tasks.register("installGitHook", Copy::class) { from(file("$rootDir/.githooks")) into(file("$rootDir/.git/hooks")) @@ -102,12 +89,6 @@ tasks.register("installGitHook", Copy::class) { } tasks.getByPath(":app:preBuild").dependsOn(tasks.named("installGitHook")) -tasks.withType { - reportsOutputDirectory.set( - File(project.buildDir, "reports/ktlint/merged-ktlint-results.xml") - ) -} - tasks.register("clean", Delete::class) { delete(rootProject.buildDir) } From 42091828e15b944547bf5be8903c23c5e818e52a Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Fri, 7 Oct 2022 02:14:05 +0530 Subject: [PATCH 12/47] tried once more that scripts is working or not --- build.gradle.kts | 29 +++++++++++++++++++++++++++-- git-hooks/{pre-push.sh => pre-push} | 0 gradle/install-git-hooks.gradle | 11 +++++++++++ scripts/pre-push | 26 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) rename git-hooks/{pre-push.sh => pre-push} (100%) create mode 100644 gradle/install-git-hooks.gradle create mode 100644 scripts/pre-push diff --git a/build.gradle.kts b/build.gradle.kts index 985f0ac..affb315 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,12 @@ allprojects { apply(plugin = "io.gitlab.arturbosch.detekt") configureDetekt() configureKtLint() +// apply(from = rootProject.file("gradle/install-git-hooks.gradle")) +} + +copy { + from("$rootProject.rootDir/scripts/pre-push") + into { file("$rootProject.rootDir/.git/hooks") } } configureDetekt() @@ -83,11 +89,30 @@ tasks.withType { // Tasks for automatically installing git-hooks and making it executable also. tasks.register("installGitHook", Copy::class) { - from(file("$rootDir/.githooks")) + from(file("$rootDir/scripts/pre-push")) into(file("$rootDir/.git/hooks")) fileMode = 0b0111101101 // -rwxr-xr-x } -tasks.getByPath(":app:preBuild").dependsOn(tasks.named("installGitHook")) + +tasks.create(name = "gitExecutableHooks") { + doLast { + Runtime.getRuntime().exec("chmod -R +x .git/hooks/"); + } +} + +tasks.getByPath("gitExecutableHooks").dependsOn(tasks.named("installGitHook")) +tasks.getByPath(":app:clean").dependsOn(tasks.named("gitExecutableHooks")) +//tasks.getByPath(":app:preBuild").dependsOn(tasks.named("installGitHook")) + + +//tasks.register("installLocalGitHook", Copy::class ) { +// from(file("$rootProject.rootDir/scripts/pre-push")) +// into { file("$rootProject.rootDir/.git/hooks")} +// fileMode = 0b0111101101 +//} +//tasks.getByPath(":app:build").dependsOn(tasks.named("installLocalGitHook")) + + tasks.register("clean", Delete::class) { delete(rootProject.buildDir) diff --git a/git-hooks/pre-push.sh b/git-hooks/pre-push similarity index 100% rename from git-hooks/pre-push.sh rename to git-hooks/pre-push diff --git a/gradle/install-git-hooks.gradle b/gradle/install-git-hooks.gradle new file mode 100644 index 0000000..0325015 --- /dev/null +++ b/gradle/install-git-hooks.gradle @@ -0,0 +1,11 @@ +tasks.create(name: 'gitExecutableHooks') { + doLast { + Runtime.getRuntime().exec("chmod -R +x .git/hooks/"); + } +} +//task installGitHooks(type: Copy) { +// from new File(rootProject.rootDir, '/scripts/pre-push') +// into { new File(rootProject.rootDir, '.git/hooks') } +//} +gitExecutableHooks.dependsOn installGitHooks +clean.dependsOn gitExecutableHooks \ No newline at end of file diff --git a/scripts/pre-push b/scripts/pre-push new file mode 100644 index 0000000..02aff6f --- /dev/null +++ b/scripts/pre-push @@ -0,0 +1,26 @@ +#!/bin/sh + +echo "*********************************************************" +echo "Running git pre-push hook. Running Static analysis... " +echo "*********************************************************" + +git stash -q --keep-index + +./gradlew detekt ktlintCheck --daemon + +status=$? + +git stash pop -q + +if [ "$status" = 0 ] ; then + echo "Static analysis found no problems." + exit 0 +else + echo "*********************************************************" + echo " ******************************************** " + echo 1>&2 "Static analysis found violations it could not fix." + echo "Run ./gradlew ktlintFormat to fix formatting related issues." + echo " ******************************************** " + echo "*********************************************************" + exit 1 +fi From d6e00e8d14fb0f75bfcfc37dfdeadc7241ade1a0 Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Fri, 7 Oct 2022 02:25:27 +0530 Subject: [PATCH 13/47] fixed detekt and lint errors. --- .../notex/ExampleInstrumentedTest.kt | 6 ++--- .../database/converter/InstantConverter.kt | 1 - .../notex/database/entity/Folder.kt | 2 +- .../com/hadiyarajesh/notex/ui/NoteXApp.kt | 2 +- .../hadiyarajesh/notex/ui/note/NotesScreen.kt | 1 + .../com/hadiyarajesh/notex/ExampleUnitTest.kt | 3 +-- build.gradle.kts | 22 +------------------ config/detekt/detekt.yml | 1 + gradle/install-git-hooks.gradle | 11 ---------- 9 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 gradle/install-git-hooks.gradle diff --git a/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt index 90e2355..38b26bc 100644 --- a/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/hadiyarajesh/notex/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.hadiyarajesh.notex -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.assertEquals - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt b/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt index 36bdc44..c430c79 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/database/converter/InstantConverter.kt @@ -16,7 +16,6 @@ object InstantConverter { @TypeConverter fun toInstant(value: String?): Instant? = value?.let { Instant.parse(value) } - @JvmStatic @TypeConverter fun getLocalDate(instant: Instant): LocalDate { diff --git a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Folder.kt b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Folder.kt index bc46b8c..19c1bd9 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/database/entity/Folder.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/database/entity/Folder.kt @@ -14,7 +14,7 @@ data class Folder( val title: String, val description: String?, val folderType: FolderType, - //HexCode of a color + // HexCode of a color val color: String? = null, val createdOn: Instant, val updatedOn: Instant diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/NoteXApp.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/NoteXApp.kt index 8788091..b0982c4 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/NoteXApp.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/NoteXApp.kt @@ -23,7 +23,7 @@ fun NoteXApp() { NoteXTheme { val navController = rememberNavController() // A state that maintains visibility of a bottom bar - val bottomBarState = rememberSaveable { (mutableStateOf(true)) } + val bottomBarState = rememberSaveable { mutableStateOf(true) } Scaffold( bottomBar = { diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt index 6686782..285cdae 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/note/NotesScreen.kt @@ -59,6 +59,7 @@ fun NotesScreen( } } +@SuppressWarnings("OptionalWhenBraces") @Composable private fun AllNotesView( modifier: Modifier = Modifier, diff --git a/app/src/test/java/com/hadiyarajesh/notex/ExampleUnitTest.kt b/app/src/test/java/com/hadiyarajesh/notex/ExampleUnitTest.kt index e0f2f08..f4f091a 100644 --- a/app/src/test/java/com/hadiyarajesh/notex/ExampleUnitTest.kt +++ b/app/src/test/java/com/hadiyarajesh/notex/ExampleUnitTest.kt @@ -1,8 +1,7 @@ package com.hadiyarajesh.notex -import org.junit.Test - import org.junit.Assert.* +import org.junit.Test /** * Example local unit test, which will execute on the development machine (host). diff --git a/build.gradle.kts b/build.gradle.kts index affb315..e39ff20 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,12 +26,6 @@ allprojects { apply(plugin = "io.gitlab.arturbosch.detekt") configureDetekt() configureKtLint() -// apply(from = rootProject.file("gradle/install-git-hooks.gradle")) -} - -copy { - from("$rootProject.rootDir/scripts/pre-push") - into { file("$rootProject.rootDir/.git/hooks") } } configureDetekt() @@ -96,26 +90,12 @@ tasks.register("installGitHook", Copy::class) { tasks.create(name = "gitExecutableHooks") { doLast { - Runtime.getRuntime().exec("chmod -R +x .git/hooks/"); + Runtime.getRuntime().exec("chmod -R +x .git/hooks/") } } - tasks.getByPath("gitExecutableHooks").dependsOn(tasks.named("installGitHook")) tasks.getByPath(":app:clean").dependsOn(tasks.named("gitExecutableHooks")) -//tasks.getByPath(":app:preBuild").dependsOn(tasks.named("installGitHook")) - - -//tasks.register("installLocalGitHook", Copy::class ) { -// from(file("$rootProject.rootDir/scripts/pre-push")) -// into { file("$rootProject.rootDir/.git/hooks")} -// fileMode = 0b0111101101 -//} -//tasks.getByPath(":app:build").dependsOn(tasks.named("installLocalGitHook")) - - tasks.register("clean", Delete::class) { delete(rootProject.buildDir) } - - diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index d8cb181..b4e0bb1 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -330,6 +330,7 @@ naming: functionPattern: '[a-z][a-zA-Z0-9]*' excludeClassPattern: '$^' ignoreOverridden: true + ignoreAnnotated: [ 'Composable' ] FunctionParameterNaming: active: true parameterPattern: '[a-z][A-Za-z0-9]*' diff --git a/gradle/install-git-hooks.gradle b/gradle/install-git-hooks.gradle deleted file mode 100644 index 0325015..0000000 --- a/gradle/install-git-hooks.gradle +++ /dev/null @@ -1,11 +0,0 @@ -tasks.create(name: 'gitExecutableHooks') { - doLast { - Runtime.getRuntime().exec("chmod -R +x .git/hooks/"); - } -} -//task installGitHooks(type: Copy) { -// from new File(rootProject.rootDir, '/scripts/pre-push') -// into { new File(rootProject.rootDir, '.git/hooks') } -//} -gitExecutableHooks.dependsOn installGitHooks -clean.dependsOn gitExecutableHooks \ No newline at end of file From 877b81ed36f8a48ab968b584a11e6dcb3a8f6bb8 Mon Sep 17 00:00:00 2001 From: Abhinav Suman Date: Fri, 7 Oct 2022 02:26:50 +0530 Subject: [PATCH 14/47] fixed detekt errors. --- .../java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt index c05988f..1d9b703 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt @@ -51,6 +51,7 @@ fun RemindersScreen( } } +@SuppressWarnings("OptionalWhenBraces") @Composable private fun AllRemindersView( modifier: Modifier = Modifier, From 2423f28852ed8c9e7ba50263c73af385a1c23c3a Mon Sep 17 00:00:00 2001 From: MosesATJTC Date: Sat, 17 Sep 2022 13:01:53 +0530 Subject: [PATCH 15/47] Working on Notification and WorkManager --- .idea/gradle.xml | 1 + .idea/misc.xml | 2 +- app/build.gradle.kts | 5 ++ app/src/main/AndroidManifest.xml | 2 + .../com/hadiyarajesh/notex/MainActivity.kt | 25 ++++++ .../com/hadiyarajesh/notex/MyApplication.kt | 16 +++- .../NotificationBroadCastReceiver.kt | 54 +++++++++++++ .../notification/NotificationHelper.kt | 65 ++++++++++++++++ .../reminder/worker/ReminderWorkManager.kt | 77 +++++++++++++++++++ .../notex/reminder/worker/ReminderWorker.kt | 53 +++++++++++++ .../reminders/RemindersRepository.kt | 28 ++++--- app/src/main/res/values/strings.xml | 6 ++ 12 files changed, 321 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt create mode 100644 app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt create mode 100644 app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt create mode 100644 app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt diff --git a/.idea/gradle.xml b/.idea/gradle.xml index a2d7c21..7b46144 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,6 +7,7 @@ - \ No newline at end of file + From fedd0ccc9407bbecb3d49b74ebcec764a8ab92fe Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:42:58 +0530 Subject: [PATCH 25/47] Update gradle.xml From d75bb8e561f62874c0e2db95076d84b8524e3f7c Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:18 +0530 Subject: [PATCH 26/47] Update gradle.xml From 346278e7e06557218ad422ebae7f77975d2758be Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:36 +0530 Subject: [PATCH 27/47] Update misc.xml From e96a86d173a1c3e5c8b5b8f615e6abf93ed71e55 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:44:05 +0530 Subject: [PATCH 28/47] Delete misc.xml --- .idea/misc.xml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 43328cf..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - From 73da5c601bbcaa4d69378296485ef1ace9fbed80 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:44:16 +0530 Subject: [PATCH 29/47] Delete gradle.xml --- .idea/gradle.xml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .idea/gradle.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index ac1c045..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - From d7086df0f205e433fcddb02307fafce542d96e89 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:42:58 +0530 Subject: [PATCH 30/47] Update gradle.xml From ad29d435f090024d8be5d9e3ecc7d0d67958aa90 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:18 +0530 Subject: [PATCH 31/47] Update gradle.xml From d86ee460e5796e22a5c092078e1f537746269c6c Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:36 +0530 Subject: [PATCH 32/47] Update misc.xml From cc58c5f15eed45a9aa8c637bfb13bb33ac94f213 Mon Sep 17 00:00:00 2001 From: Arunshaik2001 Date: Thu, 22 Sep 2022 21:48:51 +0530 Subject: [PATCH 33/47] changed NoteXApp to myContent --- app/src/main/java/com/hadiyarajesh/notex/MainActivity.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/hadiyarajesh/notex/MainActivity.kt b/app/src/main/java/com/hadiyarajesh/notex/MainActivity.kt index 4ee3315..490735a 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/MainActivity.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/MainActivity.kt @@ -2,16 +2,12 @@ package com.hadiyarajesh.notex import android.app.NotificationChannel import android.app.NotificationManager -import android.app.PendingIntent import android.content.Context -import android.content.Intent import android.os.Build import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat -import com.hadiyarajesh.notex.ui.NoteXApp +import com.hadiyarajesh.notex.ui.reminders.myContent import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -19,7 +15,7 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - NoteXApp() + myContent() } createNotificationChannel() From 3ca953438ceccf0ed029a220595e5e0b28f5aedc Mon Sep 17 00:00:00 2001 From: Arunshaik2001 Date: Sat, 24 Sep 2022 09:28:26 +0530 Subject: [PATCH 34/47] added NotificationDTO.kt --- .../com/hadiyarajesh/notex/di/ScopeModule.kt | 7 +++++++ .../reminder/notification/NotificationDTO.kt | 9 +++++++++ .../notification/NotificationHelper.kt | 18 +++++++----------- .../notex/reminder/worker/ReminderWorker.kt | 14 +++++++++----- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt diff --git a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt index 6b3a54c..49c5a0a 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt @@ -1,5 +1,6 @@ package com.hadiyarajesh.notex.di +import com.hadiyarajesh.notex.reminder.notification.NotificationHelper import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -18,4 +19,10 @@ class ScopeModule { fun provideCoroutineScope(): CoroutineScope { return CoroutineScope(SupervisorJob() + Dispatchers.IO) } + + @Singleton + @Provides + fun provideNotificationHelper(): NotificationHelper{ + return NotificationHelper() + } } diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt new file mode 100644 index 0000000..cf99c1c --- /dev/null +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt @@ -0,0 +1,9 @@ +package com.hadiyarajesh.notex.reminder.notification + +data class NotificationDTO( + val title: String, + val subTitle: String, + val reminderId: Long, + val workerTag: String +) { +} \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt index 41736ca..1bdbc1d 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt @@ -8,17 +8,13 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.hadiyarajesh.notex.MainActivity import com.hadiyarajesh.notex.R -import javax.inject.Inject import kotlin.random.Random -class NotificationHelper @Inject constructor() { +class NotificationHelper{ fun createNotification( context: Context, - title: String, - text: String, - reminderId: Long, - workerTag: String + notificationDTO: NotificationDTO ) { val actionIntent = Intent(context, MainActivity::class.java) val actionPendingIntent = PendingIntent.getActivity( @@ -31,8 +27,8 @@ class NotificationHelper @Inject constructor() { val postponeIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { action = context.resources.getString(R.string.postpone_action) - putExtra(context.resources.getString(R.string.worker_tag), workerTag) - putExtra(context.resources.getString(R.string.reminder_id), reminderId) + putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) + putExtra(context.resources.getString(R.string.reminder_id), notificationDTO.reminderId) putExtra(context.resources.getString(R.string.notification_id),notificationId) } @@ -43,7 +39,7 @@ class NotificationHelper @Inject constructor() { val cancelIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { action = context.resources.getString(R.string.done_action) - putExtra(context.resources.getString(R.string.worker_tag), workerTag) + putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) putExtra(context.resources.getString(R.string.notification_id),notificationId) } @@ -55,8 +51,8 @@ class NotificationHelper @Inject constructor() { val builder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_id)) .setSmallIcon(R.drawable.ic_note_filled) - .setContentTitle(title) - .setContentText(text) + .setContentTitle(notificationDTO.title) + .setContentText(notificationDTO.subTitle) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(actionPendingIntent) .addAction(R.drawable.ic_note_filled, context.getString(R.string.one_hour), postponePendingIntent) diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt index 8559285..af416cd 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt @@ -7,6 +7,7 @@ import com.hadiyarajesh.notex.R import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.entity.Reminder import com.hadiyarajesh.notex.database.model.RepetitionStrategy +import com.hadiyarajesh.notex.reminder.notification.NotificationDTO import com.hadiyarajesh.notex.reminder.notification.NotificationHelper import dagger.assisted.Assisted import dagger.assisted.AssistedInject @@ -35,16 +36,19 @@ class ReminderWorker @AssistedInject constructor( notificationHelper.createNotification( applicationContext, - text = "${localDate.hour}:${localDate.minute}", - title = reminder.content, - reminderId = reminderId, - workerTag = inputData.getString(applicationContext.getString(R.string.worker_tag)) ?: "" + NotificationDTO( + title = reminder.content, + subTitle = "${localDate.hour}:${localDate.minute}", + reminderId = reminderId, + workerTag = inputData.getString(applicationContext.getString(R.string.worker_tag)) + ?: "" + ) ) if (reminder.repeat != RepetitionStrategy.None) { reminderWorkManager.createWorkRequestAndEnqueue( - reminderId= reminderId, + reminderId = reminderId, context = applicationContext, isFirstTime = false, time = reminder.reminderTime From dd985f9715e986833b8f6ab6973a79cd20cf27bf Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:41:28 +0530 Subject: [PATCH 35/47] Update misc.xml --- .idea/misc.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e69de29 From 9caee956d085ac06af2a99aabe85cf54d148121a Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:42:18 +0530 Subject: [PATCH 36/47] Update gradle.xml --- .idea/gradle.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .idea/gradle.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..e69de29 From a03316f3da0a246d40e629e1cac2c5e4af0c8291 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:42:58 +0530 Subject: [PATCH 37/47] Update gradle.xml From 08e02781ed12c36cacbfb267b33993290147e80c Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:18 +0530 Subject: [PATCH 38/47] Update gradle.xml From fbe210951a0309c8565544c9d94da3fab636ec91 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:36 +0530 Subject: [PATCH 39/47] Update misc.xml From 6fe9454ac37ed9914295482830a8739e2374a2c8 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:42:58 +0530 Subject: [PATCH 40/47] Update gradle.xml From e2097f658aa0e59da8a7b537194f3d7f1b99c939 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:18 +0530 Subject: [PATCH 41/47] Update gradle.xml From 28d5c575aef4b6124d77628b13b949aee2dafe49 Mon Sep 17 00:00:00 2001 From: Shaik Ahron <50947867+Arunshaik2001@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:43:36 +0530 Subject: [PATCH 42/47] Update misc.xml From 4088be4b2aff25de85a4ac3a95eb1ee2cab7aa57 Mon Sep 17 00:00:00 2001 From: geetgobindsingh Date: Sun, 16 Oct 2022 11:54:32 +0530 Subject: [PATCH 43/47] detekt requested changes applied --- .../NotificationBroadCastReceiver.kt | 8 +++--- .../reminder/notification/NotificationDTO.kt | 3 +-- .../notification/NotificationHelper.kt | 3 ++- .../reminder/worker/ReminderWorkManager.kt | 26 ++++++------------- .../notex/reminder/worker/ReminderWorker.kt | 8 +++--- .../reminders/RemindersRepository.kt | 10 ++++--- .../notex/ui/reminders/RemindersScreen.kt | 13 ++++++---- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt index 7982192..73fb2e5 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt @@ -27,12 +27,11 @@ class NotificationBroadCastReceiver : HiltBroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { super.onReceive(context, intent) when (intent.action) { - context.resources.getString(R.string.done_action) -> { + context.resources.getString(R.string.done_action) -> reminderWorkManager.cancelWorkRequest( context, intent.getStringExtra(context.resources.getString(R.string.worker_tag)) ?: "" ) - } context.resources.getString(R.string.postpone_action) -> { reminderWorkManager.cancelWorkRequest( context, @@ -49,9 +48,7 @@ class NotificationBroadCastReceiver : HiltBroadcastReceiver() { ) ) } - else -> { - Log.i(TAG, "Nothing to Perform this Action ${intent.action}") - } + else -> Log.i(TAG, "Nothing to Perform this Action ${intent.action}") } with(NotificationManagerCompat.from(context)) { @@ -61,6 +58,7 @@ class NotificationBroadCastReceiver : HiltBroadcastReceiver() { } abstract class HiltBroadcastReceiver : BroadcastReceiver() { + @SuppressWarnings("EmptyFunctionBlock") @CallSuper override fun onReceive(context: Context, intent: Intent) { } diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt index cf99c1c..f51b6fa 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.kt @@ -5,5 +5,4 @@ data class NotificationDTO( val subTitle: String, val reminderId: Long, val workerTag: String -) { -} \ No newline at end of file +) diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt index 1bdbc1d..c149f24 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt @@ -22,6 +22,7 @@ class NotificationHelper{ actionIntent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE ) + @SuppressWarnings("MagicNumber") val notificationId = Random(121).nextInt(10000) @@ -65,4 +66,4 @@ class NotificationHelper{ notify(notificationId, builder.build()) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt index 425495c..95fb5a4 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt @@ -40,8 +40,8 @@ class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { val reminder = reminderDao.getById(reminderId) - val initialDelay = if (isFirstTime) time.toEpochMilli() - Instant.now().toEpochMilli() - else getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) + val initialDelay = if (isFirstTime) {time.toEpochMilli() - Instant.now().toEpochMilli() } + else { getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) } val dailyWorkRequest: WorkRequest = OneTimeWorkRequestBuilder() .setInitialDelay( @@ -64,25 +64,15 @@ class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { ): Long { val duration: Long when (reminderStrategy) { - RepetitionStrategy.Daily -> { - duration = Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli() - } - RepetitionStrategy.Monthly -> { - duration = Instant.now().plus(1, ChronoUnit.MONTHS).toEpochMilli() - } - RepetitionStrategy.Yearly -> { - duration = Instant.now().plus(1, ChronoUnit.YEARS).toEpochMilli() - } - RepetitionStrategy.Weekly -> { - duration = Instant.now().plus(1, ChronoUnit.WEEKS).toEpochMilli() - } - else -> { - duration = reminderTime.toEpochMilli() - } + RepetitionStrategy.Daily -> duration = Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli() + RepetitionStrategy.Monthly -> duration = Instant.now().plus(1, ChronoUnit.MONTHS).toEpochMilli() + RepetitionStrategy.Yearly -> duration = Instant.now().plus(1, ChronoUnit.YEARS).toEpochMilli() + RepetitionStrategy.Weekly -> duration = Instant.now().plus(1, ChronoUnit.WEEKS).toEpochMilli() + else -> duration = reminderTime.toEpochMilli() } return duration - Instant.now().toEpochMilli() } fun cancelWorkRequest(context: Context, tag: String) = WorkManager.getInstance(context).cancelAllWorkByTag(tag) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt index af416cd..06542b8 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt @@ -2,7 +2,8 @@ package com.hadiyarajesh.notex.reminder.worker import android.content.Context import androidx.hilt.work.HiltWorker -import androidx.work.* +import androidx.work.CoroutineWorker +import androidx.work.WorkerParameters import com.hadiyarajesh.notex.R import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.entity.Reminder @@ -27,8 +28,9 @@ class ReminderWorker @AssistedInject constructor( override suspend fun doWork(): Result { val reminderId = inputData.getLong(applicationContext.getString(R.string.reminder_instance_key), -1) - if (reminderId == -1L) + if (reminderId == -1L) { return Result.failure() + } val reminder: Reminder = reminderDao.getById(reminderId) val localDate: LocalDateTime = @@ -57,4 +59,4 @@ class ReminderWorker @AssistedInject constructor( return Result.success() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt index 33a832b..840dc6f 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt @@ -8,7 +8,6 @@ import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.entity.Reminder import com.hadiyarajesh.notex.database.model.RepetitionStrategy import com.hadiyarajesh.notex.reminder.worker.ReminderWorkManager -import com.hadiyarajesh.notex.reminder.worker.ReminderWorker import kotlinx.coroutines.flow.Flow import java.time.Instant import javax.inject.Inject @@ -41,8 +40,13 @@ class RemindersRepository @Inject constructor( val reminderWorkManager = ReminderWorkManager(reminderDao) reminderWorkManager.reminderDao = reminderDao - if(context != null) - reminderWorkManager.createWorkRequestAndEnqueue(context, reminderId = reminderId, time = reminderTime) + if (context != null) { + reminderWorkManager.createWorkRequestAndEnqueue( + context, + reminderId = reminderId, + time = reminderTime + ) + } } fun getAllReminders(): Flow> = Pager( diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt index 7f66884..3232828 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt @@ -5,7 +5,11 @@ import android.app.TimePickerDialog import android.os.Build import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material3.* +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -33,7 +37,6 @@ import com.hadiyarajesh.notex.ui.component.RetryItem import java.time.Instant import java.time.LocalDateTime import java.time.LocalTime -import java.time.ZoneOffset @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -150,12 +153,12 @@ fun myContent(): LocalDateTime { val mCalendar = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { LocalDateTime.now() } else { - TODO("VERSION.SDK_INT < O") + // TODO("VERSION.SDK_INT < O") } val mHour = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mCalendar.hour } else { - TODO("VERSION.SDK_INT < O") + // TODO("VERSION.SDK_INT < O") } val mMinute = mCalendar.minute // Value for storing time as a string @@ -218,4 +221,4 @@ fun DefaultPreview() { Scaffold( content = { myContent() } ) -} \ No newline at end of file +} From 93795fa10684bc37b89bdc9fc17c1a29a2cf44c4 Mon Sep 17 00:00:00 2001 From: geetgobindsingh Date: Sun, 16 Oct 2022 11:58:03 +0530 Subject: [PATCH 44/47] ktlint changes applied --- app/build.gradle.kts | 1 - .../java/com/hadiyarajesh/notex/MyApplication.kt | 1 - .../java/com/hadiyarajesh/notex/di/ScopeModule.kt | 2 +- .../notification/NotificationBroadCastReceiver.kt | 1 - .../reminder/notification/NotificationHelper.kt | 8 +++----- .../notex/reminder/worker/ReminderWorkManager.kt | 15 +++++---------- .../notex/reminder/worker/ReminderWorker.kt | 2 -- .../repository/reminders/RemindersRepository.kt | 2 +- .../notex/ui/reminders/RemindersScreen.kt | 4 ---- 9 files changed, 10 insertions(+), 26 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 22b787b..d5531ad 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -135,7 +135,6 @@ dependencies { debugImplementation("androidx.compose.ui:ui-tooling:${LibVersion.composeVersion}") debugImplementation("androidx.compose.ui:ui-test-manifest:${LibVersion.composeVersion}") - implementation("androidx.hilt:hilt-work:1.0.0") kapt("androidx.hilt:hilt-compiler:1.0.0") } diff --git a/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt b/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt index 5e51299..d3299a0 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/MyApplication.kt @@ -17,5 +17,4 @@ class MyApplication : Application(), Configuration.Provider { .setWorkerFactory(workerFactory) .build() } - } diff --git a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt index 49c5a0a..544b04b 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/di/ScopeModule.kt @@ -22,7 +22,7 @@ class ScopeModule { @Singleton @Provides - fun provideNotificationHelper(): NotificationHelper{ + fun provideNotificationHelper(): NotificationHelper { return NotificationHelper() } } diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt index 73fb2e5..ef09e5a 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.kt @@ -23,7 +23,6 @@ class NotificationBroadCastReceiver : HiltBroadcastReceiver() { @Inject lateinit var reminderWorkManager: ReminderWorkManager - override fun onReceive(context: Context, intent: Intent) { super.onReceive(context, intent) when (intent.action) { diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt index c149f24..4e3f37a 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.kt @@ -10,7 +10,7 @@ import com.hadiyarajesh.notex.MainActivity import com.hadiyarajesh.notex.R import kotlin.random.Random -class NotificationHelper{ +class NotificationHelper { fun createNotification( context: Context, @@ -25,12 +25,11 @@ class NotificationHelper{ @SuppressWarnings("MagicNumber") val notificationId = Random(121).nextInt(10000) - val postponeIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { action = context.resources.getString(R.string.postpone_action) putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) putExtra(context.resources.getString(R.string.reminder_id), notificationDTO.reminderId) - putExtra(context.resources.getString(R.string.notification_id),notificationId) + putExtra(context.resources.getString(R.string.notification_id), notificationId) } val postponePendingIntent = PendingIntent.getBroadcast( @@ -41,7 +40,7 @@ class NotificationHelper{ val cancelIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { action = context.resources.getString(R.string.done_action) putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) - putExtra(context.resources.getString(R.string.notification_id),notificationId) + putExtra(context.resources.getString(R.string.notification_id), notificationId) } val cancelPendingIntent = PendingIntent.getBroadcast( @@ -60,7 +59,6 @@ class NotificationHelper{ .addAction(R.drawable.ic_note_filled, context.getString(R.string.done), cancelPendingIntent) .setAutoCancel(true) - with(NotificationManagerCompat.from(context)) { // notificationId is a unique int for each notification that you must define notify(notificationId, builder.build()) diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt index 95fb5a4..d2f50ec 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt @@ -8,17 +8,16 @@ import androidx.work.WorkRequest import com.hadiyarajesh.notex.R import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.model.RepetitionStrategy -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import java.time.Instant import java.time.temporal.ChronoUnit import java.util.concurrent.TimeUnit import javax.inject.Inject +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { - fun createWorkRequestAndEnqueue( context: Context, reminderId: Long, @@ -33,15 +32,13 @@ class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { ) val workerTag = - "${context.resources.getString(R.string.reminder_worker_tag)}${reminderId}" + "${context.resources.getString(R.string.reminder_worker_tag)}$reminderId" data.putString(context.resources.getString(R.string.worker_tag), workerTag) - val reminder = reminderDao.getById(reminderId) - val initialDelay = if (isFirstTime) {time.toEpochMilli() - Instant.now().toEpochMilli() } - else { getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) } + val initialDelay = if (isFirstTime) { time.toEpochMilli() - Instant.now().toEpochMilli() } else { getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) } val dailyWorkRequest: WorkRequest = OneTimeWorkRequestBuilder() .setInitialDelay( @@ -54,10 +51,8 @@ class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { WorkManager.getInstance(context) .enqueue(dailyWorkRequest) } - } - private fun getDurationInMilli( reminderStrategy: RepetitionStrategy, reminderTime: Instant diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt index 06542b8..493fbb8 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorker.kt @@ -47,7 +47,6 @@ class ReminderWorker @AssistedInject constructor( ) ) - if (reminder.repeat != RepetitionStrategy.None) { reminderWorkManager.createWorkRequestAndEnqueue( reminderId = reminderId, @@ -58,5 +57,4 @@ class ReminderWorker @AssistedInject constructor( } return Result.success() } - } diff --git a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt index 840dc6f..692a033 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/repository/reminders/RemindersRepository.kt @@ -8,10 +8,10 @@ import com.hadiyarajesh.notex.database.dao.ReminderDao import com.hadiyarajesh.notex.database.entity.Reminder import com.hadiyarajesh.notex.database.model.RepetitionStrategy import com.hadiyarajesh.notex.reminder.worker.ReminderWorkManager -import kotlinx.coroutines.flow.Flow import java.time.Instant import javax.inject.Inject import javax.inject.Singleton +import kotlinx.coroutines.flow.Flow @Singleton class RemindersRepository @Inject constructor( diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt index 3232828..4e0b18d 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/reminders/RemindersScreen.kt @@ -140,10 +140,8 @@ private fun ReminderItem( } } - @Composable fun myContent(): LocalDateTime { - val reminderViewModel = hiltViewModel() // Fetching local context @@ -193,7 +191,6 @@ fun myContent(): LocalDateTime { verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { - // On button click, TimePicker is // displayed, user can select a time Button( @@ -212,7 +209,6 @@ fun myContent(): LocalDateTime { return mTimeStore.value } - @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @OptIn(ExperimentalMaterial3Api::class) @Preview(showBackground = true) From 51c316e66a827f5381f91a777f8550864fa65fc7 Mon Sep 17 00:00:00 2001 From: geetgobindsingh Date: Sun, 16 Oct 2022 12:01:10 +0530 Subject: [PATCH 45/47] ktlint changes applied --- .../notex/reminder/worker/ReminderWorkManager.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt index d2f50ec..1c9663b 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/reminder/worker/ReminderWorkManager.kt @@ -38,7 +38,11 @@ class ReminderWorkManager @Inject constructor(var reminderDao: ReminderDao) { val reminder = reminderDao.getById(reminderId) - val initialDelay = if (isFirstTime) { time.toEpochMilli() - Instant.now().toEpochMilli() } else { getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) } + val initialDelay = if (isFirstTime) { + time.toEpochMilli() - Instant.now().toEpochMilli() + } else { + getDurationInMilli(reminderStrategy = reminder.repeat, reminderTime = time) + } val dailyWorkRequest: WorkRequest = OneTimeWorkRequestBuilder() .setInitialDelay( From df228f49be39d45a84075007c4ce0a865f4845cf Mon Sep 17 00:00:00 2001 From: geetgobindsingh Date: Sat, 17 Dec 2022 20:17:06 +0530 Subject: [PATCH 46/47] project gradle changes --- .idea/gradle.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index e69de29..0634512 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file From d15a0d3983aa459f8a0b82d1050bd3c2b98002e8 Mon Sep 17 00:00:00 2001 From: geetgobindsingh Date: Sat, 17 Dec 2022 20:18:35 +0530 Subject: [PATCH 47/47] project gradle changes --- .idea/gradle.xml | 8 ++++++++ .idea/misc.xml | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0634512..18b5da5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index e69de29..4bc4fc6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file