Skip to content

Commit 4358762

Browse files
authored
Merge pull request #1016 from wordpress-mobile/analysis/all-warnings-as-errors
[Compile Warnings As Errors] Resolve Warnings & Enable All Warnings as Errors
2 parents 96fb186 + a27076d commit 4358762

File tree

16 files changed

+102
-76
lines changed

16 files changed

+102
-76
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package org.wordpress.aztec.demo
24

35
import android.util.Log

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/GutenbergCompatTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class GutenbergCompatTests : BaseTest() {
328328
val editorPage = EditorPage()
329329
val audioShortcodePlugin = AudioShortcodePlugin()
330330
val aztecText = mActivityIntentsTestRule.activity.findViewById<AztecText>(R.id.aztec)
331-
aztecText.plugins?.add(audioShortcodePlugin)
331+
aztecText.plugins.add(audioShortcodePlugin)
332332

333333
// let's test the plugin works as expected, i.e. it preserves the Gutenberg block structure
334334
editorPage

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,13 @@ open class MainActivity : AppCompatActivity(),
253253

254254
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
255255
if (resultCode == Activity.RESULT_OK) {
256-
var bitmap: Bitmap
257-
258256
when (requestCode) {
259257
REQUEST_MEDIA_CAMERA_PHOTO -> {
260258
// By default, BitmapFactory.decodeFile sets the bitmap's density to the device default so, we need
261259
// to correctly set the input density to 160 ourselves.
262260
val options = BitmapFactory.Options()
263261
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
264-
bitmap = BitmapFactory.decodeFile(mediaPath, options)
262+
val bitmap = BitmapFactory.decodeFile(mediaPath, options)
265263
insertImageAndSimulateUpload(bitmap, mediaPath)
266264
}
267265
REQUEST_MEDIA_PHOTO -> {
@@ -271,7 +269,7 @@ open class MainActivity : AppCompatActivity(),
271269
// to correctly set the input density to 160 ourselves.
272270
val options = BitmapFactory.Options()
273271
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
274-
bitmap = BitmapFactory.decodeStream(stream, null, options)
272+
val bitmap = BitmapFactory.decodeStream(stream, null, options)
275273

276274
insertImageAndSimulateUpload(bitmap, mediaPath)
277275
}
@@ -287,7 +285,7 @@ open class MainActivity : AppCompatActivity(),
287285

288286
override fun onThumbnailLoaded(drawable: Drawable?) {
289287
val conf = Bitmap.Config.ARGB_8888 // see other conf types
290-
bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
288+
val bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
291289
val canvas = Canvas(bitmap)
292290
drawable.setBounds(0, 0, canvas.width, canvas.height)
293291
drawable.draw(canvas)
@@ -527,7 +525,7 @@ open class MainActivity : AppCompatActivity(),
527525
super.onSaveInstanceState(outState)
528526

529527
if (mediaUploadDialog != null && mediaUploadDialog!!.isShowing) {
530-
outState?.putBoolean("isMediaUploadDialogVisible", true)
528+
outState.putBoolean("isMediaUploadDialogVisible", true)
531529
}
532530
}
533531

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import org.wordpress.aztec.spans.createTaskListSpan
5353
import org.wordpress.aztec.spans.createUnorderedListSpan
5454
import org.wordpress.aztec.util.getLast
5555
import org.xml.sax.Attributes
56+
import java.util.Locale
5657

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

78-
when (tag.toLowerCase()) {
79+
when (tag.lowercase(Locale.getDefault())) {
7980
LIST_LI -> {
8081
val span = createListItemSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes))
8182
handleElement(output, opening, span)

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ import java.security.MessageDigest
132132
import java.security.NoSuchAlgorithmException
133133
import java.util.Arrays
134134
import java.util.LinkedList
135+
import java.util.Locale
135136

136137
@Suppress("UNUSED_PARAMETER")
137138
open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlTappedListener, IEventInjector {
@@ -705,7 +706,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
705706
temp
706707
}
707708

708-
val emptyEditTextBackspaceDetector = InputFilter { source, start, end, dest, dstart, dend ->
709+
val emptyEditTextBackspaceDetector = InputFilter { source, start, _, _, dstart, dend ->
709710
if (selectionStart == 0 && selectionEnd == 0
710711
&& start == 0
711712
&& dstart == 0 && dend == 0
@@ -897,7 +898,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
897898
history.inputLast = InstanceStateUtils.readAndPurgeTempInstance<String>(INPUT_LAST_KEY, "", savedState.state)
898899
visibility = customState.getInt(VISIBILITY_KEY)
899900

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

@@ -942,9 +945,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
942945
return false
943946
}
944947

945-
override fun onSaveInstanceState(): Parcelable {
948+
override fun onSaveInstanceState(): Parcelable? {
946949
val superState = super.onSaveInstanceState()
947-
val savedState = SavedState(superState)
950+
val savedState = superState?.let { SavedState(it) }
948951
val bundle = Bundle()
949952
InstanceStateUtils.writeTempInstance(context, externalLogger, HISTORY_LIST_KEY, ArrayList<String>(history.historyList), bundle)
950953
bundle.putInt(HISTORY_CURSOR_KEY, history.historyCursor)
@@ -977,7 +980,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
977980

978981
bundle.putBoolean(IS_MEDIA_ADDED_KEY, isMediaAdded)
979982

980-
savedState.state = bundle
983+
savedState?.state = bundle
981984
return savedState
982985
}
983986

@@ -987,7 +990,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
987990
constructor(superState: Parcelable) : super(superState)
988991

989992
constructor(parcel: Parcel) : super(parcel) {
990-
state = parcel.readBundle(javaClass.classLoader)
993+
parcel.readBundle(javaClass.classLoader)?.let {
994+
state = it
995+
}
991996
}
992997

993998
override fun writeToParcel(out: Parcel, flags: Int) {
@@ -1818,7 +1823,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
18181823
// Android 8 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
18191824
clipboardIdentifier -> {
18201825
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.P
1821-
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
1826+
&& Build.MANUFACTURER.lowercase(Locale.getDefault()).equals("samsung")) {
18221827
// Nope return true
18231828
Toast.makeText(context, context.getString(R.string.samsung_disabled_custom_clipboard, Build.VERSION.RELEASE), Toast.LENGTH_LONG).show()
18241829
} else {
@@ -2078,8 +2083,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
20782083

20792084
unknownBlockSpanStart = text.getSpanStart(unknownHtmlSpan)
20802085
blockEditorDialog = builder.create()
2081-
blockEditorDialog!!.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
2082-
blockEditorDialog!!.show()
2086+
blockEditorDialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
2087+
blockEditorDialog?.show()
20832088
}
20842089

20852090
private fun deleteInlineStyleFromTheBeginning() {

aztec/src/main/kotlin/org/wordpress/aztec/formatting/BlockFormatter.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class BlockFormatter(editor: AztecText,
823823
for (i in lines.indices) {
824824
val lineLength = lines[i].length
825825

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

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

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

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

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

866866
val lineLength = lineEnd - lineStart
@@ -901,7 +901,7 @@ class BlockFormatter(editor: AztecText,
901901
val list = ArrayList<Int>()
902902

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

907907
if (lineStart > lineEnd) {
@@ -947,7 +947,7 @@ class BlockFormatter(editor: AztecText,
947947
return emptyList()
948948
}
949949

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

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

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

989989
if (lineStart >= lineEnd) {
@@ -1017,7 +1017,7 @@ class BlockFormatter(editor: AztecText,
10171017
return false
10181018
}
10191019

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

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

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

11191119
if (lineStart >= lineEnd) {
@@ -1146,7 +1146,7 @@ class BlockFormatter(editor: AztecText,
11461146
return false
11471147
}
11481148

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

11521152
if (start >= end) {

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
6464
fun toggleAny(textFormats: Set<ITextFormat>) {
6565
if (!textFormats
6666
.filter { containsInlineStyle(it) }
67-
.fold(false) { found, containedTextFormat -> removeInlineStyle(containedTextFormat); true }) {
67+
.fold(false) { _, containedTextFormat -> removeInlineStyle(containedTextFormat); true }) {
6868
removeAllExclusiveFormats()
6969
applyInlineStyle(textFormats.first())
7070
}
@@ -211,7 +211,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
211211
joinStyleSpans(start, end)
212212
}
213213

214-
private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd, attrs: AztecAttributes = AztecAttributes()) {
214+
private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd) {
215215
val previousSpans = editableText.getSpans(start, end, MarkSpan::class.java)
216216
previousSpans.forEach {
217217
it.applyInlineStyleAttributes(editableText, start, end)

aztec/src/main/kotlin/org/wordpress/aztec/formatting/LineBlockFormatter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
3030
val list = ArrayList<Int>()
3131

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

3636
if (lineStart >= lineEnd) {
@@ -64,7 +64,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
6464
return false
6565
}
6666

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

7070
if (start >= end) {

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/spans/AztecHeadingSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fun createHeadingSpan(nestingLevel: Int,
2020
alignmentRendering: AlignmentRendering,
2121
headerStyle: BlockFormatter.HeaderStyles = BlockFormatter.HeaderStyles(0, emptyMap())
2222
): AztecHeadingSpan {
23-
val textFormat = when (tag.toLowerCase(Locale.getDefault())) {
23+
val textFormat = when (tag.lowercase(Locale.getDefault())) {
2424
"h1" -> AztecTextFormat.FORMAT_HEADING_1
2525
"h2" -> AztecTextFormat.FORMAT_HEADING_2
2626
"h3" -> AztecTextFormat.FORMAT_HEADING_3

0 commit comments

Comments
 (0)