Skip to content

Commit 837bfc5

Browse files
authored
Merge pull request #409 from wordpress-mobile/feature/wp-comments-plugin
WordPress Comments Plugin
2 parents 6fa33c3 + b8c24bf commit 837bfc5

File tree

111 files changed

+1704
-1005
lines changed

Some content is hidden

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

111 files changed

+1704
-1005
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: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +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
3740
import org.wordpress.aztec.toolbar.AztecToolbar
38-
import org.wordpress.aztec.toolbar.AztecToolbarClickListener
41+
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
3942
import org.xml.sax.Attributes
4043
import java.io.File
4144

4245
class MainActivity : AppCompatActivity(),
4346
AztecText.OnImeBackListener,
4447
AztecText.OnImageTappedListener,
4548
AztecText.OnVideoTappedListener,
46-
AztecToolbarClickListener,
47-
HistoryListener,
49+
IAztecToolbarClickListener,
50+
IHistoryListener,
4851
OnRequestPermissionsResultCallback,
4952
PopupMenu.OnMenuItemClickListener,
5053
View.OnTouchListener {
@@ -142,11 +145,9 @@ class MainActivity : AppCompatActivity(),
142145
private val REQUEST_MEDIA_PHOTO: Int = 2003
143146
private val REQUEST_MEDIA_VIDEO: Int = 2004
144147

145-
private lateinit var aztec: AztecText
148+
private lateinit var aztec: Aztec
146149
private lateinit var mediaFile: String
147150
private lateinit var mediaPath: String
148-
private lateinit var source: SourceViewEditText
149-
private lateinit var formattingToolbar: AztecToolbar
150151

151152
private lateinit var invalidateOptionsHandler: Handler
152153
private lateinit var invalidateOptionsRunnable: Runnable
@@ -190,7 +191,7 @@ class MainActivity : AppCompatActivity(),
190191
REQUEST_MEDIA_VIDEO -> {
191192
mediaPath = data?.data.toString()
192193

193-
aztec.videoThumbnailGetter?.loadVideoThumbnail(mediaPath, object : Html.VideoThumbnailGetter.Callbacks {
194+
aztec.visualEditor.videoThumbnailGetter?.loadVideoThumbnail(mediaPath, object : Html.VideoThumbnailGetter.Callbacks {
194195
override fun onThumbnailFailed() {
195196
}
196197

@@ -217,13 +218,13 @@ class MainActivity : AppCompatActivity(),
217218

218219
fun insertImageAndSimulateUpload(bitmap: Bitmap?, mediaPath: String) {
219220
val (id, attrs) = generateAttributesForMedia(mediaPath, isVideo = false)
220-
aztec.insertImage(BitmapDrawable(resources, bitmap), attrs)
221+
aztec.visualEditor.insertImage(BitmapDrawable(resources, bitmap), attrs)
221222
insertMediaAndSimulateUpload(id, attrs)
222223
}
223224

224225
fun insertVideoAndSimulateUpload(bitmap: Bitmap?, mediaPath: String) {
225226
val (id, attrs) = generateAttributesForMedia(mediaPath, isVideo = true)
226-
aztec.insertVideo(BitmapDrawable(resources, bitmap), attrs)
227+
aztec.visualEditor.insertVideo(BitmapDrawable(resources, bitmap), attrs)
227228
insertMediaAndSimulateUpload(id, attrs)
228229
}
229230

@@ -249,35 +250,35 @@ class MainActivity : AppCompatActivity(),
249250
}
250251
}
251252

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

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

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

262263
var progress = 0
263264

264265
// simulate an upload delay
265266
val runnable: Runnable = Runnable {
266-
aztec.setOverlayLevel(predicate, 1, progress)
267-
aztec.updateElementAttributes(predicate, attrs)
268-
aztec.resetAttributedMediaSpan(predicate)
267+
aztec.visualEditor.setOverlayLevel(predicate, 1, progress)
268+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
269+
aztec.visualEditor.resetAttributedMediaSpan(predicate)
269270
progress += 2000
270271

271272
if (progress >= 10000) {
272273
attrs.removeAttribute(attrs.getIndex("uploading"))
273-
aztec.clearOverlays(predicate)
274+
aztec.visualEditor.clearOverlays(predicate)
274275

275276
if (attrs.hasAttribute("video")) {
276277
attrs.removeAttribute(attrs.getIndex("video"))
277-
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)
278279
}
279280

280-
aztec.updateElementAttributes(predicate, attrs)
281+
aztec.visualEditor.updateElementAttributes(predicate, attrs)
281282
}
282283
}
283284

@@ -287,7 +288,7 @@ class MainActivity : AppCompatActivity(),
287288
Handler().postDelayed(runnable, 6000)
288289
Handler().postDelayed(runnable, 8000)
289290

290-
aztec.refreshText()
291+
aztec.visualEditor.refreshText()
291292
}
292293

293294
override fun onCreate(savedInstanceState: Bundle?) {
@@ -300,37 +301,32 @@ class MainActivity : AppCompatActivity(),
300301
mHideActionBarOnSoftKeyboardUp = true
301302
}
302303

303-
aztec = findViewById(R.id.aztec) as AztecText
304-
305-
aztec.imageGetter = PicassoImageLoader(this, aztec)
306-
aztec.videoThumbnailGetter = GlideVideoThumbnailLoader(this)
307-
308-
aztec.setOnImageTappedListener(this)
309-
aztec.setOnVideoTappedListener(this)
310-
311-
source = findViewById(R.id.source) as SourceViewEditText
312-
313-
formattingToolbar = findViewById(R.id.formatting_toolbar) as AztecToolbar
314-
formattingToolbar.setEditor(aztec, source)
315-
formattingToolbar.setToolbarListener(this)
316-
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))
317319

318320
// initialize the text & HTML
319321
if (!isRunningTest) {
320-
source.displayStyledAndFormattedHtml(EXAMPLE)
322+
aztec.sourceEditor.displayStyledAndFormattedHtml(EXAMPLE)
321323
}
322324

323325
if (savedInstanceState == null) {
324-
aztec.fromHtml(source.getPureHtml())
325-
source.history = aztec.history
326+
aztec.visualEditor.fromHtml(aztec.sourceEditor.getPureHtml())
327+
aztec.initHistory()
326328
}
327329

328-
aztec.history.setHistoryListener(this)
329-
aztec.setOnImeBackListener(this)
330-
aztec.setOnTouchListener(this)
331-
source.setOnImeBackListener(this)
332-
source.setOnTouchListener(this)
333-
334330
invalidateOptionsHandler = Handler()
335331
invalidateOptionsRunnable = Runnable { invalidateOptionsMenu() }
336332
}
@@ -363,7 +359,7 @@ class MainActivity : AppCompatActivity(),
363359
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
364360
super.onRestoreInstanceState(savedInstanceState)
365361

366-
source.history = aztec.history
362+
aztec.initHistory()
367363

368364
savedInstanceState?.let {
369365
if (savedInstanceState.getBoolean("isPhotoMediaDialogVisible")) {
@@ -464,16 +460,16 @@ class MainActivity : AppCompatActivity(),
464460
override fun onOptionsItemSelected(item: MenuItem): Boolean {
465461
when (item.itemId) {
466462
R.id.undo ->
467-
if (aztec.visibility == View.VISIBLE) {
468-
aztec.undo()
463+
if (aztec.visualEditor.visibility == View.VISIBLE) {
464+
aztec.visualEditor.undo()
469465
} else {
470-
source.undo()
466+
aztec.sourceEditor.undo()
471467
}
472468
R.id.redo ->
473-
if (aztec.visibility == View.VISIBLE) {
474-
aztec.redo()
469+
if (aztec.visualEditor.visibility == View.VISIBLE) {
470+
aztec.visualEditor.redo()
475471
} else {
476-
source.redo()
472+
aztec.sourceEditor.redo()
477473
}
478474
else -> {
479475
}
@@ -483,8 +479,8 @@ class MainActivity : AppCompatActivity(),
483479
}
484480

485481
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
486-
menu?.findItem(R.id.redo)?.isEnabled = aztec.history.redoValid()
487-
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()
488484
return super.onPrepareOptionsMenu(menu)
489485
}
490486

@@ -658,7 +654,7 @@ class MainActivity : AppCompatActivity(),
658654
override fun onToolbarExpandButtonClicked() {
659655
}
660656

661-
override fun onToolbarFormatButtonClicked(format: TextFormat, isKeyboardShortcut: Boolean) {
657+
override fun onToolbarFormatButtonClicked(format: ITextFormat, isKeyboardShortcut: Boolean) {
662658
}
663659

664660
override fun onToolbarHeadingButtonClicked() {
@@ -671,20 +667,20 @@ class MainActivity : AppCompatActivity(),
671667
}
672668
}
673669

674-
val mediaPending = aztec.getAllElementAttributes(uploadingPredicate).isNotEmpty()
670+
val mediaPending = aztec.visualEditor.getAllElementAttributes(uploadingPredicate).isNotEmpty()
675671

676672
if (mediaPending) {
677673
ToastUtils.showToast(this, R.string.media_upload_dialog_message)
678674
} else {
679-
formattingToolbar.toggleEditorMode()
675+
aztec.toolbar.toggleEditorMode()
680676
}
681677
}
682678

683679
override fun onToolbarListButtonClicked() {
684680
}
685681

686682
override fun onToolbarMediaButtonClicked() {
687-
mediaMenu = PopupMenu(this, formattingToolbar)
683+
mediaMenu = PopupMenu(this, aztec.toolbar)
688684
mediaMenu?.setOnMenuItemClickListener(this)
689685
mediaMenu?.inflate(R.menu.media)
690686
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)