Skip to content

Commit f2fbc3d

Browse files
authored
Merge pull request #650 from wordpress-mobile/feature/Aztec-for-React-Native
Prepare Aztec for integration in React Native - step 1
2 parents 1e18a82 + 0e506f9 commit f2fbc3d

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import org.wordpress.aztec.plugins.IAztecPlugin
77
import org.wordpress.aztec.plugins.IToolbarButton
88
import org.wordpress.aztec.source.SourceViewEditText
99
import org.wordpress.aztec.toolbar.AztecToolbar
10+
import org.wordpress.aztec.toolbar.IAztecToolbar
1011
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
1112
import java.util.ArrayList
1213

13-
open class Aztec private constructor(val visualEditor: AztecText, val toolbar: AztecToolbar,
14+
open class Aztec private constructor(val visualEditor: AztecText, val toolbar: IAztecToolbar,
1415
private val toolbarClickListener: IAztecToolbarClickListener) {
1516
private var imageGetter: Html.ImageGetter? = null
1617
private var videoThumbnailGetter: Html.VideoThumbnailGetter? = null

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import org.wordpress.aztec.spans.IAztecAttributedSpan
8484
import org.wordpress.aztec.spans.IAztecBlockSpan
8585
import org.wordpress.aztec.spans.UnknownClickableSpan
8686
import org.wordpress.aztec.spans.UnknownHtmlSpan
87-
import org.wordpress.aztec.toolbar.AztecToolbar
87+
import org.wordpress.aztec.toolbar.IAztecToolbar
8888
import org.wordpress.aztec.util.AztecLog
8989
import org.wordpress.aztec.util.InstanceStateUtils
9090
import org.wordpress.aztec.util.SpanWrapper
@@ -115,7 +115,7 @@ import java.util.Arrays
115115
import java.util.LinkedList
116116

117117
@Suppress("UNUSED_PARAMETER")
118-
class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlTappedListener, IEventInjector {
118+
open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlTappedListener, IEventInjector {
119119
companion object {
120120
val BLOCK_EDITOR_HTML_KEY = "RETAINED_BLOCK_HTML_KEY"
121121
val BLOCK_EDITOR_START_INDEX_KEY = "BLOCK_EDITOR_START_INDEX_KEY"
@@ -191,7 +191,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
191191

192192
private var unknownBlockSpanStart = -1
193193

194-
private var formatToolbar: AztecToolbar? = null
194+
private var formatToolbar: IAztecToolbar? = null
195195

196196
val selectedStyles = ArrayList<ITextFormat>()
197197

@@ -862,10 +862,14 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
862862
}
863863
}
864864

865-
fun setToolbar(toolbar: AztecToolbar) {
865+
fun setToolbar(toolbar: IAztecToolbar) {
866866
formatToolbar = toolbar
867867
}
868868

869+
fun getToolbar() : IAztecToolbar? {
870+
return formatToolbar
871+
}
872+
869873
private fun addWatcherNestingLevel() : Int {
870874
watchersNestingLevel++
871875
return watchersNestingLevel
@@ -1192,7 +1196,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
11921196
return consumeSelectionChangedEvent
11931197
}
11941198

1195-
fun refreshText() {
1199+
open fun refreshText() {
11961200
disableTextChangedListener()
11971201
val selStart = selectionStart
11981202
val selEnd = selectionEnd

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ import java.util.Locale
3838
* Contains both Styling and Media toolbars.
3939
* Supports RTL layout direction on API 19+
4040
*/
41-
class AztecToolbar : FrameLayout, OnMenuItemClickListener {
41+
class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
4242
private var aztecToolbarListener: IAztecToolbarClickListener? = null
4343
private var editor: AztecText? = null
4444
private var headingMenu: PopupMenu? = null
4545
private var listMenu: PopupMenu? = null
4646
private var sourceEditor: SourceViewEditText? = null
4747
private var dialogShortcuts: AlertDialog? = null
4848
private var isAdvanced: Boolean = false
49+
private var isMediaToolbarAvailable: Boolean = false
4950
private var isExpanded: Boolean = false
5051
private var isMediaToolbarVisible: Boolean = false
5152
private var isMediaModeEnabled: Boolean = false
@@ -87,7 +88,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
8788
initView(attrs)
8889
}
8990

90-
fun setToolbarListener(listener: IAztecToolbarClickListener) {
91+
override fun setToolbarListener(listener: IAztecToolbarClickListener) {
9192
aztecToolbarListener = listener
9293
}
9394

@@ -360,7 +361,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
360361
return editor != null && editor is AztecText
361362
}
362363

363-
fun setEditor(editor: AztecText, sourceEditor: SourceViewEditText?) {
364+
override fun setEditor(editor: AztecText, sourceEditor: SourceViewEditText?) {
364365
this.sourceEditor = sourceEditor
365366
this.editor = editor
366367

@@ -375,6 +376,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
375376
private fun initView(attrs: AttributeSet?) {
376377
val styles = context.obtainStyledAttributes(attrs, R.styleable.AztecToolbar, 0, R.style.AztecToolbarStyle)
377378
isAdvanced = styles.getBoolean(R.styleable.AztecToolbar_advanced, false)
379+
isMediaToolbarAvailable = styles.getBoolean(R.styleable.AztecToolbar_mediaToolbarAvailable, true)
378380
styles.recycle()
379381

380382
val layout = if (isAdvanced) R.layout.aztec_format_bar_advanced else R.layout.aztec_format_bar_basic
@@ -399,7 +401,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
399401
}
400402
}
401403

402-
fun addButton(buttonPlugin: IToolbarButton) {
404+
override fun addButton(buttonPlugin: IToolbarButton) {
403405
val pluginContainer = if (buttonPlugin is IMediaToolbarButton) {
404406
findViewById(R.id.media_toolbar)
405407
} else {
@@ -549,7 +551,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
549551
}
550552
}
551553

552-
fun toggleEditorMode() {
554+
override fun toggleEditorMode() {
553555
// only allow toggling if sourceEditor is present
554556
if (sourceEditor == null) return
555557

@@ -738,6 +740,10 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
738740
}
739741

740742
private fun setupMediaToolbar() {
743+
val mediaToolbarContainer : LinearLayout = findViewById(R.id.media_button_container)
744+
mediaToolbarContainer.visibility = if (isMediaToolbarAvailable) View.VISIBLE else View.GONE
745+
if (!isMediaToolbarAvailable) return
746+
741747
mediaToolbar = findViewById(R.id.media_toolbar)
742748
stylingToolbar = findViewById(R.id.styling_toolbar)
743749

@@ -760,6 +766,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
760766
}
761767

762768
private fun setupMediaToolbarAnimations() {
769+
if (!isMediaToolbarAvailable) return
763770
layoutMediaTranslateInEnd = AnimationUtils.loadAnimation(context, R.anim.translate_in_end)
764771

765772
layoutMediaTranslateOutEnd = AnimationUtils.loadAnimation(context, R.anim.translate_out_end)
@@ -1025,7 +1032,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
10251032
isMediaToolbarVisible = true
10261033
}
10271034

1028-
fun toggleMediaToolbar() {
1035+
override fun toggleMediaToolbar() {
10291036
if (isMediaToolbarVisible) {
10301037
hideMediaToolbar()
10311038
} else {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.wordpress.aztec.toolbar
2+
3+
import android.view.KeyEvent
4+
import org.wordpress.aztec.AztecText
5+
import org.wordpress.aztec.plugins.IToolbarButton
6+
import org.wordpress.aztec.source.SourceViewEditText
7+
8+
interface IAztecToolbar {
9+
fun onKeyUp(keyCode: Int, keyEvent: KeyEvent): Boolean
10+
fun addButton(buttonPlugin: IToolbarButton)
11+
fun setEditor(editor: AztecText, sourceEditor: SourceViewEditText?)
12+
fun setToolbarListener(listener: IAztecToolbarClickListener)
13+
fun toggleMediaToolbar()
14+
fun toggleEditorMode()
15+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<declare-styleable name="AztecToolbar">
3838
<attr name="advanced" format="reference|boolean" />
39+
<attr name="mediaToolbarAvailable" format="reference|boolean" />
3940
</declare-styleable>
4041

4142
<declare-styleable name="SourceViewEditText">

0 commit comments

Comments
 (0)