Skip to content

Commit dc5f7ec

Browse files
authored
Merge pull request #276 from wordpress-mobile/issue/181-update-placeholder-images
Issue/181 update placeholder images
2 parents 077d36d + 443746d commit dc5f7ec

File tree

8 files changed

+69
-53
lines changed

8 files changed

+69
-53
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public interface ImageGetter {
9090

9191
interface Callbacks {
9292
void onUseDefaultImage();
93+
void onImageFailed();
9394
void onImageLoaded(Drawable drawable);
94-
void onImageLoadingFailed();
95+
void onImageLoading(Drawable drawable);
9596
}
9697
}
9798

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class AztecTagHandler : Html.TagHandler {
103103

104104
private fun createImageSpan(attributes: Attributes?, onMediaTappedListener: AztecText.OnMediaTappedListener?,
105105
context: Context) : AztecMediaSpan {
106-
val loadingDrawable = ContextCompat.getDrawable(context, R.drawable.ic_image_loading)
106+
val styles = context.obtainStyledAttributes(R.styleable.AztecText)
107+
val loadingDrawable = ContextCompat.getDrawable(context, styles.getResourceId(R.styleable.AztecText_drawableLoading, R.drawable.ic_image_loading))
108+
styles.recycle()
107109
return AztecMediaSpan(context, loadingDrawable, attributes, onMediaTappedListener)
108110
}
109111

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

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
9797

9898
private var isNewStyleSelected = false
9999

100+
private var drawableFailed: Int = 0
101+
private var drawableLoading: Int = 0
102+
100103
var isMediaAdded = false
101104

102105
lateinit var history: History
@@ -135,57 +138,60 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
135138
}
136139

137140
private fun init(attrs: AttributeSet?) {
138-
val array = context.obtainStyledAttributes(attrs, R.styleable.AztecText, 0, R.style.AztecTextStyle)
141+
val styles = context.obtainStyledAttributes(attrs, R.styleable.AztecText, 0, R.style.AztecTextStyle)
139142
setLineSpacing(
140-
array.getDimension(
143+
styles.getDimension(
141144
R.styleable.AztecText_lineSpacingExtra,
142145
resources.getDimension(R.dimen.spacing_extra)
143146
),
144-
array.getFloat(
147+
styles.getFloat(
145148
R.styleable.AztecText_lineSpacingMultiplier,
146149
resources.getString(R.dimen.spacing_multiplier).toFloat()
147150
)
148151
)
149-
setBackgroundColor(array.getColor(R.styleable.AztecText_backgroundColor, ContextCompat.getColor(context, R.color.background)))
150-
setTextColor(array.getColor(R.styleable.AztecText_textColor, ContextCompat.getColor(context, R.color.text)))
151-
setHintTextColor(array.getColor(R.styleable.AztecText_textColorHint, ContextCompat.getColor(context, R.color.text_hint)))
152+
setBackgroundColor(styles.getColor(R.styleable.AztecText_backgroundColor, ContextCompat.getColor(context, R.color.background)))
153+
setTextColor(styles.getColor(R.styleable.AztecText_textColor, ContextCompat.getColor(context, R.color.text)))
154+
setHintTextColor(styles.getColor(R.styleable.AztecText_textColorHint, ContextCompat.getColor(context, R.color.text_hint)))
155+
156+
drawableLoading = styles.getResourceId(R.styleable.AztecText_drawableLoading, R.drawable.ic_image_loading)
157+
drawableFailed = styles.getResourceId(R.styleable.AztecText_drawableFailed, R.drawable.ic_image_failed)
152158

153-
historyEnable = array.getBoolean(R.styleable.AztecText_historyEnable, historyEnable)
154-
historySize = array.getInt(R.styleable.AztecText_historySize, historySize)
159+
historyEnable = styles.getBoolean(R.styleable.AztecText_historyEnable, historyEnable)
160+
historySize = styles.getInt(R.styleable.AztecText_historySize, historySize)
155161

156162
inlineFormatter = InlineFormatter(this,
157163
InlineFormatter.CodeStyle(
158-
array.getColor(R.styleable.AztecText_codeBackground, 0),
159-
array.getFraction(R.styleable.AztecText_codeBackgroundAlpha, 1, 1, 0f),
160-
array.getColor(R.styleable.AztecText_codeColor, 0)),
164+
styles.getColor(R.styleable.AztecText_codeBackground, 0),
165+
styles.getFraction(R.styleable.AztecText_codeBackgroundAlpha, 1, 1, 0f),
166+
styles.getColor(R.styleable.AztecText_codeColor, 0)),
161167
LineBlockFormatter.HeaderStyle(
162-
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))
168+
styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))
163169

164170
blockFormatter = BlockFormatter(this,
165171
BlockFormatter.ListStyle(
166-
array.getColor(R.styleable.AztecText_bulletColor, 0),
167-
array.getDimensionPixelSize(R.styleable.AztecText_bulletMargin, 0),
168-
array.getDimensionPixelSize(R.styleable.AztecText_bulletPadding, 0),
169-
array.getDimensionPixelSize(R.styleable.AztecText_bulletWidth, 0),
170-
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)),
172+
styles.getColor(R.styleable.AztecText_bulletColor, 0),
173+
styles.getDimensionPixelSize(R.styleable.AztecText_bulletMargin, 0),
174+
styles.getDimensionPixelSize(R.styleable.AztecText_bulletPadding, 0),
175+
styles.getDimensionPixelSize(R.styleable.AztecText_bulletWidth, 0),
176+
styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)),
171177
BlockFormatter.QuoteStyle(
172-
array.getColor(R.styleable.AztecText_quoteBackground, 0),
173-
array.getColor(R.styleable.AztecText_quoteColor, 0),
174-
array.getFraction(R.styleable.AztecText_quoteBackgroundAlpha, 1, 1, 0f),
175-
array.getDimensionPixelSize(R.styleable.AztecText_quoteMargin, 0),
176-
array.getDimensionPixelSize(R.styleable.AztecText_quotePadding, 0),
177-
array.getDimensionPixelSize(R.styleable.AztecText_quoteWidth, 0),
178-
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)
178+
styles.getColor(R.styleable.AztecText_quoteBackground, 0),
179+
styles.getColor(R.styleable.AztecText_quoteColor, 0),
180+
styles.getFraction(R.styleable.AztecText_quoteBackgroundAlpha, 1, 1, 0f),
181+
styles.getDimensionPixelSize(R.styleable.AztecText_quoteMargin, 0),
182+
styles.getDimensionPixelSize(R.styleable.AztecText_quotePadding, 0),
183+
styles.getDimensionPixelSize(R.styleable.AztecText_quoteWidth, 0),
184+
styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)
179185
))
180186

181-
linkFormatter = LinkFormatter(this, LinkFormatter.LinkStyle(array.getColor(
187+
linkFormatter = LinkFormatter(this, LinkFormatter.LinkStyle(styles.getColor(
182188
R.styleable.AztecText_linkColor, 0),
183-
array.getBoolean(R.styleable.AztecText_linkUnderline, true)))
189+
styles.getBoolean(R.styleable.AztecText_linkUnderline, true)))
184190

185191
lineBlockFormatter = LineBlockFormatter(this, LineBlockFormatter.HeaderStyle(
186-
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))
192+
styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))
187193

188-
array.recycle()
194+
styles.recycle()
189195

190196
if (historyEnable && historySize <= 0) {
191197
throw IllegalArgumentException("historySize must > 0")
@@ -674,17 +680,20 @@ class AztecText : EditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlClickListe
674680
spans.forEach {
675681
val callbacks = object : Html.ImageGetter.Callbacks {
676682

677-
override fun onUseDefaultImage() {
678-
// we already have a default image loaded so, noop
683+
override fun onImageFailed() {
684+
replaceImage(ContextCompat.getDrawable(context, drawableFailed))
679685
}
680686

681687
override fun onImageLoaded(drawable: Drawable?) {
682688
replaceImage(drawable)
683689
}
684690

685-
override fun onImageLoadingFailed() {
686-
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_image_failed)
687-
replaceImage(drawable)
691+
override fun onImageLoading(drawable: Drawable?) {
692+
replaceImage(ContextCompat.getDrawable(context, drawableLoading))
693+
}
694+
695+
override fun onUseDefaultImage() {
696+
// we already have a default image loaded so, noop
688697
}
689698

690699
private fun replaceImage(drawable: Drawable?) {

aztec/src/main/res/drawable/ic_image_failed.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
<vector
44
xmlns:android="http://schemas.android.com/apk/res/android"
5-
android:height="96dp"
6-
android:width="96dp"
7-
android:viewportHeight="96"
8-
android:viewportWidth="96" >
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
99

1010
<!-- @color/grey_8_40 -->
1111
<path
1212
android:fillColor="#66888888"
13-
android:pathData="M0,0h96v96H0V0" >
13+
android:pathData="M48,48H0V0h48V48z" >
1414
</path>
1515

1616
<!-- @color/grey_a_40 -->
1717
<path
1818
android:fillColor="#66aaaaaa"
19-
android:pathData="M57.6,36.8h7.5v7.5h-7.5V36.8z M31.1,36.8h7.5v7.5h-7.5V36.8z M57.6,48h15v7.5h-15V48z M23.6,48h15v7.5h-15V48z M57.4,59.2h22.5v7.5H57.4V59.2z M16.1,59.2h22.5v7.5H16.1V59.2z" >
19+
android:pathData="M26.8,27.8l-5.6,0V11.6h5.6V27.8z M26.8,29.6l-5.6,0l0,4.7l0,0h5.6h0L26.8,29.6z" >
2020
</path>
2121

2222
<!-- @color/grey_a_40 -->
2323
<path
2424
android:fillColor="#66aaaaaa"
25-
android:pathData="M42.4,23.2h11.2v32.2H42.4V23.2z M53.6,68.6H42.4v-9.4h11.2V68.6z" >
25+
android:pathData="M32.5,22.1l-3.7,0l0-3.7l3.7,0L32.5,22.1z M19.3,18.4l-3.7,0l0,3.7l3.7,0L19.3,18.4z M36.3,24l-7.5,0l0,3.7 l7.5,0L36.3,24z M19.3,24l-7.5,0l0,3.7l7.5,0L19.3,24z M39.9,29.6l-11.2,0l0,3.7l11.2,0L39.9,29.6z M19.3,29.6l-11.2,0l0,3.7l11.2,0 L19.3,29.6z" >
2626
</path>
2727

2828
</vector>

aztec/src/main/res/drawable/ic_image_loading.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
<vector
44
xmlns:android="http://schemas.android.com/apk/res/android"
5-
android:height="96dp"
6-
android:width="96dp"
7-
android:viewportHeight="96"
8-
android:viewportWidth="96" >
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
99

1010
<!-- @color/grey_8_40 -->
1111
<path
1212
android:fillColor="#66888888"
13-
android:pathData="M0,0h96v96H0V0z" >
13+
android:pathData="M48,48H0V0h48V48z" >
1414
</path>
1515

1616
<!-- @color/grey_a_40 -->
1717
<path
1818
android:fillColor="#66aaaaaa"
19-
android:pathData="M57.6,36.8h7.5v7.5h-7.5V36.8z M31.1,36.8h7.5v7.5h-7.5V36.8z M57.6,48h15v7.5h-15V48z M23.6,48h15v7.5h-15V48z M57.4,59.2h22.5v7.5H57.4V59.2z M16.1,59.2h22.5v7.5H16.1V59.2z" >
19+
android:pathData="M21.2,18.4h5.6v15l-2.8,3l-2.8-3V18.4z M24.9,11.6h-1.8c0,0-1.9,0-1.9,1.9v2.8h5.6v-2.8 C26.8,11.6,24.9,11.6,24.9,11.6z" >
2020
</path>
2121

2222
<!-- @color/grey_a_40 -->
2323
<path
2424
android:fillColor="#66aaaaaa"
25-
android:pathData="M48,72.7l5.6-5.9H42.4L48,72.7z M42.4,36.8h11.2v30H42.4V36.8z M53.6,32.6H42.4V27c0-3.8,3.8-3.8,3.8-3.8h3.7 c0,0,3.8,0,3.8,3.8V32.6z" >
25+
android:pathData="M32.5,22.1l-3.7,0l0-3.7l3.7,0L32.5,22.1z M19.3,18.4l-3.7,0l0,3.7l3.7,0L19.3,18.4z M36.3,24l-7.5,0l0,3.7 l7.5,0L36.3,24z M19.3,24l-7.5,0l0,3.7l7.5,0L19.3,24z M39.9,29.6l-11.2,0l0,3.7l11.2,0L39.9,29.6z M19.3,29.6l-11.2,0l0,3.7l11.2,0 L19.3,29.6z" >
2626
</path>
2727

2828
</vector>

aztec/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<attr name="codeBackground" format="reference|color" />
1313
<attr name="codeBackgroundAlpha" format="reference|fraction" />
1414
<attr name="codeColor" format="reference|color" />
15+
<attr name="drawableFailed" format="reference" />
16+
<attr name="drawableLoading" format="reference" />
1517
<attr name="historyEnable" format="reference|boolean" />
1618
<attr name="historySize" format="reference|integer" />
1719
<attr name="lineSpacingExtra" format="reference|dimension" />

glide-loader/src/main/java/org/wordpress/aztec/glideloader/GlideImageLoader.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class GlideImageLoader(private val context: Context) : Html.ImageGetter {
1717
override fun loadImage(source: String, callbacks: Html.ImageGetter.Callbacks, maxWidth: Int) {
1818
Glide.with(context).load(source).fitCenter().into(object : Target<GlideDrawable> {
1919
override fun onLoadStarted(placeholder: Drawable?) {
20-
val r = context.resources
20+
callbacks.onImageLoading(placeholder)
2121
}
2222

2323
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
24-
callbacks.onImageLoadingFailed()
24+
callbacks.onImageFailed()
2525
}
2626

2727
override fun onResourceReady(resource: GlideDrawable?, glideAnimation: GlideAnimation<in GlideDrawable>?) {

picasso-loader/src/main/java/org/wordpress/aztec/picassoloader/PicassoImageLoader.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ class PicassoImageLoader(private val context: Context, aztec: AztecText) : Html.
3535
}
3636

3737
override fun onBitmapFailed(errorDrawable: Drawable?) {
38-
callbacks.onImageLoadingFailed()
38+
callbacks.onImageFailed()
3939
targets.remove(source)
4040
}
4141

42-
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {}
42+
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
43+
callbacks.onImageLoading(placeHolderDrawable)
44+
}
4345
}
4446

4547
// add a strong reference to the target until it's called or the view gets destroyed

0 commit comments

Comments
 (0)