Skip to content

Commit

Permalink
make the legacy editor works in the example project
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Feb 13, 2015
1 parent 6f0d297 commit d33a9be
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package org.wordpress.android.editor.example;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

import org.wordpress.android.editor.EditorFragmentAbstract;
import org.wordpress.android.editor.EditorFragmentAbstract.EditorFragmentListener;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.helpers.MediaFile;

public class EditorExampleActivity extends ActionBarActivity implements EditorFragmentListener {
public static final String EDITOR_CHOICE = "EDITOR_CHOICE";
public static final String EDITOR_PARAM = "EDITOR_PARAM";
public static final String TITLE_PARAM = "TITLE_PARAM";
public static final String CONTENT_PARAM = "CONTENT_PARAM";
public static final int USE_NEW_EDITOR = 1;
public static final int USE_LEGACY_EDITOR = 2;

private EditorFragmentAbstract mEditorFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getIntExtra(EDITOR_CHOICE, USE_NEW_EDITOR) == USE_NEW_EDITOR) {
if (getIntent().getIntExtra(EDITOR_PARAM, USE_NEW_EDITOR) == USE_NEW_EDITOR) {
ToastUtils.showToast(this, R.string.starting_new_editor);
setContentView(R.layout.activity_new_editor);
} else {
Expand All @@ -23,6 +31,14 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override
public void onAttachFragment(Fragment fragment) {
super.onAttachFragment(fragment);
if (fragment instanceof EditorFragmentAbstract) {
mEditorFragment = (EditorFragmentAbstract) fragment;
}
}

@Override
public void onSettingsClicked() {
// TODO
Expand All @@ -32,4 +48,23 @@ public void onSettingsClicked() {
public void onAddMediaButtonClicked() {
// TODO
}

@Override
public void onEditorFragmentInitialized() {
// arbitrary setup
mEditorFragment.setLocalDraft(false);
mEditorFragment.setFeaturedImageSupported(true);
mEditorFragment.setBlogSettingMaxImageWidth("600");

// set title and content
String title = getIntent().getStringExtra(TITLE_PARAM);
String content = getIntent().getStringExtra(CONTENT_PARAM);
mEditorFragment.setTitle(title);
mEditorFragment.setContent(content);
}

@Override
public void saveMediaFile(MediaFile mediaFile) {
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override public void onClick(View v) {
Intent intent = new Intent(MainExampleActivity.this, EditorExampleActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(EditorExampleActivity.EDITOR_CHOICE, EditorExampleActivity.USE_NEW_EDITOR);
bundle.putString(EditorExampleActivity.TITLE_PARAM, getString(R.string.example_post_1_title));
bundle.putString(EditorExampleActivity.CONTENT_PARAM, getString(R.string.example_post_1_content));
bundle.putInt(EditorExampleActivity.EDITOR_PARAM, EditorExampleActivity.USE_NEW_EDITOR);
intent.putExtras(bundle);
startActivity(intent);
}
Expand All @@ -31,7 +33,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override public void onClick(View v) {
Intent intent = new Intent(MainExampleActivity.this, EditorExampleActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(EditorExampleActivity.EDITOR_CHOICE, EditorExampleActivity.USE_LEGACY_EDITOR);
bundle.putString(EditorExampleActivity.TITLE_PARAM, getString(R.string.example_post_1_title));
bundle.putString(EditorExampleActivity.CONTENT_PARAM, getString(R.string.example_post_1_content));
bundle.putInt(EditorExampleActivity.EDITOR_PARAM, EditorExampleActivity.USE_LEGACY_EDITOR);
intent.putExtras(bundle);
startActivity(intent);
}
Expand Down
2 changes: 1 addition & 1 deletion example/src/main/res/layout/activity_legacy_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<fragment
android:id="@+id/postEditor"
android:name="org.wordpress.android.editor.EditorFragment"
android:name="org.wordpress.android.editor.LegacyEditorFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
7 changes: 7 additions & 0 deletions example/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
<string name="title_activity_example">ExampleActivity</string>
<string name="starting_legacy_editor">Starting legacy editor</string>
<string name="starting_new_editor">Starting new editor</string>

<string name="example_post_1_title">Post 1</string>
<string name="example_post_1_content">Post 1 Content:\nBest post ever!</string>
<string name="example_post_2_title">Post 2</string>
<string name="example_post_2_content">
<![CDATA[<p>Post 2 Content</p><blockquote>Quoted text</blockquote><br/>]]>
</string>
</resources>

0 comments on commit d33a9be

Please sign in to comment.