├── LICENSE
├── README.md
├── app
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jetpack
│ │ └── todonotes
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jetpack
│ │ │ └── todonotes
│ │ │ ├── MainActivity.kt
│ │ │ ├── ToDoNotesApplication.kt
│ │ │ ├── components
│ │ │ ├── DisplayAlertDialog.kt
│ │ │ └── PriorityDropDown.kt
│ │ │ ├── database
│ │ │ ├── ToDoDao.kt
│ │ │ ├── ToDoDatabase.kt
│ │ │ ├── di
│ │ │ │ └── DatabaseModule.kt
│ │ │ ├── model
│ │ │ │ ├── Priority.kt
│ │ │ │ └── ToDoTask.kt
│ │ │ └── repositories
│ │ │ │ ├── DataStoreRepository.kt
│ │ │ │ └── ToDoRepository.kt
│ │ │ ├── navigation
│ │ │ ├── Navigation.kt
│ │ │ ├── Screens.kt
│ │ │ └── destinations
│ │ │ │ ├── ListComposable.kt
│ │ │ │ └── TaskComposable.kt
│ │ │ ├── ui
│ │ │ └── theme
│ │ │ │ ├── Color.kt
│ │ │ │ ├── Dimensions.kt
│ │ │ │ ├── Shape.kt
│ │ │ │ ├── Theme.kt
│ │ │ │ └── Type.kt
│ │ │ ├── utils
│ │ │ ├── Action.kt
│ │ │ ├── Constants.kt
│ │ │ ├── RequestState.kt
│ │ │ ├── SearchAppBarState.kt
│ │ │ └── TrailingIconState.kt
│ │ │ ├── view
│ │ │ ├── EmptyContent.kt
│ │ │ ├── ListAppBar.kt
│ │ │ ├── ListContent.kt
│ │ │ ├── ListScreen.kt
│ │ │ └── task
│ │ │ │ ├── TaskAppBar.kt
│ │ │ │ ├── TaskContent.kt
│ │ │ │ └── TaskScreen.kt
│ │ │ └── viewmodel
│ │ │ └── ToDoNotesViewModel.kt
│ └── res
│ │ ├── drawable-v24
│ │ ├── ic_filter_list.xml
│ │ ├── ic_launcher_foreground.xml
│ │ ├── ic_sad_face.xml
│ │ └── ic_vertical_menu.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── values-night
│ │ └── themes.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── jetpack
│ └── todonotes
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Jetpack-Compose-ToDo-Notes
2 |
3 | ## [Watch it On YouTube](https://youtu.be/KsNAfZf7WqI)
4 |
5 | ## License
6 | ```
7 | Copyright 2020 MakeItEasyDev
8 |
9 | Licensed under the Apache License, Version 2.0 (the "License");
10 | you may not use this file except in compliance with the License.
11 | You may obtain a copy of the License at
12 |
13 | http://www.apache.org/licenses/LICENSE-2.0
14 |
15 | Unless required by applicable law or agreed to in writing, software
16 | distributed under the License is distributed on an "AS IS" BASIS,
17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | See the License for the specific language governing permissions and
19 | limitations under the License.
20 | ```
21 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-kapt'
5 | id 'dagger.hilt.android.plugin'
6 | }
7 |
8 | android {
9 | compileSdk 31
10 |
11 | defaultConfig {
12 | applicationId "com.jetpack.todonotes"
13 | minSdk 22
14 | targetSdk 31
15 | versionCode 1
16 | versionName "1.0"
17 |
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | vectorDrawables {
20 | useSupportLibrary true
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | kotlinOptions {
35 | jvmTarget = '1.8'
36 | useIR = true
37 | }
38 | buildFeatures {
39 | compose true
40 | }
41 | composeOptions {
42 | kotlinCompilerExtensionVersion compose_version
43 | kotlinCompilerVersion '1.5.10'
44 | }
45 | packagingOptions {
46 | resources {
47 | excludes += '/META-INF/{AL2.0,LGPL2.1}'
48 | }
49 | }
50 | }
51 |
52 | dependencies {
53 |
54 | implementation 'androidx.core:core-ktx:1.7.0'
55 | implementation 'androidx.appcompat:appcompat:1.4.1'
56 | implementation 'com.google.android.material:material:1.5.0'
57 | implementation "androidx.compose.ui:ui:$compose_version"
58 | implementation "androidx.compose.material:material:$compose_version"
59 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
60 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
61 | implementation 'androidx.activity:activity-compose:1.4.0'
62 | testImplementation 'junit:junit:4.+'
63 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
64 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
65 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
66 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
67 |
68 | //Compose Navigation
69 | implementation "androidx.navigation:navigation-compose:2.4.0-alpha10"
70 |
71 | //DataStore Preferences
72 | implementation "androidx.datastore:datastore-preferences:1.0.0"
73 |
74 | //Room Database
75 | implementation "androidx.room:room-runtime:2.3.0"
76 | kapt "androidx.room:room-compiler:2.3.0"
77 | implementation "androidx.room:room-ktx:2.3.0"
78 |
79 | //Dagger Hilt
80 | implementation "com.google.dagger:hilt-android:2.36"
81 | kapt "com.google.dagger:hilt-android-compiler:2.36"
82 | kapt 'androidx.hilt:hilt-compiler:1.0.0'
83 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jetpack/todonotes/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jetpack.todonotes", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.activity.viewModels
7 | import androidx.compose.material.ExperimentalMaterialApi
8 | import androidx.compose.material.MaterialTheme
9 | import androidx.compose.material.Surface
10 | import androidx.navigation.NavHostController
11 | import androidx.navigation.compose.rememberNavController
12 | import com.jetpack.todonotes.navigation.ToDoNotesNavigation
13 | import com.jetpack.todonotes.ui.theme.ToDoNotesTheme
14 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
15 | import dagger.hilt.android.AndroidEntryPoint
16 |
17 | @AndroidEntryPoint
18 | class MainActivity : ComponentActivity() {
19 | private lateinit var navController: NavHostController
20 | private val toDoNotesViewModel: ToDoNotesViewModel by viewModels()
21 |
22 | @ExperimentalMaterialApi
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 | setContent {
26 | ToDoNotesTheme {
27 | Surface(color = MaterialTheme.colors.background) {
28 | navController = rememberNavController()
29 | ToDoNotesNavigation(
30 | navHostController = navController,
31 | toDoNotesViewModel = toDoNotesViewModel
32 | )
33 | }
34 | }
35 | }
36 | }
37 | }
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ToDoNotesApplication.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | @HiltAndroidApp
7 | class ToDoNotesApplication: Application() {
8 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/components/DisplayAlertDialog.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.components
2 |
3 | import androidx.compose.material.*
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.ui.res.stringResource
6 | import androidx.compose.ui.text.font.FontWeight
7 | import com.jetpack.todonotes.R
8 |
9 | @Composable
10 | fun DisplayAlertDialog(
11 | title: String,
12 | message: String,
13 | openDialog: Boolean,
14 | closeDialog: () -> Unit,
15 | onYesClicked: () -> Unit
16 | ) {
17 | if (openDialog) {
18 | AlertDialog(
19 | onDismissRequest = { closeDialog() },
20 | title = {
21 | Text(
22 | text = title,
23 | fontSize = MaterialTheme.typography.h5.fontSize,
24 | fontWeight = FontWeight.Bold
25 | )
26 | },
27 | text = {
28 | Text(
29 | text = message,
30 | fontSize = MaterialTheme.typography.subtitle1.fontSize,
31 | fontWeight = FontWeight.Normal
32 | )
33 | },
34 | confirmButton = {
35 | Button(
36 | onClick = {
37 | closeDialog()
38 | onYesClicked()
39 | }
40 | ) {
41 | Text(text = stringResource(id = R.string.yes))
42 | }
43 | },
44 | dismissButton = {
45 | OutlinedButton(
46 | onClick = { closeDialog() }
47 | ) {
48 | Text(text = stringResource(id = R.string.no))
49 | }
50 | }
51 | )
52 | }
53 | }
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/components/PriorityDropDown.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.components
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.animation.core.animateFloatAsState
5 | import androidx.compose.foundation.background
6 | import androidx.compose.foundation.border
7 | import androidx.compose.foundation.clickable
8 | import androidx.compose.foundation.layout.*
9 | import androidx.compose.material.*
10 | import androidx.compose.material.icons.Icons
11 | import androidx.compose.material.icons.filled.ArrowDropDown
12 | import androidx.compose.runtime.*
13 | import androidx.compose.ui.Alignment
14 | import androidx.compose.ui.Modifier
15 | import androidx.compose.ui.draw.alpha
16 | import androidx.compose.ui.draw.rotate
17 | import androidx.compose.ui.unit.dp
18 | import com.jetpack.todonotes.database.model.Priority
19 | import com.jetpack.todonotes.ui.theme.*
20 |
21 | @Composable
22 | fun PriorityDropDown(
23 | priority: Priority,
24 | onPrioritySelected: (Priority) -> Unit
25 | ) {
26 | var expanded by remember { mutableStateOf(false) }
27 | val angel: Float by animateFloatAsState(targetValue = if (expanded) 180f else 0f)
28 |
29 | Row(
30 | modifier = Modifier
31 | .fillMaxWidth()
32 | .background(MaterialTheme.colors.background)
33 | .height(PRIORITY_DROP_DOWN_HEIGHT)
34 | .clickable {
35 | expanded = true
36 | }
37 | .border(
38 | width = 1.dp,
39 | color = MaterialTheme.colors.onSurface.copy(
40 | alpha = ContentAlpha.disabled
41 | ),
42 | shape = MaterialTheme.shapes.small
43 | ),
44 | verticalAlignment = Alignment.CenterVertically
45 | ) {
46 | Canvas(
47 | modifier = Modifier
48 | .size(PRIORITY_INDICATOR_SIZE)
49 | .weight(1f)
50 | ) {
51 | drawCircle(color = priority.color)
52 | }
53 | Text(
54 | text = priority.name,
55 | modifier = Modifier
56 | .weight(8f),
57 | style = MaterialTheme.typography.subtitle2
58 | )
59 | IconButton(
60 | onClick = { expanded = true },
61 | modifier = Modifier
62 | .alpha(ContentAlpha.medium)
63 | .rotate(degrees = angel)
64 | .weight(1.5f)
65 | ) {
66 | Icon(
67 | imageVector = Icons.Filled.ArrowDropDown,
68 | contentDescription = "Drop Down"
69 | )
70 | }
71 |
72 | DropdownMenu(
73 | expanded = expanded,
74 | onDismissRequest = {
75 | expanded = false
76 | },
77 | modifier = Modifier
78 | .fillMaxWidth(fraction = 0.94f)
79 | ) {
80 | DropdownMenuItem(
81 | onClick = {
82 | expanded = false
83 | onPrioritySelected(Priority.LOW)
84 | }
85 | ) {
86 | PriorityItem(priority = Priority.LOW)
87 | }
88 | DropdownMenuItem(
89 | onClick = {
90 | expanded = false
91 | onPrioritySelected(Priority.MEDIUM)
92 | }
93 | ) {
94 | PriorityItem(priority = Priority.MEDIUM)
95 | }
96 | DropdownMenuItem(
97 | onClick = {
98 | expanded = false
99 | onPrioritySelected(Priority.HIGH)
100 | }
101 | ) {
102 | PriorityItem(priority = Priority.HIGH)
103 | }
104 | }
105 | }
106 | }
107 |
108 | @Composable
109 | fun PriorityItem(
110 | priority: Priority
111 | ) {
112 | Row(
113 | verticalAlignment = Alignment.CenterVertically
114 | ) {
115 | Canvas(
116 | modifier = Modifier
117 | .size(PRIORITY_INDICATOR_SIZE)
118 | ) {
119 | drawCircle(color = priority.color)
120 | }
121 | Text(
122 | text = priority.name,
123 | modifier = Modifier
124 | .padding(start = LARGE_PADDING),
125 | style = Typography.subtitle2,
126 | color = MaterialTheme.colors.onSurface
127 | )
128 | }
129 | }
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/ToDoDao.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database
2 |
3 | import androidx.room.*
4 | import com.jetpack.todonotes.database.model.ToDoTask
5 | import kotlinx.coroutines.flow.Flow
6 |
7 | @Dao
8 | interface ToDoDao {
9 | @Query("SELECT * FROM todo_table ORDER BY id ASC")
10 | fun getAllTasks(): Flow>
11 |
12 | @Query("SELECT * FROM todo_table WHERE id = :taskId")
13 | fun getSelectedTask(taskId: Int): Flow
14 |
15 | @Insert(onConflict = OnConflictStrategy.IGNORE)
16 | suspend fun addTask(toDoTask: ToDoTask)
17 |
18 | @Update
19 | suspend fun updateTask(toDoTask: ToDoTask)
20 |
21 | @Delete
22 | suspend fun deleteTask(toDoTask: ToDoTask)
23 |
24 | @Query("DELETE FROM todo_table")
25 | suspend fun deleteAllTasks()
26 |
27 | @Query("SELECT * FROM todo_table WHERE title LIKE :searchQuery OR description LIKE :searchQuery")
28 | fun searchDatabase(searchQuery: String): Flow>
29 |
30 | @Query("SELECT * FROM todo_table ORDER BY CASE WHEN priority LIKE 'L%' THEN 1 WHEN priority LIKE 'M%' THEN 2 WHEN priority LIKE 'H%' THEN 3 END")
31 | fun sortByLowPriority(): Flow>
32 |
33 | @Query("SELECT * FROM TODO_TABLE ORDER BY CASE WHEN priority LIKE 'H%' THEN 1 WHEN priority LIKE 'M%' THEN 2 WHEN priority LIKE 'L%' THEN 3 END")
34 | fun sortByHighPriority(): Flow>
35 | }
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/ToDoDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import com.jetpack.todonotes.database.model.ToDoTask
6 |
7 | @Database(entities = [ToDoTask::class], version = 1 , exportSchema = false)
8 | abstract class ToDoDatabase: RoomDatabase() {
9 |
10 | abstract fun toDoDao() : ToDoDao
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/di/DatabaseModule.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database.di
2 |
3 | import android.content.Context
4 | import androidx.room.Room
5 | import com.jetpack.todonotes.database.ToDoDatabase
6 | import com.jetpack.todonotes.utils.Constants.DATABASE_NAME
7 | import dagger.Module
8 | import dagger.Provides
9 | import dagger.hilt.InstallIn
10 | import dagger.hilt.android.qualifiers.ApplicationContext
11 | import dagger.hilt.components.SingletonComponent
12 | import javax.inject.Singleton
13 |
14 | @Module
15 | @InstallIn(SingletonComponent::class)
16 | object DatabaseModule {
17 |
18 | @Singleton
19 | @Provides
20 | fun provideDatabase(
21 | @ApplicationContext context: Context
22 | ) = Room.databaseBuilder(
23 | context, ToDoDatabase::class.java,
24 | DATABASE_NAME
25 | ).build()
26 |
27 | @Singleton
28 | @Provides
29 | fun provideDao(database: ToDoDatabase) = database.toDoDao()
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/model/Priority.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database.model
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import com.jetpack.todonotes.ui.theme.HighPriorityColor
5 | import com.jetpack.todonotes.ui.theme.LowPriorityColor
6 | import com.jetpack.todonotes.ui.theme.MediumPriorityColor
7 | import com.jetpack.todonotes.ui.theme.NonePriorityColor
8 |
9 | enum class Priority(val color: Color) {
10 | HIGH(HighPriorityColor),
11 | MEDIUM(MediumPriorityColor),
12 | LOW(LowPriorityColor),
13 | NONE(NonePriorityColor)
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/model/ToDoTask.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database.model
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 | import com.jetpack.todonotes.utils.Constants.DATABASE_TABLE
6 |
7 | @Entity(tableName = DATABASE_TABLE)
8 | data class ToDoTask(
9 | @PrimaryKey(autoGenerate = true)
10 | val id: Int = 0,
11 | val title: String,
12 | val description: String,
13 | val priority: Priority
14 | )
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/repositories/DataStoreRepository.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database.repositories
2 |
3 | import android.content.Context
4 | import androidx.datastore.core.DataStore
5 | import androidx.datastore.preferences.core.Preferences
6 | import androidx.datastore.preferences.core.edit
7 | import androidx.datastore.preferences.core.emptyPreferences
8 | import androidx.datastore.preferences.core.stringPreferencesKey
9 | import androidx.datastore.preferences.preferencesDataStore
10 | import com.jetpack.todonotes.database.model.Priority
11 | import com.jetpack.todonotes.utils.Constants.PREFERENCE_KEY
12 | import com.jetpack.todonotes.utils.Constants.PREFERENCE_NAME
13 | import dagger.hilt.android.qualifiers.ApplicationContext
14 | import dagger.hilt.android.scopes.ViewModelScoped
15 | import kotlinx.coroutines.flow.Flow
16 | import kotlinx.coroutines.flow.catch
17 | import kotlinx.coroutines.flow.map
18 | import java.io.IOException
19 | import javax.inject.Inject
20 |
21 | val Context.dataStore: DataStore by preferencesDataStore(name = PREFERENCE_NAME)
22 |
23 | @ViewModelScoped
24 | class DataStoreRepository @Inject constructor(
25 | @ApplicationContext private val context: Context
26 | ) {
27 | private object PreferenceKeys {
28 | val sortKey = stringPreferencesKey(name = PREFERENCE_KEY)
29 | }
30 | private val dataStore = context.dataStore
31 |
32 | suspend fun persistSortState(priority: Priority) {
33 | dataStore.edit { preference ->
34 | preference[PreferenceKeys.sortKey] = priority.name
35 | }
36 | }
37 |
38 | val readSortState: Flow = dataStore.data
39 | .catch { exception ->
40 | if (exception is IOException) {
41 | emit(emptyPreferences())
42 | } else {
43 | throw exception
44 | }
45 | }.map { preferences ->
46 | val sortState = preferences[PreferenceKeys.sortKey] ?: Priority.NONE
47 | sortState
48 | }
49 | }
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/database/repositories/ToDoRepository.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.database.repositories
2 |
3 | import com.jetpack.todonotes.database.ToDoDao
4 | import com.jetpack.todonotes.database.model.ToDoTask
5 | import dagger.hilt.android.scopes.ViewModelScoped
6 | import kotlinx.coroutines.flow.Flow
7 | import javax.inject.Inject
8 |
9 | @ViewModelScoped
10 | class ToDoRepository @Inject constructor(
11 | private val toDoDao: ToDoDao
12 | ) {
13 | val getAllTasks: Flow> = toDoDao.getAllTasks()
14 | val sortByLowPriority: Flow> = toDoDao.sortByLowPriority()
15 | val sortByHighPriority: Flow> = toDoDao.sortByHighPriority()
16 |
17 | fun getSelectedTask(taskId: Int): Flow {
18 | return toDoDao.getSelectedTask(taskId)
19 | }
20 |
21 | suspend fun addTask(toDoTask: ToDoTask) {
22 | toDoDao.addTask(toDoTask)
23 | }
24 |
25 | suspend fun updateTask(toDoTask: ToDoTask) {
26 | toDoDao.updateTask(toDoTask)
27 | }
28 |
29 | suspend fun deleteTask(toDoTask: ToDoTask) {
30 | toDoDao.deleteTask(toDoTask)
31 | }
32 |
33 | suspend fun deleteAllTasks() {
34 | toDoDao.deleteAllTasks()
35 | }
36 |
37 | fun searchDatabase(searchQuery: String): Flow> {
38 | return toDoDao.searchDatabase(searchQuery)
39 | }
40 | }
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/navigation/Navigation.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.navigation
2 |
3 | import androidx.compose.material.ExperimentalMaterialApi
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.runtime.remember
6 | import androidx.navigation.NavHostController
7 | import androidx.navigation.compose.NavHost
8 | import com.jetpack.todonotes.navigation.destinations.listComposable
9 | import com.jetpack.todonotes.navigation.destinations.taskComposable
10 | import com.jetpack.todonotes.utils.Constants.LIST_SCREEN
11 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
12 |
13 | @ExperimentalMaterialApi
14 | @Composable
15 | fun ToDoNotesNavigation(
16 | navHostController: NavHostController,
17 | toDoNotesViewModel: ToDoNotesViewModel
18 | ) {
19 | val screen = remember(navHostController) { Screens(navHostController) }
20 |
21 | NavHost(
22 | navController = navHostController,
23 | startDestination = LIST_SCREEN
24 | ) {
25 | listComposable(
26 | navigateToTaskScreen = screen.task,
27 | toDoNotesViewModel = toDoNotesViewModel
28 | )
29 | taskComposable(
30 | toDoNotesViewModel = toDoNotesViewModel,
31 | navigateToListScreen = screen.list
32 | )
33 | }
34 | }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/navigation/Screens.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.navigation
2 |
3 | import androidx.navigation.NavHostController
4 | import com.jetpack.todonotes.utils.Action
5 | import com.jetpack.todonotes.utils.Constants.LIST_SCREEN
6 |
7 | class Screens(navController: NavHostController) {
8 | val list: (Action) -> Unit = { action ->
9 | navController.navigate("list/${action.name}") {
10 | popUpTo(LIST_SCREEN) { inclusive = true }
11 | }
12 | }
13 |
14 | val task: (Int) -> Unit = { taskId ->
15 | navController.navigate("task/$taskId")
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/navigation/destinations/ListComposable.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.navigation.destinations
2 |
3 | import android.annotation.SuppressLint
4 | import androidx.compose.material.ExperimentalMaterialApi
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.runtime.LaunchedEffect
7 | import androidx.compose.runtime.mutableStateListOf
8 | import androidx.navigation.NavGraphBuilder
9 | import androidx.navigation.NavType
10 | import androidx.navigation.compose.composable
11 | import androidx.navigation.navArgument
12 | import com.jetpack.todonotes.utils.Constants.LIST_ARGUMENT_KEY
13 | import com.jetpack.todonotes.utils.Constants.LIST_SCREEN
14 | import com.jetpack.todonotes.utils.toAction
15 | import com.jetpack.todonotes.view.ListScreen
16 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
17 |
18 | @SuppressLint("UnrememberedMutableState")
19 | @ExperimentalMaterialApi
20 | fun NavGraphBuilder.listComposable(
21 | navigateToTaskScreen: (taskId: Int) -> Unit,
22 | toDoNotesViewModel: ToDoNotesViewModel
23 | ) {
24 | composable(
25 | route = LIST_SCREEN,
26 | arguments = mutableStateListOf(
27 | navArgument(LIST_ARGUMENT_KEY) {
28 | type = NavType.StringType
29 | }
30 | )
31 | ) { navBackStackEntry ->
32 | val action = navBackStackEntry.arguments?.getString(LIST_ARGUMENT_KEY).toAction()
33 | LaunchedEffect(key1 = action) {
34 | toDoNotesViewModel.action.value = action
35 | }
36 |
37 | ListScreen(
38 | navigateToTaskScreen = navigateToTaskScreen,
39 | toDoNotesViewModel = toDoNotesViewModel
40 | )
41 | }
42 | }
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/navigation/destinations/TaskComposable.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.navigation.destinations
2 |
3 | import android.annotation.SuppressLint
4 | import androidx.compose.runtime.*
5 | import androidx.navigation.NavGraphBuilder
6 | import androidx.navigation.NavType
7 | import androidx.navigation.compose.composable
8 | import androidx.navigation.navArgument
9 | import com.jetpack.todonotes.utils.Action
10 | import com.jetpack.todonotes.utils.Constants.TASK_ARGUMENT_KEY
11 | import com.jetpack.todonotes.utils.Constants.TASK_SCREEN
12 | import com.jetpack.todonotes.view.task.TaskScreen
13 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
14 |
15 | @SuppressLint("UnrememberedMutableState")
16 | fun NavGraphBuilder.taskComposable(
17 | toDoNotesViewModel: ToDoNotesViewModel,
18 | navigateToListScreen: (Action) -> Unit
19 | ) {
20 | composable(
21 | route = TASK_SCREEN,
22 | arguments = mutableStateListOf(
23 | navArgument(TASK_ARGUMENT_KEY) {
24 | type = NavType.IntType
25 | }
26 | )
27 | ) { navBackStackEntry ->
28 | val taskId = navBackStackEntry.arguments!!.getInt(TASK_ARGUMENT_KEY)
29 | LaunchedEffect(key1 = taskId) {
30 | toDoNotesViewModel.getSelectedTask(taskId)
31 | }
32 | val selectedTask by toDoNotesViewModel.selectedTask.collectAsState()
33 |
34 | LaunchedEffect(key1 = selectedTask) {
35 | if (selectedTask != null || taskId == -1) {
36 | toDoNotesViewModel.updateTaskField(selectedTask)
37 | }
38 | }
39 |
40 | TaskScreen(
41 | selectedTask = selectedTask,
42 | toDoNotesViewModel = toDoNotesViewModel,
43 | navigateToListScreen = navigateToListScreen
44 | )
45 | }
46 | }
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.ui.theme
2 |
3 | import androidx.compose.material.Colors
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.ui.graphics.Color
6 |
7 | val Purple200 = Color(0xFFBB86FC)
8 | val Purple500 = Color(0xFFFEECC9)
9 | val Purple700 = Color(0xFF3700B3)
10 | val Teal200 = Color(0xFF03DAC5)
11 |
12 | val LightGray = Color(0xFFFCFCFC)
13 | val MediumGray = Color(0xFF9C9C9C)
14 | val DarkGray = Color(0xFF141414)
15 |
16 | val LowPriorityColor = Color(0xFF00C980)
17 | val MediumPriorityColor = Color(0xFFFFC114)
18 | val HighPriorityColor = Color(0xFFFF4646)
19 | val NonePriorityColor = MediumGray
20 |
21 | val Colors.taskItemTextColor : Color
22 | @Composable
23 | get() = if (isLight) DarkGray else LightGray
24 |
25 | val Colors.taskItemBackgroundColor : Color
26 | @Composable
27 | get() = if (isLight) Color.White else DarkGray
28 |
29 | val Colors.fabBackgroundColor : Color
30 | @Composable
31 | get() = if (isLight) Purple500 else Purple700
32 |
33 | val Colors.topAppBarContentColor : Color
34 | @Composable
35 | get() = if (!isLight) Color.White else DarkGray
36 |
37 | val Colors.topAppBarBackgroundColor : Color
38 | @Composable
39 | get() = if (isLight) Purple500 else Color.Black
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ui/theme/Dimensions.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.ui.theme
2 |
3 | import androidx.compose.ui.unit.dp
4 |
5 | val LARGEST_PADDING = 24.dp
6 | val LARGE_PADDING = 12.dp
7 | val MEDIUM_PADDING = 8.dp
8 | val SMALL_PADDING = 6.dp
9 | val PRIORITY_INDICATOR_SIZE = 16.dp
10 | val TOP_APP_BAR_HEIGHT = 56.dp
11 | val PRIORITY_DROP_DOWN_HEIGHT = 60.dp
12 | val TASK_ITEM_ELEVATION = 2.dp
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val Shapes = Shapes(
8 | small = RoundedCornerShape(4.dp),
9 | medium = RoundedCornerShape(4.dp),
10 | large = RoundedCornerShape(0.dp)
11 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.darkColors
6 | import androidx.compose.material.lightColors
7 | import androidx.compose.runtime.Composable
8 |
9 | private val DarkColorPalette = darkColors(
10 | primary = Purple200,
11 | primaryVariant = Purple700,
12 | secondary = Teal200
13 | )
14 |
15 | private val LightColorPalette = lightColors(
16 | primary = Purple500,
17 | primaryVariant = Purple700,
18 | secondary = Teal200
19 |
20 | /* Other default colors to override
21 | background = Color.White,
22 | surface = Color.White,
23 | onPrimary = Color.White,
24 | onSecondary = Color.Black,
25 | onBackground = Color.Black,
26 | onSurface = Color.Black,
27 | */
28 | )
29 |
30 | @Composable
31 | fun ToDoNotesTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
32 | val colors = if (darkTheme) {
33 | DarkColorPalette
34 | } else {
35 | LightColorPalette
36 | }
37 |
38 | MaterialTheme(
39 | colors = colors,
40 | typography = Typography,
41 | shapes = Shapes,
42 | content = content
43 | )
44 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.ui.theme
2 |
3 | import androidx.compose.material.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | body1 = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp
15 | )
16 | /* Other default text styles to override
17 | button = TextStyle(
18 | fontFamily = FontFamily.Default,
19 | fontWeight = FontWeight.W500,
20 | fontSize = 14.sp
21 | ),
22 | caption = TextStyle(
23 | fontFamily = FontFamily.Default,
24 | fontWeight = FontWeight.Normal,
25 | fontSize = 12.sp
26 | )
27 | */
28 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/utils/Action.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.utils
2 |
3 | enum class Action {
4 | ADD, UPDATE, DELETE, DELETE_ALL, UNDO, NO_ACTION
5 | }
6 |
7 | fun String?.toAction(): Action {
8 | return when {
9 | this == "ADD" -> Action.ADD
10 | this == "UPDATE" -> Action.UPDATE
11 | this == "DELETE" -> Action.DELETE
12 | this == "DELETE_ALL" -> Action.DELETE_ALL
13 | this == "UNDO" -> Action.UNDO
14 | else -> Action.NO_ACTION
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/utils/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.utils
2 |
3 | object Constants {
4 | const val DATABASE_TABLE = "todo_table"
5 | const val DATABASE_NAME = "todo_database"
6 | const val LIST_SCREEN = "list/{action}"
7 | const val TASK_SCREEN = "task/{taskId}"
8 | const val LIST_ARGUMENT_KEY = "action"
9 | const val TASK_ARGUMENT_KEY = "taskId"
10 | const val PREFERENCE_NAME = "todo_preferences"
11 | const val PREFERENCE_KEY = "sort_state"
12 | const val MAX_TITLE_LENGTH = 25
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/utils/RequestState.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.utils
2 |
3 | sealed class RequestState {
4 | object Idle: RequestState()
5 | object Loading: RequestState()
6 | data class Success (val data: T): RequestState()
7 | data class Error (val error: Throwable): RequestState()
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/utils/SearchAppBarState.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.utils
2 |
3 | enum class SearchAppBarState {
4 | OPENED, CLOSED, TRIGGERED
5 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/utils/TrailingIconState.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.utils
2 |
3 | enum class TrailingIconState {
4 | READY_TO_DELETE, READY_TO_CLOSE
5 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/EmptyContent.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.Arrangement
5 | import androidx.compose.foundation.layout.Column
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.size
8 | import androidx.compose.material.Icon
9 | import androidx.compose.material.MaterialTheme
10 | import androidx.compose.material.Text
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.ui.Alignment
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.res.painterResource
15 | import androidx.compose.ui.res.stringResource
16 | import androidx.compose.ui.text.font.FontWeight
17 | import androidx.compose.ui.unit.dp
18 | import com.jetpack.todonotes.R
19 | import com.jetpack.todonotes.ui.theme.MediumGray
20 |
21 | @Composable
22 | fun EmptyContent() {
23 | Column(
24 | modifier = Modifier
25 | .fillMaxSize()
26 | .background(MaterialTheme.colors.background),
27 | horizontalAlignment = Alignment.CenterHorizontally,
28 | verticalArrangement = Arrangement.Center
29 | ) {
30 | Icon(
31 | painter = painterResource(id = R.drawable.ic_sad_face),
32 | contentDescription = "No data",
33 | modifier = Modifier
34 | .size(120.dp),
35 | tint = MediumGray
36 | )
37 | Text(
38 | text = stringResource(id = R.string.empty_content),
39 | color = MediumGray,
40 | fontWeight = FontWeight.Bold,
41 | fontSize = MaterialTheme.typography.h6.fontSize
42 | )
43 | }
44 | }
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/ListAppBar.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view
2 |
3 | import androidx.compose.foundation.layout.fillMaxWidth
4 | import androidx.compose.foundation.layout.height
5 | import androidx.compose.foundation.layout.padding
6 | import androidx.compose.foundation.text.KeyboardActions
7 | import androidx.compose.foundation.text.KeyboardOptions
8 | import androidx.compose.material.*
9 | import androidx.compose.material.icons.Icons
10 | import androidx.compose.material.icons.filled.Close
11 | import androidx.compose.material.icons.filled.Search
12 | import androidx.compose.runtime.*
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.draw.alpha
15 | import androidx.compose.ui.graphics.Color
16 | import androidx.compose.ui.res.painterResource
17 | import androidx.compose.ui.res.stringResource
18 | import androidx.compose.ui.text.TextStyle
19 | import androidx.compose.ui.text.input.ImeAction
20 | import com.jetpack.todonotes.R
21 | import com.jetpack.todonotes.components.DisplayAlertDialog
22 | import com.jetpack.todonotes.components.PriorityItem
23 | import com.jetpack.todonotes.database.model.Priority
24 | import com.jetpack.todonotes.ui.theme.*
25 | import com.jetpack.todonotes.utils.Action
26 | import com.jetpack.todonotes.utils.SearchAppBarState
27 | import com.jetpack.todonotes.utils.TrailingIconState
28 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
29 |
30 | @Composable
31 | fun ListAppBar(
32 | toDoNotesViewModel: ToDoNotesViewModel,
33 | searchAppBarState : SearchAppBarState,
34 | searchTextState : String
35 | ) {
36 | when(searchAppBarState) {
37 | SearchAppBarState.CLOSED -> {
38 | DefaultListAppBar(
39 | onSearchClicked = {
40 | toDoNotesViewModel.searchAppBarState.value =
41 | SearchAppBarState.OPENED
42 | },
43 | onSortClicked = {toDoNotesViewModel.persistSortState(it)},
44 | onDeleteAllConfirmed = {
45 | toDoNotesViewModel.action.value = Action.DELETE_ALL
46 | }
47 | )
48 | }
49 | else -> {
50 | SearchAppBar(
51 | text = searchTextState,
52 | onTextChange = {newText ->
53 | toDoNotesViewModel.searchTextState.value = newText
54 | },
55 | onCloseClicked = {
56 | toDoNotesViewModel.searchAppBarState.value =
57 | SearchAppBarState.CLOSED
58 | toDoNotesViewModel.searchTextState.value = ""
59 | },
60 | onSearchClicked = {
61 | toDoNotesViewModel.searchDatabase(searchQuery = it)
62 | }
63 | )
64 | }
65 | }
66 | }
67 |
68 | @Composable
69 | fun DefaultListAppBar(
70 | onSearchClicked : () -> Unit,
71 | onSortClicked : (Priority) -> Unit,
72 | onDeleteAllConfirmed : () -> Unit
73 | ) {
74 | TopAppBar(
75 | title = {
76 | Text(
77 | text = stringResource(R.string.list_screen_title),
78 | color = MaterialTheme.colors.topAppBarContentColor,
79 | )
80 | },
81 | actions = {
82 | ListAppBarActions(
83 | onSearchClicked = onSearchClicked,
84 | onSortClicked = onSortClicked,
85 | onDeleteAllConfirmed = onDeleteAllConfirmed
86 | )
87 | },
88 | backgroundColor = MaterialTheme.colors.topAppBarBackgroundColor
89 | )
90 | }
91 |
92 | @Composable
93 | fun ListAppBarActions(
94 | onSearchClicked : () -> Unit,
95 | onSortClicked : (Priority) -> Unit,
96 | onDeleteAllConfirmed : () -> Unit
97 | ) {
98 | var openDialog by remember {mutableStateOf(false) }
99 | DisplayAlertDialog(
100 | title = stringResource(id = R.string.delete_all_tasks),
101 | message = stringResource(id = R.string.delete_all_tasks_confirmation),
102 | openDialog = openDialog,
103 | closeDialog = { openDialog = false },
104 | onYesClicked = { onDeleteAllConfirmed() }
105 | )
106 |
107 | SearchAction(onSearchClicked = onSearchClicked)
108 | SortAction(onSortClicked = onSortClicked)
109 | DeleteAllAction(onDeleteAllConfirmed = { openDialog = true})
110 | }
111 |
112 | @Composable
113 | fun SearchAction(
114 | onSearchClicked : () -> Unit
115 | ) {
116 | IconButton(onClick = onSearchClicked) {
117 | Icon(
118 | imageVector = Icons.Filled.Search,
119 | contentDescription = stringResource(id = R.string.search_action),
120 | tint = MaterialTheme.colors.topAppBarContentColor
121 | )
122 | }
123 | }
124 |
125 | @Composable
126 | fun SortAction(
127 | onSortClicked: (Priority) -> Unit
128 | ) {
129 | var expanded by remember { mutableStateOf(false)}
130 | IconButton(
131 | onClick = {expanded = true}
132 | ) {
133 | Icon(
134 | painter = painterResource(id = R.drawable.ic_filter_list),
135 | contentDescription = stringResource(id = R.string.sort_action),
136 | tint = MaterialTheme.colors.topAppBarContentColor
137 | )
138 | DropdownMenu(
139 | expanded = expanded ,
140 | onDismissRequest = { expanded = false}
141 | ) {
142 | DropdownMenuItem(
143 | onClick = {
144 | expanded = false
145 | onSortClicked(Priority.LOW)
146 | }
147 | ) {
148 | PriorityItem(priority = Priority.LOW)
149 | }
150 | DropdownMenuItem(
151 | onClick = {
152 | expanded = false
153 | onSortClicked(Priority.HIGH)
154 | }
155 | ) {
156 | PriorityItem(priority = Priority.HIGH)
157 | }
158 | DropdownMenuItem(
159 | onClick = {
160 | expanded = false
161 | onSortClicked(Priority.NONE)
162 | }
163 | ) {
164 | PriorityItem(priority = Priority.NONE)
165 | }
166 | }
167 | }
168 | }
169 |
170 | @Composable
171 | fun DeleteAllAction(
172 | onDeleteAllConfirmed: () -> Unit
173 | ) {
174 | var expanded by remember { mutableStateOf(false) }
175 | IconButton(
176 | onClick = { expanded = true }
177 | ) {
178 | Icon(
179 | painter = painterResource(id = R.drawable.ic_vertical_menu),
180 | contentDescription = stringResource(id = R.string.delete_all_action),
181 | tint = MaterialTheme.colors.topAppBarContentColor
182 | )
183 | DropdownMenu(
184 | expanded = expanded,
185 | onDismissRequest = { expanded = false }
186 | ) {
187 | DropdownMenuItem(
188 | onClick = {
189 | expanded = false
190 | onDeleteAllConfirmed()
191 | }
192 | ) {
193 | Text (
194 | modifier = Modifier
195 | .padding(start = LARGE_PADDING),
196 | text = stringResource(R.string.delete_all_action),
197 | style = Typography.subtitle2
198 | )
199 | }
200 | }
201 | }
202 | }
203 |
204 | @Composable
205 | fun SearchAppBar(
206 | text: String,
207 | onTextChange : (String) -> Unit,
208 | onCloseClicked : () -> Unit,
209 | onSearchClicked : (String) -> Unit
210 | ) {
211 | var trailingIconState by remember {
212 | mutableStateOf(TrailingIconState.READY_TO_DELETE)
213 | }
214 |
215 | Surface(modifier = Modifier
216 | .fillMaxWidth()
217 | .height(TOP_APP_BAR_HEIGHT),
218 | elevation = AppBarDefaults.TopAppBarElevation,
219 | color = MaterialTheme.colors.topAppBarBackgroundColor
220 |
221 | ) {
222 | TextField(
223 | modifier = Modifier
224 | .fillMaxWidth(),
225 | value = text,
226 | onValueChange = {
227 | onTextChange(it)
228 | },
229 | placeholder = {
230 | Text(
231 | modifier = Modifier
232 | .alpha(ContentAlpha.medium),
233 | text = stringResource(R.string.search_placeholder),
234 | color = Color.White
235 | )
236 | },
237 | textStyle = TextStyle(
238 | color = MaterialTheme.colors.topAppBarContentColor,
239 | fontSize = MaterialTheme.typography.subtitle1.fontSize
240 | ),
241 | singleLine = true,
242 | leadingIcon = {
243 | IconButton(
244 | modifier = Modifier
245 | .alpha(ContentAlpha.disabled),
246 | onClick = {}
247 | ) {
248 | Icon(
249 | imageVector = Icons.Filled.Search,
250 | contentDescription = stringResource(R.string.search_icon),
251 | tint = MaterialTheme.colors.topAppBarContentColor
252 | )
253 | }
254 | },
255 | trailingIcon = {
256 | IconButton(
257 | onClick = {
258 | when(trailingIconState) {
259 | TrailingIconState.READY_TO_DELETE -> {
260 | onTextChange("")
261 | trailingIconState = TrailingIconState.READY_TO_CLOSE
262 | }
263 | TrailingIconState.READY_TO_CLOSE -> {
264 | if (text.isNotEmpty()) {
265 | onTextChange("")
266 | } else {
267 | onCloseClicked()
268 | trailingIconState = TrailingIconState.READY_TO_DELETE
269 | }
270 | }
271 | }
272 | }
273 | ) {
274 | Icon(
275 | imageVector = Icons.Filled.Close,
276 | contentDescription = stringResource(R.string.close_icon),
277 | tint = MaterialTheme.colors.topAppBarContentColor
278 | )
279 | }
280 | },
281 | keyboardOptions = KeyboardOptions(
282 | imeAction = ImeAction.Search
283 | ),
284 | keyboardActions = KeyboardActions(
285 | onSearch = {
286 | onSearchClicked(text)
287 | }
288 | ),
289 | colors = TextFieldDefaults.textFieldColors(
290 | cursorColor = MaterialTheme.colors.topAppBarContentColor,
291 | focusedIndicatorColor = Color.Transparent,
292 | disabledIndicatorColor = Color.Transparent,
293 | unfocusedIndicatorColor = Color.Transparent,
294 | backgroundColor = Color.Transparent
295 | )
296 | )
297 | }
298 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/ListContent.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view
2 |
3 | import androidx.compose.animation.core.animateFloatAsState
4 | import androidx.compose.foundation.Canvas
5 | import androidx.compose.foundation.background
6 | import androidx.compose.foundation.layout.*
7 | import androidx.compose.foundation.lazy.LazyColumn
8 | import androidx.compose.foundation.lazy.items
9 | import androidx.compose.foundation.shape.RoundedCornerShape
10 | import androidx.compose.material.*
11 | import androidx.compose.material.icons.Icons
12 | import androidx.compose.material.icons.filled.Delete
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.runtime.getValue
15 | import androidx.compose.ui.Alignment
16 | import androidx.compose.ui.Modifier
17 | import androidx.compose.ui.draw.rotate
18 | import androidx.compose.ui.graphics.Color
19 | import androidx.compose.ui.graphics.RectangleShape
20 | import androidx.compose.ui.res.stringResource
21 | import androidx.compose.ui.text.font.FontWeight
22 | import androidx.compose.ui.text.style.TextOverflow
23 | import androidx.compose.ui.unit.dp
24 | import com.jetpack.todonotes.R
25 | import com.jetpack.todonotes.database.model.Priority
26 | import com.jetpack.todonotes.database.model.ToDoTask
27 | import com.jetpack.todonotes.ui.theme.*
28 | import com.jetpack.todonotes.utils.Action
29 | import com.jetpack.todonotes.utils.RequestState
30 | import com.jetpack.todonotes.utils.SearchAppBarState
31 |
32 | @ExperimentalMaterialApi
33 | @Composable
34 | fun ListContent(
35 | allTasks : RequestState>,
36 | searchedTasks : RequestState>,
37 | lowPriorityTasks: List,
38 | highPriorityTasks: List,
39 | searchAppBarState: SearchAppBarState,
40 | sortState: RequestState,
41 | onSwipeToDelete: (Action, ToDoTask) -> Unit,
42 | navigateToTaskScreen : (taskId: Int) -> Unit
43 | ) {
44 | if (sortState is RequestState.Success) {
45 | when {
46 | searchAppBarState == SearchAppBarState.TRIGGERED -> {
47 | if (searchedTasks is RequestState.Success) {
48 | HandleListContent(
49 | tasks = searchedTasks.data,
50 | onSwipeToDelete = onSwipeToDelete,
51 | navigateToTaskScreen = navigateToTaskScreen
52 | )
53 | }
54 | }
55 | sortState.data == Priority.NONE -> {
56 | if (allTasks is RequestState.Success) {
57 | HandleListContent(
58 | tasks = allTasks.data,
59 | onSwipeToDelete = onSwipeToDelete,
60 | navigateToTaskScreen = navigateToTaskScreen
61 | )
62 | }
63 | }
64 | sortState.data == Priority.LOW -> {
65 | HandleListContent(
66 | tasks = lowPriorityTasks,
67 | onSwipeToDelete = onSwipeToDelete,
68 | navigateToTaskScreen = navigateToTaskScreen
69 | )
70 | }
71 | sortState.data == Priority.HIGH -> {
72 | HandleListContent(
73 | tasks = highPriorityTasks,
74 | onSwipeToDelete = onSwipeToDelete,
75 | navigateToTaskScreen = navigateToTaskScreen
76 | )
77 | }
78 | }
79 | }
80 | }
81 |
82 | @ExperimentalMaterialApi
83 | @Composable
84 | fun HandleListContent(
85 | tasks: List,
86 | onSwipeToDelete:(Action, ToDoTask) -> Unit,
87 | navigateToTaskScreen: (taskId: Int) -> Unit
88 | ) {
89 | if (tasks.isEmpty()) {
90 | EmptyContent()
91 | } else {
92 | DisplayTasks(
93 | tasks = tasks,
94 | onSwipeToDelete = onSwipeToDelete,
95 | navigateToTaskScreen = navigateToTaskScreen
96 | )
97 | }
98 | }
99 |
100 | @ExperimentalMaterialApi
101 | @Composable
102 | fun DisplayTasks(
103 | tasks : List,
104 | onSwipeToDelete:(Action, ToDoTask) -> Unit,
105 | navigateToTaskScreen : (taskId: Int) -> Unit
106 | ) {
107 | LazyColumn {
108 | items(
109 | items = tasks,
110 | key = { task ->
111 | task.id
112 | }
113 | ) { task ->
114 | val dismissState = rememberDismissState()
115 | val dismissDirection = dismissState.dismissDirection
116 | val isDismissed = dismissState.isDismissed(direction = DismissDirection.EndToStart)
117 | if (isDismissed && dismissDirection == DismissDirection.EndToStart) {
118 | onSwipeToDelete(Action.DELETE, task)
119 | }
120 |
121 | val degrees by animateFloatAsState(if (dismissState.targetValue == DismissValue.Default) 0f else -45f)
122 |
123 | Card(
124 | modifier = Modifier
125 | .fillMaxWidth()
126 | .padding(MEDIUM_PADDING),
127 | elevation = 10.dp,
128 | shape = RoundedCornerShape(MEDIUM_PADDING)
129 | ) {
130 | SwipeToDismiss(
131 | state = dismissState,
132 | directions= setOf(DismissDirection.EndToStart),
133 | dismissThresholds = {FractionalThreshold(0.2f)},
134 | background = { RedBackground(degrees = degrees)},
135 | dismissContent = {
136 | TaskItem(
137 | toDoTask = task,
138 | navigateToTaskScreen = navigateToTaskScreen
139 | )
140 | }
141 | )
142 | }
143 | }
144 | }
145 | }
146 |
147 | @Composable
148 | fun RedBackground(degrees : Float) {
149 | Box(modifier = Modifier
150 | .fillMaxSize()
151 | .background(HighPriorityColor)
152 | .padding(horizontal = LARGEST_PADDING),
153 | contentAlignment = Alignment.CenterEnd
154 | ) {
155 | Icon(
156 | modifier = Modifier.rotate(degrees = degrees),
157 | imageVector = Icons.Filled.Delete,
158 | contentDescription = stringResource(id = R.string.delete_icon),
159 | tint = Color.White
160 | )
161 | }
162 | }
163 |
164 | @ExperimentalMaterialApi
165 | @Composable
166 | fun TaskItem(
167 | toDoTask : ToDoTask,
168 | navigateToTaskScreen : (taskId: Int) -> Unit
169 | ) {
170 | Surface(
171 | modifier = Modifier
172 | .fillMaxWidth(),
173 | color = MaterialTheme.colors.taskItemBackgroundColor,
174 | shape = RectangleShape,
175 | elevation = TASK_ITEM_ELEVATION,
176 | onClick = {
177 | navigateToTaskScreen(toDoTask.id)
178 | }
179 | ) {
180 | Column(modifier = Modifier
181 | .padding(all = LARGE_PADDING)
182 | .fillMaxWidth()
183 | ) {
184 | Row {
185 | Text(
186 | modifier = Modifier.weight(8f),
187 | text = toDoTask.title,
188 | color = MaterialTheme.colors.taskItemTextColor,
189 | style = MaterialTheme.typography.h5,
190 | fontWeight = FontWeight.Bold,
191 | maxLines = 1
192 | )
193 | Box(
194 | modifier = Modifier
195 | .fillMaxWidth()
196 | .weight(1f),
197 | contentAlignment = Alignment.TopEnd
198 | ) {
199 | Canvas(
200 | modifier = Modifier
201 | .size(PRIORITY_INDICATOR_SIZE)
202 | ) {
203 | drawCircle(
204 | color = toDoTask.priority.color
205 | )
206 | }
207 | }
208 | }
209 | Text(
210 | modifier = Modifier.fillMaxWidth(),
211 | text = toDoTask.description,
212 | color = MaterialTheme.colors.taskItemTextColor,
213 | style = MaterialTheme.typography.subtitle1,
214 | maxLines = 2,
215 | overflow = TextOverflow.Ellipsis
216 | )
217 | }
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/ListScreen.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view
2 |
3 | import androidx.compose.material.*
4 | import androidx.compose.material.icons.Icons
5 | import androidx.compose.material.icons.filled.Add
6 | import androidx.compose.runtime.*
7 | import androidx.compose.ui.graphics.Color
8 | import androidx.compose.ui.res.stringResource
9 | import com.jetpack.todonotes.R
10 | import com.jetpack.todonotes.ui.theme.fabBackgroundColor
11 | import com.jetpack.todonotes.utils.Action
12 | import com.jetpack.todonotes.utils.SearchAppBarState
13 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
14 | import kotlinx.coroutines.launch
15 |
16 | @ExperimentalMaterialApi
17 | @Composable
18 | fun ListScreen(
19 | navigateToTaskScreen: (taskId: Int ) -> Unit,
20 | toDoNotesViewModel: ToDoNotesViewModel
21 | ) {
22 | LaunchedEffect(key1 = true) {
23 | toDoNotesViewModel.getAllTasks()
24 | toDoNotesViewModel.readSortState()
25 | }
26 | val action by toDoNotesViewModel.action
27 | val allTasks by toDoNotesViewModel.allTasks.collectAsState()
28 | val sortState by toDoNotesViewModel.sortState.collectAsState()
29 | val lowPriorityTasks by toDoNotesViewModel.lowPriorityTasks.collectAsState()
30 | val highPriorityTasks by toDoNotesViewModel.highPriorityTasks.collectAsState()
31 | val searchedTasks by toDoNotesViewModel.searchedTasks.collectAsState()
32 | val searchAppBarState : SearchAppBarState by toDoNotesViewModel.searchAppBarState
33 | val searchTextState : String by toDoNotesViewModel.searchTextState
34 | val scaffoldState = rememberScaffoldState()
35 |
36 | DisplaySnackBar(
37 | scaffoldState = scaffoldState,
38 | handleDatabaseActions = {toDoNotesViewModel.handleDatabaseActions(action = action)},
39 | onUndoClicked = {
40 | toDoNotesViewModel.action.value = it
41 | },
42 | taskTitle = toDoNotesViewModel.title.value ,
43 | action = action
44 | )
45 |
46 | Scaffold(
47 | scaffoldState = scaffoldState,
48 | topBar = {
49 | ListAppBar(
50 | toDoNotesViewModel = toDoNotesViewModel,
51 | searchAppBarState = searchAppBarState,
52 | searchTextState = searchTextState
53 | )
54 | },
55 | content = {
56 | ListContent(
57 | allTasks = allTasks,
58 | searchedTasks = searchedTasks,
59 | lowPriorityTasks = lowPriorityTasks,
60 | highPriorityTasks= highPriorityTasks,
61 | sortState = sortState,
62 | searchAppBarState = searchAppBarState,
63 | onSwipeToDelete = {action,task ->
64 | toDoNotesViewModel.action.value = action
65 | toDoNotesViewModel.updateTaskField(selectedTask = task)
66 |
67 | },
68 | navigateToTaskScreen = navigateToTaskScreen
69 | )
70 | },
71 | floatingActionButton = {
72 | ListFab(onFabClicked = navigateToTaskScreen)
73 | }
74 | )
75 | }
76 |
77 | @Composable
78 | fun ListFab(
79 | onFabClicked: (taskId: Int ) -> Unit
80 | ) {
81 | FloatingActionButton(
82 | onClick = {
83 | onFabClicked(-1)
84 | },
85 | backgroundColor = MaterialTheme.colors.fabBackgroundColor
86 | ) {
87 | Icon(
88 | imageVector = Icons.Filled.Add,
89 | contentDescription = stringResource(
90 | id = R.string.add_button),
91 | tint = Color.White
92 | )
93 | }
94 | }
95 |
96 | @Composable
97 | fun DisplaySnackBar(
98 | scaffoldState: ScaffoldState,
99 | handleDatabaseActions: () -> Unit,
100 | onUndoClicked: (Action) -> Unit,
101 | taskTitle : String,
102 | action: Action
103 | ) {
104 | handleDatabaseActions()
105 | val scope = rememberCoroutineScope()
106 | LaunchedEffect(key1 = action) {
107 | if (action != Action.NO_ACTION) {
108 | scope.launch {
109 | val snackBarResult = scaffoldState.snackbarHostState.showSnackbar(
110 | message = setMessage(action = action,taskTitle = taskTitle),
111 | actionLabel = setActionLabel(action = action)
112 | )
113 | undoDeletedTask(action = action,
114 | snackBarResult = snackBarResult,
115 | onUndoClicked = onUndoClicked)
116 | }
117 | }
118 | }
119 | }
120 |
121 | private fun setMessage(action: Action, taskTitle: String) : String {
122 | return when(action) {
123 | Action.DELETE_ALL -> "All Tasks Removed"
124 | else -> "${action.name}: $taskTitle"
125 | }
126 | }
127 |
128 | private fun setActionLabel(action: Action): String {
129 | return if (action.name == "DELETE" ) "UNDO" else "OK"
130 | }
131 |
132 | private fun undoDeletedTask(
133 | action: Action,
134 | snackBarResult: SnackbarResult,
135 | onUndoClicked : (Action) -> Unit,
136 | ) {
137 | if (snackBarResult == SnackbarResult.ActionPerformed && action == Action.DELETE) {
138 | onUndoClicked(Action.UNDO)
139 | }
140 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/task/TaskAppBar.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view.task
2 |
3 | import androidx.compose.material.*
4 | import androidx.compose.material.icons.Icons
5 | import androidx.compose.material.icons.filled.ArrowBack
6 | import androidx.compose.material.icons.filled.Check
7 | import androidx.compose.material.icons.filled.Close
8 | import androidx.compose.material.icons.filled.Delete
9 | import androidx.compose.runtime.*
10 | import androidx.compose.ui.res.stringResource
11 | import androidx.compose.ui.text.style.TextOverflow
12 | import com.jetpack.todonotes.R
13 | import com.jetpack.todonotes.components.DisplayAlertDialog
14 | import com.jetpack.todonotes.database.model.ToDoTask
15 | import com.jetpack.todonotes.ui.theme.topAppBarBackgroundColor
16 | import com.jetpack.todonotes.ui.theme.topAppBarContentColor
17 | import com.jetpack.todonotes.utils.Action
18 |
19 | @Composable
20 | fun TaskAppBar(
21 | selectedTask : ToDoTask?,
22 | navigateToListScreen: (Action) -> Unit
23 | ) {
24 | if (selectedTask == null) {
25 | NewTaskAppBar(navigateToListScreen = navigateToListScreen)
26 | } else {
27 | ExistingTaskAppBar(
28 | selectedTask = selectedTask,
29 | navigateToListScreen = navigateToListScreen
30 | )
31 | }
32 | }
33 |
34 | @Composable
35 | fun NewTaskAppBar(
36 | navigateToListScreen: (Action) -> Unit
37 | ) {
38 | TopAppBar(
39 | navigationIcon = {
40 | BackAction(onBackClicked = navigateToListScreen)
41 | },
42 | title = {
43 | Text(
44 | text = stringResource(R.string.add_task),
45 | color = MaterialTheme.colors.topAppBarContentColor
46 | )
47 | },
48 | backgroundColor = MaterialTheme.colors.topAppBarBackgroundColor,
49 | actions = {
50 | AddAction(onAddClicked = navigateToListScreen)
51 | }
52 | )
53 | }
54 |
55 | @Composable
56 | fun BackAction(
57 | onBackClicked : (Action) -> Unit
58 | ) {
59 | IconButton(onClick = { onBackClicked(Action.NO_ACTION ) }) {
60 | Icon(
61 | imageVector = Icons.Filled.ArrowBack,
62 | contentDescription = stringResource(R.string.back_arrow),
63 | tint = MaterialTheme.colors.topAppBarContentColor
64 | )
65 | }
66 | }
67 |
68 | @Composable
69 | fun AddAction(
70 | onAddClicked : (Action) -> Unit
71 | ) {
72 | IconButton(onClick = { onAddClicked(Action.ADD) }) {
73 | Icon(
74 | imageVector = Icons.Filled.Check,
75 | contentDescription = stringResource(R.string.add_task),
76 | tint = MaterialTheme.colors.topAppBarContentColor
77 | )
78 | }
79 | }
80 |
81 |
82 | @Composable
83 | fun ExistingTaskAppBar(
84 | selectedTask : ToDoTask,
85 | navigateToListScreen: (Action) -> Unit
86 | ) {
87 | TopAppBar(
88 | navigationIcon = {
89 | CloseAction(onCloseClicked = navigateToListScreen)
90 | },
91 | title = {
92 | Text(
93 | text = selectedTask.title,
94 | color = MaterialTheme.colors.topAppBarContentColor,
95 | maxLines = 1,
96 | overflow = TextOverflow.Ellipsis
97 | )
98 | },
99 | backgroundColor = MaterialTheme.colors.topAppBarBackgroundColor,
100 | actions = {
101 | ExistingTaskAppBarActions(
102 | selectedTask = selectedTask,
103 | navigateToListScreen = navigateToListScreen
104 | )
105 | }
106 | )
107 | }
108 |
109 | @Composable
110 | fun CloseAction(
111 | onCloseClicked : (Action) -> Unit
112 | ) {
113 | IconButton(onClick = { onCloseClicked(Action.NO_ACTION ) }) {
114 | Icon(
115 | imageVector = Icons.Filled.Close,
116 | contentDescription = stringResource(R.string.close_icon),
117 | tint = MaterialTheme.colors.topAppBarContentColor
118 | )
119 | }
120 | }
121 |
122 | @Composable
123 | fun ExistingTaskAppBarActions(
124 | selectedTask : ToDoTask,
125 | navigateToListScreen: (Action) -> Unit
126 | ) {
127 | var openDialog by remember { mutableStateOf(value = false) }
128 | DisplayAlertDialog(
129 | title = stringResource(
130 | id = R.string.delete_task,
131 | selectedTask.title
132 | ),
133 | message = stringResource(
134 | id = R.string.delete_task_confirmation,
135 | selectedTask.title
136 | ),
137 | openDialog =openDialog,
138 | closeDialog = {openDialog = false },
139 | onYesClicked = {navigateToListScreen(Action.DELETE)}
140 | )
141 |
142 | DeleteAction(onDeleteClicked = {
143 | openDialog = true
144 | })
145 | UpdateAction(onUpdateClicked = navigateToListScreen)
146 | }
147 |
148 | @Composable
149 | fun DeleteAction(
150 | onDeleteClicked : () -> Unit
151 | ) {
152 | IconButton(onClick = { onDeleteClicked() }) {
153 | Icon(
154 | imageVector = Icons.Filled.Delete,
155 | contentDescription = stringResource(R.string.delete_icon),
156 | tint = MaterialTheme.colors.topAppBarContentColor
157 | )
158 | }
159 | }
160 |
161 | @Composable
162 | fun UpdateAction(
163 | onUpdateClicked : (Action) -> Unit
164 | ) {
165 | IconButton(onClick = { onUpdateClicked(Action.UPDATE ) }) {
166 | Icon(
167 | imageVector = Icons.Filled.Check,
168 | contentDescription = stringResource(R.string.update_icon),
169 | tint = MaterialTheme.colors.topAppBarContentColor
170 | )
171 | }
172 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/task/TaskContent.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view.task
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.material.Divider
6 | import androidx.compose.material.MaterialTheme
7 | import androidx.compose.material.OutlinedTextField
8 | import androidx.compose.material.Text
9 | import androidx.compose.runtime.Composable
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.res.stringResource
12 | import com.jetpack.todonotes.R
13 | import com.jetpack.todonotes.components.PriorityDropDown
14 | import com.jetpack.todonotes.database.model.Priority
15 | import com.jetpack.todonotes.ui.theme.LARGE_PADDING
16 | import com.jetpack.todonotes.ui.theme.MEDIUM_PADDING
17 |
18 | @Composable
19 | fun TaskContent(
20 | title: String,
21 | onTitleChange: (String) -> Unit,
22 | description: String,
23 | onDescriptionChange: (String) -> Unit,
24 | priority: Priority,
25 | onPrioritySelected: (Priority) -> Unit
26 | ) {
27 | Column(
28 | modifier = Modifier
29 | .fillMaxSize()
30 | .background(MaterialTheme.colors.background)
31 | .padding(LARGE_PADDING)
32 | ) {
33 | OutlinedTextField(
34 | value = title,
35 | onValueChange = { onTitleChange(it) },
36 | modifier = Modifier.fillMaxWidth(),
37 | label = { Text(text = stringResource(id = R.string.title)) },
38 | textStyle = MaterialTheme.typography.body1,
39 | singleLine = true
40 | )
41 |
42 | Divider(
43 | modifier = Modifier.height(MEDIUM_PADDING),
44 | color = MaterialTheme.colors.background
45 | )
46 |
47 | PriorityDropDown(
48 | priority = priority,
49 | onPrioritySelected = onPrioritySelected
50 | )
51 |
52 | OutlinedTextField(
53 | value = description,
54 | onValueChange = { onDescriptionChange(it) },
55 | modifier = Modifier.fillMaxSize(),
56 | label = { Text(text = stringResource(id = R.string.description)) },
57 | textStyle = MaterialTheme.typography.body1
58 | )
59 | }
60 | }
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/view/task/TaskScreen.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.view.task
2 |
3 | import android.widget.Toast
4 | import androidx.compose.material.Scaffold
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.runtime.getValue
7 | import androidx.compose.ui.platform.LocalContext
8 | import com.jetpack.todonotes.database.model.Priority
9 | import com.jetpack.todonotes.database.model.ToDoTask
10 | import com.jetpack.todonotes.utils.Action
11 | import com.jetpack.todonotes.viewmodel.ToDoNotesViewModel
12 |
13 | @Composable
14 | fun TaskScreen(
15 | selectedTask: ToDoTask?,
16 | toDoNotesViewModel: ToDoNotesViewModel,
17 | navigateToListScreen: (Action) -> Unit
18 | ) {
19 | val title: String by toDoNotesViewModel.title
20 | val description: String by toDoNotesViewModel.description
21 | val priority: Priority by toDoNotesViewModel.priority
22 | val context = LocalContext.current
23 |
24 | Scaffold(
25 | topBar = {
26 | TaskAppBar(
27 | selectedTask = selectedTask,
28 | navigateToListScreen = { action ->
29 | if (action == Action.NO_ACTION) {
30 | navigateToListScreen(action)
31 | } else {
32 | if (toDoNotesViewModel.validateFields()) {
33 | navigateToListScreen(action)
34 | } else {
35 | Toast.makeText(context, "Fields Empty", Toast.LENGTH_SHORT).show()
36 | }
37 | }
38 | }
39 | )
40 | },
41 | content = {
42 | TaskContent(
43 | title = title,
44 | onTitleChange = {
45 | toDoNotesViewModel.updateTitle(it)
46 | },
47 | description = description,
48 | onDescriptionChange = {
49 | toDoNotesViewModel.description.value = it
50 | },
51 | priority = priority,
52 | onPrioritySelected = {
53 | toDoNotesViewModel.priority.value = it
54 | }
55 | )
56 | }
57 | )
58 | }
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jetpack/todonotes/viewmodel/ToDoNotesViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes.viewmodel
2 |
3 | import androidx.compose.runtime.MutableState
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.jetpack.todonotes.database.model.Priority
8 | import com.jetpack.todonotes.database.model.ToDoTask
9 | import com.jetpack.todonotes.database.repositories.DataStoreRepository
10 | import com.jetpack.todonotes.database.repositories.ToDoRepository
11 | import com.jetpack.todonotes.utils.Action
12 | import com.jetpack.todonotes.utils.Constants.MAX_TITLE_LENGTH
13 | import com.jetpack.todonotes.utils.RequestState
14 | import com.jetpack.todonotes.utils.SearchAppBarState
15 | import dagger.hilt.android.lifecycle.HiltViewModel
16 | import kotlinx.coroutines.Dispatchers
17 | import kotlinx.coroutines.flow.*
18 | import kotlinx.coroutines.launch
19 | import java.util.*
20 | import javax.inject.Inject
21 |
22 | @HiltViewModel
23 | class ToDoNotesViewModel @Inject constructor(
24 | private val repository: ToDoRepository,
25 | private val dataStoreRepository: DataStoreRepository
26 | ): ViewModel() {
27 | val action: MutableState = mutableStateOf(Action.NO_ACTION)
28 | val id: MutableState = mutableStateOf(0)
29 | val title: MutableState = mutableStateOf("")
30 | val description: MutableState = mutableStateOf("")
31 | val priority: MutableState = mutableStateOf(Priority.LOW)
32 | val searchAppBarState: MutableState = mutableStateOf(SearchAppBarState.CLOSED)
33 | val searchTextState: MutableState = mutableStateOf("")
34 | private val _searchedTasks = MutableStateFlow>>(RequestState.Idle)
35 | val searchedTasks: StateFlow>> = _searchedTasks
36 |
37 | fun searchDatabase(searchQuery: String) {
38 | _searchedTasks.value = RequestState.Loading
39 | try {
40 | viewModelScope.launch {
41 | repository.searchDatabase(searchQuery = "%$searchQuery")
42 | .collect { searchTasks ->
43 | _searchedTasks.value = RequestState.Success(searchTasks)
44 | }
45 | }
46 | } catch (e: Exception) {
47 | _searchedTasks.value = RequestState.Error(e)
48 | }
49 | searchAppBarState.value = SearchAppBarState.TRIGGERED
50 | }
51 |
52 | val lowPriorityTasks: StateFlow> =
53 | repository.sortByLowPriority.stateIn(
54 | scope = viewModelScope,
55 | started = SharingStarted.WhileSubscribed(),
56 | Collections.emptyList()
57 | )
58 |
59 | val highPriorityTasks: StateFlow> =
60 | repository.sortByHighPriority.stateIn(
61 | scope = viewModelScope,
62 | started = SharingStarted.WhileSubscribed(),
63 | Collections.emptyList()
64 | )
65 |
66 | private val _sortState = MutableStateFlow>(RequestState.Idle)
67 | val sortState: StateFlow> = _sortState
68 |
69 | fun readSortState() {
70 | _sortState.value = RequestState.Loading
71 | try {
72 | viewModelScope.launch {
73 | dataStoreRepository.readSortState
74 | .map { Priority.valueOf(it.toString()) }
75 | .collect { _sortState.value = RequestState.Success(it) }
76 | }
77 | } catch (e: Exception) {
78 | _sortState.value = RequestState.Error(e)
79 | }
80 | }
81 |
82 | fun persistSortState(priority: Priority) {
83 | viewModelScope.launch(Dispatchers.IO) {
84 | dataStoreRepository.persistSortState(priority)
85 | }
86 | }
87 |
88 | private val _allTasks = MutableStateFlow>>(RequestState.Idle)
89 | val allTasks: StateFlow>> = _allTasks
90 |
91 | fun getAllTasks() {
92 | _allTasks.value = RequestState.Loading
93 | try {
94 | viewModelScope.launch {
95 | repository.getAllTasks.collect {
96 | _allTasks.value = RequestState.Success(it)
97 | }
98 | }
99 | } catch (e: Exception) {
100 | _allTasks.value = RequestState.Error(e)
101 | }
102 | }
103 |
104 | private val _selectedTask: MutableStateFlow = MutableStateFlow(null)
105 | val selectedTask: StateFlow = _selectedTask
106 |
107 | fun getSelectedTask(taskId: Int) {
108 | viewModelScope.launch {
109 | repository.getSelectedTask(taskId).collect { task ->
110 | _selectedTask.value = task
111 | }
112 | }
113 | }
114 |
115 | private fun addTask() {
116 | viewModelScope.launch(Dispatchers.IO) {
117 | val toDoTask = ToDoTask(
118 | title = title.value,
119 | description = description.value,
120 | priority = priority.value
121 | )
122 | repository.addTask(toDoTask)
123 | }
124 | searchAppBarState.value = SearchAppBarState.CLOSED
125 | }
126 |
127 | private fun updateTask() {
128 | viewModelScope.launch(Dispatchers.IO) {
129 | val toDoTask = ToDoTask(
130 | id = id.value,
131 | title = title.value,
132 | description = description.value,
133 | priority = priority.value
134 | )
135 | repository.updateTask(toDoTask = toDoTask)
136 | }
137 | }
138 |
139 | private fun deleteTask() {
140 | viewModelScope.launch(Dispatchers.IO) {
141 | val toDoTask = ToDoTask(
142 | id = id.value,
143 | title = title.value,
144 | description = description.value,
145 | priority = priority.value
146 | )
147 | repository.deleteTask(toDoTask = toDoTask)
148 | }
149 | }
150 |
151 | private fun deleteAllTasks() {
152 | viewModelScope.launch(Dispatchers.IO) {
153 | repository.deleteAllTasks()
154 | }
155 | }
156 |
157 | fun handleDatabaseActions(action: Action) {
158 | when (action) {
159 | Action.ADD -> addTask()
160 | Action.UPDATE -> updateTask()
161 | Action.DELETE -> deleteTask()
162 | Action.DELETE_ALL -> deleteAllTasks()
163 | Action.UNDO -> addTask()
164 | else -> {}
165 | }
166 | this.action.value = Action.NO_ACTION
167 | }
168 |
169 | fun updateTaskField(selectedTask: ToDoTask?) {
170 | if (selectedTask != null) {
171 | id.value = selectedTask.id
172 | title.value = selectedTask.title
173 | description.value = selectedTask.description
174 | priority.value = selectedTask.priority
175 | } else {
176 | id.value = 0
177 | title.value = ""
178 | description.value = ""
179 | priority.value = Priority.LOW
180 | }
181 | }
182 |
183 | fun updateTitle(newTitle: String) {
184 | if (newTitle.length < MAX_TITLE_LENGTH) {
185 | title.value = newTitle
186 | }
187 | }
188 |
189 | fun validateFields(): Boolean {
190 | return title.value.isNotEmpty() && description.value.isNotEmpty()
191 | }
192 | }
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_filter_list.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_sad_face.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
13 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_vertical_menu.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FFFEECC9
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ToDoNotes
3 |
4 | Remove All ToDo Notes?
5 | Are you sure you want to remove all ToDo Notes? There is no going back after this action.
6 | Add Button
7 | Search Action
8 | Sort ToDo Notes
9 | Delete All
10 | ToDo Notes
11 | Search
12 | Search Icon
13 | Close Icon
14 | Sad Face Icon
15 | No ToDo Notes Found
16 | Back Arrow
17 | Add ToDo Notes
18 | Delete Icon
19 | Update Icon
20 | Drop-Down Arrow Icon
21 | Title
22 | Description
23 | Yes
24 | No
25 | Remove \'%1$s\'?
26 | Are you sure want to remove \'%1$s\'?
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
18 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jetpack/todonotes/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jetpack.todonotes
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext {
4 | compose_version = '1.0.0'
5 | }
6 | repositories {
7 | google()
8 | mavenCentral()
9 | }
10 | dependencies {
11 | classpath "com.android.tools.build:gradle:7.0.0"
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
13 | classpath "com.google.dagger:hilt-android-gradle-plugin:2.36"
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | task clean(type: Delete) {
21 | delete rootProject.buildDir
22 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MakeItEasyDev/Jetpack-Compose-ToDo-Notes/2ec2b17c95a460f309086ceca6a884a82bb31b57/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Feb 12 15:03:10 IST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "ToDoNotes"
10 | include ':app'
11 |
--------------------------------------------------------------------------------