Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compile Warnings As Errors] Resolve Warnings & Enable All Warnings as Errors #1016

Merged
merged 17 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6ba043c
Analysis: Resolve kotlin stdlib's to lower case deprecated warnings
ParaskP7 Nov 17, 2022
0e8e308
Analysis: Resolve parameter is never and could be renamed to _ warnings
ParaskP7 Nov 17, 2022
811ca51
Analysis: Resolve variable is never used warning
ParaskP7 Nov 17, 2022
f0f47f0
Analysis: Resolve type mismatch type warnings
ParaskP7 Nov 17, 2022
8ce75c2
Analysis: Resolve unsafe use of a nullable receiver type warning
ParaskP7 Nov 17, 2022
1e7f4a9
Analysis: Resolve kotlin stdlib's sum by deprecated warnings
ParaskP7 Nov 17, 2022
96c9668
Analysis: Resolve name shadowed warning
ParaskP7 Nov 17, 2022
56892fd
Analysis: Resolve parameter supertype naming type warnings
ParaskP7 Nov 17, 2022
3c54be7
Analysis: Resolve non exhaustive when statements when warning
ParaskP7 Nov 17, 2022
c32e320
Analysis: Suppress get color deprecated warning
ParaskP7 Nov 17, 2022
6c5296d
Analysis: Resolve open has no effect in an object warnings
ParaskP7 Nov 17, 2022
1315ae8
Analysis: Suppress variable initializer is redundant warning
ParaskP7 Nov 17, 2022
d09302b
Analysis: Resolve type mismatch type warning for app module
ParaskP7 Nov 17, 2022
fcbb63c
Analysis: Resolve unnecessary safe call type warning for app module
ParaskP7 Nov 17, 2022
e190bc1
Analysis: Suppress android junit4 deprecated warnings for ui tests
ParaskP7 Nov 17, 2022
95df07b
Analysis: Resolve unnecessary safe call type warning for ui tests
ParaskP7 Nov 17, 2022
a27076d
Analysis: Enable all warnings as errors for all modules
ParaskP7 Nov 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package org.wordpress.aztec.demo

import android.util.Log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class GutenbergCompatTests : BaseTest() {
val editorPage = EditorPage()
val audioShortcodePlugin = AudioShortcodePlugin()
val aztecText = mActivityIntentsTestRule.activity.findViewById<AztecText>(R.id.aztec)
aztecText.plugins?.add(audioShortcodePlugin)
aztecText.plugins.add(audioShortcodePlugin)

// let's test the plugin works as expected, i.e. it preserves the Gutenberg block structure
editorPage
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,13 @@ open class MainActivity : AppCompatActivity(),

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK) {
var bitmap: Bitmap

when (requestCode) {
REQUEST_MEDIA_CAMERA_PHOTO -> {
// By default, BitmapFactory.decodeFile sets the bitmap's density to the device default so, we need
// to correctly set the input density to 160 ourselves.
val options = BitmapFactory.Options()
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
bitmap = BitmapFactory.decodeFile(mediaPath, options)
val bitmap = BitmapFactory.decodeFile(mediaPath, options)
insertImageAndSimulateUpload(bitmap, mediaPath)
}
REQUEST_MEDIA_PHOTO -> {
Expand All @@ -271,7 +269,7 @@ open class MainActivity : AppCompatActivity(),
// to correctly set the input density to 160 ourselves.
val options = BitmapFactory.Options()
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
bitmap = BitmapFactory.decodeStream(stream, null, options)
val bitmap = BitmapFactory.decodeStream(stream, null, options)

insertImageAndSimulateUpload(bitmap, mediaPath)
}
Expand All @@ -287,7 +285,7 @@ open class MainActivity : AppCompatActivity(),

override fun onThumbnailLoaded(drawable: Drawable?) {
val conf = Bitmap.Config.ARGB_8888 // see other conf types
bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
val bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
Expand Down Expand Up @@ -527,7 +525,7 @@ open class MainActivity : AppCompatActivity(),
super.onSaveInstanceState(outState)

if (mediaUploadDialog != null && mediaUploadDialog!!.isShowing) {
outState?.putBoolean("isMediaUploadDialogVisible", true)
outState.putBoolean("isMediaUploadDialogVisible", true)
}
}

Expand Down
3 changes: 2 additions & 1 deletion aztec/src/main/kotlin/org/wordpress/aztec/AztecTagHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.wordpress.aztec.spans.createTaskListSpan
import org.wordpress.aztec.spans.createUnorderedListSpan
import org.wordpress.aztec.util.getLast
import org.xml.sax.Attributes
import java.util.Locale

class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = ArrayList(), private val alignmentRendering: AlignmentRendering
) : Html.TagHandler {
Expand All @@ -75,7 +76,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
return true
}

when (tag.toLowerCase()) {
when (tag.lowercase(Locale.getDefault())) {
LIST_LI -> {
val span = createListItemSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes))
handleElement(output, opening, span)
Expand Down
23 changes: 14 additions & 9 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.util.Arrays
import java.util.LinkedList
import java.util.Locale

@Suppress("UNUSED_PARAMETER")
open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlTappedListener, IEventInjector {
Expand Down Expand Up @@ -705,7 +706,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
temp
}

val emptyEditTextBackspaceDetector = InputFilter { source, start, end, dest, dstart, dend ->
val emptyEditTextBackspaceDetector = InputFilter { source, start, _, _, dstart, dend ->
if (selectionStart == 0 && selectionEnd == 0
&& start == 0
&& dstart == 0 && dend == 0
Expand Down Expand Up @@ -897,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 @@ -942,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 @@ -977,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 @@ -987,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 Expand Up @@ -1818,7 +1823,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
// Android 8 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
clipboardIdentifier -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.P
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
&& Build.MANUFACTURER.lowercase(Locale.getDefault()).equals("samsung")) {
// Nope return true
Toast.makeText(context, context.getString(R.string.samsung_disabled_custom_clipboard, Build.VERSION.RELEASE), Toast.LENGTH_LONG).show()
} else {
Expand Down Expand Up @@ -2078,8 +2083,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown

unknownBlockSpanStart = text.getSpanStart(unknownHtmlSpan)
blockEditorDialog = builder.create()
blockEditorDialog!!.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
blockEditorDialog!!.show()
blockEditorDialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
blockEditorDialog?.show()
}

private fun deleteInlineStyleFromTheBeginning() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ class BlockFormatter(editor: AztecText,
for (i in lines.indices) {
val lineLength = lines[i].length

val lineStart = (0 until i).sumBy { lines[it].length + 1 }
val lineStart = (0 until i).sumOf { lines[it].length + 1 }

val lineEnd = (lineStart + lineLength).let {
if ((start + it) != editableText.length) it + 1 else it // include the newline or not
Expand All @@ -843,7 +843,7 @@ class BlockFormatter(editor: AztecText,
for (i in lines.indices) {
val splitLength = lines[i].length

val lineStart = start + (0 until i).sumBy { lines[it].length + 1 }
val lineStart = start + (0 until i).sumOf { lines[it].length + 1 }
val lineEnd = (lineStart + splitLength + 1).coerceAtMost(end) // +1 to include the newline

val lineLength = lineEnd - lineStart
Expand All @@ -860,7 +860,7 @@ class BlockFormatter(editor: AztecText,
for (i in lines.indices) {
val splitLength = lines[i].length

val lineStart = start + (0 until i).sumBy { lines[it].length + 1 }
val lineStart = start + (0 until i).sumOf { lines[it].length + 1 }
val lineEnd = (lineStart + splitLength + 1).coerceAtMost(end) // +1 to include the newline

val lineLength = lineEnd - lineStart
Expand Down Expand Up @@ -901,7 +901,7 @@ class BlockFormatter(editor: AztecText,
val list = ArrayList<Int>()

for (i in lines.indices) {
val lineStart = (0 until i).sumBy { lines[it].length + 1 }
val lineStart = (0 until i).sumOf { lines[it].length + 1 }
val lineEnd = lineStart + lines[i].length

if (lineStart > lineEnd) {
Expand Down Expand Up @@ -947,7 +947,7 @@ class BlockFormatter(editor: AztecText,
return emptyList()
}

val start = (0 until index).sumBy { lines[it].length + 1 }
val start = (0 until index).sumOf { lines[it].length + 1 }
val end = start + lines[index].length

if (start > end) {
Expand Down Expand Up @@ -983,7 +983,7 @@ class BlockFormatter(editor: AztecText,
val list = ArrayList<Int>()

for (i in lines.indices) {
val lineStart = (0 until i).sumBy { lines[it].length + 1 }
val lineStart = (0 until i).sumOf { lines[it].length + 1 }
val lineEnd = lineStart + lines[i].length

if (lineStart >= lineEnd) {
Expand Down Expand Up @@ -1017,7 +1017,7 @@ class BlockFormatter(editor: AztecText,
return false
}

val start = (0 until index).sumBy { lines[it].length + 1 }
val start = (0 until index).sumOf { lines[it].length + 1 }
val end = start + lines[index].length

if (start >= end) {
Expand Down Expand Up @@ -1113,7 +1113,7 @@ class BlockFormatter(editor: AztecText,
val list = ArrayList<Int>()

for (i in lines.indices) {
val lineStart = (0 until i).sumBy { lines[it].length + 1 }
val lineStart = (0 until i).sumOf { lines[it].length + 1 }
val lineEnd = lineStart + lines[i].length

if (lineStart >= lineEnd) {
Expand Down Expand Up @@ -1146,7 +1146,7 @@ class BlockFormatter(editor: AztecText,
return false
}

val start = (0 until index).sumBy { lines[it].length + 1 }
val start = (0 until index).sumOf { lines[it].length + 1 }
val end = start + lines[index].length

if (start >= end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
fun toggleAny(textFormats: Set<ITextFormat>) {
if (!textFormats
.filter { containsInlineStyle(it) }
.fold(false) { found, containedTextFormat -> removeInlineStyle(containedTextFormat); true }) {
.fold(false) { _, containedTextFormat -> removeInlineStyle(containedTextFormat); true }) {
removeAllExclusiveFormats()
applyInlineStyle(textFormats.first())
}
Expand Down Expand Up @@ -211,7 +211,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
joinStyleSpans(start, end)
}

private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd, attrs: AztecAttributes = AztecAttributes()) {
private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd) {
val previousSpans = editableText.getSpans(start, end, MarkSpan::class.java)
previousSpans.forEach {
it.applyInlineStyleAttributes(editableText, start, end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
val list = ArrayList<Int>()

for (i in lines.indices) {
val lineStart = (0..i - 1).sumBy { lines[it].length + 1 }
val lineStart = (0..i - 1).sumOf { lines[it].length + 1 }
val lineEnd = lineStart + lines[i].length

if (lineStart >= lineEnd) {
Expand Down Expand Up @@ -64,7 +64,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
return false
}

val start = (0..index - 1).sumBy { lines[it].length + 1 }
val start = (0..index - 1).sumOf { lines[it].length + 1 }
val end = start + lines[index].length

if (start >= end) {
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 @@ -20,7 +20,7 @@ fun createHeadingSpan(nestingLevel: Int,
alignmentRendering: AlignmentRendering,
headerStyle: BlockFormatter.HeaderStyles = BlockFormatter.HeaderStyles(0, emptyMap())
): AztecHeadingSpan {
val textFormat = when (tag.toLowerCase(Locale.getDefault())) {
val textFormat = when (tag.lowercase(Locale.getDefault())) {
"h1" -> AztecTextFormat.FORMAT_HEADING_1
"h2" -> AztecTextFormat.FORMAT_HEADING_2
"h3" -> AztecTextFormat.FORMAT_HEADING_3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ open class AztecOrderedListSpan(
p.color = listStyle.indicatorColor
p.style = Paint.Style.FILL

val start = if (attributes.hasAttribute("start") == true) {
val startAttribute = if (attributes.hasAttribute("start") == true) {
attributes.getValue("start").toInt()
} else {
0
Expand All @@ -92,9 +92,9 @@ open class AztecOrderedListSpan(
var textToDraw = ""
getIndexOfProcessedLine(text, end)?.let {
val isReversed = attributes.hasAttribute("reversed")
val lineIndex = if (start > 0) {
if (isReversed) start - (it - 1)
else start + (it - 1)
val lineIndex = if (startAttribute > 0) {
if (isReversed) startAttribute - (it - 1)
else startAttribute + (it - 1)
} else {
val number = getNumberOfItemsInProcessedLine(text)
if (isReversed) number - (it - 1)
Expand Down
Loading