17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codility/todoapp/model/Todo.kt:
--------------------------------------------------------------------------------
1 | package com.codility.todoapp.model
2 |
3 | import java.io.Serializable
4 |
5 | /**
6 | * Created by Govind on 2/14/2018.
7 | */
8 | class Todo(var name: String) : Serializable {
9 | var id: Int? = null
10 | var title: String? = null
11 | var desc: String? = null
12 | var timestamp: String? = null
13 |
14 | constructor(id: Int, title: String, desc: String, timestamp: String) : this(title) {
15 | this.id = id
16 | this.title = title
17 | this.desc = desc
18 | this.timestamp = timestamp
19 | }
20 |
21 | constructor(title: String, desc: String) : this(title) {
22 | this.title = title
23 | this.desc = desc
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codility/todoapp/AboutActivity.kt:
--------------------------------------------------------------------------------
1 | package com.codility.todoapp
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.MenuItem
6 |
7 | /**
8 | * Created by Govind on 3/28/2018.
9 | */
10 |
11 | class AboutActivity : AppCompatActivity() {
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.about)
16 |
17 | supportActionBar!!.setDisplayHomeAsUpEnabled(true)
18 | }
19 |
20 | override fun onOptionsItemSelected(item: MenuItem?): Boolean {
21 | if (item!!.itemId == android.R.id.home) {
22 | finish()
23 | }
24 | return super.onOptionsItemSelected(item)
25 | }
26 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx512m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/codility/todoapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.codility.todoapp
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.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.getTargetContext()
22 | assertEquals("com.codility.todoapp", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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/res/layout/content_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 AndroidCodility
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 26
9 | defaultConfig {
10 | applicationId "com.codility.todoapp"
11 | minSdkVersion 15
12 | targetSdkVersion 26
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28 | implementation 'com.android.support:appcompat-v7:26.1.0'
29 | implementation 'com.android.support:design:26.1.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
33 | }
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TodoApp-SQLite
2 | Android application to make Todos-list to Organize your to-do, work using offline mode with SQLite storage using Kotlin Programming Language.
3 |
4 | TodoApp is the easiest way to get stuff done. Whether you’re planning a holiday, sharing a shopping list with a partner or managing multiple work projects, TodoApp is here to help you tick off all your personal and professional to-dos.
5 |
6 | Organize and share your to-do, work, grocery, movies and household lists. No matter what you’re planning, how big or small the task may be, TodoApp makes it super easy to get stuff done.
7 |
8 | TodoApp has become my digital brain for juggling different aspects of my job. This makes the busyness and craziness feel so much simpler.
9 |
10 | TODO 1 | TODO 2 | TODO 3 |
11 | :---------:|:----------:|:---------:
12 |  |  | 
13 |
14 | # Play Video
15 | [](https://youtu.be/3kFx2kEnNoQ "Click here to watch")
16 |
17 | # Like Facebook Page
18 | [](https://www.facebook.com/androidcodility/ "Click here")
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
25 |
26 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codility/todoapp/adapter/MyAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.codility.recyclerview
2 |
3 | import android.support.v7.widget.RecyclerView
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.widget.TextView
8 | import com.codility.todoapp.R
9 | import com.codility.todoapp.model.Todo
10 | import kotlinx.android.synthetic.main.list_item.view.*
11 |
12 | /**
13 | * Created by Govind on 2/16/2018.
14 | */
15 | class MyAdapter(private val todoList: ArrayList) : RecyclerView.Adapter() {
16 | private var listener: OnClickListener? = null
17 |
18 | fun setListener(clickListener: OnClickListener) {
19 | this.listener = clickListener
20 | }
21 |
22 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
23 | val todo: Todo = todoList[position]
24 | holder.bindItems(todo)
25 |
26 | holder.itemView.setOnClickListener(View.OnClickListener {
27 | if (listener != null) {
28 | listener!!.onItemClick(todo, position)
29 | }
30 | })
31 |
32 | holder.itemView.btDelete.setOnClickListener(View.OnClickListener {
33 | if (listener != null) {
34 | listener!!.onItemDelete(todo)
35 | }
36 | })
37 | }
38 |
39 | override fun getItemCount(): Int {
40 | return todoList.size
41 | }
42 |
43 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyAdapter.ViewHolder {
44 | return ViewHolder(LayoutInflater.from(parent!!.context).inflate(R.layout.list_item, parent, false))
45 | }
46 |
47 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
48 | fun bindItems(todo: Todo) {
49 | val tvTitle = itemView.findViewById(R.id.tvTitle)
50 | val tvDesc = itemView.findViewById(R.id.tvDesc)
51 | val tvTimestamp = itemView.findViewById(R.id.tvTimestamp)
52 | tvTitle.text = todo.title
53 | tvDesc.text = todo.desc
54 | tvTimestamp.text = todo.timestamp
55 | }
56 | }
57 |
58 | interface OnClickListener {
59 | fun onItemClick(todo: Todo, position: Int)
60 | fun onItemDelete(todo: Todo)
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
23 |
24 |
36 |
37 |
48 |
49 |
59 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/add_todo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
23 |
24 |
31 |
32 |
37 |
38 |
46 |
47 |
52 |
53 |
63 |
64 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TODO App
3 |
4 | "Material is the metaphor.\n\n"
5 |
6 | "A material metaphor is the unifying theory of a rationalized space and a system of motion."
7 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet "
8 | "technologically advanced and open to imagination and magic.\n"
9 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The "
10 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the "
11 | "flexibility of the material creates new affordances that supercede those in the physical "
12 | "world, without breaking the rules of physics.\n"
13 | "The fundamentals of light, surface, and movement are key to conveying how objects move, "
14 | "interact, and exist in space and in relation to each other. Realistic lighting shows "
15 | "seams, divides space, and indicates moving parts.\n\n"
16 |
17 | "Bold, graphic, intentional.\n\n"
18 |
19 | "The foundational elements of print based design typography, grids, space, scale, color, "
20 | "and use of imagery guide visual treatments. These elements do far more than please the "
21 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge "
22 | "imagery, large scale typography, and intentional white space create a bold and graphic "
23 | "interface that immerse the user in the experience.\n"
24 | "An emphasis on user actions makes core functionality immediately apparent and provides "
25 | "waypoints for the user.\n\n"
26 |
27 | "Motion provides meaning.\n\n"
28 |
29 | "Motion respects and reinforces the user as the prime mover. Primary user actions are "
30 | "inflection points that initiate motion, transforming the whole design.\n"
31 | "All action takes place in a single environment. Objects are presented to the user without "
32 | "breaking the continuity of experience even as they transform and reorganize.\n"
33 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. "
34 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n"
35 |
36 |
37 |
38 | Settings
39 | Update
40 | Cancel
41 | Add
42 | Title
43 | Description
44 |
45 | Notes
46 | No notes found!
47 | New Todo
48 | Edit Todo
49 | Enter your todo!
50 | About
51 | TodoApp is the easiest way to get stuff done. Whether you’re planning a holiday, sharing a shopping list with a partner or managing multiple work projects, TodoApp is here to help you tick off all your personal and professional to-dos.
52 | \n\nOrganize and share your to-do, work, grocery, movies and household lists. No matter what you’re planning, how big or small the task may be, TodoApp makes it super easy to get stuff done.
53 | \n\nTodoApp has become my digital brain for juggling different aspects of my job. This makes the busyness and craziness feel so much simpler.
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codility/todoapp/helper/DBHelper.kt:
--------------------------------------------------------------------------------
1 | package com.codility.todoapp.helper
2 |
3 | import android.content.ContentValues
4 | import android.content.Context
5 | import android.database.sqlite.SQLiteDatabase
6 | import android.database.sqlite.SQLiteOpenHelper
7 | import com.codility.todoapp.model.Todo
8 | import java.util.*
9 |
10 | /**
11 | * Created by Govind on 3/26/2018.
12 | */
13 |
14 | class DBHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
15 |
16 | companion object {
17 | private val DATABASE_VERSION = 1 // Database Version
18 | private val DATABASE_NAME = "todos_db" // Database Name
19 | }
20 |
21 | // Database Table Name
22 | private val TABLE_NAME = "todoTable"
23 | // Attributes for Tables
24 | private val COLUMN_ID = "id"
25 | private val COLUMN_TITLE = "title"
26 | private val COLUMN_DESCRIPTION = "description"
27 | private val COLUMN_TIMESTAMP = "timestamp"
28 |
29 | // Create table SQL query
30 | private val CREATE_TABLE = (
31 | "CREATE TABLE " + TABLE_NAME + "("
32 | + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
33 | + COLUMN_TITLE + " TEXT,"
34 | + COLUMN_DESCRIPTION + " TEXT,"
35 | + COLUMN_TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP"
36 | + ")")
37 |
38 | // 1) Select All Query, 2)looping through all rows and adding to list 3) close db connection, 4) return todos list
39 | val allNotes: ArrayList
40 | get() {
41 | val notes = ArrayList()
42 | val selectQuery = "SELECT * FROM " + TABLE_NAME + " ORDER BY " + COLUMN_TIMESTAMP + " DESC"
43 |
44 | val db = this.writableDatabase
45 | val cursor = db.rawQuery(selectQuery, null)
46 | if (cursor.moveToFirst()) {
47 | do {
48 | val todo = Todo(cursor!!.getInt(cursor.getColumnIndex(COLUMN_ID)), cursor.getString(cursor.getColumnIndex(COLUMN_TITLE)),
49 | cursor.getString(cursor.getColumnIndex(COLUMN_DESCRIPTION)), cursor.getString(cursor.getColumnIndex(COLUMN_TIMESTAMP)))
50 | todo.id = cursor.getInt(cursor.getColumnIndex(COLUMN_ID))
51 | todo.title = cursor.getString(cursor.getColumnIndex(COLUMN_TITLE))
52 | todo.desc = cursor.getString(cursor.getColumnIndex(COLUMN_DESCRIPTION))
53 | todo.timestamp = cursor.getString(cursor.getColumnIndex(COLUMN_TIMESTAMP))
54 | notes.add(todo)
55 | } while (cursor.moveToNext())
56 | }
57 | db.close()
58 | return notes
59 | }
60 |
61 | // return count
62 | val notesCount: Int
63 | get() {
64 | val countQuery = "SELECT * FROM " + TABLE_NAME
65 | val db = this.readableDatabase
66 | val cursor = db.rawQuery(countQuery, null)
67 | val count = cursor.count
68 | cursor.close()
69 | return count
70 | }
71 |
72 | // Creating Tables
73 | override fun onCreate(db: SQLiteDatabase) {
74 | db.execSQL(CREATE_TABLE) // create notes table
75 | }
76 |
77 | // Upgrading database
78 | override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
79 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME) // Drop older table if existed
80 | onCreate(db) // Create tables again
81 | }
82 |
83 | fun insertTodo(todo: Todo): Long {
84 | val db = this.writableDatabase // get writable database as we want to write data
85 | val values = ContentValues()
86 | // `id` and `timestamp` will be inserted automatically, no need to add them
87 | values.put(COLUMN_TITLE, todo.title)
88 | values.put(COLUMN_DESCRIPTION, todo.desc)
89 | val id = db.insert(TABLE_NAME, null, values) // insert row
90 | db.close() // close db connection
91 |
92 | return id // return newly inserted row id
93 | }
94 |
95 | fun getTodo(id: Long): Todo {
96 | val db = this.readableDatabase // get readable database as we are not inserting anything
97 | val cursor = db.query(TABLE_NAME,
98 | arrayOf(COLUMN_ID, COLUMN_TITLE, COLUMN_DESCRIPTION, COLUMN_TIMESTAMP), COLUMN_ID + "=?",
99 | arrayOf(id.toString()), null, null, null, null)
100 |
101 | cursor?.moveToFirst()
102 | // prepare todos object
103 | val todo = Todo(
104 | cursor!!.getInt(cursor.getColumnIndex(COLUMN_ID)),
105 | cursor.getString(cursor.getColumnIndex(COLUMN_TITLE)),
106 | cursor.getString(cursor.getColumnIndex(COLUMN_DESCRIPTION)),
107 | cursor.getString(cursor.getColumnIndex(COLUMN_TIMESTAMP)))
108 |
109 | cursor.close() // close the db connection
110 | return todo
111 | }
112 |
113 | fun updateTodo(todo: Todo): Int {
114 | val db = this.writableDatabase
115 | val values = ContentValues()
116 | values.put(COLUMN_TITLE, todo.title)
117 | values.put(COLUMN_DESCRIPTION, todo.desc)
118 | return db.update(TABLE_NAME, values, COLUMN_ID + " = ?", arrayOf(todo.id.toString())) // updating row
119 | }
120 |
121 | fun deleteTodo(todo: Todo): Boolean {
122 | val db = writableDatabase // Gets the data repository in write mode
123 | db.delete(TABLE_NAME, COLUMN_ID + " LIKE ?", arrayOf(todo.id.toString())) // Issue SQL statement.
124 | return true
125 | }
126 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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/java/com/codility/todoapp/ScrollingActivity.kt:
--------------------------------------------------------------------------------
1 | package com.codility.todoapp
2 |
3 | import android.content.DialogInterface
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.support.v7.app.AlertDialog
7 | import android.support.v7.app.AppCompatActivity
8 | import android.support.v7.widget.LinearLayoutManager
9 | import android.text.TextUtils
10 | import android.view.LayoutInflater
11 | import android.view.Menu
12 | import android.view.MenuItem
13 | import android.view.View
14 | import android.widget.Button
15 | import android.widget.EditText
16 | import android.widget.TextView
17 | import android.widget.Toast
18 | import com.codility.recyclerview.MyAdapter
19 | import com.codility.todoapp.helper.DBHelper
20 | import com.codility.todoapp.model.Todo
21 | import kotlinx.android.synthetic.main.activity_scrolling.*
22 | import kotlinx.android.synthetic.main.content_scrolling.*
23 | import java.util.*
24 |
25 | class ScrollingActivity : AppCompatActivity(), MyAdapter.OnClickListener {
26 |
27 | override fun onItemDelete(todo: Todo) {
28 | deleteConfirmation(todo)
29 | }
30 |
31 | override fun onItemClick(todo: Todo, position: Int) {
32 | showNoteDialog(true, todo, position)
33 | }
34 |
35 | private var myAdapter: MyAdapter? = null
36 | private var dbHelper: DBHelper? = null
37 | private var todoList = ArrayList()
38 |
39 | override fun onCreate(savedInstanceState: Bundle?) {
40 | super.onCreate(savedInstanceState)
41 | setContentView(R.layout.activity_scrolling)
42 | setSupportActionBar(toolbar)
43 | dbHelper = DBHelper(this)
44 |
45 | fab.setOnClickListener {
46 | showNoteDialog(false, null, -1)
47 | }
48 | //Set the TodoList in myAdapter
49 | getTodoList()
50 | }
51 |
52 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
53 | menuInflater.inflate(R.menu.menu_scrolling, menu)
54 | return true
55 | }
56 |
57 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
58 | return when (item.itemId) {
59 | R.id.action_about -> {
60 | startActivity(Intent(this, AboutActivity::class.java))
61 | return true
62 | }
63 | else -> super.onOptionsItemSelected(item)
64 | }
65 | }
66 |
67 | override fun onResume() {
68 | super.onResume()
69 | if (myAdapter != null) {
70 | getTodoList()
71 | myAdapter!!.notifyDataSetChanged()
72 | }
73 | }
74 |
75 | private fun getTodoList() {
76 | todoList = dbHelper!!.allNotes
77 | recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
78 | myAdapter = MyAdapter(todoList)
79 | myAdapter!!.setListener(this)
80 | recyclerView.adapter = myAdapter
81 | }
82 |
83 | private fun deleteConfirmation(todo: Todo) {
84 | val alertDialog = AlertDialog.Builder(this)
85 | alertDialog.setTitle("Confirm Delete...")
86 | alertDialog.setMessage("Are you sure you want to delete this?")
87 | alertDialog.setIcon(R.drawable.ic_delete)
88 | alertDialog.setPositiveButton("YES", DialogInterface.OnClickListener { dialog, which ->
89 | dbHelper!!.deleteTodo(todo)
90 | getTodoList() // refreshing the list
91 | })
92 |
93 | alertDialog.setNegativeButton("NO", DialogInterface.OnClickListener { dialog, which ->
94 | dialog.cancel() //Cancel the dialog
95 | })
96 | alertDialog.show()
97 | }
98 |
99 | /**
100 | * Shows alert dialog with EditText options to enter / edit a note.
101 | * when shouldUpdate=true, it automatically displays old note and changes the button text to UPDATE
102 | */
103 | private fun showNoteDialog(shouldUpdate: Boolean, todo: Todo?, position: Int) {
104 | val view = LayoutInflater.from(applicationContext).inflate(R.layout.add_todo, null)
105 |
106 | val alertDialogView = AlertDialog.Builder(this).create()
107 | alertDialogView.setView(view)
108 |
109 | val tvHeader = view.findViewById(R.id.tvHeader)
110 | val edTitle = view.findViewById(R.id.edTitle)
111 | val edDesc = view.findViewById(R.id.edDesc)
112 | val btAddUpdate = view.findViewById