Support wikiless
This commit is contained in:
parent
cfd12ff64f
commit
66af3670c0
|
@ -371,6 +371,29 @@ public class Status implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
matcher = Helper.wikipediaPattern.matcher(content);
|
||||
boolean wikipedia = Helper.getSharedValue(context, Helper.REPLACE_WIKIPEDIA);
|
||||
if (wikipedia) {
|
||||
while (matcher.find()) {
|
||||
String subdomain = matcher.group(1);
|
||||
String path = matcher.group(2);
|
||||
String wikipediaReplaceHost = sharedpreferences.getString(Helper.REPLACE_WIKIPEDIA_HOST, Helper.DEFAULT_REPLACE_WIKIPEDIA_HOST).toLowerCase();
|
||||
String lang = "";
|
||||
if (path != null && subdomain != null && !subdomain.equals("www")) {
|
||||
lang = (path.contains("?")) ? TextUtils.htmlEncode("&") : "?";
|
||||
lang = lang + "lang=" + subdomain;
|
||||
}
|
||||
content = content.replaceAll(
|
||||
"https://" + Pattern.quote(matcher.group()),
|
||||
Matcher.quoteReplacement("https://" + wikipediaReplaceHost + "/" + path + lang)
|
||||
);
|
||||
content = content.replaceAll(
|
||||
">" + Pattern.quote(matcher.group()),
|
||||
Matcher.quoteReplacement(">" + wikipediaReplaceHost + "/" + path)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Pattern aLink = Pattern.compile("<a((?!href).)*href=\"([^\"]*)\"[^>]*(((?!</a).)*)</a>");
|
||||
Matcher matcherALink = aLink.matcher(content);
|
||||
int count = 0;
|
||||
|
|
|
@ -2304,6 +2304,54 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
EditText replace_wikipedia_host_edit_text = rootView.findViewById(R.id.replace_wikipedia_host);
|
||||
boolean replace_wikipedia = Helper.getSharedValue(context, Helper.REPLACE_WIKIPEDIA);
|
||||
final SwitchCompat replace_wikipedia_switch = rootView.findViewById(R.id.replace_wikipedia);
|
||||
replace_wikipedia_switch.setChecked(replace_wikipedia);
|
||||
|
||||
replace_wikipedia_switch.setOnClickListener(v -> {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.REPLACE_WIKIPEDIA, replace_wikipedia_switch.isChecked());
|
||||
editor.apply();
|
||||
if (replace_wikipedia_switch.isChecked()) {
|
||||
replace_wikipedia_host_edit_text.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
replace_wikipedia_host_edit_text.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
if (replace_wikipedia) {
|
||||
replace_wikipedia_host_edit_text.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
replace_wikipedia_host_edit_text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
String replaceWikipediaHost = sharedpreferences.getString(Helper.REPLACE_WIKIPEDIA_HOST, null);
|
||||
if (replaceWikipediaHost != null) {
|
||||
replace_wikipedia_host_edit_text.setText(replaceWikipediaHost);
|
||||
}
|
||||
replace_wikipedia_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_WIKIPEDIA_HOST, s.toString().toLowerCase().trim());
|
||||
} else {
|
||||
editor.putString(Helper.REPLACE_WIKIPEDIA_HOST, null);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
} else if (type == MENU) {
|
||||
rootView = inflater.inflate(R.layout.fragment_settings_menu, container, false);
|
||||
|
||||
|
|
|
@ -458,6 +458,10 @@ public class BaseHelper {
|
|||
public static final String REPLACE_MEDIUM_HOST = "medium_replace_host";
|
||||
public static final String DEFAULT_REPLACE_MEDIUM_HOST = "scribe.rip";
|
||||
|
||||
public static final String REPLACE_WIKIPEDIA = "replace_wikipedia";
|
||||
public static final String REPLACE_WIKIPEDIA_HOST = "wikipedia_replace_host";
|
||||
public static final String DEFAULT_REPLACE_WIKIPEDIA_HOST = "wikiless.org";
|
||||
|
||||
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";
|
||||
|
@ -543,6 +547,7 @@ public class BaseHelper {
|
|||
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-]+)");
|
||||
public static final Pattern wikipediaPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)");
|
||||
//Default values
|
||||
public final static int DEFAULT_VIDEO_WIDTH = 640;
|
||||
public final static int DEFAULT_VIDEO_BITRATE = 450000;
|
||||
|
@ -4475,6 +4480,12 @@ public class BaseHelper {
|
|||
} else {
|
||||
return sharedpreferences.getBoolean(type, false);
|
||||
}
|
||||
} else if (type.compareTo(Helper.REPLACE_WIKIPEDIA) == 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;
|
||||
|
|
|
@ -270,6 +270,52 @@
|
|||
android:hint="@string/replace_medium_host"
|
||||
android:inputType="textWebEditText" />
|
||||
|
||||
<!-- Wikipedia 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_wikipedia"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/replace_wikipedia_description"
|
||||
android:textColor="@color/mastodonC2"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/replace_wikipedia"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/replace_wikipedia_host"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:hint="@string/replace_wikipedia_host"
|
||||
android:inputType="textWebEditText" />
|
||||
|
||||
<!-- utm parameters -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1122,6 +1122,10 @@
|
|||
<string name="replace_medium_description">Replace medium.com links with an open source alternative front-end focused on privacy.</string>
|
||||
<string name="replace_medium_host">Default: scribe.rip</string>
|
||||
|
||||
<string name="replace_wikipedia">Replace Wikipedia links</string>
|
||||
<string name="replace_wikipedia_description">Replace Wikipedia link with an open source alternative front-end focused on privacy.</string>
|
||||
<string name="replace_wikipedia_host">Default: wikiless.org</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