Support scribe.rip
This commit is contained in:
parent
39e12ceef9
commit
3c9fb0da26
|
@ -355,6 +355,22 @@ public class Status implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
matcher = Helper.mediumPattern.matcher(content);
|
||||
boolean medium = Helper.getSharedValue(context, Helper.REPLACE_MEDIUM);
|
||||
if (medium) {
|
||||
while (matcher.find()) {
|
||||
String path = matcher.group(2);
|
||||
String user = matcher.group(1);
|
||||
if (user != null && user.length() > 0 & !user.equals("www")) {
|
||||
path = user + "/" + path;
|
||||
}
|
||||
|
||||
String mediumReplaceHost = sharedpreferences.getString(Helper.REPLACE_MEDIUM_HOST, Helper.DEFAULT_REPLACE_MEDIUM_HOST).toLowerCase();
|
||||
content = content.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + mediumReplaceHost + "/" + path));
|
||||
content = content.replaceAll(">" + Pattern.quote(matcher.group()), Matcher.quoteReplacement(">" + mediumReplaceHost + "/" + path));
|
||||
}
|
||||
}
|
||||
|
||||
Pattern aLink = Pattern.compile("<a((?!href).)*href=\"([^\"]*)\"[^>]*(((?!</a).)*)</a>");
|
||||
Matcher matcherALink = aLink.matcher(content);
|
||||
int count = 0;
|
||||
|
|
|
@ -2256,6 +2256,54 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
EditText replace_medium_host_edit_text = rootView.findViewById(R.id.replace_medium_host);
|
||||
boolean replace_medium = Helper.getSharedValue(context, Helper.REPLACE_MEDIUM);
|
||||
final SwitchCompat replace_medium_switch = rootView.findViewById(R.id.replace_medium);
|
||||
replace_medium_switch.setChecked(replace_medium);
|
||||
|
||||
replace_medium_switch.setOnClickListener(v -> {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.REPLACE_MEDIUM, replace_medium_switch.isChecked());
|
||||
editor.apply();
|
||||
if (replace_medium_switch.isChecked()) {
|
||||
replace_medium_host_edit_text.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
replace_medium_host_edit_text.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
if (replace_medium) {
|
||||
replace_medium_host_edit_text.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
replace_medium_host_edit_text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
String replaceMediumHost = sharedpreferences.getString(Helper.REPLACE_MEDIUM_HOST, null);
|
||||
if (replaceMediumHost != null) {
|
||||
replace_medium_host_edit_text.setText(replaceMediumHost);
|
||||
}
|
||||
replace_medium_host_edit_text.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
if (s.toString().trim().length() > 0) {
|
||||
editor.putString(Helper.REPLACE_MEDIUM_HOST, s.toString().toLowerCase().trim());
|
||||
} else {
|
||||
editor.putString(Helper.REPLACE_MEDIUM_HOST, null);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
} else if (type == MENU) {
|
||||
rootView = inflater.inflate(R.layout.fragment_settings_menu, container, false);
|
||||
|
||||
|
|
|
@ -454,6 +454,10 @@ public class BaseHelper {
|
|||
public static final String SET_LIBREDDIT_HOST = "set_libreddit_host";
|
||||
public static final String DEFAULT_LIBREDDIT_HOST = "libredd.it";
|
||||
|
||||
public static final String REPLACE_MEDIUM = "replace_medium";
|
||||
public static final String REPLACE_MEDIUM_HOST = "medium_replace_host";
|
||||
public static final String DEFAULT_REPLACE_MEDIUM_HOST = "scribe.rip";
|
||||
|
||||
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";
|
||||
|
@ -538,6 +542,7 @@ public class BaseHelper {
|
|||
public static final Pattern libredditPattern = Pattern.compile("(www\\.|m\\.)?(reddit\\.com|preview\\.redd\\.it|i\\.redd\\.it|redd\\.it)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern ouichesPattern = Pattern.compile("https?://ouich\\.es/tag/(\\w+)");
|
||||
public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
|
||||
public static final Pattern mediumPattern = Pattern.compile("([\\w@-]*)?\\.?medium.com/@?([/\\w-]+)");
|
||||
//Default values
|
||||
public final static int DEFAULT_VIDEO_WIDTH = 640;
|
||||
public final static int DEFAULT_VIDEO_BITRATE = 450000;
|
||||
|
@ -4464,6 +4469,12 @@ public class BaseHelper {
|
|||
} else {
|
||||
return sharedpreferences.getBoolean(type, false);
|
||||
}
|
||||
} else if (type.compareTo(Helper.REPLACE_MEDIUM) == 0) {
|
||||
if (BuildConfig.lite) {
|
||||
return true;
|
||||
} else {
|
||||
return sharedpreferences.getBoolean(type, false);
|
||||
}
|
||||
} else if (type.compareTo(Helper.SET_CONSOLE_MODE) == 0) {
|
||||
if (BuildConfig.lite) {
|
||||
return false;
|
||||
|
|
|
@ -224,6 +224,52 @@
|
|||
android:hint="@string/set_libreddit_host"
|
||||
android:inputType="textWebEditText" />
|
||||
|
||||
<!-- Medium Replacement -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_option_margin"
|
||||
android:layout_marginBottom="@dimen/settings_option_margin"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/replace_medium"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/replace_medium_description"
|
||||
android:textColor="@color/mastodonC2"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/replace_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/replace_medium_host"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:hint="@string/replace_medium_host"
|
||||
android:inputType="textWebEditText" />
|
||||
|
||||
<!-- utm parameters -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1118,6 +1118,10 @@
|
|||
<string name="set_libreddit_indication">Libreddit is an open source alternative Reddit front-end focused on privacy.</string>
|
||||
<string name="set_libreddit_host">Enter your custom host or leave blank for using libredd.it</string>
|
||||
|
||||
<string name="replace_medium">Replace Medium links</string>
|
||||
<string name="replace_medium_description">Replace medium.com link with an open source alternative front-end focused on privacy.</string>
|
||||
<string name="replace_medium_host">Default: scribe.rip</string>
|
||||
|
||||
<string name="set_hide_status_bar">Hide Fedilab notification bar</string>
|
||||
<string name="set_hide_status_bar_indication">For hiding the remaining notification in the status bar, tap on the eye icon button then uncheck: \"Display in status bar\"</string>
|
||||
<string name="set_push_notifications">Use a push notifications system for getting notifications in real time.</string>
|
||||
|
|
Loading…
Reference in New Issue