SponsorBlock: Made entering the API Url more user-friendly
Added a custom preference to make the dialog easier to use (if a bit janky). Also did some related string refactoring.
This commit is contained in:
parent
639c238d3f
commit
b407ae4824
7 changed files with 204 additions and 6 deletions
|
@ -10,6 +10,7 @@ import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -143,7 +144,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
Preference sponsorBlockWebsitePreference =
|
Preference sponsorBlockWebsitePreference =
|
||||||
findPreference(getString(R.string.sponsorblock_home_page));
|
findPreference(getString(R.string.sponsorblock_home_page));
|
||||||
sponsorBlockWebsitePreference.setOnPreferenceClickListener((Preference p) -> {
|
sponsorBlockWebsitePreference.setOnPreferenceClickListener((Preference p) -> {
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://sponsor.ajay.app/"));
|
Intent i = new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse(getString(R.string.sponsorblock_homepage_url)));
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -152,12 +154,46 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
findPreference(getString(R.string.sponsorblock_privacy));
|
findPreference(getString(R.string.sponsorblock_privacy));
|
||||||
sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> {
|
sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> {
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW,
|
Intent i = new Intent(Intent.ACTION_VIEW,
|
||||||
Uri.parse(
|
Uri.parse(getString(R.string.sponsorblock_privacy_policy_url)));
|
||||||
"https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796"
|
|
||||||
+ "#requests-sent-to-the-server-while-using-the-extension"));
|
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Preference sponsorBlockApiUrlPreference =
|
||||||
|
findPreference(getString(R.string.sponsorblock_api_url));
|
||||||
|
|
||||||
|
// workaround to force dependency updates due to using a custom preference
|
||||||
|
sponsorBlockApiUrlPreference
|
||||||
|
.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
findPreference(getString(R.string.sponsorblock_enable))
|
||||||
|
.onDependencyChanged(preference,
|
||||||
|
newValue == null || newValue.equals(""));
|
||||||
|
findPreference(getString(R.string.sponsorblock_notifications))
|
||||||
|
.onDependencyChanged(preference,
|
||||||
|
newValue == null || newValue.equals(""));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
// workaround to force dependency updates due to using a custom preference
|
||||||
|
Preference sponsorBlockApiUrlPreference =
|
||||||
|
findPreference(getString(R.string.sponsorblock_api_url));
|
||||||
|
String sponsorBlockApiUrlPreferenceValue =
|
||||||
|
getPreferenceManager()
|
||||||
|
.getSharedPreferences()
|
||||||
|
.getString(getString(R.string.sponsorblock_api_url), null);
|
||||||
|
findPreference(getString(R.string.sponsorblock_enable))
|
||||||
|
.onDependencyChanged(sponsorBlockApiUrlPreference,
|
||||||
|
sponsorBlockApiUrlPreferenceValue == null
|
||||||
|
|| sponsorBlockApiUrlPreferenceValue.equals(""));
|
||||||
|
findPreference(getString(R.string.sponsorblock_notifications))
|
||||||
|
.onDependencyChanged(sponsorBlockApiUrlPreference,
|
||||||
|
sponsorBlockApiUrlPreferenceValue == null
|
||||||
|
|| sponsorBlockApiUrlPreferenceValue.equals(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
package org.schabi.newpipe.settings.custom;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.R;
|
||||||
|
|
||||||
|
public class SponsorBlockApiUrlPreference extends Preference {
|
||||||
|
public SponsorBlockApiUrlPreference(final Context context, final AttributeSet attrs,
|
||||||
|
final int defStyleAttr, final int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SponsorBlockApiUrlPreference(final Context context, final AttributeSet attrs,
|
||||||
|
final int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SponsorBlockApiUrlPreference(final Context context, final AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SponsorBlockApiUrlPreference(final Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
super.onClick();
|
||||||
|
|
||||||
|
View alertDialogView = LayoutInflater.from(getContext())
|
||||||
|
.inflate(R.layout.dialog_sponsorblock_api_url, null);
|
||||||
|
|
||||||
|
EditText editText = alertDialogView.findViewById(R.id.api_url_edit);
|
||||||
|
editText.setText(getSharedPreferences().getString(getKey(), null));
|
||||||
|
editText.setOnFocusChangeListener((v, hasFocus) -> editText.post(() -> {
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) getContext()
|
||||||
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager
|
||||||
|
.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}));
|
||||||
|
editText.requestFocus();
|
||||||
|
|
||||||
|
alertDialogView.findViewById(R.id.icon_api_url_help)
|
||||||
|
.setOnClickListener(v -> {
|
||||||
|
Uri privacyPolicyUri = Uri.parse(getContext()
|
||||||
|
.getString(R.string.sponsorblock_privacy_policy_url));
|
||||||
|
View helpDialogView = LayoutInflater.from(getContext())
|
||||||
|
.inflate(R.layout.dialog_sponsorblock_api_url_help, null);
|
||||||
|
View privacyPolicyButton = helpDialogView
|
||||||
|
.findViewById(R.id.sponsorblock_privacy_policy_button);
|
||||||
|
privacyPolicyButton.setOnClickListener(v1 -> {
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW, privacyPolicyUri);
|
||||||
|
getContext().startActivity(i);
|
||||||
|
});
|
||||||
|
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setView(helpDialogView)
|
||||||
|
.setPositiveButton("Use Official", (dialog, which) -> {
|
||||||
|
editText.setText(getContext()
|
||||||
|
.getString(R.string.sponsorblock_default_api_url));
|
||||||
|
dialog.dismiss();
|
||||||
|
})
|
||||||
|
.setNeutralButton("Close", (dialog, which) -> dialog.dismiss())
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog alertDialog =
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setView(alertDialogView)
|
||||||
|
.setTitle(getContext().getString(R.string.sponsorblock_api_url_title))
|
||||||
|
.setPositiveButton("OK", (dialog, which) -> {
|
||||||
|
String newValue = editText.getText().toString();
|
||||||
|
SharedPreferences.Editor editor =
|
||||||
|
getPreferenceManager().getSharedPreferences().edit();
|
||||||
|
editor.putString(getKey(), newValue);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
callChangeListener(newValue);
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
})
|
||||||
|
.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel())
|
||||||
|
.create();
|
||||||
|
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
}
|
33
app/src/main/res/layout/dialog_sponsorblock_api_url.xml
Normal file
33
app/src/main/res/layout/dialog_sponsorblock_api_url.xml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:clickable="false"
|
||||||
|
android:paddingLeft="@dimen/video_item_search_padding"
|
||||||
|
android:paddingRight="@dimen/video_item_search_padding"
|
||||||
|
android:paddingTop="@dimen/video_item_search_padding">
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/api_url_edit"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="6dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:saveEnabled="true"
|
||||||
|
android:inputType="textUri"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:hint="https://domain.com/api/"/>
|
||||||
|
<androidx.appcompat.widget.AppCompatImageButton
|
||||||
|
android:id="@+id/icon_api_url_help"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
app:srcCompat="@drawable/ic_help_white_24dp"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:tint="?attr/colorAccent"/>
|
||||||
|
</LinearLayout>
|
25
app/src/main/res/layout/dialog_sponsorblock_api_url_help.xml
Normal file
25
app/src/main/res/layout/dialog_sponsorblock_api_url_help.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:clickable="false"
|
||||||
|
android:paddingLeft="@dimen/video_item_search_padding"
|
||||||
|
android:paddingRight="@dimen/video_item_search_padding"
|
||||||
|
android:paddingTop="@dimen/video_item_search_padding">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/api_url_edit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginBottom="6dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="@string/sponsorblock_api_url_help_text"/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/sponsorblock_privacy_policy_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/sponsorblock_privacy_policy_text"/>
|
||||||
|
</LinearLayout>
|
|
@ -241,7 +241,7 @@
|
||||||
|
|
||||||
<string name="sponsorblock_home_page" translatable="false">sponsorblock_home_page</string>
|
<string name="sponsorblock_home_page" translatable="false">sponsorblock_home_page</string>
|
||||||
<string name="sponsorblock_enable" translatable="false">sponsorblock_enable</string>
|
<string name="sponsorblock_enable" translatable="false">sponsorblock_enable</string>
|
||||||
<string name="sponsorblock_api_url" translatable="false">sponsorblock_custom_api_url</string>
|
<string name="sponsorblock_api_url" translatable="false">sponsorblock_api_url</string>
|
||||||
<string name="sponsorblock_notifications" translatable="false">sponsorblock_notifications</string>
|
<string name="sponsorblock_notifications" translatable="false">sponsorblock_notifications</string>
|
||||||
<string name="sponsorblock_privacy" translatable="false">sponsorblock_privacy</string>
|
<string name="sponsorblock_privacy" translatable="false">sponsorblock_privacy</string>
|
||||||
|
|
||||||
|
|
|
@ -678,4 +678,9 @@
|
||||||
<string name="sponsorblock_notifications_summary">Show a toast notification when a sponsor is automatically skipped.</string>
|
<string name="sponsorblock_notifications_summary">Show a toast notification when a sponsor is automatically skipped.</string>
|
||||||
<string name="sponsorblock_privacy_title">View Privacy Policy</string>
|
<string name="sponsorblock_privacy_title">View Privacy Policy</string>
|
||||||
<string name="sponsorblock_privacy_summary">View SponsorBlock\'s privacy policy.</string>
|
<string name="sponsorblock_privacy_summary">View SponsorBlock\'s privacy policy.</string>
|
||||||
|
<string name="sponsorblock_api_url_help_text">This is the URL that will be queried when the application needs to know which parts of a video to skip.\n\nYou can set the official URL by clicking the \'Use Official\' option below, though it is highly recommended you view SponsorBlock\'s privacy policy before you do.</string>
|
||||||
|
<string name="sponsorblock_privacy_policy_text">SponsorBlock Privacy Policy</string>
|
||||||
|
<string name="sponsorblock_homepage_url">https://sponsor.ajay.app/</string>
|
||||||
|
<string name="sponsorblock_default_api_url">https://sponsor.ajay.app/api/</string>
|
||||||
|
<string name="sponsorblock_privacy_policy_url">https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796</string>
|
||||||
</resources>
|
</resources>
|
|
@ -134,7 +134,7 @@
|
||||||
android:title="@string/sponsorblock_privacy_title"
|
android:title="@string/sponsorblock_privacy_title"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<EditTextPreference
|
<org.schabi.newpipe.settings.custom.SponsorBlockApiUrlPreference
|
||||||
android:key="@string/sponsorblock_api_url"
|
android:key="@string/sponsorblock_api_url"
|
||||||
android:summary="@string/sponsorblock_api_url_summary"
|
android:summary="@string/sponsorblock_api_url_summary"
|
||||||
android:title="@string/sponsorblock_api_url_title"
|
android:title="@string/sponsorblock_api_url_title"
|
||||||
|
|
Loading…
Reference in a new issue