Allow to customize instances

This commit is contained in:
tom79 2019-09-04 17:16:57 +02:00
parent 17fda44c19
commit a10d9aa3c3
6 changed files with 48 additions and 3 deletions

View File

@ -648,7 +648,8 @@ public class Status implements Parcelable{
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));
String invidiousHost = sharedpreferences.getString(Helper.SET_INVIDIOUS_HOST, Helper.DEFAULT_INVIDIOUS_HOST);
content = content.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(invidiousHost + "/watch?v=" + youtubeId));
}
}

View File

@ -2587,7 +2587,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
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"));
String invidiousHost = sharedpreferences.getString(Helper.SET_INVIDIOUS_HOST, Helper.DEFAULT_INVIDIOUS_HOST);
url = url.replaceAll(Pattern.quote(matcher.group()), Matcher.quoteReplacement(invidiousHost+"/embed/" + youtubeId+"?feature=oembed"));
}
}

View File

@ -743,6 +743,10 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
set_blur_sensitive_text.setOnClickListener(v -> set_blur_sensitive.performClick());
TextView set_invidious_host = rootView.findViewById(R.id.set_invidious_host);
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false);
final CheckBox set_invidious = rootView.findViewById(R.id.set_invidious);
set_invidious.setChecked(invidious);
@ -753,6 +757,37 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_INVIDIOUS, set_invidious.isChecked());
editor.apply();
if( set_invidious.isChecked() ){
set_invidious_host.setVisibility(View.VISIBLE);
}else{
set_invidious_host.setVisibility(View.GONE);
}
}
});
if( invidious ){
set_invidious_host.setVisibility(View.VISIBLE);
}else{
set_invidious_host.setVisibility(View.GONE);
}
String invidiousHost = sharedpreferences.getString(Helper.SET_INVIDIOUS_HOST, null);
if( invidiousHost != null){
set_invidious_host.setText(invidiousHost);
}
set_invidious_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();
editor.putString(Helper.SET_INVIDIOUS_HOST, s.toString().trim());
editor.apply();
}
});

View File

@ -428,6 +428,8 @@ public class Helper {
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_INVIDIOUS_HOST = "set_invidious_host";
public static final String DEFAULT_INVIDIOUS_HOST = "invidio.us";
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";

View File

@ -182,6 +182,11 @@
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<EditText
android:hint="@string/set_invidious_host"
android:id="@+id/set_invidious_host"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout

View File

@ -1204,6 +1204,7 @@
<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">Replace Youtube with Invidio.us</string>
<string name="set_invidious_indication">Invidious is an alternative front-end to YouTube</string>
<string name="set_invidious_host">Enter your custom host or leave blank for using invidio.us</string>
</resources>