Skip to content

Commit db247eb

Browse files
authored
Merge pull request #1087 from wordpress-mobile/issue/remove-redundant-context-form-image-span
Remove redundant context from AztecDynamicImageSpan
2 parents 3c95e7b + 4c8c6af commit db247eb

File tree

16 files changed

+19
-34
lines changed

16 files changed

+19
-34
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
120120
return true
121121
}
122122
IMAGE -> {
123-
handleMediaElement(opening, output, AztecImageSpan(context, loadingDrawable, nestingLevel, AztecAttributes(attributes)))
123+
handleMediaElement(opening, output, AztecImageSpan(loadingDrawable, nestingLevel, AztecAttributes(attributes)))
124124
return true
125125
}
126126
VIDEO -> {
@@ -145,7 +145,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
145145
LINE -> {
146146
if (opening) {
147147
// Add an extra newline above the line to prevent weird typing on the line above
148-
start(output, AztecHorizontalRuleSpan(context, AppCompatResources.getDrawable(context, R.drawable.img_hr)!!,
148+
start(output, AztecHorizontalRuleSpan(AppCompatResources.getDrawable(context, R.drawable.img_hr)!!,
149149
nestingLevel, AztecAttributes(attributes)))
150150
output.append(Constants.MAGIC_CHAR)
151151
} else {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
104104
}
105105

106106
val span = AztecHorizontalRuleSpan(
107-
editor.context,
108107
AppCompatResources.getDrawable(editor.context, R.drawable.img_hr)!!,
109108
nestingLevel,
110109
AztecAttributes(),
@@ -134,7 +133,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
134133
fun insertImage(inline: Boolean, drawable: Drawable?, attributes: Attributes, onImageTappedListener: AztecText.OnImageTappedListener?,
135134
onMediaDeletedListener: AztecText.OnMediaDeletedListener?) {
136135
val nestingLevel = if (inline) IAztecNestable.getNestingLevelAt(editableText, selectionStart) else 0
137-
val span = AztecImageSpan(editor.context, drawable, nestingLevel, AztecAttributes(attributes), onImageTappedListener,
136+
val span = AztecImageSpan(drawable, nestingLevel, AztecAttributes(attributes), onImageTappedListener,
138137
onMediaDeletedListener, editor)
139138
insertMediaSpan(inline, span)
140139
}

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecAudioSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AztecAudioSpan(context: Context, drawable: Drawable?, override var nesting
1212
var onAudioTappedListener: AztecText.OnAudioTappedListener? = null,
1313
onMediaDeletedListener: AztecText.OnMediaDeletedListener? = null,
1414
editor: AztecText? = null) :
15-
AztecMediaSpan(context, drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
15+
AztecMediaSpan(drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
1616
override val TAG: String = "audio"
1717

1818
init {

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecDynamicImageSpan.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.wordpress.aztec.spans
22

3-
import android.content.Context
43
import android.graphics.Canvas
54
import android.graphics.Paint
65
import android.graphics.Rect
@@ -9,7 +8,7 @@ import android.text.style.DynamicDrawableSpan
98
import org.wordpress.aztec.AztecText
109
import java.lang.ref.WeakReference
1110

12-
abstract class AztecDynamicImageSpan(val context: Context, protected var imageDrawable: Drawable?) : DynamicDrawableSpan() {
11+
abstract class AztecDynamicImageSpan(protected var imageDrawable: Drawable?) : DynamicDrawableSpan() {
1312
var textView: WeakReference<AztecText>? = null
1413
var aspectRatio: Double = 1.0
1514

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHorizontalRuleSpan.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package org.wordpress.aztec.spans
22

3-
import android.content.Context
43
import android.graphics.drawable.Drawable
54
import org.wordpress.aztec.AztecAttributes
65
import org.wordpress.aztec.AztecText
76
import java.lang.ref.WeakReference
87

9-
class AztecHorizontalRuleSpan(context: Context, drawable: Drawable, override var nestingLevel: Int,
8+
class AztecHorizontalRuleSpan(drawable: Drawable, override var nestingLevel: Int,
109
override var attributes: AztecAttributes = AztecAttributes(), editor: AztecText? = null) :
11-
AztecDynamicImageSpan(context, drawable), IAztecFullWidthImageSpan, IAztecSpan {
10+
AztecDynamicImageSpan(drawable), IAztecFullWidthImageSpan, IAztecSpan {
1211
init {
1312
textView = WeakReference(editor)
1413
}

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecImageSpan.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package org.wordpress.aztec.spans
22

3-
import android.content.Context
43
import android.graphics.drawable.Drawable
54
import org.wordpress.aztec.AztecAttributes
65
import org.wordpress.aztec.AztecText
76

8-
class AztecImageSpan(context: Context, drawable: Drawable?,
7+
class AztecImageSpan(drawable: Drawable?,
98
override var nestingLevel: Int,
109
attributes: AztecAttributes = AztecAttributes(),
1110
var onImageTappedListener: AztecText.OnImageTappedListener? = null,
1211
onMediaDeletedListener: AztecText.OnMediaDeletedListener? = null,
1312
editor: AztecText? = null) : IAztecFullWidthImageSpan,
14-
AztecMediaSpan(context, drawable, attributes, onMediaDeletedListener, editor) {
13+
AztecMediaSpan(drawable, attributes, onMediaDeletedListener, editor) {
1514
override val TAG: String = "img"
1615

1716
override fun onClick() {

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecMediaSpan.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.wordpress.aztec.spans
22

3-
import android.content.Context
43
import android.graphics.Canvas
54
import android.graphics.Paint
65
import android.graphics.Rect
@@ -11,9 +10,9 @@ import org.wordpress.aztec.AztecText
1110
import java.lang.ref.WeakReference
1211
import java.util.ArrayList
1312

14-
abstract class AztecMediaSpan(context: Context, drawable: Drawable?, override var attributes: AztecAttributes = AztecAttributes(),
13+
abstract class AztecMediaSpan(drawable: Drawable?, override var attributes: AztecAttributes = AztecAttributes(),
1514
var onMediaDeletedListener: AztecText.OnMediaDeletedListener? = null,
16-
editor: AztecText? = null) : AztecDynamicImageSpan(context, drawable), IAztecAttributedSpan {
15+
editor: AztecText? = null) : AztecDynamicImageSpan(drawable), IAztecAttributedSpan {
1716
abstract val TAG: String
1817

1918
private val overlays: ArrayList<Pair<Drawable?, Int>> = ArrayList()

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecVideoSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AztecVideoSpan(context: Context, drawable: Drawable?, override var nesting
1212
var onVideoTappedListener: AztecText.OnVideoTappedListener? = null,
1313
onMediaDeletedListener: AztecText.OnMediaDeletedListener? = null,
1414
editor: AztecText? = null) :
15-
AztecMediaSpan(context, drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
15+
AztecMediaSpan(drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
1616
override val TAG: String = "video"
1717

1818
init {

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/AztecPlaceholderSpan.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.wordpress.aztec.placeholders
22

3-
import android.content.Context
43
import android.graphics.drawable.Drawable
54
import kotlinx.coroutines.runBlocking
65
import org.wordpress.aztec.AztecAttributes
@@ -11,15 +10,14 @@ import org.wordpress.aztec.spans.IAztecSpan
1110
import java.lang.ref.WeakReference
1211

1312
class AztecPlaceholderSpan(
14-
context: Context,
1513
drawable: Drawable?,
1614
override var nestingLevel: Int,
1715
attributes: AztecAttributes = AztecAttributes(),
1816
onMediaDeletedListener: AztecText.OnMediaDeletedListener? = null,
1917
editor: AztecText? = null,
2018
private val adapter: WeakReference<PlaceholderManager.PlaceholderAdapter>,
2119
override val TAG: String) :
22-
AztecMediaSpan(context, drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
20+
AztecMediaSpan(drawable, attributes, onMediaDeletedListener, editor), IAztecFullWidthImageSpan, IAztecSpan {
2321
override fun onClick() {
2422

2523
}

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class PlaceholderManager(
9999
?: throw IllegalArgumentException("Adapter for inserted type not found. Register it with `registerAdapter` method")
100100
val attrs = getAttributesForMedia(type, attributes)
101101
val drawable = buildPlaceholderDrawable(adapter, attrs)
102-
aztecText.insertMediaSpan(AztecPlaceholderSpan(aztecText.context, drawable, 0, attrs,
102+
aztecText.insertMediaSpan(AztecPlaceholderSpan(drawable, 0, attrs,
103103
this, aztecText, WeakReference(adapter), TAG = htmlTag))
104104
insertContentOverSpanWithId(attrs.getValue(UUID_ATTRIBUTE))
105105
}
@@ -166,7 +166,7 @@ class PlaceholderManager(
166166
attrs.setValue(UUID_ATTRIBUTE, uuid)
167167
attrs.setValue(TYPE_ATTRIBUTE, type)
168168
val drawable = buildPlaceholderDrawable(adapter, attrs)
169-
val span = AztecPlaceholderSpan(aztecText.context, drawable, 0, attrs,
169+
val span = AztecPlaceholderSpan(drawable, 0, attrs,
170170
this, aztecText, WeakReference(adapter), TAG = htmlTag)
171171
aztecText.replaceMediaSpan(span) { attributes ->
172172
attributes.getValue(UUID_ATTRIBUTE) == uuid
@@ -460,7 +460,6 @@ class PlaceholderManager(
460460
aztecAttributes.setValue(UUID_ATTRIBUTE, generateUuid())
461461
val drawable = runBlocking { buildPlaceholderDrawable(adapter, aztecAttributes) }
462462
val span = AztecPlaceholderSpan(
463-
context = aztecText.context,
464463
drawable = drawable,
465464
nestingLevel = nestingLevel,
466465
attributes = aztecAttributes,

0 commit comments

Comments
 (0)