Skip to content

Commit

Permalink
Analysis: Resolve type mismatch type warnings
Browse files Browse the repository at this point in the history
Warning Message: "Type mismatch: inferred type is Xyz?
but Xyz was expected"
  • Loading branch information
ParaskP7 committed Nov 17, 2022
1 parent 811ca51 commit f0f47f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
14 changes: 9 additions & 5 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
history.inputLast = InstanceStateUtils.readAndPurgeTempInstance<String>(INPUT_LAST_KEY, "", savedState.state)
visibility = customState.getInt(VISIBILITY_KEY)

initialEditorContentParsedSHA256 = customState.getByteArray(RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)
customState.getByteArray(RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)?.let {
initialEditorContentParsedSHA256 = it
}
val retainedHtml = InstanceStateUtils.readAndPurgeTempInstance<String>(RETAINED_HTML_KEY, "", savedState.state)
fromHtml(retainedHtml)

Expand Down Expand Up @@ -943,9 +945,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
return false
}

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

bundle.putBoolean(IS_MEDIA_ADDED_KEY, isMediaAdded)

savedState.state = bundle
savedState?.state = bundle
return savedState
}

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

constructor(parcel: Parcel) : super(parcel) {
state = parcel.readBundle(javaClass.classLoader)
parcel.readBundle(javaClass.classLoader)?.let {
state = it
}
}

override fun writeToParcel(out: Parcel, flags: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ open class SourceViewEditText : AppCompatEditText, TextWatcher {
visibility = customState.getInt("visibility")
val retainedContent = InstanceStateUtils.readAndPurgeTempInstance<String>(RETAINED_CONTENT_KEY, "", savedState.state)
setText(retainedContent)
initialEditorContentParsedSHA256 = customState.getByteArray(AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)
customState.getByteArray(AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)?.let {
initialEditorContentParsedSHA256 = it
}
}

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

override fun onSaveInstanceState(): Parcelable {
override fun onSaveInstanceState(): Parcelable? {
val bundle = Bundle()
bundle.putByteArray(org.wordpress.aztec.AztecText.RETAINED_INITIAL_HTML_PARSED_SHA256_KEY,
initialEditorContentParsedSHA256)
InstanceStateUtils.writeTempInstance(context, null, RETAINED_CONTENT_KEY, text.toString(), bundle)
val superState = super.onSaveInstanceState()
val savedState = SavedState(superState)
val savedState = superState?.let { SavedState(it) }
bundle.putInt("visibility", visibility)
savedState.state = bundle
savedState?.state = bundle
return savedState
}

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

constructor(parcel: Parcel) : super(parcel) {
state = parcel.readBundle(javaClass.classLoader)
parcel.readBundle(javaClass.classLoader)?.let {
state = it
}
}

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

if (withCursorTag) {
val withCursor = StringBuffer(text)
val withCursor = StringBuffer(text.toString())
if (!isCursorInsideTag()) {
withCursor.insert(selectionEnd, "<aztec_cursor></aztec_cursor>")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,25 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
isMediaToolbarVisible = restoredState.getBoolean("isMediaToolbarVisible")
setAdvancedState()
setupMediaToolbar()
editorContentParsedSHA256LastSwitch = restoredState.getByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY)
sourceContentParsedSHA256LastSwitch = restoredState.getByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY)
restoredState.getByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY)?.let {
editorContentParsedSHA256LastSwitch = it
}
restoredState.getByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY)?.let {
sourceContentParsedSHA256LastSwitch = it
}
}

override fun onSaveInstanceState(): Parcelable {
override fun onSaveInstanceState(): Parcelable? {
val superState = super.onSaveInstanceState()
val savedState = SourceViewEditText.SavedState(superState)
val savedState = superState?.let { SourceViewEditText.SavedState(it) }
val bundle = Bundle()
bundle.putBoolean("isSourceVisible", sourceEditor?.visibility == View.VISIBLE)
bundle.putBoolean("isMediaMode", isMediaModeEnabled)
bundle.putBoolean("isExpanded", isExpanded)
bundle.putBoolean("isMediaToolbarVisible", isMediaToolbarVisible)
bundle.putByteArray(RETAINED_EDITOR_HTML_PARSED_SHA256_KEY, editorContentParsedSHA256LastSwitch)
bundle.putByteArray(RETAINED_SOURCE_HTML_PARSED_SHA256_KEY, sourceContentParsedSHA256LastSwitch)
savedState.state = bundle
savedState?.state = bundle
return savedState
}

Expand Down

0 comments on commit f0f47f0

Please sign in to comment.