Removed adapter leaks in EntriesFragment.kt

pull/49/head
Arty Bishop 2020-11-17 11:18:06 +00:00
rodzic e5b9c7a132
commit e59cf9e58a
8 zmienionych plików z 48 dodań i 37 usunięć

3
.gitignore vendored
Wyświetl plik

@ -56,3 +56,6 @@ fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
/app/release/app-release.aab
/app/release/app-release.apk
/app/release/output-metadata.json

Wyświetl plik

@ -20,7 +20,6 @@
package com.rtbishop.look4sat.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SearchView
import androidx.recyclerview.widget.RecyclerView
@ -94,7 +93,7 @@ class EntriesAdapter : RecyclerView.Adapter<EntriesAdapter.SatEntryHolder>(),
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatEntryHolder {
val binding = ItemSatEntryBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
return SatEntryHolder(binding.root, binding)
return SatEntryHolder(binding)
}
override fun onBindViewHolder(holder: SatEntryHolder, position: Int) {
@ -105,8 +104,8 @@ class EntriesAdapter : RecyclerView.Adapter<EntriesAdapter.SatEntryHolder>(),
return currentEntries.size
}
inner class SatEntryHolder(itemView: View, private val binding: ItemSatEntryBinding) :
RecyclerView.ViewHolder(itemView) {
inner class SatEntryHolder(private val binding: ItemSatEntryBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(satEntry: SatEntry) {
binding.satEntryCheckbox.text = satEntry.name

Wyświetl plik

@ -21,7 +21,6 @@ package com.rtbishop.look4sat.ui.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.navigation.findNavController
@ -89,11 +88,11 @@ class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false)
return if (viewType == 0) {
val bindingLeo = ItemPassLeoBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
SatPassLeoHolder(bindingLeo.root, bindingLeo)
SatPassLeoHolder(bindingLeo)
} else {
val bindingGeo = ItemPassGeoBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
SatPassGeoHolder(bindingGeo.root, bindingGeo)
SatPassGeoHolder(bindingGeo)
}
}
@ -105,8 +104,8 @@ class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false)
}
}
inner class SatPassLeoHolder(itemView: View, private val binding: ItemPassLeoBinding) :
RecyclerView.ViewHolder(itemView) {
inner class SatPassLeoHolder(private val binding: ItemPassLeoBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(satPass: SatPass) {
binding.apply {
@ -130,8 +129,8 @@ class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false)
}
}
inner class SatPassGeoHolder(itemView: View, private val binding: ItemPassGeoBinding) :
RecyclerView.ViewHolder(itemView) {
inner class SatPassGeoHolder(private val binding: ItemPassGeoBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(satPass: SatPass) {
val satPos = satPass.predictor.getSatPos(satPass.pass.startTime)

Wyświetl plik

@ -20,7 +20,6 @@
package com.rtbishop.look4sat.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.doOnTextChanged
import androidx.recyclerview.widget.RecyclerView
@ -45,7 +44,7 @@ class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
val binding = ItemTleSourceBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
return TleSourceHolder(binding.root, binding)
return TleSourceHolder(binding)
}
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
@ -56,8 +55,8 @@ class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf
return sources.size
}
inner class TleSourceHolder(itemView: View, private val binding: ItemTleSourceBinding) :
RecyclerView.ViewHolder(itemView) {
inner class TleSourceHolder(private val binding: ItemTleSourceBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(source: TleSource) {
binding.tleSourceUrl.setText(source.url)

Wyświetl plik

@ -21,7 +21,6 @@ package com.rtbishop.look4sat.ui.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.rtbishop.look4sat.R
@ -66,15 +65,15 @@ class TransAdapter(context: Context, private val satPass: SatPass) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TransHolder {
val binding = ItemTransBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
return TransHolder(binding.root, binding)
return TransHolder(binding)
}
override fun onBindViewHolder(holder: TransHolder, position: Int) {
holder.bind(transmittersList[position])
}
inner class TransHolder(itemView: View, private val binding: ItemTransBinding) :
RecyclerView.ViewHolder(itemView) {
inner class TransHolder(private val binding: ItemTransBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(satTrans: SatTrans) {
binding.description.text = satTrans.description

Wyświetl plik

@ -21,8 +21,8 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class EntriesFragment : Fragment(R.layout.fragment_entries) {
private lateinit var binding: FragmentEntriesBinding
private lateinit var entriesAdapter: EntriesAdapter
private var binding: FragmentEntriesBinding? = null
private var entriesAdapter: EntriesAdapter? = null
private val viewModel: SharedViewModel by activityViewModels()
private val pickFileReqCode = 100
@ -35,7 +35,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
private fun setupComponents() {
entriesAdapter = EntriesAdapter()
binding.apply {
binding?.apply {
entriesRecycler.apply {
setHasFixedSize(true)
adapter = entriesAdapter
@ -44,7 +44,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
}
importWeb.setOnClickListener { showImportFromWebDialog() }
importFile.setOnClickListener { showImportFromFileDialog() }
selectAll.setOnClickListener { entriesAdapter.selectAll() }
selectAll.setOnClickListener { entriesAdapter?.selectAll() }
entriesFab.setOnClickListener { navigateToPasses() }
searchBar.setOnQueryTextListener(entriesAdapter)
searchBar.clearFocus()
@ -56,7 +56,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
if (entries.isNullOrEmpty()) setError()
else {
viewModel.setEntries(entries)
entriesAdapter.setEntries(entries as MutableList<SatEntry>)
entriesAdapter?.setEntries(entries as MutableList<SatEntry>)
setLoaded()
}
observeEvents()
@ -88,26 +88,32 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
}
private fun setLoaded() {
binding.entriesError.visibility = View.INVISIBLE
binding.entriesProgress.visibility = View.INVISIBLE
binding.entriesRecycler.visibility = View.VISIBLE
binding?.apply {
entriesError.visibility = View.INVISIBLE
entriesProgress.visibility = View.INVISIBLE
entriesRecycler.visibility = View.VISIBLE
}
}
private fun setLoading() {
binding.entriesError.visibility = View.INVISIBLE
binding.entriesRecycler.visibility = View.INVISIBLE
binding.entriesProgress.visibility = View.VISIBLE
binding?.apply {
entriesError.visibility = View.INVISIBLE
entriesRecycler.visibility = View.INVISIBLE
entriesProgress.visibility = View.VISIBLE
}
}
private fun setError() {
binding.entriesProgress.visibility = View.INVISIBLE
binding.entriesRecycler.visibility = View.INVISIBLE
binding.entriesError.visibility = View.VISIBLE
binding?.apply {
entriesProgress.visibility = View.INVISIBLE
entriesRecycler.visibility = View.INVISIBLE
entriesError.visibility = View.VISIBLE
}
}
private fun navigateToPasses() {
binding.searchBar.clearFocus()
viewModel.updateEntriesSelection(entriesAdapter.getEntries())
binding?.searchBar?.clearFocus()
entriesAdapter?.let { viewModel.updateEntriesSelection(it.getEntries()) }
requireView().findNavController().navigate(R.id.action_entries_to_passes)
}
@ -116,4 +122,10 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
data?.data?.also { uri -> viewModel.updateEntriesFromFile(uri) }
} else super.onActivityResult(requestCode, resultCode, data)
}
override fun onDestroyView() {
entriesAdapter = null
binding = null
super.onDestroyView()
}
}

Wyświetl plik

@ -19,10 +19,10 @@
buildscript {
ext {
gradle_version = '4.1.0'
gradle_version = '4.1.1'
gradle_plugin_version = '1.4.10'
material_version = '1.2.1'
constraint_layout_version = '2.0.2'
constraint_layout_version = '2.0.4'
navigation_version = '2.3.1'
preference_version = '1.1.1'
room_version = '2.2.5'

0
gradlew vendored 100755 → 100644
Wyświetl plik