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" /> <option value="$PROJECT_DIR$/app" />
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@ -12,13 +12,13 @@ plugins {
} }
android { android {
compileSdkVersion 31 compileSdkVersion 32
buildToolsVersion "30.0.3" buildToolsVersion "30.0.3"
defaultConfig { defaultConfig {
applicationId "com.example.todoapp" applicationId "com.example.todoapp"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 31 targetSdkVersion 32
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -57,17 +57,17 @@ android {
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Navigation Component // Navigation Component
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1' implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
// Room components // Room components
implementation "androidx.room:room-runtime:2.4.2" implementation "androidx.room:room-runtime:2.4.2"
@ -77,11 +77,11 @@ dependencies {
// Lifecycle components // Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1" implementation "androidx.lifecycle:lifecycle-common-java8:2.5.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0"
// Kotlin components // Kotlin components
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0" 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.os.Bundle
import android.view.* import android.view.*
import android.widget.Toast import android.widget.Toast
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
@ -27,24 +29,27 @@ class AddFragment : Fragment() {
// Inflate the layout for this fragment // Inflate the layout for this fragment
_binding = FragmentAddBinding.inflate(layoutInflater, container, false) _binding = FragmentAddBinding.inflate(layoutInflater, container, false)
// Set Menu
setHasOptionsMenu(true)
// Spinner Item Selected Listener // Spinner Item Selected Listener
binding.prioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener binding.prioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener
return binding.root return binding.root
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
inflater.inflate(R.menu.add_fragment_menu, menu) 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 { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if(item.itemId == R.id.menu_add){ if (menuItem.itemId == R.id.menu_add) {
insertDataToDb() insertDataToDb()
} }
return super.onOptionsItemSelected(item) return true
}
})
} }
private fun insertDataToDb() { private fun insertDataToDb() {
@ -53,7 +58,7 @@ class AddFragment : Fragment() {
val mDescription = binding.descriptionEt.text.toString() val mDescription = binding.descriptionEt.text.toString()
val validation = mSharedViewModel.verifyDataFromUser(mTitle, mDescription) val validation = mSharedViewModel.verifyDataFromUser(mTitle, mDescription)
if(validation){ if (validation) {
// Insert Data to Database // Insert Data to Database
val newData = ToDoData( val newData = ToDoData(
0, 0,
@ -65,8 +70,9 @@ class AddFragment : Fragment() {
Toast.makeText(requireContext(), "Successfully added!", Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), "Successfully added!", Toast.LENGTH_SHORT).show()
// Navigate Back // Navigate Back
findNavController().navigate(R.id.action_addFragment_to_listFragment) findNavController().navigate(R.id.action_addFragment_to_listFragment)
}else{ } 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.view.*
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.example.todoapp.R import com.example.todoapp.R
@ -45,14 +46,11 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
setupRecyclerview() setupRecyclerview()
// Observe LiveData // Observe LiveData
mToDoViewModel.getAllData.observe(viewLifecycleOwner, { data -> mToDoViewModel.getAllData.observe(viewLifecycleOwner) { data ->
mSharedViewModel.checkIfDatabaseEmpty(data) mSharedViewModel.checkIfDatabaseEmpty(data)
adapter.setData(data) adapter.setData(data)
binding.recyclerView.scheduleLayoutAnimation() binding.recyclerView.scheduleLayoutAnimation()
}) }
// Set Menu
setHasOptionsMenu(true)
// Hide soft keyboard // Hide soft keyboard
hideKeyboard(requireActivity()) hideKeyboard(requireActivity())
@ -60,10 +58,42 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
return binding.root 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() { private fun setupRecyclerview() {
val recyclerView = binding.recyclerView val recyclerView = binding.recyclerView
recyclerView.adapter = adapter recyclerView.adapter = adapter
recyclerView.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL) recyclerView.layoutManager =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
// Swipe to Delete // Swipe to Delete
swipeToDelete(recyclerView) swipeToDelete(recyclerView)
@ -95,24 +125,6 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
snackBar.show() 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 { override fun onQueryTextSubmit(query: String?): Boolean {
if (query != null) { if (query != null) {
searchThroughDatabase(query) searchThroughDatabase(query)
@ -130,12 +142,12 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
private fun searchThroughDatabase(query: String) { private fun searchThroughDatabase(query: String) {
val searchQuery = "%$query%" val searchQuery = "%$query%"
mToDoViewModel.searchDatabase(searchQuery).observeOnce(viewLifecycleOwner, { list -> mToDoViewModel.searchDatabase(searchQuery).observeOnce(viewLifecycleOwner) { list ->
list?.let { list?.let {
Log.d("ListFragment", "searchThroughDatabase") Log.d("ListFragment", "searchThroughDatabase")
adapter.setData(it) adapter.setData(it)
} }
}) }
} }
// Show AlertDialog to Confirm Removal of All Items from Database Table // 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.os.Bundle
import android.view.* import android.view.*
import android.widget.Toast import android.widget.Toast
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
@ -32,25 +34,28 @@ class UpdateFragment : Fragment() {
_binding = FragmentUpdateBinding.inflate(inflater, container, false) _binding = FragmentUpdateBinding.inflate(inflater, container, false)
binding.args = args binding.args = args
// Set Menu
setHasOptionsMenu(true)
// Spinner Item Selected Listener // Spinner Item Selected Listener
binding.currentPrioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener binding.currentPrioritiesSpinner.onItemSelectedListener = mSharedViewModel.listener
return binding.root return binding.root
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
inflater.inflate(R.menu.update_fragment_menu, menu) 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 { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (item.itemId) { when (menuItem.itemId) {
R.id.menu_save -> updateItem() R.id.menu_save -> updateItem()
R.id.menu_delete -> confirmItemRemoval() R.id.menu_delete -> confirmItemRemoval()
} }
return super.onOptionsItemSelected(item) return true
}
})
} }
private fun updateItem() { private fun updateItem() {

View File

@ -6,10 +6,10 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { 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 "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 // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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