Merge branch 'Bazsalanszky/fedilab-develop' into develop

This commit is contained in:
Thomas 2021-02-10 10:07:02 +01:00
commit efbad90f87
8 changed files with 162 additions and 0 deletions

View File

@ -229,6 +229,34 @@ public class SettingsActivity extends BaseActivity {
}
});
TextView set_libreddit_host = findViewById(R.id.set_libreddit_host);
String libredditHost = sharedpreferences.getString(Helper.SET_LIBREDDIT_HOST, null);
if (libredditHost != null) {
set_libreddit_host.setText(libredditHost);
}
set_libreddit_host.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.SET_LIBREDDIT_HOST, s.toString().toLowerCase().trim());
} else {
editor.putString(Helper.SET_LIBREDDIT_HOST, null);
}
editor.apply();
}
});
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
final SwitchCompat set_expand_cw = findViewById(R.id.set_expand_cw);

View File

@ -615,5 +615,19 @@
android:hint="@string/set_bibliogram_host"
android:inputType="textWebEditText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_libreddit"
android:textSize="16sp" />
<EditText
android:id="@+id/set_libreddit_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/settings_option_margin"
android:hint="@string/set_libreddit_host"
android:inputType="textWebEditText" />
</LinearLayout>
</ScrollView>

View File

@ -317,6 +317,17 @@ public class Status implements Parcelable {
}
}
matcher = Helper.libredditPattern.matcher(content);
boolean libreddit = Helper.getSharedValue(context, Helper.SET_LIBREDDIT);
if (libreddit) {
while (matcher.find()) {
final String libreddit_directory = matcher.group(3);
String libreddit_host = sharedpreferences.getString(Helper.SET_LIBREDDIT_HOST, Helper.DEFAULT_LIBREDDIT_HOST).toLowerCase();
content = content.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + libreddit_host +"/"+ libreddit_directory));
content = content.replaceAll(">" + Pattern.quote(matcher.group()), Matcher.quoteReplacement(">" + libreddit_host +"/"+ libreddit_directory));
}
}
matcher = Helper.ouichesPattern.matcher(content);
while (matcher.find()) {

View File

@ -2131,6 +2131,15 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + bibliogramHost + bibliogram_directory));
}
}
boolean libreddit = Helper.getSharedValue(context, Helper.SET_LIBREDDIT);
if (libreddit) {
Matcher matcher = Helper.libredditPattern.matcher(url);
while (matcher.find()) {
final String libreddit_directory = matcher.group(2);
String libredditHost = sharedpreferences.getString(Helper.SET_LIBREDDIT_HOST, Helper.DEFAULT_LIBREDDIT_HOST).toLowerCase();
url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + libredditHost +"/"+ libreddit_directory));
}
}
Helper.openBrowser(context, url);
});
} else if (card.getType().toLowerCase().equals("video") && (display_video_preview || (type == RetrieveFeedsAsyncTask.Type.CONTEXT && viewHolder.getAdapterPosition() == conversationPosition))) {

View File

@ -2309,7 +2309,53 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
editor.apply();
}
});
TextView set_libreddit_host = rootView.findViewById(R.id.set_libreddit_host);
boolean libreddit = Helper.getSharedValue(context, Helper.SET_LIBREDDIT);
final SwitchCompat set_libreddit = rootView.findViewById(R.id.set_libreddit);
set_libreddit.setChecked(libreddit);
set_libreddit.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_LIBREDDIT, set_libreddit.isChecked());
editor.apply();
if (set_libreddit.isChecked()) {
set_libreddit_host.setVisibility(View.VISIBLE);
} else {
set_libreddit_host.setVisibility(View.GONE);
}
});
if (libreddit) {
set_libreddit_host.setVisibility(View.VISIBLE);
} else {
set_libreddit_host.setVisibility(View.GONE);
}
String libredditHost = sharedpreferences.getString(Helper.SET_LIBREDDIT_HOST, null);
if (libredditHost != null) {
set_libreddit_host.setText(libredditHost);
}
set_libreddit_host.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.SET_LIBREDDIT_HOST, s.toString().toLowerCase().trim());
} else {
editor.putString(Helper.SET_LIBREDDIT_HOST, null);
}
editor.apply();
}
});
} else if (type == MENU) {
rootView = inflater.inflate(R.layout.fragment_settings_menu, container, false);

View File

@ -450,6 +450,10 @@ public class BaseHelper {
public static final String SET_BIBLIOGRAM_HOST = "set_bibliogram_host";
public static final String DEFAULT_BIBLIOGRAM_HOST = "bibliogram.art";
public static final String SET_LIBREDDIT = "set_libreddit";
public static final String SET_LIBREDDIT_HOST = "set_libreddit_host";
public static final String DEFAULT_LIBREDDIT_HOST = "libredd.it";
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";
@ -531,6 +535,7 @@ public class BaseHelper {
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
public static final Pattern bibliogramPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)");
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+&@#/%=~_|]");
//Default values

View File

@ -178,6 +178,51 @@
android:ellipsize="end"
android:hint="@string/set_bibliogram_host"
android:inputType="textWebEditText" />
<!-- libreddit -->
<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/set_libreddit"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_libreddit_indication"
android:textColor="@color/mastodonC2"
android:textSize="12sp" />
</LinearLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/set_libreddit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<EditText
android:id="@+id/set_libreddit_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:hint="@string/set_libreddit_host"
android:inputType="textWebEditText" />
<!-- utm parameters -->
<LinearLayout

View File

@ -1115,6 +1115,10 @@
<string name="set_bibliogram_indication">Bibliogram is an open source alternative Instagram front-end focused on privacy.</string>
<string name="set_bibliogram_host">Enter your custom host or leave blank for using bibliogram.art</string>
<string name="set_libreddit">Replace Reddit with Libreddit</string>
<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="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_live_type_indication">Notifications will be delayed every 30 seconds. That will allow to drain less battery.</string>