Skip to content

Commit f0f47f0

Browse files
committed
Analysis: Resolve type mismatch type warnings
Warning Message: "Type mismatch: inferred type is Xyz? but Xyz was expected"
1 parent 811ca51 commit f0f47f0

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
898898
history.inputLast = InstanceStateUtils.readAndPurgeTempInstance<String>(INPUT_LAST_KEY, "", savedState.state)
899899
visibility = customState.getInt(VISIBILITY_KEY)
900900

901-
initialEditorContentParsedSHA256 = customState.getByteArray(RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)
901+
customState.getByteArray(RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)?.let {
902+
initialEditorContentParsedSHA256 = it
903+
}
902904
val retainedHtml = InstanceStateUtils.readAndPurgeTempInstance<String>(RETAINED_HTML_KEY, "", savedState.state)
903905
fromHtml(retainedHtml)
904906

@@ -943,9 +945,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
943945
return false
944946
}
945947

946-
override fun onSaveInstanceState(): Parcelable {
948+
override fun onSaveInstanceState(): Parcelable? {
947949
val superState = super.onSaveInstanceState()
948-
val savedState = SavedState(superState)
950+
val savedState = superState?.let { SavedState(it) }
949951
val bundle = Bundle()
950952
InstanceStateUtils.writeTempInstance(context, externalLogger, HISTORY_LIST_KEY, ArrayList<String>(history.historyList), bundle)
951953
bundle.putInt(HISTORY_CURSOR_KEY, history.historyCursor)
@@ -978,7 +980,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
978980

979981
bundle.putBoolean(IS_MEDIA_ADDED_KEY, isMediaAdded)
980982

981-
savedState.state = bundle
983+
savedState?.state = bundle
982984
return savedState
983985
}
984986

@@ -988,7 +990,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
988990
constructor(superState: Parcelable) : super(superState)
989991

990992
constructor(parcel: Parcel) : super(parcel) {
991-
state = parcel.readBundle(javaClass.classLoader)
993+
parcel.readBundle(javaClass.classLoader)?.let {
994+
state = it
995+
}
992996
}
993997

994998
override fun writeToParcel(out: Parcel, flags: Int) {

aztec/src/main/kotlin/org/wordpress/aztec/source/SourceViewEditText.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ open class SourceViewEditText : AppCompatEditText, TextWatcher {
9898
visibility = customState.getInt("visibility")
9999
val retainedContent = InstanceStateUtils.readAndPurgeTempInstance<String>(RETAINED_CONTENT_KEY, "", savedState.state)
100100
setText(retainedContent)
101-
initialEditorContentParsedSHA256 = customState.getByteArray(AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)
101+
customState.getByteArray(AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)?.let {
102+
initialEditorContentParsedSHA256 = it
103+
}
102104
}
103105

104106
// Do not include the content of the editor when saving state to bundle.
@@ -109,15 +111,15 @@ open class SourceViewEditText : AppCompatEditText, TextWatcher {
109111
return false
110112
}
111113

112-
override fun onSaveInstanceState(): Parcelable {
114+
override fun onSaveInstanceState(): Parcelable? {
113115
val bundle = Bundle()
114116
bundle.putByteArray(org.wordpress.aztec.AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY,
115117
initialEditorContentParsedSHA256)
116118
InstanceStateUtils.writeTempInstance(context, null, RETAINED_CONTENT_KEY, text.toString(), bundle)
117119
val superState = super.onSaveInstanceState()
118-
val savedState = SavedState(superState)
120+
val savedState = superState?.let { SavedState(it) }
119121
bundle.putInt("visibility", visibility)
120-
savedState.state = bundle
122+
savedState?.state = bundle
121123
return savedState
122124
}
123125

@@ -127,7 +129,9 @@ open class SourceViewEditText : AppCompatEditText, TextWatcher {
127129
constructor(superState: Parcelable) : super(superState)
128130

129131
constructor(parcel: Parcel) : super(parcel) {
130-
state = parcel.readBundle(javaClass.classLoader)
132+
parcel.readBundle(javaClass.classLoader)?.let {
133+
state = it
134+
}
131135
}
132136

133137
override fun writeToParcel(out: Parcel, flags: Int) {
@@ -265,7 +269,7 @@ open class SourceViewEditText : AppCompatEditText, TextWatcher {
265269
val str: String
266270

267271
if (withCursorTag) {
268-
val withCursor = StringBuffer(text)
272+
val withCursor = StringBuffer(text.toString())
269273
if (!isCursorInsideTag()) {
270274
withCursor.insert(selectionEnd, "<aztec_cursor></aztec_cursor>")
271275
} else {

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,25 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
378378
isMediaToolbarVisible = restoredState.getBoolean("isMediaToolbarVisible")
379379
setAdvancedState()
380380
setupMediaToolbar()
381-
editorContentParsedSHA256LastSwitch = restoredState.getByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY)
382-
sourceContentParsedSHA256LastSwitch = restoredState.getByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY)
381+
restoredState.getByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY)?.let {
382+
editorContentParsedSHA256LastSwitch = it
383+
}
384+
restoredState.getByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY)?.let {
385+
sourceContentParsedSHA256LastSwitch = it
386+
}
383387
}
384388

385-
override fun onSaveInstanceState(): Parcelable {
389+
override fun onSaveInstanceState(): Parcelable? {
386390
val superState = super.onSaveInstanceState()
387-
val savedState = SourceViewEditText.SavedState(superState)
391+
val savedState = superState?.let { SourceViewEditText.SavedState(it) }
388392
val bundle = Bundle()
389393
bundle.putBoolean("isSourceVisible", sourceEditor?.visibility == View.VISIBLE)
390394
bundle.putBoolean("isMediaMode", isMediaModeEnabled)
391395
bundle.putBoolean("isExpanded", isExpanded)
392396
bundle.putBoolean("isMediaToolbarVisible", isMediaToolbarVisible)
393397
bundle.putByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY, editorContentParsedSHA256LastSwitch)
394398
bundle.putByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY, sourceContentParsedSHA256LastSwitch)
395-
savedState.state = bundle
399+
savedState?.state = bundle
396400
return savedState
397401
}
398402

0 commit comments

Comments
 (0)