Removed Deprecated Code

This commit is contained in:
Stevdza-San 2022-07-27 09:33:59 +02:00
parent 09f52b8228
commit 4fb7dd9f86
7 changed files with 89 additions and 67 deletions

1
.idea/gradle.xml generated
View File

@ -14,7 +14,6 @@
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View File

@ -12,13 +12,13 @@ plugins {
}
android {
compileSdkVersion 31
compileSdkVersion 32
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.todoapp"
minSdkVersion 26
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.0"
@ -57,17 +57,17 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Navigation Component
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
// Room components
implementation "androidx.room:room-runtime:2.4.2"
@ -77,11 +77,11 @@ dependencies {
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-common-java8:2.5.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0"
// Kotlin components
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1"
}

View File

@ -3,6 +3,8 @@ package com.example.todoapp.fragments.add
import android.os.Bundle
import android.view.*
import android.widget.Toast
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
@ -27,24 +29,27 @@ class AddFragment : Fragment() {
// Inflate the layout for this fragment
_binding = FragmentAddBinding.inflate(layoutInflater, container, false)
// Set Menu
setHasOptionsMenu(true)
// Spinner Item Selected Listener
binding.prioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener
return binding.root
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.add_fragment_menu, menu)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.add_fragment_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if(item.itemId == R.id.menu_add){
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if (menuItem.itemId == R.id.menu_add) {
insertDataToDb()
}
return super.onOptionsItemSelected(item)
return true
}
})
}
private fun insertDataToDb() {
@ -66,7 +71,8 @@ class AddFragment : Fragment() {
// Navigate Back
findNavController().navigate(R.id.action_addFragment_to_listFragment)
} else {
Toast.makeText(requireContext(), "Please fill out all fields.", Toast.LENGTH_SHORT).show()
Toast.makeText(requireContext(), "Please fill out all fields.", Toast.LENGTH_SHORT)
.show()
}
}

View File

@ -6,10 +6,11 @@ import android.util.Log
import android.view.*
import android.widget.Toast
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.example.todoapp.R
@ -45,14 +46,11 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
setupRecyclerview()
// Observe LiveData
mToDoViewModel.getAllData.observe(viewLifecycleOwner, { data ->
mToDoViewModel.getAllData.observe(viewLifecycleOwner) { data ->
mSharedViewModel.checkIfDatabaseEmpty(data)
adapter.setData(data)
binding.recyclerView.scheduleLayoutAnimation()
})
// Set Menu
setHasOptionsMenu(true)
}
// Hide soft keyboard
hideKeyboard(requireActivity())
@ -60,10 +58,42 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.list_fragment_menu, menu)
val search = menu.findItem(R.id.menu_search)
val searchView = search.actionView as? SearchView
searchView?.isSubmitButtonEnabled = true
searchView?.setOnQueryTextListener(this@ListFragment)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.menu_delete_all -> confirmRemoval()
R.id.menu_priority_high ->
mToDoViewModel.sortByHighPriority.observe(viewLifecycleOwner) {
adapter.setData(it)
}
R.id.menu_priority_low ->
mToDoViewModel.sortByLowPriority.observe(viewLifecycleOwner) {
adapter.setData(it)
}
}
return true
}
})
}
private fun setupRecyclerview() {
val recyclerView = binding.recyclerView
recyclerView.adapter = adapter
recyclerView.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
recyclerView.layoutManager =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
// Swipe to Delete
swipeToDelete(recyclerView)
@ -95,24 +125,6 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
snackBar.show()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.list_fragment_menu, menu)
val search = menu.findItem(R.id.menu_search)
val searchView = search.actionView as? SearchView
searchView?.isSubmitButtonEnabled = true
searchView?.setOnQueryTextListener(this)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_delete_all -> confirmRemoval()
R.id.menu_priority_high -> mToDoViewModel.sortByHighPriority.observe(viewLifecycleOwner, { adapter.setData(it) })
R.id.menu_priority_low -> mToDoViewModel.sortByLowPriority.observe(viewLifecycleOwner, { adapter.setData(it) })
}
return super.onOptionsItemSelected(item)
}
override fun onQueryTextSubmit(query: String?): Boolean {
if (query != null) {
searchThroughDatabase(query)
@ -130,12 +142,12 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
private fun searchThroughDatabase(query: String) {
val searchQuery = "%$query%"
mToDoViewModel.searchDatabase(searchQuery).observeOnce(viewLifecycleOwner, { list ->
mToDoViewModel.searchDatabase(searchQuery).observeOnce(viewLifecycleOwner) { list ->
list?.let {
Log.d("ListFragment", "searchThroughDatabase")
adapter.setData(it)
}
})
}
}
// Show AlertDialog to Confirm Removal of All Items from Database Table

View File

@ -4,6 +4,8 @@ import android.app.AlertDialog
import android.os.Bundle
import android.view.*
import android.widget.Toast
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
@ -32,25 +34,28 @@ class UpdateFragment : Fragment() {
_binding = FragmentUpdateBinding.inflate(inflater, container, false)
binding.args = args
// Set Menu
setHasOptionsMenu(true)
// Spinner Item Selected Listener
binding.currentPrioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener
return binding.root
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.update_fragment_menu, menu)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val menuHost: MenuHost = requireActivity()
menuHost.addMenuProvider(object: MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.update_fragment_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.menu_save -> updateItem()
R.id.menu_delete -> confirmItemRemoval()
}
return super.onOptionsItemSelected(item)
return true
}
})
}
private fun updateItem() {

View File

@ -6,10 +6,10 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip