Allow to replace YouTube videos with Invidious
This commit is contained in:
parent
50f51873f6
commit
40096e6de5
|
@ -642,8 +642,18 @@ public class Status implements Parcelable{
|
|||
content = content.replaceFirst(Pattern.quote(beforemodification), Matcher.quoteReplacement(urlText));
|
||||
}
|
||||
}
|
||||
Matcher matcher = Helper.youtubePattern.matcher(content);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false);
|
||||
if( invidious ) {
|
||||
while (matcher.find()) {
|
||||
final String youtubeId = matcher.group(2);
|
||||
content = content.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement("invidio.us/watch?v=" + youtubeId));
|
||||
|
||||
}
|
||||
}
|
||||
Pattern imgPattern = Pattern.compile("<img [^>]*src=\"([^\"]+)\"[^>]*>");
|
||||
Matcher matcher = imgPattern.matcher(content);
|
||||
matcher = imgPattern.matcher(content);
|
||||
List<String> imgs = new ArrayList<>();
|
||||
int i = 1;
|
||||
while (matcher.find()) {
|
||||
|
@ -807,32 +817,6 @@ public class Status implements Parcelable{
|
|||
spannableStringT.removeSpan(span);
|
||||
}
|
||||
|
||||
matcher = Helper.twitterPattern.matcher(spannableStringT);
|
||||
while (matcher.find()){
|
||||
int matchStart = matcher.start(2);
|
||||
int matchEnd = matcher.end();
|
||||
final String twittername = matcher.group(2);
|
||||
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
|
||||
spannableStringT.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View textView) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+twittername.substring(1).replace("@twitter.com","")));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
super.updateDrawState(ds);
|
||||
ds.setUnderlineText(false);
|
||||
if (theme == THEME_DARK)
|
||||
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
|
||||
else if (theme == THEME_BLACK)
|
||||
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
|
||||
else if (theme == THEME_LIGHT)
|
||||
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
|
||||
}
|
||||
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
if( accountsMentionUnknown.size() > 0 ) {
|
||||
|
||||
Iterator it = accountsMentionUnknown.entrySet().iterator();
|
||||
|
|
|
@ -2580,7 +2580,19 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.webview_preview.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
status.setWebviewURL(finalSrc);
|
||||
String url = finalSrc;
|
||||
if( url != null) {
|
||||
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false);
|
||||
Matcher matcher = Helper.youtubeOembedPattern.matcher(url);
|
||||
if (invidious) {
|
||||
while (matcher.find()) {
|
||||
final String youtubeId = matcher.group(2);
|
||||
url = url.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement("invidio.us/embed/" + youtubeId+"?feature=oembed"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
status.setWebviewURL(url);
|
||||
notifyStatusChanged(status);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -742,6 +742,20 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
|||
final LinearLayout set_blur_sensitive_text = rootView.findViewById(R.id.set_blur_sensitive_text);
|
||||
set_blur_sensitive_text.setOnClickListener(v -> set_blur_sensitive.performClick());
|
||||
|
||||
|
||||
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false);
|
||||
final CheckBox set_invidious = rootView.findViewById(R.id.set_invidious);
|
||||
set_invidious.setChecked(invidious);
|
||||
|
||||
set_invidious.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_INVIDIOUS, set_invidious.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
boolean long_press_media = sharedpreferences.getBoolean(Helper.SET_LONG_PRESS_MEDIA, true);
|
||||
final CheckBox set_long_press_media = rootView.findViewById(R.id.set_long_press_media);
|
||||
set_long_press_media.setChecked(long_press_media);
|
||||
|
|
|
@ -427,6 +427,7 @@ public class Helper {
|
|||
public static final String SET_FILTER_REGEX_LOCAL = "set_filter_regex_local";
|
||||
public static final String SET_FILTER_REGEX_PUBLIC = "set_filter_regex_public";
|
||||
|
||||
public static final String SET_INVIDIOUS = "set_invidious";
|
||||
public static final String SET_NOTIF_VALIDATION = "set_share_validation";
|
||||
public static final String SET_NOTIF_VALIDATION_FAV = "set_share_validation_fav";
|
||||
public static final String SET_WIFI_ONLY = "set_wifi_only";
|
||||
|
@ -513,6 +514,8 @@ public class Helper {
|
|||
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
|
||||
public static final Pattern groupPattern = Pattern.compile("(\\![\\w_]+(\\s|$))");
|
||||
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.)?youtube\\.com\\/watch\\?v=(\\w+)");
|
||||
public static final Pattern youtubeOembedPattern = Pattern.compile("(www\\.)?youtube\\.com\\/embed\\/(\\w+)\\?feature=oembed");
|
||||
private static final Pattern mentionPattern = Pattern.compile("(@[\\w_]+(\\s|$))");
|
||||
private static final Pattern mentionLongPattern = Pattern.compile("(@[\\w_-]+@[a-z0-9.\\-]+[.][a-z]{2,10})");
|
||||
public static final Pattern xmppPattern = Pattern.compile("xmpp\\:[-a-zA-Z0-9+$&@#\\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\\/%=~_|]");
|
||||
|
|
|
@ -153,6 +153,37 @@
|
|||
</SeekBar>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||
android:layout_marginBottom="@dimen/settings_checkbox_margin"
|
||||
android:orientation="horizontal">
|
||||
<CheckBox
|
||||
android:id="@+id/set_invidious"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:id="@+id/set_invidious_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:textSize="16sp"
|
||||
android:text="@string/set_invidious"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textColor="@color/mastodonC2"
|
||||
android:text="@string/set_invidious_indication"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -1204,4 +1204,6 @@
|
|||
<string name="set_allow_live_notifications_indication">Live notifications will be enabled for this account.</string>
|
||||
<string name="set_clear_cache_exit">Clear cache when leaving</string>
|
||||
<string name="set_clear_cache_exit_indication">The cache (media, cached messages, data from the built-in browser) will be automatically cleared when leaving the application.</string>
|
||||
<string name="set_invidious">Replace Youtuve with Invidio.us</string>
|
||||
<string name="set_invidious_indication">Invidious is an alternative front-end to YouTube</string>
|
||||
</resources>
|
Loading…
Reference in New Issue