Try to fix leak

This commit is contained in:
J-Jamet
2020-09-15 20:12:44 +02:00
parent f39065044f
commit 23c8735568
2 changed files with 27 additions and 17 deletions

View File

@@ -172,18 +172,13 @@ class EntryEditActivity : LockingActivity(),
// Build fragment to manage entry modification // Build fragment to manage entry modification
entryEditFragment = supportFragmentManager.findFragmentByTag(ENTRY_EDIT_FRAGMENT_TAG) as? EntryEditFragment? entryEditFragment = supportFragmentManager.findFragmentByTag(ENTRY_EDIT_FRAGMENT_TAG) as? EntryEditFragment?
if (entryEditFragment == null) { if (entryEditFragment == null) {
entryEditFragment = EntryEditFragment() entryEditFragment = EntryEditFragment.getInstance(tempEntryInfo)
} }
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.entry_edit_contents, entryEditFragment!!, ENTRY_EDIT_FRAGMENT_TAG) .replace(R.id.entry_edit_contents, entryEditFragment!!, ENTRY_EDIT_FRAGMENT_TAG)
.commit() .commit()
entryEditFragment?.drawFactory = mDatabase?.drawFactory
// TODO Fix leak
tempEntryInfo?.let {
entryEditFragment?.setEntryInfo(it)
}
entryEditFragment?.apply { entryEditFragment?.apply {
applyFontVisibilityToFields(PreferencesUtil.fieldFontIsInVisibility(this@EntryEditActivity)) drawFactory = mDatabase?.drawFactory
setOnDateClickListener = View.OnClickListener { setOnDateClickListener = View.OnClickListener {
expiryTime.date.let { expiresDate -> expiryTime.date.let { expiresDate ->
val dateTime = DateTime(expiresDate) val dateTime = DateTime(expiresDate)

View File

@@ -44,6 +44,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.icons.IconDrawableFactory import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.icons.assignDatabaseIcon import com.kunzisoft.keepass.icons.assignDatabaseIcon
import com.kunzisoft.keepass.model.* import com.kunzisoft.keepass.model.*
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.view.applyFontVisibility import com.kunzisoft.keepass.view.applyFontVisibility
import com.kunzisoft.keepass.view.collapse import com.kunzisoft.keepass.view.collapse
import com.kunzisoft.keepass.view.expand import com.kunzisoft.keepass.view.expand
@@ -92,6 +93,8 @@ class EntryEditFragment: StylishFragment() {
val rootView = inflater.cloneInContext(contextThemed) val rootView = inflater.cloneInContext(contextThemed)
.inflate(R.layout.fragment_entry_edit_contents, container, false) .inflate(R.layout.fragment_entry_edit_contents, container, false)
fontInVisibility = PreferencesUtil.fieldFontIsInVisibility(requireContext())
entryTitleLayoutView = rootView.findViewById(R.id.entry_edit_container_title) entryTitleLayoutView = rootView.findViewById(R.id.entry_edit_container_title)
entryTitleView = rootView.findViewById(R.id.entry_edit_title) entryTitleView = rootView.findViewById(R.id.entry_edit_title)
entryIconView = rootView.findViewById(R.id.entry_edit_icon_button) entryIconView = rootView.findViewById(R.id.entry_edit_icon_button)
@@ -145,7 +148,9 @@ class EntryEditFragment: StylishFragment() {
taIconColor?.recycle() taIconColor?.recycle()
// Retrieve the new entry after an orientation change // Retrieve the new entry after an orientation change
if (savedInstanceState?.containsKey(KEY_TEMP_ENTRY_INFO) == true) { if (arguments?.containsKey(KEY_TEMP_ENTRY_INFO) == true)
mEntryInfo = arguments?.getParcelable<EntryInfo>(KEY_TEMP_ENTRY_INFO) ?: mEntryInfo
else if (savedInstanceState?.containsKey(KEY_TEMP_ENTRY_INFO) == true) {
mEntryInfo = savedInstanceState.getParcelable(KEY_TEMP_ENTRY_INFO) ?: mEntryInfo mEntryInfo = savedInstanceState.getParcelable(KEY_TEMP_ENTRY_INFO) ?: mEntryInfo
} }
@@ -158,16 +163,22 @@ class EntryEditFragment: StylishFragment() {
return rootView return rootView
} }
override fun onDetach() {
super.onDetach()
drawFactory = null
setOnDateClickListener = null
setOnPasswordGeneratorClickListener = null
setOnIconViewClickListener = null
setOnRemoveAttachment = null
setOnEditCustomField = null
}
fun getEntryInfo(): EntryInfo? { fun getEntryInfo(): EntryInfo? {
populateEntryWithViews() populateEntryWithViews()
return mEntryInfo return mEntryInfo
} }
fun setEntryInfo(entryInfo: EntryInfo) {
populateViewsWithEntry()
mEntryInfo = entryInfo
}
private fun populateViewsWithEntry() { private fun populateViewsWithEntry() {
try { try {
// Set info in view // Set info in view
@@ -203,10 +214,6 @@ class EntryEditFragment: StylishFragment() {
} catch (e: Exception) {} } catch (e: Exception) {}
} }
fun applyFontVisibilityToFields(fontInVisibility: Boolean) {
this.fontInVisibility = fontInVisibility
}
var title: String var title: String
get() { get() {
return entryTitleView.text.toString() return entryTitleView.text.toString()
@@ -489,6 +496,14 @@ class EntryEditFragment: StylishFragment() {
companion object { companion object {
const val KEY_TEMP_ENTRY_INFO = "KEY_TEMP_ENTRY_INFO" const val KEY_TEMP_ENTRY_INFO = "KEY_TEMP_ENTRY_INFO"
const val KEY_LAST_FOCUSED_FIELD = "KEY_LAST_FOCUSED_FIELD" const val KEY_LAST_FOCUSED_FIELD = "KEY_LAST_FOCUSED_FIELD"
fun getInstance(entryInfo: EntryInfo?): EntryEditFragment {
return EntryEditFragment().apply {
arguments = Bundle().apply {
putParcelable(KEY_TEMP_ENTRY_INFO, entryInfo)
}
}
}
} }
} }