Skip to content

Commit 220cac4

Browse files
committed
Squashed 'libs/editor/' changes from 7932116..087a5b2
087a5b2 Merge pull request #450 from wordpress-mobile/issue/445-image-settings-alignement-issue 88577e2 Fix typo s/alignement/alignment/ 65a253c Fix translated alignement issue in ImageSettings screen d846356 Merge pull request #449 from wordpress-mobile/issue/broken-example-and-tests 333855c Clear test dependencies from library gradle file f540179 Fix broken integration tests 81054ec Correct require paths in mocha tests and update README 50d827c Move unit tests to example project 40b2966 Implement EditorDragAndrDropListener in EditorExampleActivity and MockEditorActivity 364a1fc Moved example activities to android.editor.example package git-subtree-dir: libs/editor git-subtree-split: 087a5b20733f4ac06eaa81c1c4e75b608f6d6300
1 parent 8730fb5 commit 220cac4

File tree

17 files changed

+89
-43
lines changed

17 files changed

+89
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ This project also has unit tests for the JS part of the editor using [Mocha](htt
2222

2323
To be able to run the tests, [npm](https://www.npmjs.com/) and Mocha (`npm install -g mocha`) are required.
2424

25-
With npm and Mocha installed, from within `WordPressEditor/src/test/js`, run:
25+
With npm and Mocha installed, from within `example/src/test/js`, run:
2626

2727
npm install chai
2828

2929
And then run `mocha` inside the same folder:
3030

31-
cd WordPressEditor/src/test/js; mocha test*; cd -
31+
cd example/src/test/js; mocha test*; cd -
3232

3333
## LICENSE ##
3434

WordPressEditor/build.gradle

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ dependencies {
4949
compile 'com.android.support:support-v4:24.1.1'
5050
compile 'com.android.support:design:24.1.1'
5151
compile 'org.wordpress:utils:1.11.0'
52-
53-
// Test libraries
54-
testCompile 'junit:junit:4.11'
55-
testCompile 'org.mockito:mockito-core:1.10.19'
56-
testCompile 'org.robolectric:robolectric:3.0'
57-
58-
// Workaround for IDE bug
59-
// http://stackoverflow.com/questions/22246183/android-studio-doesnt-recognize-espresso-classes
60-
provided 'junit:junit:4.11'
61-
provided 'org.mockito:mockito-core:1.10.19'
6252
}
6353

6454
signing {
@@ -116,12 +106,3 @@ uploadArchives {
116106
}
117107
}
118108
}
119-
120-
//
121-
// Testing
122-
//
123-
124-
android.testOptions.unitTests.all {
125-
include '**/*Test.class'
126-
exclude '**/ApplicationTest.class'
127-
}

WordPressEditor/src/androidTest/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="org.wordpress.android.editor" >
44
<application>
55
<activity android:name=".MockActivity"
6+
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
67
android:exported="false" />
78
<activity android:name=".MockEditorActivity"
89
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testFormatBarToggledOnSelectedFieldChanged() {
8080
selectionArgs.put("id", "zss_field_content");
8181
mFragment.onSelectionChanged(selectionArgs);
8282

83-
waitFor(100);
83+
waitFor(500);
8484

8585
// The formatting buttons should be enabled while the content field is selected
8686
assertTrue(mediaButton.isEnabled());
@@ -130,6 +130,8 @@ public void run() {
130130

131131
uiThreadLatch1.await();
132132

133+
waitFor(500);
134+
133135
// The HTML mode fields should be populated with the raw HTML loaded into the WebView on load
134136
// (see MockEditorActivity)
135137
assertEquals("A title", titleText.getText().toString());

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
import android.app.FragmentManager;
44
import android.app.FragmentTransaction;
5+
import android.net.Uri;
56
import android.os.Bundle;
67
import android.support.v7.app.AppCompatActivity;
8+
import android.view.DragEvent;
79
import android.widget.LinearLayout;
810

11+
import org.wordpress.android.editor.EditorFragmentAbstract.EditorDragAndDropListener;
12+
import org.wordpress.android.editor.EditorFragmentAbstract.EditorFragmentListener;
913
import org.wordpress.android.editor.EditorFragmentAbstract.TrackableEvent;
1014
import org.wordpress.android.util.helpers.MediaFile;
1115

12-
public class MockEditorActivity extends AppCompatActivity implements EditorFragmentAbstract.EditorFragmentListener {
16+
import java.util.ArrayList;
17+
18+
public class MockEditorActivity extends AppCompatActivity implements EditorFragmentListener,
19+
EditorDragAndDropListener {
1320
public static final int LAYOUT_ID = 999;
1421

1522
EditorFragment mEditorFragment;
@@ -34,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
3441
@Override
3542
public void onEditorFragmentInitialized() {
3643
mEditorFragment.setTitle("A title");
37-
mEditorFragment.setContent(Utils.getHtmlFromFile(this, "example/example-content.html"));
44+
mEditorFragment.setContent("<p>Example <strong>content</strong></p>");
3845
}
3946

4047
@Override
@@ -81,5 +88,15 @@ public void saveMediaFile(MediaFile mediaFile) {
8188
public void onTrackableEvent(TrackableEvent event) {
8289

8390
}
91+
92+
@Override
93+
public void onMediaDropped(ArrayList<Uri> mediaUri) {
94+
95+
}
96+
97+
@Override
98+
public void onRequestDragAndDropPermissions(DragEvent dragEvent) {
99+
100+
}
84101
}
85102

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.wordpress.android.util.ToastUtils;
3333

3434
import java.util.Arrays;
35-
import java.util.Locale;
3635
import java.util.Map;
3736

3837
/**
@@ -52,6 +51,7 @@ public class ImageSettingsDialogFragment extends DialogFragment {
5251
private EditText mCaptionText;
5352
private EditText mAltText;
5453
private Spinner mAlignmentSpinner;
54+
private String[] mAlignmentKeyArray;
5555
private EditText mLinkTo;
5656
private EditText mWidthText;
5757
private CheckBox mFeaturedCheckBox;
@@ -159,12 +159,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
159159
mAltText.setText(mImageMeta.getString("alt"));
160160

161161
String alignment = mImageMeta.getString("align");
162-
163-
// Capitalize the alignment value to match the spinner entries
164-
alignment = alignment.substring(0, 1).toUpperCase(Locale.US) + alignment.substring(1);
165-
166-
String[] alignmentArray = getResources().getStringArray(R.array.alignment_array);
167-
mAlignmentSpinner.setSelection(Arrays.asList(alignmentArray).indexOf(alignment));
162+
mAlignmentKeyArray = getResources().getStringArray(R.array.alignment_key_array);
163+
int alignmentIndex = Arrays.asList(mAlignmentKeyArray).indexOf(alignment);
164+
mAlignmentSpinner.setSelection(alignmentIndex == -1 ? 0 : alignmentIndex);
168165

169166
mLinkTo.setText(mImageMeta.getString("linkUrl"));
170167

@@ -306,7 +303,9 @@ private JSONObject extractMetaDataFromFields(JSONObject metaData) {
306303
metaData.put("title", mTitleText.getText().toString());
307304
metaData.put("caption", mCaptionText.getText().toString());
308305
metaData.put("alt", mAltText.getText().toString());
309-
metaData.put("align", mAlignmentSpinner.getSelectedItem().toString().toLowerCase(Locale.US));
306+
if (mAlignmentSpinner.getSelectedItemPosition() < mAlignmentKeyArray.length) {
307+
metaData.put("align", mAlignmentKeyArray[mAlignmentSpinner.getSelectedItemPosition()]);
308+
}
310309
metaData.put("linkUrl", mLinkTo.getText().toString());
311310

312311
int newWidth = getEditTextIntegerClamped(mWidthText, 10, mMaxImageWidth);

WordPressEditor/src/main/res/values/strings.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,23 @@
5252
<string name="image_link_to">Link to</string>
5353
<string name="image_width">Width</string>
5454

55-
<string-array name="alignment_array">
56-
<item>None</item>
57-
<item>Left</item>
58-
<item>Center</item>
59-
<item>Right</item>
55+
<string name="alignment_none">None</string>
56+
<string name="alignment_left">Left</string>
57+
<string name="alignment_center">Center</string>
58+
<string name="alignment_right">Right</string>
59+
60+
<string-array name="alignment_key_array" translatable="false">
61+
<item>none</item>
62+
<item>left</item>
63+
<item>center</item>
64+
<item>right</item>
65+
</string-array>
66+
67+
<string-array name="alignment_array" translatable="false">
68+
<item>@string/alignment_none</item>
69+
<item>@string/alignment_left</item>
70+
<item>@string/alignment_center</item>
71+
<item>@string/alignment_right</item>
6072
</string-array>
6173

6274
<!-- Accessibility - format bar button descriptions -->

example/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,23 @@ android {
3434

3535
dependencies {
3636
compile project(":WordPressEditor");
37+
38+
// Test libraries
39+
testCompile 'junit:junit:4.11'
40+
testCompile 'org.mockito:mockito-core:1.10.19'
41+
testCompile 'org.robolectric:robolectric:3.0'
42+
43+
// Workaround for IDE bug
44+
// http://stackoverflow.com/questions/22246183/android-studio-doesnt-recognize-espresso-classes
45+
provided 'junit:junit:4.11'
46+
provided 'org.mockito:mockito-core:1.10.19'
3747
}
48+
49+
//
50+
// Testing
51+
//
52+
53+
android.testOptions.unitTests.all {
54+
include '**/*Test.class'
55+
exclude '**/ApplicationTest.class'
56+
}

example/src/main/java/org/wordpress/example/EditorExampleActivity.java renamed to example/src/main/java/org/wordpress/android/editor/example/EditorExampleActivity.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import android.os.Bundle;
77
import android.support.v7.app.AppCompatActivity;
88
import android.view.ContextMenu;
9+
import android.view.DragEvent;
910
import android.view.MenuItem;
1011
import android.view.View;
1112

1213
import org.wordpress.android.editor.EditorFragmentAbstract;
14+
import org.wordpress.android.editor.EditorFragmentAbstract.EditorDragAndDropListener;
1315
import org.wordpress.android.editor.EditorFragmentAbstract.EditorFragmentListener;
1416
import org.wordpress.android.editor.EditorFragmentAbstract.TrackableEvent;
1517
import org.wordpress.android.editor.EditorMediaUploadListener;
@@ -19,10 +21,12 @@
1921
import org.wordpress.android.util.ToastUtils;
2022
import org.wordpress.android.util.helpers.MediaFile;
2123

24+
import java.util.ArrayList;
2225
import java.util.HashMap;
2326
import java.util.Map;
2427

25-
public class EditorExampleActivity extends AppCompatActivity implements EditorFragmentListener {
28+
public class EditorExampleActivity extends AppCompatActivity implements EditorFragmentListener,
29+
EditorDragAndDropListener {
2630
public static final String EDITOR_PARAM = "EDITOR_PARAM";
2731
public static final String TITLE_PARAM = "TITLE_PARAM";
2832
public static final String CONTENT_PARAM = "CONTENT_PARAM";
@@ -331,4 +335,14 @@ public void run() {
331335

332336
thread.start();
333337
}
338+
339+
@Override
340+
public void onMediaDropped(ArrayList<Uri> mediaUri) {
341+
// TODO
342+
}
343+
344+
@Override
345+
public void onRequestDragAndDropPermissions(DragEvent dragEvent) {
346+
// TODO
347+
}
334348
}

example/src/main/java/org/wordpress/example/MainExampleActivity.java renamed to example/src/main/java/org/wordpress/android/editor/example/MainExampleActivity.java

File renamed without changes.

0 commit comments

Comments
 (0)