Skip to content

Commit

Permalink
Add actions command implementation to Android
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloercoli committed Aug 20, 2018
1 parent 93cf14e commit 9f8f01a
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.facebook.react.views.textinput.ScrollWatcher;

import org.wordpress.aztec.AztecText;
import org.wordpress.aztec.AztecTextFormat;
import org.wordpress.aztec.ITextFormat;
import org.wordpress.aztec.glideloader.GlideImageLoader;
import org.wordpress.aztec.glideloader.GlideVideoThumbnailLoader;
import org.wordpress.aztec.plugins.CssUnderlinePlugin;
Expand Down Expand Up @@ -147,14 +149,49 @@ public void setIsSettingTextFromJS(boolean mIsSettingTextFromJS) {
}

public void applyFormat(String format) {
ArrayList<ITextFormat> newFormats = new ArrayList<>();
switch (format) {
case ("bold"):
newFormats.add(AztecTextFormat.FORMAT_STRONG);
newFormats.add(AztecTextFormat.FORMAT_BOLD);
break;
case ("italic"):
newFormats.add(AztecTextFormat.FORMAT_ITALIC);
newFormats.add(AztecTextFormat.FORMAT_CITE);
break;
case ("strikethrough"):
newFormats.add(AztecTextFormat.FORMAT_STRIKETHROUGH);
break;
}

if (newFormats.size() == 0) {
return;
}

if (!isTextSelected()) {
setSelectedStyles(getNewStylesList(newFormats));
} else {
toggleFormatting(newFormats.get(0));
}
}

// Removes all formats in the list but if none found, applies the first one
private ArrayList<ITextFormat> getNewStylesList(ArrayList<ITextFormat> newFormats) {
ArrayList<ITextFormat> textFormats = new ArrayList<>();
textFormats.addAll(getSelectedStyles());
boolean wasRemoved = false;
for (ITextFormat currentFormat : newFormats) {
if (textFormats.contains(currentFormat)) {
wasRemoved = true;
textFormats.remove(currentFormat);
}
}

if (!wasRemoved) {
textFormats.add(newFormats.get(0));
}

return textFormats;
}

/**
Expand Down

0 comments on commit 9f8f01a

Please sign in to comment.