Small cleanup

This commit is contained in:
Dimitry Ivanov 2018-07-21 18:09:30 +03:00
parent 830ec9180b
commit 9e8ed10e70
3 changed files with 31 additions and 81 deletions

View File

@ -166,7 +166,7 @@ public class SpannableBuilder {
final int length = impl.length(); final int length = impl.length();
if (length > 0) { if (length > 0) {
int amount = 0; int amount = 0;
for (int i = length - 1; i >=0 ; i--) { for (int i = length - 1; i >= 0; i--) {
if (Character.isWhitespace(impl.charAt(i))) { if (Character.isWhitespace(impl.charAt(i))) {
amount += 1; amount += 1;
} else { } else {
@ -192,18 +192,35 @@ public class SpannableBuilder {
final boolean reverse = spanned instanceof SpannedReversed; final boolean reverse = spanned instanceof SpannedReversed;
final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class); final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class);
final int length = spans != null
? spans.length
: 0;
iterate(reverse, spans, new Action() { if (length > 0) {
@Override if (reverse) {
public void apply(Object o) { Object o;
setSpan( for (int i = length - 1; i >= 0; i--) {
o, o = spans[i];
index + spanned.getSpanStart(o), setSpan(
index + spanned.getSpanEnd(o), o,
spanned.getSpanFlags(o) index + spanned.getSpanStart(o),
); index + spanned.getSpanEnd(o),
spanned.getSpanFlags(o)
);
}
} else {
Object o;
for (int i = 0; i < length; i++) {
o = spans[i];
setSpan(
o,
index + spanned.getSpanStart(o),
index + spanned.getSpanEnd(o),
spanned.getSpanFlags(o)
);
}
} }
}); }
} }
} }
@ -221,25 +238,4 @@ public class SpannableBuilder {
this.flags = flags; this.flags = flags;
} }
} }
private interface Action {
void apply(Object o);
}
private static void iterate(boolean reverse, @Nullable Object[] array, @NonNull Action action) {
final int length = array != null
? array.length
: 0;
if (length > 0) {
if (reverse) {
for (int i = length - 1; i >= 0; i--) {
action.apply(array[i]);
}
} else {
for (int i = 0; i < length; i++) {
action.apply(array[i]);
}
}
}
}
} }

View File

@ -26,6 +26,9 @@ import ru.noties.markwon.spans.TableRowSpan;
import ru.noties.markwon.spans.TaskListSpan; import ru.noties.markwon.spans.TaskListSpan;
import ru.noties.markwon.spans.ThematicBreakSpan; import ru.noties.markwon.spans.ThematicBreakSpan;
/**
* @since 1.1.0
*/
public class SpannableFactoryDef implements SpannableFactory { public class SpannableFactoryDef implements SpannableFactory {
@NonNull @NonNull

View File

@ -23,55 +23,6 @@ import ru.noties.markwon.spans.SpannableTheme;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public class SpannableHtmlParser { public class SpannableHtmlParser {
// // creates default parser
// @NonNull
// public static SpannableHtmlParser create(
// @NonNull SpannableTheme theme,
// @NonNull AsyncDrawable.Loader loader
// ) {
// return builderWithDefaults(theme, loader, null, null, null)
// .build();
// }
//
// /**
// * @since 1.0.1
// */
// @NonNull
// public static SpannableHtmlParser create(
// @NonNull SpannableTheme theme,
// @NonNull AsyncDrawable.Loader loader,
// @NonNull ImageSizeResolver imageSizeResolver
// ) {
// return builderWithDefaults(theme, loader, null, null, imageSizeResolver)
// .build();
// }
//
// @NonNull
// public static SpannableHtmlParser create(
// @NonNull SpannableTheme theme,
// @NonNull AsyncDrawable.Loader loader,
// @NonNull UrlProcessor urlProcessor,
// @NonNull LinkSpan.Resolver resolver
// ) {
// return builderWithDefaults(theme, loader, urlProcessor, resolver, null)
// .build();
// }
// /**
// * @since 1.0.1
// */
// @NonNull
// public static SpannableHtmlParser create(
// @NonNull SpannableTheme theme,
// @NonNull AsyncDrawable.Loader loader,
// @NonNull UrlProcessor urlProcessor,
// @NonNull LinkSpan.Resolver resolver,
// @NonNull ImageSizeResolver imageSizeResolver
// ) {
// return builderWithDefaults(theme, loader, urlProcessor, resolver, imageSizeResolver)
// .build();
// }
/** /**
* @since 1.1.0 * @since 1.1.0
*/ */