Skip to content

Commit df74729

Browse files
committed
Merge branch 'develop' of github.com:wordpress-mobile/WordPress-Aztec-Android into issue/345-fixing-toolbar-highlight-issues
# Conflicts: # aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt
2 parents 1625312 + 837bfc5 commit df74729

File tree

113 files changed

+1775
-1049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1775
-1049
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ android:
99
- extra-google-m2repository
1010
- platform-tools
1111
- tools
12-
- build-tools-25.0.2
12+
- build-tools-25.0.3
1313
- android-25
1414

1515
env:
1616
global:
1717
- MALLOC_ARENA_MAX=2
1818
- GRADLE_OPTS="-XX:MaxPermSize=4g -Xmx4g"
19-
- ANDROID_SDKS=android-14
20-
- ANDROID_TARGET=android-14
19+
- ANDROID_SDKS=android-16
20+
- ANDROID_TARGET=android-16
2121

2222
before_install:
2323
# TODO: Remove the following line when Travis' platform-tools are updated to v24+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Aztec (which extends EditText) is a rich-text editor component for writing HTML
77
documents in Android.
88

9-
Supports Android 4.0+
9+
Supports Android 4.1+ (API 16 - Jelly Bean)
1010

1111
## Build and test
1212

app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
33

44
android {
55
compileSdkVersion 25
6-
buildToolsVersion "25.0.2"
6+
buildToolsVersion "25.0.3"
77

88
defaultConfig {
99
applicationId "org.wordpress.aztec"
10-
minSdkVersion 14
10+
minSdkVersion 16
1111
targetSdkVersion 25
1212
versionCode 1
1313
versionName "1.0"
@@ -34,11 +34,12 @@ dependencies {
3434
compile project(':aztec')
3535
compile project(':glide-loader')
3636
compile project(':picasso-loader')
37+
compile project(':wordpress-comments')
3738

3839
//noinspection GradleCompatible
39-
compile "com.android.support:appcompat-v7:25.3.1"
40+
compile "com.android.support:appcompat-v7:25.4.0"
4041
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41-
compile "org.wordpress:utils:1.14.0"
42+
compile "org.wordpress:utils:1.16.0"
4243
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
4344
exclude group: 'com.android.support', module: 'support-annotations'
4445
}

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

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ import org.wordpress.android.util.ToastUtils
3333
import org.wordpress.aztec.*
3434
import org.wordpress.aztec.glideloader.GlideVideoThumbnailLoader
3535
import org.wordpress.aztec.picassoloader.PicassoImageLoader
36+
import org.wordpress.aztec.plugins.wpcomments.WordPressCommentsPlugin
37+
import org.wordpress.aztec.plugins.wpcomments.toolbar.MoreToolbarButton
38+
import org.wordpress.aztec.plugins.wpcomments.toolbar.PageToolbarButton
3639
import org.wordpress.aztec.source.SourceViewEditText
37-
import org.wordpress.aztec.spans.AztecMediaSpan
3840
import org.wordpress.aztec.toolbar.AztecToolbar
39-
import org.wordpress.aztec.toolbar.AztecToolbarClickListener
41+
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
4042
import org.xml.sax.Attributes
4143
import java.io.File
4244

4345
class MainActivity : AppCompatActivity(),
4446
AztecText.OnImeBackListener,
4547
AztecText.OnImageTappedListener,
4648
AztecText.OnVideoTappedListener,
47-
AztecToolbarClickListener,
48-
HistoryListener,
49+
IAztecToolbarClickListener,
50+
IHistoryListener,
4951
OnRequestPermissionsResultCallback,
5052
PopupMenu.OnMenuItemClickListener,
5153
View.OnTouchListener {
@@ -124,7 +126,7 @@ class MainActivity : AppCompatActivity(),
124126
LONG_TEXT +
125127
VIDEO
126128

127-
private val isRunningTest : Boolean by lazy {
129+
private val isRunningTest: Boolean by lazy {
128130
try {
129131
Class.forName("android.support.test.espresso.Espresso")
130132
true
@@ -143,11 +145,9 @@ class MainActivity : AppCompatActivity(),
143145
private val REQUEST_MEDIA_PHOTO: Int = 2003
144146
private val REQUEST_MEDIA_VIDEO: Int = 2004
145147

146-
private lateinit var aztec: AztecText
148+
private lateinit var aztec: Aztec
147149
private lateinit var mediaFile: String
148150
private lateinit var mediaPath: String
149-
private lateinit var source: SourceViewEditText
150-
private lateinit var formattingToolbar: AztecToolbar
151151

152152
private lateinit var invalidateOptionsHandler: Handler
153153
private lateinit var invalidateOptionsRunnable: Runnable
@@ -191,7 +191,7 @@ class MainActivity : AppCompatActivity(),
191191
REQUEST_MEDIA_VIDEO -> {
192192
mediaPath = data?.data.toString()
193193

194-
aztec.videoThumbnailGetter?.loadVideoThumbnail(mediaPath, object : Html.VideoThumbnailGetter.Callbacks {
194+
aztec.visualEditor.videoThumbnailGetter?.loadVideoThumbnail(mediaPath, object : Html.VideoThumbnailGetter.Callbacks {
195195
override fun onThumbnailFailed() {
196196
}
197197

@@ -218,14 +218,14 @@ class MainActivity : AppCompatActivity(),
218218

219219
fun insertImageAndSimulateUpload(bitmap: Bitmap?, mediaPath: String) {
220220
val (id, attrs) = generateAttributesForMedia(mediaPath, isVideo = false)
221-
val mediaSpan = aztec.insertImage(BitmapDrawable(resources, bitmap), attrs)
222-
insertMediaAndSimulateUpload(id, attrs, mediaSpan)
221+
aztec.visualEditor.insertImage(BitmapDrawable(resources, bitmap), attrs)
222+
insertMediaAndSimulateUpload(id, attrs)
223223
}
224224

225225
fun insertVideoAndSimulateUpload(bitmap: Bitmap?, mediaPath: String) {
226226
val (id, attrs) = generateAttributesForMedia(mediaPath, isVideo = true)
227-
val mediaSpan = aztec.insertVideo(BitmapDrawable(resources, bitmap), attrs)
228-
insertMediaAndSimulateUpload(id, attrs, mediaSpan)
227+
aztec.visualEditor.insertVideo(BitmapDrawable(resources, bitmap), attrs)
228+
insertMediaAndSimulateUpload(id, attrs)
229229
}
230230

231231
private fun generateAttributesForMedia(mediaPath: String, isVideo: Boolean): Pair<String, AztecAttributes> {
@@ -243,42 +243,42 @@ class MainActivity : AppCompatActivity(),
243243
return Pair(id, attrs)
244244
}
245245

246-
private fun insertMediaAndSimulateUpload(id: String, attrs: AztecAttributes, mediaSpan: AztecMediaSpan) {
246+
private fun insertMediaAndSimulateUpload(id: String, attrs: AztecAttributes) {
247247
val predicate = object : AztecText.AttributePredicate {
248248
override fun matches(attrs: Attributes): Boolean {
249249
return attrs.getValue("id") == id
250250
}
251251
}
252252

253-
aztec.setOverlay(predicate, 0, ColorDrawable(0x80000000.toInt()), Gravity.FILL)
254-
aztec.updateElementAttributes(predicate, attrs)
253+
aztec.visualEditor.setOverlay(predicate, 0, ColorDrawable(0x80000000.toInt()), Gravity.FILL)
254+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
255255

256256
val progressDrawable = ContextCompat.getDrawable(this, android.R.drawable.progress_horizontal)
257257
// set the height of the progress bar to 2 (it's in dp since the drawable will be adjusted by the span)
258258
progressDrawable.setBounds(0, 0, 0, 4)
259259

260-
aztec.setOverlay(predicate, 1, progressDrawable, Gravity.FILL_HORIZONTAL or Gravity.TOP)
261-
aztec.updateElementAttributes(predicate, attrs)
260+
aztec.visualEditor.setOverlay(predicate, 1, progressDrawable, Gravity.FILL_HORIZONTAL or Gravity.TOP)
261+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
262262

263263
var progress = 0
264264

265265
// simulate an upload delay
266266
val runnable: Runnable = Runnable {
267-
aztec.setOverlayLevel(predicate, 1, progress)
268-
aztec.updateElementAttributes(predicate, attrs)
269-
aztec.updateMediaSpan(mediaSpan)
267+
aztec.visualEditor.setOverlayLevel(predicate, 1, progress)
268+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
269+
aztec.visualEditor.resetAttributedMediaSpan(predicate)
270270
progress += 2000
271271

272272
if (progress >= 10000) {
273273
attrs.removeAttribute(attrs.getIndex("uploading"))
274-
aztec.clearOverlays(predicate)
274+
aztec.visualEditor.clearOverlays(predicate)
275275

276276
if (attrs.hasAttribute("video")) {
277277
attrs.removeAttribute(attrs.getIndex("video"))
278-
aztec.setOverlay(predicate, 0, ContextCompat.getDrawable(this, android.R.drawable.ic_media_play), Gravity.CENTER)
278+
aztec.visualEditor.setOverlay(predicate, 0, ContextCompat.getDrawable(this, android.R.drawable.ic_media_play), Gravity.CENTER)
279279
}
280280

281-
aztec.updateElementAttributes(predicate, attrs)
281+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
282282
}
283283
}
284284

@@ -288,7 +288,7 @@ class MainActivity : AppCompatActivity(),
288288
Handler().postDelayed(runnable, 6000)
289289
Handler().postDelayed(runnable, 8000)
290290

291-
aztec.refreshText()
291+
aztec.visualEditor.refreshText()
292292
}
293293

294294
override fun onCreate(savedInstanceState: Bundle?) {
@@ -301,37 +301,32 @@ class MainActivity : AppCompatActivity(),
301301
mHideActionBarOnSoftKeyboardUp = true
302302
}
303303

304-
aztec = findViewById(R.id.aztec) as AztecText
305-
306-
aztec.imageGetter = PicassoImageLoader(this, aztec)
307-
aztec.videoThumbnailGetter = GlideVideoThumbnailLoader(this)
308-
309-
aztec.setOnImageTappedListener(this)
310-
aztec.setOnVideoTappedListener(this)
311-
312-
source = findViewById(R.id.source) as SourceViewEditText
313-
314-
formattingToolbar = findViewById(R.id.formatting_toolbar) as AztecToolbar
315-
formattingToolbar.setEditor(aztec, source)
316-
formattingToolbar.setToolbarListener(this)
317-
aztec.setToolbar(formattingToolbar)
304+
val visualEditor = findViewById(R.id.aztec) as AztecText
305+
val sourceEditor = findViewById(R.id.source) as SourceViewEditText
306+
val toolbar = findViewById(R.id.formatting_toolbar) as AztecToolbar
307+
308+
aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
309+
.setImageGetter(PicassoImageLoader(this, visualEditor))
310+
.setVideoThumbnailGetter(GlideVideoThumbnailLoader(this))
311+
.setOnImeBackListener(this)
312+
.setOnTouchListener(this)
313+
.setHistoryListener(this)
314+
.setOnImageTappedListener(this)
315+
.setOnVideoTappedListener(this)
316+
.addPlugin(WordPressCommentsPlugin(visualEditor))
317+
.addPlugin(MoreToolbarButton(visualEditor))
318+
.addPlugin(PageToolbarButton(visualEditor))
318319

319320
// initialize the text & HTML
320321
if (!isRunningTest) {
321-
source.displayStyledAndFormattedHtml(EXAMPLE)
322+
aztec.sourceEditor.displayStyledAndFormattedHtml(EXAMPLE)
322323
}
323324

324325
if (savedInstanceState == null) {
325-
aztec.fromHtml(source.getPureHtml())
326-
source.history = aztec.history
326+
aztec.visualEditor.fromHtml(aztec.sourceEditor.getPureHtml())
327+
aztec.initHistory()
327328
}
328329

329-
aztec.history.setHistoryListener(this)
330-
aztec.setOnImeBackListener(this)
331-
aztec.setOnTouchListener(this)
332-
source.setOnImeBackListener(this)
333-
source.setOnTouchListener(this)
334-
335330
invalidateOptionsHandler = Handler()
336331
invalidateOptionsRunnable = Runnable { invalidateOptionsMenu() }
337332
}
@@ -364,7 +359,7 @@ class MainActivity : AppCompatActivity(),
364359
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
365360
super.onRestoreInstanceState(savedInstanceState)
366361

367-
source.history = aztec.history
362+
aztec.initHistory()
368363

369364
savedInstanceState?.let {
370365
if (savedInstanceState.getBoolean("isPhotoMediaDialogVisible")) {
@@ -465,16 +460,16 @@ class MainActivity : AppCompatActivity(),
465460
override fun onOptionsItemSelected(item: MenuItem): Boolean {
466461
when (item.itemId) {
467462
R.id.undo ->
468-
if (aztec.visibility == View.VISIBLE) {
469-
aztec.undo()
463+
if (aztec.visualEditor.visibility == View.VISIBLE) {
464+
aztec.visualEditor.undo()
470465
} else {
471-
source.undo()
466+
aztec.sourceEditor.undo()
472467
}
473468
R.id.redo ->
474-
if (aztec.visibility == View.VISIBLE) {
475-
aztec.redo()
469+
if (aztec.visualEditor.visibility == View.VISIBLE) {
470+
aztec.visualEditor.redo()
476471
} else {
477-
source.redo()
472+
aztec.sourceEditor.redo()
478473
}
479474
else -> {
480475
}
@@ -484,8 +479,8 @@ class MainActivity : AppCompatActivity(),
484479
}
485480

486481
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
487-
menu?.findItem(R.id.redo)?.isEnabled = aztec.history.redoValid()
488-
menu?.findItem(R.id.undo)?.isEnabled = aztec.history.undoValid()
482+
menu?.findItem(R.id.redo)?.isEnabled = aztec.visualEditor.history.redoValid()
483+
menu?.findItem(R.id.undo)?.isEnabled = aztec.visualEditor.history.undoValid()
489484
return super.onPrepareOptionsMenu(menu)
490485
}
491486

@@ -659,7 +654,7 @@ class MainActivity : AppCompatActivity(),
659654
override fun onToolbarExpandButtonClicked() {
660655
}
661656

662-
override fun onToolbarFormatButtonClicked(format: TextFormat, isKeyboardShortcut: Boolean) {
657+
override fun onToolbarFormatButtonClicked(format: ITextFormat, isKeyboardShortcut: Boolean) {
663658
}
664659

665660
override fun onToolbarHeadingButtonClicked() {
@@ -672,20 +667,20 @@ class MainActivity : AppCompatActivity(),
672667
}
673668
}
674669

675-
val mediaPending = aztec.getAllElementAttributes(uploadingPredicate).isNotEmpty()
670+
val mediaPending = aztec.visualEditor.getAllElementAttributes(uploadingPredicate).isNotEmpty()
676671

677672
if (mediaPending) {
678673
ToastUtils.showToast(this, R.string.media_upload_dialog_message)
679674
} else {
680-
formattingToolbar.toggleEditorMode()
675+
aztec.toolbar.toggleEditorMode()
681676
}
682677
}
683678

684679
override fun onToolbarListButtonClicked() {
685680
}
686681

687682
override fun onToolbarMediaButtonClicked() {
688-
mediaMenu = PopupMenu(this, formattingToolbar)
683+
mediaMenu = PopupMenu(this, aztec.toolbar)
689684
mediaMenu?.setOnMenuItemClickListener(this)
690685
mediaMenu?.inflate(R.menu.media)
691686
mediaMenu?.show()

aztec/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ apply plugin: 'kotlin-android'
33

44
android {
55
compileSdkVersion 25
6-
buildToolsVersion "25.0.2"
6+
buildToolsVersion "25.0.3"
77

88
defaultConfig {
9-
minSdkVersion 14
9+
minSdkVersion 16
1010
targetSdkVersion 25
1111
versionName "1.0"
1212
}
@@ -25,15 +25,15 @@ android {
2525
}
2626

2727
dependencies {
28-
compile "com.android.support:support-v4:25.3.1"
28+
compile "com.android.support:support-v4:25.4.0"
2929
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3030
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
3131
compile 'org.jsoup:jsoup:1.10.2'
3232

3333
testCompile 'junit:junit:4.12'
3434
testCompile 'org.robolectric:robolectric:3.3.2'
3535

36-
compile 'com.android.support:design:25.3.1'
36+
compile 'com.android.support:design:25.4.0'
3737
//https://github.com/robolectric/robolectric/issues/1932
3838
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
3939
}

0 commit comments

Comments
 (0)