Create text subpackage in util
This commit is contained in:
parent
cdd5e89b86
commit
22c201be39
14 changed files with 23 additions and 25 deletions
|
|
@ -51,7 +51,7 @@ import org.schabi.newpipe.extractor.search.SearchInfo;
|
|||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||
import org.schabi.newpipe.util.external_communication.TextLinkifier;
|
||||
import org.schabi.newpipe.util.text.TextLinkifier;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import static org.schabi.newpipe.util.TouchUtils.getOffsetForHorizontalLine;
|
||||
import static org.schabi.newpipe.util.text.TouchUtils.getOffsetForHorizontalLine;
|
||||
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
|
|
@ -12,7 +12,6 @@ import android.view.View;
|
|||
import android.widget.TextView;
|
||||
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
import org.schabi.newpipe.util.external_communication.InternalUrlsHandler;
|
||||
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
|
@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import org.schabi.newpipe.extractor.Info;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.views.LongPressClickableSpan;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
final class HashtagLongPressClickableSpan extends LongPressClickableSpan {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public abstract class LongPressClickableSpan extends ClickableSpan {
|
||||
|
||||
public abstract void onLongClick(@NonNull View view);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import static org.schabi.newpipe.util.text.TouchUtils.getOffsetForHorizontalLine;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.method.MovementMethod;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
// Class adapted from https://stackoverflow.com/a/31786969
|
||||
|
||||
public class LongPressLinkMovementMethod extends LinkMovementMethod {
|
||||
|
||||
private static final int LONG_PRESS_TIME = ViewConfiguration.getLongPressTimeout();
|
||||
|
||||
private static LongPressLinkMovementMethod instance;
|
||||
|
||||
private Handler longClickHandler;
|
||||
private boolean isLongPressed = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(@NonNull final TextView widget,
|
||||
@NonNull final Spannable buffer,
|
||||
@NonNull final MotionEvent event) {
|
||||
final int action = event.getAction();
|
||||
|
||||
if (action == MotionEvent.ACTION_CANCEL && longClickHandler != null) {
|
||||
longClickHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
|
||||
final int offset = getOffsetForHorizontalLine(widget, event);
|
||||
final LongPressClickableSpan[] link = buffer.getSpans(offset, offset,
|
||||
LongPressClickableSpan.class);
|
||||
|
||||
if (link.length != 0) {
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
if (longClickHandler != null) {
|
||||
longClickHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
if (!isLongPressed) {
|
||||
link[0].onClick(widget);
|
||||
}
|
||||
isLongPressed = false;
|
||||
} else {
|
||||
Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
|
||||
buffer.getSpanEnd(link[0]));
|
||||
if (longClickHandler != null) {
|
||||
longClickHandler.postDelayed(() -> {
|
||||
link[0].onLongClick(widget);
|
||||
isLongPressed = true;
|
||||
}, LONG_PRESS_TIME);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.onTouchEvent(widget, buffer, event);
|
||||
}
|
||||
|
||||
public static MovementMethod getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new LongPressLinkMovementMethod();
|
||||
instance.longClickHandler = new Handler(Looper.myLooper());
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
|
@ -15,8 +15,7 @@ import androidx.core.text.HtmlCompat;
|
|||
import org.schabi.newpipe.extractor.Info;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.views.LongPressClickableSpan;
|
||||
import org.schabi.newpipe.views.LongPressLinkMovementMethod;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -88,8 +87,7 @@ public final class TextLinkifier {
|
|||
@NonNull final CompositeDisposable disposables) {
|
||||
textView.setAutoLinkMask(Linkify.WEB_URLS);
|
||||
textView.setText(plainTextBlock, TextView.BufferType.SPANNABLE);
|
||||
changeIntentsOfDescriptionLinks(textView, textView.getText(), relatedInfo, disposables
|
||||
);
|
||||
changeIntentsOfDescriptionLinks(textView, textView.getText(), relatedInfo, disposables);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import static org.schabi.newpipe.util.external_communication.InternalUrlsHandler.playOnPopup;
|
||||
import static org.schabi.newpipe.util.text.InternalUrlsHandler.playOnPopup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
|
@ -10,7 +10,7 @@ import androidx.annotation.NonNull;
|
|||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||
import org.schabi.newpipe.views.LongPressClickableSpan;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.util;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.text.Layout;
|
||||
import android.view.MotionEvent;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.schabi.newpipe.util.external_communication;
|
||||
package org.schabi.newpipe.util.text;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.schabi.newpipe.views.LongPressClickableSpan;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue