mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-07 16:29:55 +00:00
Fix: Memory Leak by ViewBinding
This commit is contained in:
parent
ba05636b33
commit
9afcd3661f
@ -43,7 +43,8 @@ import kotlin.math.min
|
||||
|
||||
class EditRepositoryFragment() : ScreenFragment() {
|
||||
|
||||
private lateinit var editRepositoryBinding: EditRepositoryBinding
|
||||
private var _editRepositoryBinding: EditRepositoryBinding? = null
|
||||
private val editRepositoryBinding get() = _editRepositoryBinding!!
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_REPOSITORY_ID = "repositoryId"
|
||||
@ -86,7 +87,7 @@ class EditRepositoryFragment() : ScreenFragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
editRepositoryBinding = EditRepositoryBinding.inflate(layoutInflater)
|
||||
_editRepositoryBinding = EditRepositoryBinding.inflate(layoutInflater)
|
||||
|
||||
syncConnection.bind(requireContext())
|
||||
|
||||
@ -259,6 +260,7 @@ class EditRepositoryFragment() : ScreenFragment() {
|
||||
syncConnection.unbind(requireContext())
|
||||
checkDisposable?.dispose()
|
||||
checkDisposable = null
|
||||
_editRepositoryBinding = null
|
||||
}
|
||||
|
||||
private var addressError = false
|
||||
|
@ -11,7 +11,6 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.database.Database
|
||||
import com.looker.droidify.databinding.TitleTextItemBinding
|
||||
@ -19,7 +18,6 @@ import com.looker.droidify.service.Connection
|
||||
import com.looker.droidify.service.SyncService
|
||||
import com.looker.droidify.utility.Utils
|
||||
import com.looker.droidify.utility.extension.resources.getColorFromAttr
|
||||
import com.looker.droidify.utility.extension.resources.inflate
|
||||
import com.looker.droidify.utility.extension.resources.sizeScaled
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -28,7 +26,7 @@ import java.util.*
|
||||
|
||||
class RepositoryFragment() : ScreenFragment() {
|
||||
|
||||
private lateinit var titleBinding: TitleTextItemBinding
|
||||
private var titleBinding: TitleTextItemBinding? = null
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_REPOSITORY_ID = "repositoryId"
|
||||
@ -98,6 +96,7 @@ class RepositoryFragment() : ScreenFragment() {
|
||||
super.onDestroyView()
|
||||
|
||||
layout = null
|
||||
titleBinding = null
|
||||
syncConnection.unbind(requireContext())
|
||||
repositoryDisposable?.dispose()
|
||||
repositoryDisposable = null
|
||||
@ -164,10 +163,11 @@ class RepositoryFragment() : ScreenFragment() {
|
||||
|
||||
private fun LinearLayoutCompat.addTitleText(titleResId: Int, text: CharSequence) {
|
||||
if (text.isNotEmpty()) {
|
||||
val layout = inflate(R.layout.title_text_item)
|
||||
val titleView = layout.findViewById<MaterialTextView>(R.id.title)!!
|
||||
val binding = TitleTextItemBinding.inflate(layoutInflater)
|
||||
val layout = binding.root
|
||||
val titleView = binding.title
|
||||
val textView = binding.text
|
||||
titleView.setText(titleResId)
|
||||
val textView = layout.findViewById<MaterialTextView>(R.id.text)!!
|
||||
textView.text = text
|
||||
addView(layout)
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.looker.droidify.databinding.FragmentBinding
|
||||
|
||||
open class ScreenFragment : BaseFragment() {
|
||||
lateinit var fragmentBinding: FragmentBinding
|
||||
private var _fragmentBinding: FragmentBinding? = null
|
||||
val fragmentBinding get() = _fragmentBinding!!
|
||||
|
||||
lateinit var toolbar: Toolbar
|
||||
lateinit var collapsingToolbar: CollapsingToolbarLayout
|
||||
@ -18,17 +19,22 @@ open class ScreenFragment : BaseFragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
fragmentBinding = FragmentBinding.inflate(layoutInflater)
|
||||
_fragmentBinding = FragmentBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
this.toolbar = fragmentBinding.toolbar
|
||||
this.collapsingToolbar = fragmentBinding.collapsingToolbar
|
||||
this.appBar = fragmentBinding.appbarLayout
|
||||
return fragmentBinding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_fragmentBinding = null
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import kotlinx.coroutines.flow.collect
|
||||
|
||||
class SettingsFragment : ScreenFragment() {
|
||||
|
||||
private lateinit var preferenceBinding: PreferenceItemBinding
|
||||
private var preferenceBinding: PreferenceItemBinding? = null
|
||||
private val preferences = mutableMapOf<Preferences.Key<*>, Preference<*>>()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -173,6 +173,7 @@ class SettingsFragment : ScreenFragment() {
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
preferences.clear()
|
||||
preferenceBinding = null
|
||||
}
|
||||
|
||||
private fun updatePreference(key: Preferences.Key<*>?) {
|
||||
|
@ -39,7 +39,8 @@ import kotlin.math.*
|
||||
|
||||
class TabsFragment : ScreenFragment() {
|
||||
|
||||
private lateinit var tabsBinding: TabsToolbarBinding
|
||||
private var _tabsBinding: TabsToolbarBinding? = null
|
||||
private val tabsBinding get() = _tabsBinding!!
|
||||
|
||||
companion object {
|
||||
private const val STATE_SEARCH_FOCUSED = "searchFocused"
|
||||
@ -103,7 +104,7 @@ class TabsFragment : ScreenFragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
tabsBinding = TabsToolbarBinding.inflate(layoutInflater)
|
||||
_tabsBinding = TabsToolbarBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -312,6 +313,8 @@ class TabsFragment : ScreenFragment() {
|
||||
repositoriesDisposable = null
|
||||
sectionsAnimator?.cancel()
|
||||
sectionsAnimator = null
|
||||
|
||||
_tabsBinding = null
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user