Commit 9e45e5f0 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Fix application uses decrementing in fragments

parent 0dc66189
......@@ -133,6 +133,9 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
override fun onDestroy() {
super.onDestroy()
homeFragment.decrementApplicationUses()
searchFragment.decrementApplicationUses()
updatesFragment.decrementApplicationUses()
installManagerGetter.disconnect(this)
}
}
......@@ -121,8 +121,8 @@ class CategoryActivity : AppCompatActivity() {
override fun onDestroy() {
super.onDestroy()
if (::recyclerView.isInitialized && recyclerView.adapter != null) {
(recyclerView.adapter as ApplicationListAdapter).removeApplicationUses()
applicationList.forEach {
it.decrementUses()
}
installManagerGetter.disconnect(this)
}
......
......@@ -20,10 +20,4 @@ class ApplicationListAdapter(private val activity: Activity, private val applica
}
override fun getItemCount() = applicationList.size
fun removeApplicationUses() {
applicationList.forEach {
it.decrementUses()
}
}
}
......@@ -132,8 +132,8 @@ class HomeFragment : Fragment() {
}
}
override fun onDestroy() {
if (::categoryList.isInitialized) {
fun decrementApplicationUses() {
if (::homeViewModel.isInitialized) {
homeViewModel.getCategories().value!!.forEach {
it.value.forEach { application ->
application.decrementUses()
......@@ -143,6 +143,5 @@ class HomeFragment : Fragment() {
it.application.decrementUses()
}
}
super.onDestroy()
}
}
......@@ -182,10 +182,9 @@ class SearchFragment : Fragment(), SearchView.OnQueryTextListener, SearchView.On
super.onResume()
}
override fun onDestroy() {
if (::recyclerView.isInitialized && recyclerView.adapter != null) {
(recyclerView.adapter as ApplicationListAdapter).removeApplicationUses()
fun decrementApplicationUses() {
applicationList.forEach {
it.decrementUses()
}
super.onDestroy()
}
}
......@@ -93,10 +93,11 @@ class UpdatesFragment : Fragment() {
}
}
override fun onDestroy() {
if (::recyclerView.isInitialized && recyclerView.adapter != null) {
(recyclerView.adapter as ApplicationListAdapter).removeApplicationUses()
fun decrementApplicationUses() {
if (::updatesViewModel.isInitialized) {
updatesViewModel.getApplications().value!!.forEach {
it.decrementUses()
}
}
super.onDestroy()
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment