Skip to content

Commit 465d13c

Browse files
authored
Merge pull request #353 from wordpress-mobile/cleanup
Code Cleanup
2 parents c9c0d79 + c0a8b1c commit 465d13c

39 files changed

+78
-406
lines changed

aztec/src/main/java/org/wordpress/aztec/Html.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public static StringBuilder stringifyAttributes(Attributes attributes) {
174174
}
175175
return sb;
176176
}
177-
178177
}
179178

180179
class HtmlToSpannedConverter implements ContentHandler, LexicalHandler {
@@ -642,32 +641,26 @@ public void skippedEntity(String name) throws SAXException {
642641

643642
@Override
644643
public void startDTD(String s, String s1, String s2) throws SAXException {
645-
646644
}
647645

648646
@Override
649647
public void endDTD() throws SAXException {
650-
651648
}
652649

653650
@Override
654651
public void startEntity(String s) throws SAXException {
655-
656652
}
657653

658654
@Override
659655
public void endEntity(String s) throws SAXException {
660-
661656
}
662657

663658
@Override
664659
public void startCDATA() throws SAXException {
665-
666660
}
667661

668662
@Override
669663
public void endCDATA() throws SAXException {
670-
671664
}
672665

673666
@Override

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ class AztecParser {
239239
// at last, all checks passed so, let's mark the newline as visual!
240240
markBlockElementLineBreak(spanned, spanStart - 1)
241241
}
242-
243242
}
244243

245244
private fun markBlockElementsAsParagraphs(text: Spannable) {
@@ -497,7 +496,6 @@ class AztecParser {
497496
hiddenIndex++
498497
}
499498
}
500-
501499
} while (last != hiddenIndex)
502500
}
503501

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
271271
FullWidthImageElementWatcher.install(this)
272272

273273
EndOfBufferMarkerAdder.install(this)
274-
275274
}
276275

277276
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
@@ -328,7 +327,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
328327
setSelection(retainedSelectionStart, retainedSelectionEnd)
329328
}
330329

331-
332330
val isLinkDialogVisible = customState.getBoolean(LINK_DIALOG_VISIBLE_KEY, false)
333331
if (isLinkDialogVisible) {
334332
val retainedUrl = customState.getString(LINK_DIALOG_URL_KEY, "")
@@ -407,7 +405,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
407405
out.writeBundle(state)
408406
}
409407

410-
411408
companion object {
412409
@JvmField val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
413410
override fun createFromParcel(source: Parcel): SavedState {
@@ -466,7 +463,7 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
466463
if (!isViewInitialized) return
467464

468465
if (length() != 0) {
469-
// if the text end has the marker, let's make sure the cursor never includes it or surpusses it
466+
// if the text end has the marker, let's make sure the cursor never includes it or surpasses it
470467
if ((selStart == length() || selEnd == length()) && text[length() - 1] == Constants.END_OF_BUFFER_MARKER) {
471468
var start = selStart
472469
var end = selEnd
@@ -515,7 +512,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
515512
newSelStart--
516513
}
517514

518-
519515
TextFormat.values().forEach {
520516
if (contains(it, newSelStart, newSelEnd)) {
521517
styles.add(it)
@@ -801,7 +797,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
801797
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_CODE, start, end)
802798
}
803799

804-
805800
fun removeBlockStylesFromRange(start: Int, end: Int, ignoreLineBounds: Boolean = false) {
806801
blockFormatter.removeBlockStyle(TextFormat.FORMAT_PARAGRAPH, start, end, Arrays.asList(AztecBlockSpan::class.java), ignoreLineBounds)
807802
}
@@ -838,7 +833,7 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
838833
val parser = AztecParser()
839834
val output = SpannableStringBuilder(selectedText)
840835

841-
//Strip block elements untill we figure out copy paste completely
836+
//Strip block elements until we figure out copy paste completely
842837
output.getSpans(0, output.length, ParagraphStyle::class.java).forEach { output.removeSpan(it) }
843838
clearMetaSpans(output)
844839
parser.syncVisualNewlinesOfBlockElements(output)
@@ -895,7 +890,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
895890
}
896891
}
897892

898-
899893
fun removeLink() {
900894
val urlSpanBounds = linkFormatter.getUrlSpanBounds()
901895

@@ -927,7 +921,6 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
927921
val anchorText = anchorInput.text.toString().trim { it <= ' ' }
928922

929923
link(linkText, anchorText)
930-
931924
})
932925

933926
if (linkFormatter.isUrlSelected()) {
@@ -1008,16 +1001,11 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
10081001
history.handleHistory(this@AztecText)
10091002
return false
10101003
}
1011-
10121004
}
10131005
return super.sendKeyEvent(event)
10141006
}
10151007

10161008
override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean {
1017-
// if (beforeLength == 1 && afterLength == 0) {
1018-
// return sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) && sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL))
1019-
// }
1020-
10211009
return super.deleteSurroundingText(beforeLength, afterLength)
10221010
}
10231011
}
@@ -1069,7 +1057,7 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
10691057
attributePredicate.matches(it.attributes)
10701058
}
10711059
.forEach {
1072-
it.setOverayLevel(index, level)
1060+
it.setOverlayLevel(index, level)
10731061
}
10741062
}
10751063

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
9696
editText.isFocusable = false
9797
editText.isFocusableInTouchMode = false
9898

99-
10099
setTextFromHistory(editText)
101100

102101
historyWorking = false

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.wordpress.aztec.formatting
33
import android.text.Editable
44
import org.wordpress.aztec.AztecText
55

6-
76
abstract class AztecFormatter(editor: AztecText) {
87

98
val editor: AztecText
@@ -20,5 +19,4 @@ abstract class AztecFormatter(editor: AztecText) {
2019
init {
2120
this.editor = editor
2221
}
23-
2422
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
231231
}
232232
}
233233

234-
235234
//TODO: Come up with a better way to init spans and get their classes (all the "make" methods)
236235
fun makeBlock(textFormat: TextFormat, nestingLevel: Int, attrs: AztecAttributes = AztecAttributes()): List<AztecBlockSpan> {
237236
when (textFormat) {
@@ -287,7 +286,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
287286
}
288287
}
289288

290-
291289
fun getSelectedTextBounds(editable: Editable, selectionStart: Int, selectionEnd: Int): IntRange {
292290
val startOfLine: Int
293291
val endOfLine: Int
@@ -310,14 +308,12 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
310308
}
311309
}
312310

313-
314311
startOfLine = if (indexOfFirstLineBreak != -1) indexOfFirstLineBreak else 0
315312
endOfLine = if (indexOfLastLineBreak != -1) (indexOfLastLineBreak + 1) else editable.length
316313

317314
return IntRange(startOfLine, endOfLine)
318315
}
319316

320-
321317
fun applyBlockStyle(blockElementType: TextFormat, start: Int = selectionStart, end: Int = selectionEnd) {
322318
if (start != end) {
323319
val nestingLevel = AztecNestable.getNestingLevelAt(editableText, start)
@@ -352,7 +348,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
352348
applyBlock(makeBlockSpan(blockElementType, nestingLevel), startOfBlock + 1,
353349
(if (endOfBlock == editableText.length) endOfBlock else endOfBlock + 1))
354350
}
355-
356351
} else {
357352
val boundsOfSelectedText = getSelectedTextBounds(editableText, start, end)
358353

@@ -366,7 +361,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
366361
var startOfBlock: Int = startOfLine
367362
var endOfBlock: Int = endOfLine
368363

369-
370364
if (startOfLine != 0) {
371365
val spansOnPreviousLine = editableText.getSpans(startOfLine - 1, startOfLine - 1, spanToApply.javaClass)
372366
.firstOrNull()
@@ -404,11 +398,7 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
404398
}
405399

406400
applyBlock(spanToApply, startOfBlock, endOfBlock)
407-
408-
//if the line was empty trigger onSelectionChanged manually to update toolbar buttons status
409-
// if (isEmptyLine) {
410-
editor.onSelectionChanged(startOfLine, endOfLine)
411-
// }
401+
editor.onSelectionChanged(startOfLine, endOfLine)
412402
}
413403
}
414404

@@ -474,7 +464,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
474464
val lines = TextUtils.split(editableText.toString(), "\n")
475465
val list = ArrayList<Int>()
476466

477-
478467
for (i in lines.indices) {
479468
val lineStart = (0..i - 1).sumBy { lines[it].length + 1 }
480469
val lineEnd = lineStart + lines[i].length
@@ -520,7 +509,6 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle
520509
return spans.isNotEmpty()
521510
}
522511

523-
524512
fun containQuote(selStart: Int = selectionStart, selEnd: Int = selectionEnd): Boolean {
525513
val lines = TextUtils.split(editableText.toString(), "\n")
526514
val list = ArrayList<Int>()

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import org.wordpress.aztec.spans.*
1111
import org.wordpress.aztec.watchers.TextChangedEvent
1212
import java.util.*
1313

14-
1514
class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormatter(editor) {
1615

1716
data class CarryOverSpan(val span: AztecInlineSpan, val start: Int, val end: Int)
1817
data class CodeStyle(val codeBackground: Int, val codeBackgroundAlpha: Float, val codeColor: Int)
1918

2019
val carryOverSpans = ArrayList<CarryOverSpan>()
2120

22-
2321
fun toggleBold() {
2422
if (!containsInlineStyle(TextFormat.FORMAT_BOLD)) {
2523
applyInlineStyle(TextFormat.FORMAT_BOLD)
@@ -84,7 +82,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
8482
carryOverSpans.clear()
8583
}
8684

87-
8885
fun handleInlineStyling(textChangedEvent: TextChangedEvent) {
8986
//trailing styling
9087
if (!editor.formattingHasChanged() || textChangedEvent.isNewLineButNotAtTheBeginning()) return
@@ -113,7 +110,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
113110
editor.setFormattingChangesApplied()
114111
}
115112

116-
117113
private fun clearInlineStyles(start: Int, end: Int, ignoreSelectedStyles: Boolean) {
118114
val newStart = if (start > end) end else start
119115

@@ -134,7 +130,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
134130
}
135131
}
136132

137-
138133
fun applyInlineStyle(textFormat: TextFormat, start: Int = selectionStart, end: Int = selectionEnd) {
139134
val spanToApply = makeInlineSpan(textFormat)
140135

@@ -163,7 +158,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
163158
} else {
164159
editableText.setSpan(precedingSpan, spanStart, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
165160
}
166-
167161
}
168162
}
169163

@@ -200,7 +194,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
200194
} else {
201195
editableText.setSpan(spanToApply, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
202196
}
203-
204197
}
205198

206199
joinStyleSpans(start, end)
@@ -234,18 +227,14 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
234227
joinStyleSpans(start, end)
235228
}
236229

237-
238230
fun isSameInlineSpanType(firstSpan: AztecInlineSpan, secondSpan: AztecInlineSpan): Boolean {
239231
if (firstSpan.javaClass == secondSpan.javaClass) {
240232
//special check for StyleSpan
241233
if (firstSpan is StyleSpan && secondSpan is StyleSpan) {
242234
return firstSpan.style == secondSpan.style
243-
// } else if (firstSpan is AztecHeadingSpan && secondSpan is AztecHeadingSpan) {
244-
// return firstSpan.heading == secondSpan.heading
245235
} else {
246236
return true
247237
}
248-
249238
}
250239

251240
return false
@@ -268,7 +257,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
268257
editableText.removeSpan(outerSpan)
269258
editableText.setSpan(innerSpan, outerSpanStart, inSelectionSpanEnd, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
270259
}
271-
272260
}
273261
}
274262
}
@@ -291,7 +279,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
291279
}
292280
}
293281

294-
295282
//joins spans withing selected text
296283
val spansInSelection = editableText.getSpans(start, end, AztecInlineSpan::class.java)
297284
val spansToUse = editableText.getSpans(start, end, AztecInlineSpan::class.java)
@@ -311,7 +298,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
311298
neighbourSpan = it
312299
return@inner
313300
}
314-
315301
}
316302
}
317303

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder
1212
import org.xml.sax.Attributes
1313
import java.util.*
1414

15-
1615
class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
1716

1817
fun applyMoreComment() {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.wordpress.aztec.AztecAttributes
1010
import org.wordpress.aztec.AztecText
1111
import org.wordpress.aztec.spans.AztecURLSpan
1212

13-
1413
class LinkFormatter(editor: AztecText, val linkStyle: LinkStyle):AztecFormatter(editor) {
1514

1615
data class LinkStyle(val linkColor: Int, val linkUnderline: Boolean)
@@ -29,7 +28,6 @@ class LinkFormatter(editor: AztecText, val linkStyle: LinkStyle):AztecFormatter(
2928

3029
url = if (TextUtils.isEmpty(clipboardUrl)) "" else clipboardUrl
3130
anchor = if (selectionStart == selectionEnd) "" else editor.getSelectedText()
32-
3331
} else {
3432
val urlSpan = editableText.getSpans(selectionStart, selectionEnd, AztecURLSpan::class.java).first()
3533

@@ -51,7 +49,6 @@ class LinkFormatter(editor: AztecText, val linkStyle: LinkStyle):AztecFormatter(
5149
}
5250

5351
return Pair(url, anchor)
54-
5552
}
5653

5754
/**
@@ -81,7 +78,6 @@ class LinkFormatter(editor: AztecText, val linkStyle: LinkStyle):AztecFormatter(
8178
return Pair(spanStart, spanEnd)
8279
}
8380

84-
8581
fun addLink(link: String, anchor: String, start: Int, end: Int) {
8682
val cleanLink = link.trim()
8783

0 commit comments

Comments
 (0)