Skip to content

Commit 116526c

Browse files
committed
Merge branch 'develop' into feature/add-headless-factory-method
2 parents df77ea4 + e56783e commit 116526c

File tree

21 files changed

+173
-150
lines changed

21 files changed

+173
-150
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android:
1010
- platform-tools
1111
- tools
1212
- build-tools-25.0.3
13-
- android-25
13+
- android-26
1414

1515
env:
1616
global:

app/build.gradle

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 25
5+
compileSdkVersion 26
66
buildToolsVersion "25.0.3"
77

88
defaultConfig {
99
applicationId "org.wordpress.aztec"
1010
minSdkVersion 16
11-
targetSdkVersion 25
11+
targetSdkVersion 26
1212
versionCode 1
1313
versionName "1.0"
1414
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
@@ -30,18 +30,20 @@ android {
3030
}
3131

3232
dependencies {
33-
compile fileTree(include: ['*.jar'], dir: 'libs')
34-
compile project(':aztec')
35-
compile project(':glide-loader')
36-
compile project(':picasso-loader')
37-
compile project(':wordpress-comments')
38-
compile project(':wordpress-shortcodes')
39-
40-
//noinspection GradleCompatible
41-
compile "com.android.support:appcompat-v7:25.3.1"
42-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
43-
compile "org.wordpress:utils:1.16.0"
44-
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
33+
implementation fileTree(include: ['*.jar'], dir: 'libs')
34+
implementation project(':aztec')
35+
implementation project(':glide-loader')
36+
implementation project(':picasso-loader')
37+
implementation project(':wordpress-comments')
38+
implementation project(':wordpress-shortcodes')
39+
40+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
41+
42+
implementation "com.android.support:appcompat-v7:$supportLibVersion"
43+
implementation "org.wordpress:utils:$wordpressUtilsVersion"
44+
45+
46+
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion", {
4547
exclude group: 'com.android.support', module: 'support-annotations'
4648
}
47-
}
49+
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.support.v7.app.AppCompatActivity
2626
import android.util.DisplayMetrics
2727
import android.view.*
2828
import android.widget.PopupMenu
29+
import android.widget.TextView
2930
import android.widget.Toast
3031
import org.wordpress.android.util.AppLog
3132
import org.wordpress.android.util.PermissionUtils
@@ -312,9 +313,9 @@ class MainActivity : AppCompatActivity(),
312313
mHideActionBarOnSoftKeyboardUp = true
313314
}
314315

315-
val visualEditor = findViewById(R.id.aztec) as AztecText
316-
val sourceEditor = findViewById(R.id.source) as SourceViewEditText
317-
val toolbar = findViewById(R.id.formatting_toolbar) as AztecToolbar
316+
val visualEditor = findViewById<AztecText>(R.id.aztec)
317+
val sourceEditor = findViewById<SourceViewEditText>(R.id.source)
318+
val toolbar = findViewById<AztecToolbar>(R.id.formatting_toolbar)
318319

319320

320321
aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
@@ -738,19 +739,19 @@ class MainActivity : AppCompatActivity(),
738739
private fun showPhotoMediaDialog() {
739740
val dialog = layoutInflater.inflate(R.layout.dialog_photo_media, null)
740741

741-
val camera = dialog.findViewById(org.wordpress.aztec.R.id.media_camera)
742+
val camera = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_camera)
742743
camera.setOnClickListener({
743744
onCameraPhotoMediaOptionSelected()
744745
addPhotoMediaDialog?.dismiss()
745746
})
746747

747-
val photos = dialog.findViewById(org.wordpress.aztec.R.id.media_photos)
748+
val photos = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_photos)
748749
photos.setOnClickListener({
749750
onPhotosMediaOptionSelected()
750751
addPhotoMediaDialog?.dismiss()
751752
})
752753

753-
val library = dialog.findViewById(org.wordpress.aztec.R.id.media_library)
754+
val library = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_library)
754755
library.setOnClickListener({
755756
onPhotoLibraryMediaOptionSelected()
756757
addPhotoMediaDialog?.dismiss()
@@ -765,19 +766,19 @@ class MainActivity : AppCompatActivity(),
765766
private fun showVideoMediaDialog() {
766767
val dialog = layoutInflater.inflate(org.wordpress.aztec.R.layout.dialog_video_media, null)
767768

768-
val camera = dialog.findViewById(org.wordpress.aztec.R.id.media_camera)
769+
val camera = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_camera)
769770
camera.setOnClickListener({
770771
onCameraVideoMediaOptionSelected()
771772
addVideoMediaDialog?.dismiss()
772773
})
773774

774-
val videos = dialog.findViewById(org.wordpress.aztec.R.id.media_videos)
775+
val videos = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_videos)
775776
videos.setOnClickListener({
776777
onVideosMediaOptionSelected()
777778
addVideoMediaDialog?.dismiss()
778779
})
779780

780-
val library = dialog.findViewById(org.wordpress.aztec.R.id.media_library)
781+
val library = dialog.findViewById<TextView>(org.wordpress.aztec.R.id.media_library)
781782
library.setOnClickListener({
782783
onVideoLibraryMediaOptionSelected()
783784
addVideoMediaDialog?.dismiss()

aztec/build.gradle

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 25
5+
compileSdkVersion 26
66
buildToolsVersion "25.0.3"
77

88
defaultConfig {
99
minSdkVersion 16
10-
targetSdkVersion 25
10+
targetSdkVersion 26
1111
versionName "1.0"
1212
}
1313

@@ -17,27 +17,29 @@ android {
1717
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1818
}
1919
}
20+
2021
sourceSets {
2122
androidTest.java.srcDirs += 'src/androidTest/kotlin'
2223
main.java.srcDirs += 'src/main/kotlin'
2324
test.java.srcDirs += 'src/test/kotlin'
2425
}
26+
27+
testOptions {
28+
unitTests {
29+
includeAndroidResources = true
30+
}
31+
}
2532
}
2633

2734
dependencies {
28-
compile "com.android.support:support-v4:25.3.1"
29-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30-
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
31-
compile 'org.jsoup:jsoup:1.10.2'
35+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
3236

33-
testCompile 'junit:junit:4.12'
34-
testCompile 'org.robolectric:robolectric:3.3.2'
37+
implementation "org.ccil.cowan.tagsoup:tagsoup:$tagSoupVersion"
38+
implementation "org.jsoup:jsoup:$jSoupVersion"
3539

36-
compile 'com.android.support:design:25.3.1'
37-
//https://github.com/robolectric/robolectric/issues/1932
38-
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
39-
}
40+
implementation "com.android.support:support-v4:$supportLibVersion"
41+
implementation "com.android.support:design:$supportLibVersion"
4042

41-
repositories {
42-
mavenCentral()
43+
testImplementation "junit:junit:$jUnitVersion"
44+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
4345
}

aztec/src/androidTest/kotlin/org/wordpress/aztec/ApplicationTest.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ open class Aztec private constructor(val visualEditor: AztecText, val toolbar: A
3232

3333
private constructor(activity: Activity, @IdRes aztecTextId: Int,
3434
@IdRes sourceTextId: Int, @IdRes toolbarId: Int,
35-
toolbarClickListener: IAztecToolbarClickListener) : this(activity.findViewById(aztecTextId) as AztecText,
36-
activity.findViewById(sourceTextId) as SourceViewEditText, activity.findViewById(toolbarId) as AztecToolbar, toolbarClickListener)
35+
toolbarClickListener: IAztecToolbarClickListener) : this(activity.findViewById(aztecTextId),
36+
activity.findViewById(sourceTextId), activity.findViewById(toolbarId), toolbarClickListener)
3737

3838

3939
private constructor(activity: Activity, @IdRes aztecTextId: Int,
@@ -47,11 +47,13 @@ open class Aztec private constructor(val visualEditor: AztecText, val toolbar: A
4747
}
4848

4949
companion object Factory {
50+
@JvmStatic
5051
fun with(activity: Activity, @IdRes aztecTextId: Int, @IdRes sourceTextId: Int,
5152
@IdRes toolbarId: Int, toolbarClickListener: IAztecToolbarClickListener) : Aztec {
5253
return Aztec(activity, aztecTextId, sourceTextId, toolbarId, toolbarClickListener)
5354
}
5455

56+
@JvmStatic
5557
fun with(visualEditor: AztecText, sourceEditor: SourceViewEditText,
5658
toolbar: AztecToolbar, toolbarClickListener: IAztecToolbarClickListener) : Aztec {
5759
return Aztec(visualEditor, sourceEditor, toolbar, toolbarClickListener)

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,15 @@ class AztecTagHandler(val plugins: List<IAztecPlugin> = ArrayList()) : Html.TagH
7777
return true
7878
}
7979
IMAGE -> {
80-
handleMediaElement(opening, context, attributes, output,
81-
AztecImageSpan(context, getLoadingDrawable(context), AztecAttributes(attributes)))
80+
handleMediaElement(opening, output, AztecImageSpan(context, getLoadingDrawable(context), AztecAttributes(attributes)))
8281
return true
8382
}
8483
VIDEO -> {
85-
handleMediaElement(opening, context, attributes, output,
86-
AztecVideoSpan(context, getLoadingDrawable(context), nestingLevel, AztecAttributes(attributes)))
84+
handleMediaElement(opening, output, AztecVideoSpan(context, getLoadingDrawable(context), nestingLevel, AztecAttributes(attributes)))
8785
return true
8886
}
8987
AUDIO -> {
90-
handleMediaElement(opening, context, attributes, output,
91-
AztecAudioSpan(context, getLoadingDrawable(context), nestingLevel, AztecAttributes(attributes)))
88+
handleMediaElement(opening, output, AztecAudioSpan(context, getLoadingDrawable(context), nestingLevel, AztecAttributes(attributes)))
9289
return true
9390
}
9491
PARAGRAPH -> {
@@ -140,8 +137,7 @@ class AztecTagHandler(val plugins: List<IAztecPlugin> = ArrayList()) : Html.TagH
140137
return loadingDrawable
141138
}
142139

143-
private fun handleMediaElement(opening: Boolean, context: Context, attributes: Attributes,
144-
output: Editable, mediaSpan: AztecMediaSpan) {
140+
private fun handleMediaElement(opening: Boolean, output: Editable, mediaSpan: AztecMediaSpan) {
145141
if (opening) {
146142
start(output, mediaSpan)
147143
start(output, AztecMediaClickableSpan(mediaSpan))

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,19 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
408408
if (addLinkDialog != null && addLinkDialog!!.isShowing) {
409409
bundle.putBoolean(LINK_DIALOG_VISIBLE_KEY, true)
410410

411-
val urlInput = addLinkDialog!!.findViewById(R.id.linkURL) as EditText
412-
val anchorInput = addLinkDialog!!.findViewById(R.id.linkText) as EditText
411+
val urlInput = addLinkDialog!!.findViewById<EditText>(R.id.linkURL)
412+
val anchorInput = addLinkDialog!!.findViewById<EditText>(R.id.linkText)
413413

414-
bundle.putString(LINK_DIALOG_URL_KEY, urlInput.text.toString())
415-
bundle.putString(LINK_DIALOG_ANCHOR_KEY, anchorInput.text.toString())
414+
bundle.putString(LINK_DIALOG_URL_KEY, urlInput?.text?.toString())
415+
bundle.putString(LINK_DIALOG_ANCHOR_KEY, anchorInput?.text?.toString())
416416
}
417417

418418
if (blockEditorDialog != null && blockEditorDialog!!.isShowing) {
419-
val source = blockEditorDialog!!.findViewById(R.id.source) as SourceViewEditText
419+
val source = blockEditorDialog!!.findViewById<SourceViewEditText>(R.id.source)
420420

421421
bundle.putBoolean(BLOCK_DIALOG_VISIBLE_KEY, true)
422422
bundle.putInt(BLOCK_EDITOR_START_INDEX_KEY, unknownBlockSpanStart)
423-
bundle.putString(BLOCK_EDITOR_HTML_KEY, source.getPureHtml(false))
423+
bundle.putString(BLOCK_EDITOR_HTML_KEY, source?.getPureHtml(false))
424424
}
425425

426426
bundle.putBoolean(IS_MEDIA_ADDED_KEY, isMediaAdded)
@@ -1041,7 +1041,7 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
10411041
enableTextChangedListener()
10421042

10431043
if (clip.itemCount > 0) {
1044-
val textToPaste = clip.getItemAt(0).coerceToHtmlText(context, AztecParser(plugins))
1044+
val textToPaste = clip.getItemAt(0).coerceToHtmlText(AztecParser(plugins))
10451045

10461046
val oldHtml = toPlainHtml().replace("<aztec_cursor>", "")
10471047
val newHtml = oldHtml.replace(Constants.REPLACEMENT_MARKER_STRING, textToPaste + "<" + AztecCursorSpan.AZTEC_CURSOR_TAG + ">")
@@ -1094,29 +1094,29 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
10941094

10951095
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_link, null)
10961096

1097-
val urlInput = dialogView.findViewById(R.id.linkURL) as EditText
1098-
val anchorInput = dialogView.findViewById(R.id.linkText) as EditText
1097+
val urlInput = dialogView.findViewById<EditText>(R.id.linkURL)
1098+
val anchorInput = dialogView.findViewById<EditText>(R.id.linkText)
10991099

11001100
urlInput.setText(url)
11011101
anchorInput.setText(anchor)
11021102

11031103
builder.setView(dialogView)
11041104
builder.setTitle(R.string.link_dialog_title)
11051105

1106-
builder.setPositiveButton(R.string.link_dialog_button_ok, { dialog, which ->
1106+
builder.setPositiveButton(R.string.link_dialog_button_ok, { _, _ ->
11071107
val linkText = urlInput.text.toString().trim { it <= ' ' }
11081108
val anchorText = anchorInput.text.toString().trim { it <= ' ' }
11091109

11101110
link(linkText, anchorText)
11111111
})
11121112

11131113
if (linkFormatter.isUrlSelected()) {
1114-
builder.setNeutralButton(R.string.link_dialog_button_remove_link, { dialogInterface, i ->
1114+
builder.setNeutralButton(R.string.link_dialog_button_remove_link, { _, _ ->
11151115
removeLink()
11161116
})
11171117
}
11181118

1119-
builder.setNegativeButton(R.string.link_dialog_button_cancel, { dialogInterface, i ->
1119+
builder.setNegativeButton(R.string.link_dialog_button_cancel, { dialogInterface, _ ->
11201120
dialogInterface.dismiss()
11211121
})
11221122

@@ -1128,7 +1128,7 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
11281128
val builder = AlertDialog.Builder(context)
11291129

11301130
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_block_editor, null)
1131-
val source = dialogView.findViewById(R.id.source) as SourceViewEditText
1131+
val source = dialogView.findViewById<SourceViewEditText>(R.id.source)
11321132

11331133
var editHtml = html
11341134
if (TextUtils.isEmpty(editHtml)) {

aztec/src/main/kotlin/org/wordpress/aztec/source/Format.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.wordpress.aztec.spans.*
99
import java.util.regex.Matcher
1010
import java.util.regex.Pattern
1111

12-
object Format {
12+
internal object Format {
1313

1414
// list of block elements
1515
private val block = "div|br|blockquote|ul|ol|li|p|pre|h1|h2|h3|h4|h5|h6|iframe|hr"

0 commit comments

Comments
 (0)