Skip to content

Commit d20fb85

Browse files
committed
using WeakReference in InputConnection
1 parent 0ca13ce commit d20fb85

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ import org.wordpress.aztec.watchers.event.text.BeforeTextChangedEventData
121121
import org.wordpress.aztec.watchers.event.text.OnTextChangedEventData
122122
import org.wordpress.aztec.watchers.event.text.TextWatcherEvent
123123
import org.xml.sax.Attributes
124+
import java.lang.ref.WeakReference
124125
import java.security.MessageDigest
125126
import java.security.NoSuchAlgorithmException
126127
import java.util.ArrayList
@@ -294,7 +295,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
294295

295296
private var focusOnVisible = true
296297

297-
var inputConnection: InputConnection? = null
298+
var inputConnectionRef: WeakReference<InputConnection>? = null
298299
var inputConnectionEditorInfo: EditorInfo? = null
299300

300301
interface OnSelectionChangedListener {
@@ -673,7 +674,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
673674
}
674675

675676
// now init the InputConnection, or replace if EditorInfo contains anything different
676-
if (inputConnection == null || !EditorInfoUtils.areEditorInfosTheSame(outAttrs, inputConnectionEditorInfo!!)) {
677+
if (inputConnectionRef?.get() == null || !EditorInfoUtils.areEditorInfosTheSame(outAttrs, inputConnectionEditorInfo!!)) {
677678
// we have a new InputConnection to create, save the new EditorInfo data and create it
678679
// we make a copy of the parameters being received, because super.onCreateInputConnection may make changes
679680
// to EditorInfo params being sent to it, and we want to preserve the same data we received in order
@@ -689,11 +690,11 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
689690
}
690691
// if non null, wrap the new InputConnection around our wrapper
691692
//inputConnection = AztecTextInputConnectionWrapper(localInputConnection, this)
692-
inputConnection = localInputConnection
693+
inputConnectionRef = WeakReference(localInputConnection)
693694
}
694695

695-
// returnn the existing inputConnection
696-
return inputConnection!!
696+
// return the existing inputConnection
697+
return inputConnectionRef?.get()!!
697698
}
698699

699700
override fun onRestoreInstanceState(state: Parcelable?) {

0 commit comments

Comments
 (0)