Skip to content

Commit 41eb086

Browse files
committed
Squashed 'libs/editor/' changes from b556dfa99f..60e13dd828
60e13dd828 Merge pull request #461 from wordpress-mobile/travis-25 6b4f78a59c Update example app to API 25 3d0a8c8fcc Update Travis to use API25 5cafc2f59a Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into develop c5023cca1c Fix EditorFragmentTest after adding getContent exception throw 702a7241c5 Fix an issue in the Hybrid editor that could lead to an empty post title and content on save fead4827bb Merge pull request #4927 from wordpress-mobile/issue/460editor-content-loss a9ae13d377 Fix EditorFragmentTest after adding getContent exception throw 93a6017bd1 Fix an issue in the Hybrid editor that could lead to an empty post title and content on save 2069d60cbf Updating grade plugin c5ee8a976e Upgrade to Support Lib, build tools v25.0.1 141e508e98 Updating build tools and compile/targetSDK to 25 along with support libraries b6f8331feb update missing build files to 2.2.2 f36efa05b9 Updated to gradle v2.2.2 8a0b518157 Update to Android Gradle Plugin 2.2.1 git-subtree-dir: libs/editor git-subtree-split: 60e13dd828824b308252c9842d9c459db26a9f56
1 parent 6593e4c commit 41eb086

File tree

6 files changed

+55
-29
lines changed

6 files changed

+55
-29
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android:
77
- extra-android-support
88
- platform-tools
99
- tools
10-
- build-tools-24.0.2
11-
- android-24
10+
- build-tools-25.0.1
11+
- android-25
1212

1313
env:
1414
global:

WordPressEditor/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.2.0'
6+
classpath 'com.android.tools.build:gradle:2.2.3'
77
}
88
}
99

@@ -18,14 +18,14 @@ repositories {
1818
android {
1919
publishNonDefault true
2020

21-
compileSdkVersion 24
22-
buildToolsVersion "24.0.2"
21+
compileSdkVersion 25
22+
buildToolsVersion "25.0.1"
2323

2424
defaultConfig {
2525
versionCode 13
2626
versionName "1.3"
2727
minSdkVersion 16
28-
targetSdkVersion 24
28+
targetSdkVersion 25
2929
}
3030
buildTypes {
3131
release {
@@ -45,9 +45,9 @@ android {
4545
}
4646

4747
dependencies {
48-
compile 'com.android.support:appcompat-v7:24.2.1'
49-
compile 'com.android.support:support-v4:24.2.1'
50-
compile 'com.android.support:design:24.2.1'
48+
compile 'com.android.support:appcompat-v7:25.0.1'
49+
compile 'com.android.support:support-v4:25.0.1'
50+
compile 'com.android.support:design:25.0.1'
5151
compile 'org.wordpress:utils:1.11.0'
5252
}
5353

WordPressEditor/src/androidTest/java/org.wordpress.android.editor/EditorFragmentTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.view.View;
66
import android.widget.ToggleButton;
77

8+
import org.wordpress.android.editor.EditorFragment.IllegalEditorStateException;
9+
810
import java.util.HashMap;
911
import java.util.Map;
1012
import java.util.concurrent.CountDownLatch;
@@ -99,7 +101,7 @@ public void testFormatBarToggledOnSelectedFieldChanged() {
99101
assertTrue(htmlButton.isEnabled());
100102
}
101103

102-
public void testHtmlModeToggleTextTransfer() throws InterruptedException {
104+
public void testHtmlModeToggleTextTransfer() throws InterruptedException, IllegalEditorStateException {
103105
waitForOnDomLoaded();
104106

105107
final View view = mFragment.getView();
@@ -148,8 +150,12 @@ public void run() {
148150
contentText.setText("new <b>content</b>");
149151

150152
// Check that getTitle() and getContent() return latest version even in HTML mode
151-
assertEquals("new title", mFragment.getTitle());
152-
assertEquals("new <b>content</b>", mFragment.getContent());
153+
try {
154+
assertEquals("new title", mFragment.getTitle());
155+
assertEquals("new <b>content</b>", mFragment.getContent());
156+
} catch (IllegalEditorStateException e) {
157+
throw new RuntimeException();
158+
}
153159

154160
htmlButton.performClick(); // Turn off HTML mode
155161

@@ -174,4 +180,4 @@ private void waitForOnDomLoaded() {
174180
}
175181
}
176182
}
177-
}
183+
}

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
public class EditorFragment extends EditorFragmentAbstract implements View.OnClickListener, View.OnTouchListener,
6969
OnJsEditorStateChangedListener, OnImeBackListener, EditorWebViewAbstract.AuthHeaderRequestListener,
7070
EditorMediaUploadListener {
71+
72+
public class IllegalEditorStateException extends Exception {
73+
74+
}
75+
7176
private static final String ARG_PARAM_TITLE = "param_title";
7277
private static final String ARG_PARAM_CONTENT = "param_content";
7378

@@ -423,8 +428,12 @@ public void setUserVisibleHint(boolean isVisibleToUser) {
423428

424429
@Override
425430
public void onSaveInstanceState(Bundle outState) {
426-
outState.putCharSequence(KEY_TITLE, getTitle());
427-
outState.putCharSequence(KEY_CONTENT, getContent());
431+
try {
432+
outState.putCharSequence(KEY_TITLE, getTitle());
433+
outState.putCharSequence(KEY_CONTENT, getContent());
434+
} catch (IllegalEditorStateException e) {
435+
AppLog.e(T.EDITOR, "onSaveInstanceState: unable to get title or content");
436+
}
428437
}
429438

430439
private ActionBar getActionBar() {
@@ -636,9 +645,19 @@ public void run() {
636645
}
637646

638647
// Update mTitle and mContentHtml with the latest state from the ZSSEditor
639-
getTitle();
640-
getContent();
641-
648+
try {
649+
getTitle();
650+
getContent();
651+
} catch (IllegalEditorStateException e) {
652+
AppLog.e(T.EDITOR, "toggleHtmlMode: unable to get title or content");
653+
getActivity().runOnUiThread(new Runnable() {
654+
@Override
655+
public void run() {
656+
toggleButton.setChecked(false);
657+
}
658+
});
659+
return;
660+
}
642661
getActivity().runOnUiThread(new Runnable() {
643662
@Override
644663
public void run() {
@@ -922,9 +941,9 @@ public void setContent(CharSequence text) {
922941
* where possible.
923942
*/
924943
@Override
925-
public CharSequence getTitle() {
944+
public CharSequence getTitle() throws IllegalEditorStateException {
926945
if (!isAdded()) {
927-
return "";
946+
throw new IllegalEditorStateException();
928947
}
929948

930949
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
@@ -961,9 +980,9 @@ public void run() {
961980
* where possible.
962981
*/
963982
@Override
964-
public CharSequence getContent() {
983+
public CharSequence getContent() throws IllegalEditorStateException {
965984
if (!isAdded()) {
966-
return "";
985+
throw new IllegalEditorStateException();
967986
}
968987

969988
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.android.volley.toolbox.ImageLoader;
1111

12+
import org.wordpress.android.editor.EditorFragment.IllegalEditorStateException;
1213
import org.wordpress.android.util.helpers.MediaFile;
1314
import org.wordpress.android.util.helpers.MediaGallery;
1415

@@ -18,8 +19,8 @@
1819
public abstract class EditorFragmentAbstract extends Fragment {
1920
public abstract void setTitle(CharSequence text);
2021
public abstract void setContent(CharSequence text);
21-
public abstract CharSequence getTitle();
22-
public abstract CharSequence getContent();
22+
public abstract CharSequence getTitle() throws IllegalEditorStateException;
23+
public abstract CharSequence getContent() throws IllegalEditorStateException;
2324
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
2425
public abstract void appendGallery(MediaGallery mediaGallery);
2526
public abstract void setUrlForVideoPressId(String videoPressId, String url, String posterUrl);

example/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.2.0'
6+
classpath 'com.android.tools.build:gradle:2.2.3'
77
}
88
}
99

@@ -14,13 +14,13 @@ repositories {
1414
apply plugin: 'com.android.application'
1515

1616
android {
17-
compileSdkVersion 24
18-
buildToolsVersion "24.0.2"
17+
compileSdkVersion 25
18+
buildToolsVersion "25.0.1"
1919

2020
defaultConfig {
2121
applicationId "org.wordpress.editorexample"
2222
minSdkVersion 16
23-
targetSdkVersion 24
23+
targetSdkVersion 25
2424
versionCode 1
2525
versionName "1.0"
2626
}
@@ -53,4 +53,4 @@ dependencies {
5353
android.testOptions.unitTests.all {
5454
include '**/*Test.class'
5555
exclude '**/ApplicationTest.class'
56-
}
56+
}

0 commit comments

Comments
 (0)