mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Removed adapter leaks in EntriesFragment.kt
This commit is contained in:
1 parent
e5b9c7a132
commit
e59cf9e58a
8 files changed
+48
-37
No files matched your search
@@ -56,3 +56,6 @@ fastlane/Preview.html
|
|||||||
fastlane/screenshots
|
fastlane/screenshots
|
||||||
fastlane/test_output
|
fastlane/test_output
|
||||||
fastlane/readme.md
|
fastlane/readme.md
|
||||||
|
/app/release/app-release.aab
|
||||||
|
/app/release/app-release.apk
|
||||||
|
/app/release/output-metadata.json
|
||||||
Executable → Regular
+3
-4
@@ -20,7 +20,6 @@
|
|||||||
package com.rtbishop.look4sat.ui.adapters
|
package com.rtbishop.look4sat.ui.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.SearchView
|
import android.widget.SearchView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@@ -94,7 +93,7 @@ class EntriesAdapter : RecyclerView.Adapter<EntriesAdapter.SatEntryHolder>(),
|
|||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatEntryHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatEntryHolder {
|
||||||
val binding = ItemSatEntryBinding
|
val binding = ItemSatEntryBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return SatEntryHolder(binding.root, binding)
|
return SatEntryHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: SatEntryHolder, position: Int) {
|
override fun onBindViewHolder(holder: SatEntryHolder, position: Int) {
|
||||||
@@ -105,8 +104,8 @@ class EntriesAdapter : RecyclerView.Adapter<EntriesAdapter.SatEntryHolder>(),
|
|||||||
return currentEntries.size
|
return currentEntries.size
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class SatEntryHolder(itemView: View, private val binding: ItemSatEntryBinding) :
|
inner class SatEntryHolder(private val binding: ItemSatEntryBinding) :
|
||||||
RecyclerView.ViewHolder(itemView) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(satEntry: SatEntry) {
|
fun bind(satEntry: SatEntry) {
|
||||||
binding.satEntryCheckbox.text = satEntry.name
|
binding.satEntryCheckbox.text = satEntry.name
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package com.rtbishop.look4sat.ui.adapters
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
@@ -89,11 +88,11 @@ class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false)
|
|||||||
return if (viewType == 0) {
|
return if (viewType == 0) {
|
||||||
val bindingLeo = ItemPassLeoBinding
|
val bindingLeo = ItemPassLeoBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
SatPassLeoHolder(bindingLeo.root, bindingLeo)
|
SatPassLeoHolder(bindingLeo)
|
||||||
} else {
|
} else {
|
||||||
val bindingGeo = ItemPassGeoBinding
|
val bindingGeo = ItemPassGeoBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.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) :
|
inner class SatPassLeoHolder(private val binding: ItemPassLeoBinding) :
|
||||||
RecyclerView.ViewHolder(itemView) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(satPass: SatPass) {
|
fun bind(satPass: SatPass) {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
@@ -130,8 +129,8 @@ class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class SatPassGeoHolder(itemView: View, private val binding: ItemPassGeoBinding) :
|
inner class SatPassGeoHolder(private val binding: ItemPassGeoBinding) :
|
||||||
RecyclerView.ViewHolder(itemView) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(satPass: SatPass) {
|
fun bind(satPass: SatPass) {
|
||||||
val satPos = satPass.predictor.getSatPos(satPass.pass.startTime)
|
val satPos = satPass.predictor.getSatPos(satPass.pass.startTime)
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.rtbishop.look4sat.ui.adapters
|
package com.rtbishop.look4sat.ui.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
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 {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
|
||||||
val binding = ItemTleSourceBinding
|
val binding = ItemTleSourceBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return TleSourceHolder(binding.root, binding)
|
return TleSourceHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
|
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
|
||||||
@@ -56,8 +55,8 @@ class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf
|
|||||||
return sources.size
|
return sources.size
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class TleSourceHolder(itemView: View, private val binding: ItemTleSourceBinding) :
|
inner class TleSourceHolder(private val binding: ItemTleSourceBinding) :
|
||||||
RecyclerView.ViewHolder(itemView) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(source: TleSource) {
|
fun bind(source: TleSource) {
|
||||||
binding.tleSourceUrl.setText(source.url)
|
binding.tleSourceUrl.setText(source.url)
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package com.rtbishop.look4sat.ui.adapters
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.rtbishop.look4sat.R
|
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 {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TransHolder {
|
||||||
val binding = ItemTransBinding
|
val binding = ItemTransBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return TransHolder(binding.root, binding)
|
return TransHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: TransHolder, position: Int) {
|
override fun onBindViewHolder(holder: TransHolder, position: Int) {
|
||||||
holder.bind(transmittersList[position])
|
holder.bind(transmittersList[position])
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class TransHolder(itemView: View, private val binding: ItemTransBinding) :
|
inner class TransHolder(private val binding: ItemTransBinding) :
|
||||||
RecyclerView.ViewHolder(itemView) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(satTrans: SatTrans) {
|
fun bind(satTrans: SatTrans) {
|
||||||
binding.description.text = satTrans.description
|
binding.description.text = satTrans.description
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||||
|
|
||||||
private lateinit var binding: FragmentEntriesBinding
|
private var binding: FragmentEntriesBinding? = null
|
||||||
private lateinit var entriesAdapter: EntriesAdapter
|
private var entriesAdapter: EntriesAdapter? = null
|
||||||
private val viewModel: SharedViewModel by activityViewModels()
|
private val viewModel: SharedViewModel by activityViewModels()
|
||||||
private val pickFileReqCode = 100
|
private val pickFileReqCode = 100
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||||||
|
|
||||||
private fun setupComponents() {
|
private fun setupComponents() {
|
||||||
entriesAdapter = EntriesAdapter()
|
entriesAdapter = EntriesAdapter()
|
||||||
binding.apply {
|
binding?.apply {
|
||||||
entriesRecycler.apply {
|
entriesRecycler.apply {
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
adapter = entriesAdapter
|
adapter = entriesAdapter
|
||||||
@@ -44,7 +44,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||||||
}
|
}
|
||||||
importWeb.setOnClickListener { showImportFromWebDialog() }
|
importWeb.setOnClickListener { showImportFromWebDialog() }
|
||||||
importFile.setOnClickListener { showImportFromFileDialog() }
|
importFile.setOnClickListener { showImportFromFileDialog() }
|
||||||
selectAll.setOnClickListener { entriesAdapter.selectAll() }
|
selectAll.setOnClickListener { entriesAdapter?.selectAll() }
|
||||||
entriesFab.setOnClickListener { navigateToPasses() }
|
entriesFab.setOnClickListener { navigateToPasses() }
|
||||||
searchBar.setOnQueryTextListener(entriesAdapter)
|
searchBar.setOnQueryTextListener(entriesAdapter)
|
||||||
searchBar.clearFocus()
|
searchBar.clearFocus()
|
||||||
@@ -56,7 +56,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||||||
if (entries.isNullOrEmpty()) setError()
|
if (entries.isNullOrEmpty()) setError()
|
||||||
else {
|
else {
|
||||||
viewModel.setEntries(entries)
|
viewModel.setEntries(entries)
|
||||||
entriesAdapter.setEntries(entries as MutableList<SatEntry>)
|
entriesAdapter?.setEntries(entries as MutableList<SatEntry>)
|
||||||
setLoaded()
|
setLoaded()
|
||||||
}
|
}
|
||||||
observeEvents()
|
observeEvents()
|
||||||
@@ -88,26 +88,32 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setLoaded() {
|
private fun setLoaded() {
|
||||||
binding.entriesError.visibility = View.INVISIBLE
|
binding?.apply {
|
||||||
binding.entriesProgress.visibility = View.INVISIBLE
|
entriesError.visibility = View.INVISIBLE
|
||||||
binding.entriesRecycler.visibility = View.VISIBLE
|
entriesProgress.visibility = View.INVISIBLE
|
||||||
|
entriesRecycler.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setLoading() {
|
private fun setLoading() {
|
||||||
binding.entriesError.visibility = View.INVISIBLE
|
binding?.apply {
|
||||||
binding.entriesRecycler.visibility = View.INVISIBLE
|
entriesError.visibility = View.INVISIBLE
|
||||||
binding.entriesProgress.visibility = View.VISIBLE
|
entriesRecycler.visibility = View.INVISIBLE
|
||||||
|
entriesProgress.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setError() {
|
private fun setError() {
|
||||||
binding.entriesProgress.visibility = View.INVISIBLE
|
binding?.apply {
|
||||||
binding.entriesRecycler.visibility = View.INVISIBLE
|
entriesProgress.visibility = View.INVISIBLE
|
||||||
binding.entriesError.visibility = View.VISIBLE
|
entriesRecycler.visibility = View.INVISIBLE
|
||||||
|
entriesError.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateToPasses() {
|
private fun navigateToPasses() {
|
||||||
binding.searchBar.clearFocus()
|
binding?.searchBar?.clearFocus()
|
||||||
viewModel.updateEntriesSelection(entriesAdapter.getEntries())
|
entriesAdapter?.let { viewModel.updateEntriesSelection(it.getEntries()) }
|
||||||
requireView().findNavController().navigate(R.id.action_entries_to_passes)
|
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) }
|
data?.data?.also { uri -> viewModel.updateEntriesFromFile(uri) }
|
||||||
} else super.onActivityResult(requestCode, resultCode, data)
|
} else super.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
entriesAdapter = null
|
||||||
|
binding = null
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
gradle_version = '4.1.0'
|
gradle_version = '4.1.1'
|
||||||
gradle_plugin_version = '1.4.10'
|
gradle_plugin_version = '1.4.10'
|
||||||
material_version = '1.2.1'
|
material_version = '1.2.1'
|
||||||
constraint_layout_version = '2.0.2'
|
constraint_layout_version = '2.0.4'
|
||||||
navigation_version = '2.3.1'
|
navigation_version = '2.3.1'
|
||||||
preference_version = '1.1.1'
|
preference_version = '1.1.1'
|
||||||
room_version = '2.2.5'
|
room_version = '2.2.5'
|
||||||
|
|||||||
Reference in new issue
Block a user