├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── app_icon.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_unfinish.png
│ │ │ │ ├── ic_check_white_png.png
│ │ │ │ ├── ic_delete_white_png.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-ldpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_unfinish.png
│ │ │ │ ├── ic_check_white_png.png
│ │ │ │ ├── ic_delete_white_png.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_unfinish.png
│ │ │ │ ├── ic_check_white_png.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_delete_white_png.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_unfinish.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_check_white_png.png
│ │ │ │ └── ic_delete_white_png.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_unfinish.png
│ │ │ │ ├── ic_check_white_png.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_delete_white_png.png
│ │ │ ├── drawable
│ │ │ │ ├── ic_check_black_24dp.xml
│ │ │ │ ├── ic_add_white_24dp.xml
│ │ │ │ ├── ic_playlist_add_black_24dp.xml
│ │ │ │ ├── ic_edit_black_24dp.xml
│ │ │ │ ├── ic_cancel_black_24dp.xml
│ │ │ │ ├── ic_access_time_black_24dp.xml
│ │ │ │ ├── ic_date_range_black_24dp.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_history.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── item_todo.xml
│ │ │ │ └── activity_task.xml
│ │ │ ├── menu
│ │ │ │ └── main_menu.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── todoapp
│ │ │ │ ├── HistoryActivity.kt
│ │ │ │ ├── TodoModel.kt
│ │ │ │ ├── TodoDao.kt
│ │ │ │ ├── AppDatabase.kt
│ │ │ │ ├── TodoAdapter.kt
│ │ │ │ ├── TaskActivity.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── todoapp
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── todoapp
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── vcs.xml
├── misc.xml
├── runConfigurations.xml
└── gradle.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='TodoApp'
2 | include ':app'
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TodoApp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/app_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/app_icon.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_unfinish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-hdpi/ic_unfinish.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_unfinish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-mdpi/ic_unfinish.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_unfinish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xhdpi/ic_unfinish.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_unfinish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_unfinish.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_unfinish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_unfinish.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_check_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-hdpi/ic_check_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_delete_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-hdpi/ic_delete_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_check_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-mdpi/ic_check_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_delete_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-mdpi/ic_delete_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_check_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xhdpi/ic_check_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_delete_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xhdpi/ic_delete_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_check_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_check_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_delete_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_delete_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_check_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_check_white_png.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_delete_white_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks-archives/TodoKotlin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_delete_white_png.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 17 14:41:11 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_check_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/HistoryActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 |
6 | class HistoryActivity : AppCompatActivity() {
7 |
8 | override fun onCreate(savedInstanceState: Bundle?) {
9 | super.onCreate(savedInstanceState)
10 | setContentView(R.layout.activity_history)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/TodoModel.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 |
6 | @Entity
7 | data class TodoModel(
8 | var title:String,
9 | var description:String,
10 | var category: String,
11 | var date:Long,
12 | var time:Long,
13 | var isFinished : Int = 0,
14 | @PrimaryKey(autoGenerate = true)
15 | var id:Long = 0
16 | )
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_add_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_playlist_add_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/todoapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
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 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_history.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_edit_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_cancel_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_access_time_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_date_range_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/TodoDao.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.room.Dao
5 | import androidx.room.Insert
6 | import androidx.room.Query
7 |
8 | @Dao
9 | interface TodoDao {
10 |
11 | @Insert()
12 | suspend fun insertTask(todoModel: TodoModel):Long
13 |
14 | @Query("Select * from TodoModel where isFinished == 0")
15 | fun getTask():LiveData>
16 |
17 | @Query("Update TodoModel Set isFinished = 1 where id=:uid")
18 | fun finishTask(uid:Long)
19 |
20 | @Query("Delete from TodoModel where id=:uid")
21 | fun deleteTask(uid:Long)
22 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/todoapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
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.example.todoapp", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/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
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import android.content.Context
4 | import androidx.room.Database
5 | import androidx.room.Room
6 | import androidx.room.RoomDatabase
7 |
8 |
9 | @Database(entities = [TodoModel::class], version = 1)
10 | abstract class AppDatabase : RoomDatabase() {
11 | abstract fun todoDao(): TodoDao
12 |
13 |
14 | companion object {
15 | // Singleton prevents multiple instances of database opening at the
16 | // same time.
17 | @Volatile
18 | private var INSTANCE: AppDatabase? = null
19 |
20 | fun getDatabase(context: Context): AppDatabase {
21 | val tempInstance = INSTANCE
22 | if (tempInstance != null) {
23 | return tempInstance
24 | }
25 | synchronized(this) {
26 | val instance = Room.databaseBuilder(
27 | context.applicationContext,
28 | AppDatabase::class.java,
29 | DB_NAME
30 | ).build()
31 | INSTANCE = instance
32 | return instance
33 | }
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/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=-Xmx1536m
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
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
25 |
26 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4CAF50
4 | #388E3C
5 | #ff7058
6 | #a1a1a1
7 | #388E3C
8 | #D32F2F
9 |
10 |
11 |
12 | - #e84e40
13 | - #ec407a
14 | - #ab47bc
15 | - #7e57c2
16 | - #5c6bc0
17 | - #738ffe
18 | - #29b6f6
19 | - #26c6da
20 | - #26a69a
21 | - #2baf2b
22 | - #9ccc65
23 | - #d4e157
24 | - #ffee58
25 | - #ffa726
26 | - #ff7043
27 | - #8d6e63
28 | - #bdbdbd
29 | - #78909c
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion 29
8 | buildToolsVersion "29.0.3"
9 |
10 | defaultConfig {
11 | applicationId "com.example.todoapp"
12 | minSdkVersion 23
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | implementation 'androidx.appcompat:appcompat:1.1.0'
33 | implementation 'androidx.core:core-ktx:1.2.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | testImplementation 'junit:junit:4.12'
36 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
38 |
39 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
40 | implementation 'com.google.android.material:material:1.1.0'
41 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
42 |
43 |
44 | //database
45 | implementation "androidx.room:room-runtime:2.2.3"
46 | implementation "androidx.room:room-ktx:2.2.3"
47 | kapt "androidx.room:room-compiler:2.2.3"
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/TodoAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import androidx.recyclerview.widget.RecyclerView
7 | import kotlinx.android.synthetic.main.activity_task.*
8 | import kotlinx.android.synthetic.main.item_todo.view.*
9 | import java.text.SimpleDateFormat
10 | import java.util.*
11 |
12 | class TodoAdapter(val list: List) : RecyclerView.Adapter() {
13 |
14 |
15 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoViewHolder {
16 | return TodoViewHolder(
17 | LayoutInflater.from(parent.context)
18 | .inflate(R.layout.item_todo, parent, false)
19 | )
20 | }
21 |
22 | override fun getItemCount() = list.size
23 |
24 | override fun onBindViewHolder(holder: TodoViewHolder, position: Int) {
25 | holder.bind(list[position])
26 | }
27 |
28 | override fun getItemId(position: Int): Long {
29 | return list[position].id
30 | }
31 |
32 | class TodoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
33 | fun bind(todoModel: TodoModel) {
34 | with(itemView) {
35 | val colors = resources.getIntArray(R.array.random_color)
36 | val randomColor = colors[Random().nextInt(colors.size)]
37 | viewColorTag.setBackgroundColor(randomColor)
38 | txtShowTitle.text = todoModel.title
39 | txtShowTask.text = todoModel.description
40 | txtShowCategory.text = todoModel.category
41 | updateTime(todoModel.time)
42 | updateDate(todoModel.date)
43 |
44 | }
45 | }
46 | private fun updateTime(time: Long) {
47 | //Mon, 5 Jan 2020
48 | val myformat = "h:mm a"
49 | val sdf = SimpleDateFormat(myformat)
50 | itemView.txtShowTime.text = sdf.format(Date(time))
51 |
52 | }
53 |
54 | private fun updateDate(time: Long) {
55 | //Mon, 5 Jan 2020
56 | val myformat = "EEE, d MMM yyyy"
57 | val sdf = SimpleDateFormat(myformat)
58 | itemView.txtShowDate.text = sdf.format(Date(time))
59 |
60 | }
61 | }
62 |
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/TaskActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import android.app.DatePickerDialog
4 | import android.app.TimePickerDialog
5 | import android.os.Bundle
6 | import android.view.View
7 | import android.widget.ArrayAdapter
8 | import android.widget.DatePicker
9 | import android.widget.TimePicker
10 | import androidx.appcompat.app.AppCompatActivity
11 | import androidx.room.Room
12 | import kotlinx.android.synthetic.main.activity_task.*
13 | import kotlinx.coroutines.Dispatchers
14 | import kotlinx.coroutines.GlobalScope
15 | import kotlinx.coroutines.launch
16 | import kotlinx.coroutines.withContext
17 | import java.text.SimpleDateFormat
18 | import java.util.*
19 |
20 | const val DB_NAME = "todo.db"
21 |
22 | class TaskActivity : AppCompatActivity(), View.OnClickListener {
23 |
24 | lateinit var myCalendar: Calendar
25 |
26 | lateinit var dateSetListener: DatePickerDialog.OnDateSetListener
27 | lateinit var timeSetListener: TimePickerDialog.OnTimeSetListener
28 |
29 | var finalDate = 0L
30 | var finalTime = 0L
31 |
32 |
33 | private val labels = arrayListOf("Personal", "Business", "Insurance", "Shopping", "Banking")
34 |
35 |
36 | val db by lazy {
37 | AppDatabase.getDatabase(this)
38 | }
39 |
40 | override fun onCreate(savedInstanceState: Bundle?) {
41 | super.onCreate(savedInstanceState)
42 | setContentView(R.layout.activity_task)
43 |
44 | dateEdt.setOnClickListener(this)
45 | timeEdt.setOnClickListener(this)
46 | saveBtn.setOnClickListener(this)
47 |
48 |
49 | setUpSpinner()
50 | }
51 |
52 | private fun setUpSpinner() {
53 | val adapter =
54 | ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, labels)
55 |
56 | labels.sort()
57 |
58 | spinnerCategory.adapter = adapter
59 | }
60 |
61 | override fun onClick(v: View) {
62 | when (v.id) {
63 | R.id.dateEdt -> {
64 | setListener()
65 | }
66 | R.id.timeEdt -> {
67 | setTimeListener()
68 | }
69 | R.id.saveBtn -> {
70 | saveTodo()
71 | }
72 | }
73 |
74 | }
75 |
76 | private fun saveTodo() {
77 | val category = spinnerCategory.selectedItem.toString()
78 | val title = titleInpLay.editText?.text.toString()
79 | val description = taskInpLay.editText?.text.toString()
80 |
81 | GlobalScope.launch(Dispatchers.Main) {
82 | val id = withContext(Dispatchers.IO) {
83 | return@withContext db.todoDao().insertTask(
84 | TodoModel(
85 | title,
86 | description,
87 | category,
88 | finalDate,
89 | finalTime
90 | )
91 | )
92 | }
93 | finish()
94 | }
95 |
96 | }
97 |
98 | private fun setTimeListener() {
99 | myCalendar = Calendar.getInstance()
100 |
101 | timeSetListener =
102 | TimePickerDialog.OnTimeSetListener() { _: TimePicker, hourOfDay: Int, min: Int ->
103 | myCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay)
104 | myCalendar.set(Calendar.MINUTE, min)
105 | updateTime()
106 | }
107 |
108 | val timePickerDialog = TimePickerDialog(
109 | this, timeSetListener, myCalendar.get(Calendar.HOUR_OF_DAY),
110 | myCalendar.get(Calendar.MINUTE), false
111 | )
112 | timePickerDialog.show()
113 | }
114 |
115 | private fun updateTime() {
116 | //Mon, 5 Jan 2020
117 | val myformat = "h:mm a"
118 | val sdf = SimpleDateFormat(myformat)
119 | finalTime = myCalendar.time.time
120 | timeEdt.setText(sdf.format(myCalendar.time))
121 |
122 | }
123 |
124 | private fun setListener() {
125 | myCalendar = Calendar.getInstance()
126 |
127 | dateSetListener =
128 | DatePickerDialog.OnDateSetListener { _: DatePicker, year: Int, month: Int, dayOfMonth: Int ->
129 | myCalendar.set(Calendar.YEAR, year)
130 | myCalendar.set(Calendar.MONTH, month)
131 | myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
132 | updateDate()
133 |
134 | }
135 |
136 | val datePickerDialog = DatePickerDialog(
137 | this, dateSetListener, myCalendar.get(Calendar.YEAR),
138 | myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)
139 | )
140 | datePickerDialog.datePicker.minDate = System.currentTimeMillis()
141 | datePickerDialog.show()
142 | }
143 |
144 | private fun updateDate() {
145 | //Mon, 5 Jan 2020
146 | val myformat = "EEE, d MMM yyyy"
147 | val sdf = SimpleDateFormat(myformat)
148 | finalDate = myCalendar.time.time
149 | dateEdt.setText(sdf.format(myCalendar.time))
150 |
151 | timeInptLay.visibility = View.VISIBLE
152 |
153 | }
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_todo.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
24 |
25 |
32 |
33 |
34 |
35 |
48 |
49 |
50 |
62 |
63 |
74 |
75 |
86 |
87 |
96 |
97 |
108 |
109 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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/layout/activity_task.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
23 |
24 |
25 |
26 |
35 |
36 |
45 |
46 |
54 |
55 |
56 |
64 |
65 |
74 |
75 |
84 |
85 |
86 |
94 |
95 |
103 |
104 |
118 |
119 |
120 |
130 |
131 |
145 |
146 |
147 |
156 |
157 |
163 |
164 |
170 |
171 |
172 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/todoapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.todoapp
2 |
3 | import android.content.Intent
4 | import android.graphics.*
5 | import android.os.Bundle
6 | import android.view.Menu
7 | import android.view.MenuItem
8 | import android.view.View
9 | import androidx.appcompat.app.AppCompatActivity
10 | import androidx.appcompat.widget.SearchView
11 | import androidx.lifecycle.Observer
12 | import androidx.recyclerview.widget.ItemTouchHelper
13 | import androidx.recyclerview.widget.LinearLayoutManager
14 | import androidx.recyclerview.widget.RecyclerView
15 | import kotlinx.android.synthetic.main.activity_main.*
16 | import kotlinx.coroutines.Dispatchers
17 | import kotlinx.coroutines.GlobalScope
18 | import kotlinx.coroutines.launch
19 |
20 | class MainActivity : AppCompatActivity() {
21 |
22 | val list = arrayListOf()
23 | var adapter = TodoAdapter(list)
24 |
25 | val db by lazy {
26 | AppDatabase.getDatabase(this)
27 | }
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_main)
32 | setSupportActionBar(toolbar)
33 | todoRv.apply {
34 | layoutManager = LinearLayoutManager(this@MainActivity)
35 | adapter = this@MainActivity.adapter
36 | }
37 |
38 | initSwipe()
39 |
40 | db.todoDao().getTask().observe(this, Observer {
41 | if (!it.isNullOrEmpty()) {
42 | list.clear()
43 | list.addAll(it)
44 | adapter.notifyDataSetChanged()
45 | }else{
46 | list.clear()
47 | adapter.notifyDataSetChanged()
48 | }
49 | })
50 |
51 |
52 | }
53 |
54 | fun initSwipe() {
55 | val simpleItemTouchCallback = object : ItemTouchHelper.SimpleCallback(
56 | 0,
57 | ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
58 | ) {
59 | override fun onMove(
60 | recyclerView: RecyclerView,
61 | viewHolder: RecyclerView.ViewHolder,
62 | target: RecyclerView.ViewHolder
63 | ): Boolean = false
64 |
65 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
66 | val position = viewHolder.adapterPosition
67 |
68 | if (direction == ItemTouchHelper.LEFT) {
69 | GlobalScope.launch(Dispatchers.IO) {
70 | db.todoDao().deleteTask(adapter.getItemId(position))
71 | }
72 | } else if (direction == ItemTouchHelper.RIGHT) {
73 | GlobalScope.launch(Dispatchers.IO) {
74 | db.todoDao().finishTask(adapter.getItemId(position))
75 | }
76 | }
77 | }
78 |
79 | override fun onChildDraw(
80 | canvas: Canvas,
81 | recyclerView: RecyclerView,
82 | viewHolder: RecyclerView.ViewHolder,
83 | dX: Float,
84 | dY: Float,
85 | actionState: Int,
86 | isCurrentlyActive: Boolean
87 | ) {
88 | if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
89 | val itemView = viewHolder.itemView
90 |
91 | val paint = Paint()
92 | val icon: Bitmap
93 |
94 | if (dX > 0) {
95 |
96 | icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_check_white_png)
97 |
98 | paint.color = Color.parseColor("#388E3C")
99 |
100 | canvas.drawRect(
101 | itemView.left.toFloat(), itemView.top.toFloat(),
102 | itemView.left.toFloat() + dX, itemView.bottom.toFloat(), paint
103 | )
104 |
105 | canvas.drawBitmap(
106 | icon,
107 | itemView.left.toFloat(),
108 | itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height.toFloat()) / 2,
109 | paint
110 | )
111 |
112 |
113 | } else {
114 | icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_delete_white_png)
115 |
116 | paint.color = Color.parseColor("#D32F2F")
117 |
118 | canvas.drawRect(
119 | itemView.right.toFloat() + dX, itemView.top.toFloat(),
120 | itemView.right.toFloat(), itemView.bottom.toFloat(), paint
121 | )
122 |
123 | canvas.drawBitmap(
124 | icon,
125 | itemView.right.toFloat() - icon.width,
126 | itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height.toFloat()) / 2,
127 | paint
128 | )
129 | }
130 | viewHolder.itemView.translationX = dX
131 |
132 |
133 | } else {
134 | super.onChildDraw(
135 | canvas,
136 | recyclerView,
137 | viewHolder,
138 | dX,
139 | dY,
140 | actionState,
141 | isCurrentlyActive
142 | )
143 | }
144 | }
145 |
146 |
147 | }
148 |
149 | val itemTouchHelper = ItemTouchHelper(simpleItemTouchCallback)
150 | itemTouchHelper.attachToRecyclerView(todoRv)
151 | }
152 |
153 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
154 | menuInflater.inflate(R.menu.main_menu, menu)
155 | val item = menu.findItem(R.id.search)
156 | val searchView = item.actionView as SearchView
157 | item.setOnActionExpandListener(object :MenuItem.OnActionExpandListener{
158 | override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
159 | displayTodo()
160 | return true
161 | }
162 |
163 | override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
164 | displayTodo()
165 | return true
166 | }
167 |
168 | })
169 | searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
170 | override fun onQueryTextSubmit(query: String?): Boolean {
171 | return false
172 | }
173 |
174 | override fun onQueryTextChange(newText: String?): Boolean {
175 | if(!newText.isNullOrEmpty()){
176 | displayTodo(newText)
177 | }
178 | return true
179 | }
180 |
181 | })
182 |
183 | return super.onCreateOptionsMenu(menu)
184 | }
185 |
186 | fun displayTodo(newText: String = "") {
187 | db.todoDao().getTask().observe(this, Observer {
188 | if(it.isNotEmpty()){
189 | list.clear()
190 | list.addAll(
191 | it.filter { todo ->
192 | todo.title.contains(newText,true)
193 | }
194 | )
195 | adapter.notifyDataSetChanged()
196 | }
197 | })
198 | }
199 |
200 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
201 | when (item.itemId) {
202 | R.id.history -> {
203 | startActivity(Intent(this, HistoryActivity::class.java))
204 | }
205 | }
206 | return super.onOptionsItemSelected(item)
207 | }
208 |
209 | fun openNewTask(view: View) {
210 | startActivity(Intent(this, TaskActivity::class.java))
211 | }
212 | }
213 |
--------------------------------------------------------------------------------