From 553a7fa8c960a347c8c7947e2afef1cd021d6022 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 16 Dec 2020 13:20:11 +0100 Subject: [PATCH] Migrated from Deprecated plugin 'kotlin-android-extensions' --- app/build.gradle | 13 ++++++------ .../example/todoapp/data/models/ToDoData.kt | 2 +- .../todoapp/fragments/add/AddFragment.kt | 20 ++++++++++--------- .../fragments/update/UpdateFragment.kt | 7 +++---- build.gradle | 4 ++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fc81c06..7e508eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: "androidx.navigation.safeargs.kotlin" +apply plugin: "kotlin-parcelize" android { compileSdkVersion 30 - buildToolsVersion "30.0.0" + buildToolsVersion "30.0.2" defaultConfig { applicationId "com.example.todoapp" @@ -27,6 +27,7 @@ android { buildFeatures{ dataBinding = true + viewBinding = true } compileOptions { @@ -41,7 +42,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.20" + implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.21" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' @@ -51,8 +52,8 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' // Navigation Component - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.1' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.2' // Room components implementation "androidx.room:room-runtime:2.2.5" @@ -66,7 +67,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" // Kotlin components - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.21" api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7" api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9" diff --git a/app/src/main/java/com/example/todoapp/data/models/ToDoData.kt b/app/src/main/java/com/example/todoapp/data/models/ToDoData.kt index 21f5c76..1e0479e 100644 --- a/app/src/main/java/com/example/todoapp/data/models/ToDoData.kt +++ b/app/src/main/java/com/example/todoapp/data/models/ToDoData.kt @@ -3,7 +3,7 @@ package com.example.todoapp.data.models import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Entity(tableName = "todo_table") @Parcelize diff --git a/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt b/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt index b8977f1..0c8e08e 100644 --- a/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt +++ b/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt @@ -9,29 +9,31 @@ import androidx.navigation.fragment.findNavController import com.example.todoapp.R import com.example.todoapp.data.models.ToDoData import com.example.todoapp.data.viewmodel.ToDoViewModel +import com.example.todoapp.databinding.FragmentAddBinding import com.example.todoapp.fragments.SharedViewModel -import kotlinx.android.synthetic.main.fragment_add.* -import kotlinx.android.synthetic.main.fragment_add.view.* class AddFragment : Fragment() { private val mToDoViewModel: ToDoViewModel by viewModels() private val mSharedViewModel: SharedViewModel by viewModels() + private var _binding: FragmentAddBinding? = null + private val binding get() = _binding!! + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { // Inflate the layout for this fragment - val view = inflater.inflate(R.layout.fragment_add, container, false) + _binding = FragmentAddBinding.inflate(layoutInflater, container, false) // Set Menu setHasOptionsMenu(true) // Spinner Item Selected Listener - view.priorities_spinner.onItemSelectedListener = mSharedViewModel.listener + binding.prioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener - return view + return binding.root } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -46,9 +48,9 @@ class AddFragment : Fragment() { } private fun insertDataToDb() { - val mTitle = title_et.text.toString() - val mPriority = priorities_spinner.selectedItem.toString() - val mDescription = description_et.text.toString() + val mTitle = binding.titleEt.text.toString() + val mPriority = binding.prioritiesSpinner.selectedItem.toString() + val mDescription = binding.descriptionEt.text.toString() val validation = mSharedViewModel.verifyDataFromUser(mTitle, mDescription) if(validation){ diff --git a/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt b/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt index 3aafdbd..44fec0f 100644 --- a/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt +++ b/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt @@ -13,7 +13,6 @@ import com.example.todoapp.data.models.ToDoData import com.example.todoapp.data.viewmodel.ToDoViewModel import com.example.todoapp.databinding.FragmentUpdateBinding import com.example.todoapp.fragments.SharedViewModel -import kotlinx.android.synthetic.main.fragment_update.* class UpdateFragment : Fragment() { @@ -55,9 +54,9 @@ class UpdateFragment : Fragment() { } private fun updateItem() { - val title = current_title_et.text.toString() - val description = current_description_et.text.toString() - val getPriority = current_priorities_spinner.selectedItem.toString() + val title = binding.currentTitleEt.text.toString() + val description = binding.currentDescriptionEt.text.toString() + val getPriority = binding.currentPrioritiesSpinner.selectedItem.toString() val validation = mSharedViewModel.verifyDataFromUser(title, description) if (validation) { diff --git a/build.gradle b/build.gradle index 7790a9f..f8ed55d 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,8 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20" - classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.1" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21" + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }