Skip to content

Commit

Permalink
enable gallery handling
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Mar 12, 2015
1 parent 3ca1d97 commit 1721d30
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.annotation.SuppressLint;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.Spanned;
import android.text.style.CharacterStyle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,6 +19,7 @@
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -155,6 +154,11 @@ public void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader im
// TODO
}

@Override
public void appendGallery(MediaGallery mediaGallery) {
// TODO
}

@Override
public Spanned getSpannedContent() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import android.app.Activity;
import android.app.Fragment;
import android.text.Editable;
import android.text.Spanned;
import android.text.style.CharacterStyle;

import com.android.volley.toolbox.ImageLoader;

import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;

public abstract class EditorFragmentAbstract extends Fragment {
public abstract void setTitle(CharSequence text);
public abstract void setContent(CharSequence text);
public abstract CharSequence getTitle();
public abstract CharSequence getContent();
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
public abstract void appendGallery(MediaGallery mediaGallery);

// TODO: remove this as soon as we can (we'll need to drop the legacy editor or fix html2spanned translation)
public abstract Spanned getSpannedContent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.wordpress.android.util.ImageUtils;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.android.util.helpers.MediaGalleryImageSpan;
import org.wordpress.android.util.helpers.WPImageSpan;
import org.wordpress.android.util.helpers.WPUnderlineSpan;
Expand Down Expand Up @@ -1010,4 +1011,40 @@ public void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader im
loadWPImageSpanThumbnail(mediaFile, imageUrl, imageLoader);
}
}

public void appendGallery(MediaGallery mediaGallery) {
Editable editableText = mContentEditText.getText();
if (editableText == null) {
return;
}

int selectionStart = mContentEditText.getSelectionStart();
int selectionEnd = mContentEditText.getSelectionEnd();

if (selectionStart > selectionEnd) {
int temp = selectionEnd;
selectionEnd = selectionStart;
selectionStart = temp;
}

int line, column = 0;
if (mContentEditText.getLayout() != null) {
line = mContentEditText.getLayout().getLineForOffset(selectionStart);
column = mContentEditText.getSelectionStart() - mContentEditText.getLayout().getLineStart(line);
}

if (column != 0) {
// insert one line break if the cursor is not at the first column
editableText.insert(selectionEnd, "\n");
selectionStart = selectionStart + 1;
selectionEnd = selectionEnd + 1;
}

editableText.insert(selectionStart, " ");
MediaGalleryImageSpan is = new MediaGalleryImageSpan(getActivity(), mediaGallery, R.drawable.ab_icon_edit);
editableText.setSpan(is, selectionStart, selectionEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
AlignmentSpan.Standard as = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
editableText.setSpan(as, selectionStart, selectionEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
editableText.insert(selectionEnd + 1, "\n\n");
}
}

0 comments on commit 1721d30

Please sign in to comment.