├── .gitignore ├── .idea ├── .gitignore ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cursokotlin │ │ └── miprimeraapp │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cursokotlin │ │ │ └── miprimeraapp │ │ │ ├── MainActivity.kt │ │ │ ├── Preferences.kt │ │ │ ├── TaskAdapter.kt │ │ │ ├── TaskApplication.kt │ │ │ └── TaskViewHolder.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_check_all.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item_task.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── cursokotlin │ └── miprimeraapp │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.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 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 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 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | buildToolsVersion "29.0.3" 8 | 9 | defaultConfig { 10 | applicationId "com.cursokotlin.miprimeraapp" 11 | minSdkVersion 21 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: "libs", include: ["*.jar"]) 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 30 | implementation 'androidx.core:core-ktx:1.3.2' 31 | implementation 'androidx.appcompat:appcompat:1.2.0' 32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 33 | implementation 'com.google.android.material:material:1.2.1' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 37 | 38 | } -------------------------------------------------------------------------------- /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/cursokotlin/miprimeraapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 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.cursokotlin.miprimeraapp", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/miprimeraapp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.widget.Button 6 | import android.widget.EditText 7 | import androidx.recyclerview.widget.LinearLayoutManager 8 | import androidx.recyclerview.widget.RecyclerView 9 | import com.cursokotlin.miprimeraapp.TaskApplication.Companion.prefs 10 | 11 | class MainActivity : AppCompatActivity() { 12 | lateinit var etTask: EditText 13 | lateinit var btnAddTask: Button 14 | lateinit var rvTasks: RecyclerView 15 | 16 | lateinit var adapter:TaskAdapter 17 | 18 | var tasks = mutableListOf() 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_main) 23 | initUi() 24 | } 25 | 26 | private fun initUi() { 27 | initVariables() 28 | initListeners() 29 | initRecyclerView() 30 | } 31 | 32 | private fun initRecyclerView() { 33 | tasks = prefs.getTasks() 34 | rvTasks.layoutManager = LinearLayoutManager(this) 35 | adapter = TaskAdapter(tasks) {deleteTask(it)} 36 | rvTasks.adapter = adapter 37 | 38 | } 39 | 40 | private fun deleteTask(position: Int) { 41 | tasks.removeAt(position) 42 | adapter.notifyDataSetChanged() 43 | prefs.saveTasks(tasks) 44 | } 45 | 46 | 47 | private fun initVariables() { 48 | etTask = findViewById(R.id.etTask) 49 | btnAddTask = findViewById(R.id.btnAddTask) 50 | rvTasks = findViewById(R.id.rvTasks) 51 | } 52 | 53 | private fun initListeners() { 54 | btnAddTask.setOnClickListener {addTask()} 55 | } 56 | 57 | private fun addTask() { 58 | val newTask = etTask.text.toString() 59 | tasks.add(newTask) 60 | prefs.saveTasks(tasks) 61 | adapter.notifyDataSetChanged() 62 | etTask.setText("") 63 | } 64 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/miprimeraapp/Preferences.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 2 | 3 | import android.content.Context 4 | import android.content.SharedPreferences 5 | 6 | class Preferences(context: Context) { 7 | 8 | companion object { 9 | const val PREFS_NAME = "myDatabase" 10 | const val TASKS = "tasks_value" 11 | } 12 | 13 | val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, 0) 14 | 15 | fun saveTasks(tasks:List){ 16 | prefs.edit().putStringSet(TASKS, tasks.toSet()).apply() 17 | } 18 | 19 | fun getTasks():MutableList{ 20 | return prefs.getStringSet(TASKS, emptySet())?.toMutableList() ?: mutableListOf() 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/miprimeraapp/TaskAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | 7 | class TaskAdapter(private val tasks:List, private val onItemDone: (Int) -> Unit):RecyclerView.Adapter() { 8 | 9 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskViewHolder { 10 | val layoutInflater = LayoutInflater.from(parent.context) 11 | return TaskViewHolder(layoutInflater.inflate(R.layout.item_task, parent, false)) 12 | } 13 | 14 | override fun getItemCount() = tasks.size 15 | 16 | override fun onBindViewHolder(holder: TaskViewHolder, position: Int) { 17 | holder.render(tasks[position], onItemDone) 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/miprimeraapp/TaskApplication.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 2 | 3 | import android.app.Application 4 | 5 | class TaskApplication:Application() { 6 | 7 | companion object{ 8 | lateinit var prefs:Preferences 9 | } 10 | 11 | override fun onCreate() { 12 | super.onCreate() 13 | prefs = Preferences(baseContext) 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cursokotlin/miprimeraapp/TaskViewHolder.kt: -------------------------------------------------------------------------------- 1 | package com.cursokotlin.miprimeraapp 2 | 3 | import android.view.View 4 | import android.widget.ImageView 5 | import android.widget.TextView 6 | import androidx.recyclerview.widget.RecyclerView 7 | 8 | class TaskViewHolder(view: View):RecyclerView.ViewHolder(view){ 9 | 10 | private val tvTask:TextView = view.findViewById(R.id.tvTask) 11 | private val ivTaskDone:ImageView = view.findViewById(R.id.ivTaskDone) 12 | 13 | fun render(task:String, onItemDone:(Int) -> Unit){ 14 | tvTask.text = task 15 | ivTaskDone.setOnClickListener { onItemDone(adapterPosition) } 16 | } 17 | } -------------------------------------------------------------------------------- /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/ic_check_all.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /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_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 23 |