Skip to content

Commit c9c0d79

Browse files
authored
Merge pull request #349 from wordpress-mobile/issue/342-image-uploading-scroll
Issue/342 image uploading scroll
2 parents 36f8c10 + f9446e1 commit c9c0d79

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class MainActivity : AppCompatActivity(),
197197
attrs.setValue("id", id)
198198
attrs.setValue("uploading", "true")
199199

200-
aztec.insertMedia(BitmapDrawable(resources, bitmap), attrs)
200+
val mediaSpan = aztec.insertMedia(BitmapDrawable(resources, bitmap), attrs)
201201

202202
val predicate = object : AztecText.AttributePredicate {
203203
override fun matches(attrs: Attributes): Boolean {
@@ -221,7 +221,7 @@ class MainActivity : AppCompatActivity(),
221221
val runnable: Runnable = Runnable {
222222
aztec.setOverlayLevel(predicate, 1, progress)
223223
aztec.updateElementAttributes(predicate, attrs)
224-
aztec.refreshText()
224+
aztec.updateMediaSpan(mediaSpan)
225225
progress += 2000
226226

227227
if (progress >= 10000) {

app/src/main/res/layout-v17/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<FrameLayout
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content">
24+
android:layout_height="wrap_content" >
2525

2626
<org.wordpress.aztec.AztecText
2727
android:id="@+id/aztec"

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<FrameLayout
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content">
24+
android:layout_height="wrap_content" >
2525

2626
<org.wordpress.aztec.AztecText
2727
android:id="@+id/aztec"

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,21 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
778778
disableTextChangedListener()
779779
val selStart = selectionStart
780780
val selEnd = selectionEnd
781-
clearFocus()
781+
setFocusOnParentView()
782782
text = editableText
783783
setSelection(selStart, selEnd)
784784
enableTextChangedListener()
785785
}
786786

787+
fun setFocusOnParentView() {
788+
if (parent is View) {
789+
val parentView = parent as View
790+
parentView.isFocusable = true
791+
parentView.isFocusableInTouchMode = true
792+
parentView.requestFocus()
793+
}
794+
}
795+
787796
fun removeInlineStylesFromRange(start: Int, end: Int) {
788797
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_BOLD, start, end)
789798
inlineFormatter.removeInlineStyle(TextFormat.FORMAT_ITALIC, start, end)
@@ -1013,8 +1022,8 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
10131022
}
10141023
}
10151024

1016-
fun insertMedia(drawable: Drawable?, attributes: Attributes) {
1017-
lineBlockFormatter.insertMedia(drawable, attributes, onMediaTappedListener)
1025+
fun insertMedia(drawable: Drawable?, attributes: Attributes): AztecMediaSpan {
1026+
return lineBlockFormatter.insertMedia(drawable, attributes, onMediaTappedListener)
10181027
}
10191028

10201029
fun removeMedia(attributePredicate: AttributePredicate) {
@@ -1050,6 +1059,10 @@ class AztecText : android.support.v7.widget.AppCompatEditText, TextWatcher, Unkn
10501059
.firstOrNull()?.attributes = attrs
10511060
}
10521061

1062+
fun updateMediaSpan(mediaSpan: AztecMediaSpan) {
1063+
editableText.setSpan(mediaSpan, text.getSpanStart(mediaSpan), text.getSpanEnd(mediaSpan), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
1064+
}
1065+
10531066
fun setOverlayLevel(attributePredicate: AttributePredicate, index: Int, level: Int) {
10541067
text.getSpans(0, text.length, AztecMediaSpan::class.java)
10551068
.filter {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
118118
if (selectionEnd < EndOfBufferMarkerAdder.safeLength(editor)) selectionEnd + 1 else selectionEnd)
119119
}
120120

121-
fun insertMedia(drawable: Drawable?, attributes: Attributes, onMediaTappedListener: OnMediaTappedListener?) {
121+
fun insertMedia(drawable: Drawable?, attributes: Attributes, onMediaTappedListener: OnMediaTappedListener?): AztecMediaSpan {
122122
val span = AztecMediaSpan(editor.context, drawable, AztecAttributes(attributes), onMediaTappedListener, editor)
123123

124124
val spanBeforeMedia = editableText.getSpans(selectionStart, selectionEnd, AztecBlockSpan::class.java)
@@ -164,5 +164,7 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
164164

165165
editor.setSelection(mediaEndIndex)
166166
editor.isMediaAdded = true
167+
168+
return span
167169
}
168170
}

0 commit comments

Comments
 (0)