mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-22 16:10:31 +00:00
Ensure that imports handle disabling media tunneling correctly
Store in preferences whether media tunneling was disabled automatically. Show info in ExoPlayer settings if media tunneling was disabled autmatically.
This commit is contained in:
parent
8b63b437d8
commit
1db73370a7
@ -15,6 +15,7 @@ import android.widget.Toast;
|
|||||||
import androidx.activity.result.ActivityResult;
|
import androidx.activity.result.ActivityResult;
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@ -230,8 +231,11 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
})
|
})
|
||||||
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
manager.loadSharedPreferences(PreferenceManager
|
final Context context = requireContext();
|
||||||
.getDefaultSharedPreferences(requireContext()));
|
final SharedPreferences prefs = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(context);
|
||||||
|
manager.loadSharedPreferences(prefs);
|
||||||
|
cleanImport(context, prefs);
|
||||||
finishImport(importDataUri);
|
finishImport(importDataUri);
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
@ -243,6 +247,38 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove settings that are not supposed to be imported on different devices
|
||||||
|
* and reset them to default values.
|
||||||
|
* @param context the context used for the import
|
||||||
|
* @param prefs the preferences used while running the import
|
||||||
|
*/
|
||||||
|
private void cleanImport(@NonNull final Context context,
|
||||||
|
@NonNull final SharedPreferences prefs) {
|
||||||
|
// Check if media tunnelling needs to be disabled automatically,
|
||||||
|
// if it was disabled automatically in the imported preferences.
|
||||||
|
final String tunnelingKey = context.getString(R.string.disable_media_tunneling_key);
|
||||||
|
final String automaticTunnelingKey =
|
||||||
|
context.getString(R.string.disabled_media_tunneling_automatically_key);
|
||||||
|
// R.string.disable_media_tunneling_key should always be true
|
||||||
|
// if R.string.disabled_media_tunneling_automatically_key equals 1,
|
||||||
|
// but we double check here just to be sure and to avoid regressions
|
||||||
|
// caused by possible later modification of the media tunneling functionality.
|
||||||
|
// R.string.disabled_media_tunneling_automatically_key == 0:
|
||||||
|
// automatic value overridden by user in settings
|
||||||
|
// R.string.disabled_media_tunneling_automatically_key == -1: not set
|
||||||
|
final boolean wasMediaTunnelingEnabledAutomatically =
|
||||||
|
prefs.getInt(automaticTunnelingKey, -1) == 1
|
||||||
|
&& prefs.getBoolean(tunnelingKey, false);
|
||||||
|
if (wasMediaTunnelingEnabledAutomatically) {
|
||||||
|
prefs.edit()
|
||||||
|
.putInt(automaticTunnelingKey, -1)
|
||||||
|
.putBoolean(tunnelingKey, false)
|
||||||
|
.apply();
|
||||||
|
NewPipeSettings.setMediaTunneling(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save import path and restart system.
|
* Save import path and restart system.
|
||||||
*
|
*
|
||||||
|
@ -67,6 +67,9 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
|||||||
return ZipHelper.extractFileFromZip(file, fileLocator.settings.path, "newpipe.settings")
|
return ZipHelper.extractFileFromZip(file, fileLocator.settings.path, "newpipe.settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all shared preferences from the app and load the preferences supplied to the manager.
|
||||||
|
*/
|
||||||
fun loadSharedPreferences(preferences: SharedPreferences) {
|
fun loadSharedPreferences(preferences: SharedPreferences) {
|
||||||
try {
|
try {
|
||||||
val preferenceEditor = preferences.edit()
|
val preferenceEditor = preferences.edit()
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
package org.schabi.newpipe.settings;
|
package org.schabi.newpipe.settings;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.R;
|
||||||
|
|
||||||
public class ExoPlayerSettingsFragment extends BasePreferenceFragment {
|
public class ExoPlayerSettingsFragment extends BasePreferenceFragment {
|
||||||
|
|
||||||
@ -10,5 +16,30 @@ public class ExoPlayerSettingsFragment extends BasePreferenceFragment {
|
|||||||
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
|
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
|
||||||
@Nullable final String rootKey) {
|
@Nullable final String rootKey) {
|
||||||
addPreferencesFromResourceRegistry();
|
addPreferencesFromResourceRegistry();
|
||||||
|
|
||||||
|
final String disableMediaTunnelingAutomaticallyKey =
|
||||||
|
getString(R.string.disabled_media_tunneling_automatically_key);
|
||||||
|
final SwitchPreferenceCompat disableMediaTunnelingPref =
|
||||||
|
(SwitchPreferenceCompat) requirePreference(R.string.disable_media_tunneling_key);
|
||||||
|
final SharedPreferences prefs = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(requireContext());
|
||||||
|
final boolean mediaTunnelingAutomaticallyEnabled =
|
||||||
|
prefs.getInt(disableMediaTunnelingAutomaticallyKey, -1) == 1;
|
||||||
|
final String summaryText = getString(R.string.disable_media_tunneling_summary);
|
||||||
|
disableMediaTunnelingPref.setSummary(mediaTunnelingAutomaticallyEnabled
|
||||||
|
? summaryText + getString(R.string.disable_media_tunneling_automatic_info)
|
||||||
|
: summaryText);
|
||||||
|
|
||||||
|
disableMediaTunnelingPref.setOnPreferenceChangeListener((Preference p, Object enabled) -> {
|
||||||
|
if (Boolean.FALSE.equals(enabled)) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
.edit()
|
||||||
|
.putInt(disableMediaTunnelingAutomaticallyKey, 0)
|
||||||
|
.apply();
|
||||||
|
// the info text might have been shown before
|
||||||
|
p.setSummary(R.string.disable_media_tunneling_summary);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,8 @@ public final class NewPipeSettings {
|
|||||||
if (!DeviceUtils.shouldSupportMediaTunneling()) {
|
if (!DeviceUtils.shouldSupportMediaTunneling()) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
.putBoolean(context.getString(R.string.disable_media_tunneling_key), true)
|
.putBoolean(context.getString(R.string.disable_media_tunneling_key), true)
|
||||||
|
.putInt(context.getString(
|
||||||
|
R.string.disabled_media_tunneling_automatically_key), 1)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ public final class DeviceUtils {
|
|||||||
* See https://github.com/TeamNewPipe/NewPipe/issues/5911
|
* See https://github.com/TeamNewPipe/NewPipe/issues/5911
|
||||||
* @Note Add a new {@link org.schabi.newpipe.settings.SettingMigrations.Migration} which calls
|
* @Note Add a new {@link org.schabi.newpipe.settings.SettingMigrations.Migration} which calls
|
||||||
* {@link org.schabi.newpipe.settings.NewPipeSettings#setMediaTunneling(Context)}
|
* {@link org.schabi.newpipe.settings.NewPipeSettings#setMediaTunneling(Context)}
|
||||||
* when adding a new device to the method
|
* when adding a new device to the method.
|
||||||
* @return {@code false} if affected device; {@code true} otherwise
|
* @return {@code false} if affected device; {@code true} otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean shouldSupportMediaTunneling() {
|
public static boolean shouldSupportMediaTunneling() {
|
||||||
|
@ -1382,6 +1382,7 @@
|
|||||||
<!-- ExoPlayer settings -->
|
<!-- ExoPlayer settings -->
|
||||||
<string name="exoplayer_settings_key">exoplayer_settings_key</string>
|
<string name="exoplayer_settings_key">exoplayer_settings_key</string>
|
||||||
<string name="disable_media_tunneling_key">disable_media_tunneling_key</string>
|
<string name="disable_media_tunneling_key">disable_media_tunneling_key</string>
|
||||||
|
<string name="disabled_media_tunneling_automatically_key">disabled_media_tunneling_automatically_key</string>
|
||||||
<string name="use_exoplayer_decoder_fallback_key">use_exoplayer_decoder_fallback_key</string>
|
<string name="use_exoplayer_decoder_fallback_key">use_exoplayer_decoder_fallback_key</string>
|
||||||
<string name="always_use_exoplayer_set_output_surface_workaround_key">always_use_exoplayer_set_output_surface_workaround_key</string>
|
<string name="always_use_exoplayer_set_output_surface_workaround_key">always_use_exoplayer_set_output_surface_workaround_key</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -480,7 +480,8 @@
|
|||||||
<string name="show_original_time_ago_title">Show original time ago on items</string>
|
<string name="show_original_time_ago_title">Show original time ago on items</string>
|
||||||
<string name="show_original_time_ago_summary">Original texts from services will be visible in stream items</string>
|
<string name="show_original_time_ago_summary">Original texts from services will be visible in stream items</string>
|
||||||
<string name="disable_media_tunneling_title">Disable media tunneling</string>
|
<string name="disable_media_tunneling_title">Disable media tunneling</string>
|
||||||
<string name="disable_media_tunneling_summary">Disable media tunneling if you experience a black screen or stuttering on video playback</string>
|
<string name="disable_media_tunneling_summary">Disable media tunneling if you experience a black screen or stuttering on video playback.</string>
|
||||||
|
<string name="disable_media_tunneling_automatic_info">Media tunneling was disabled by default on your device because your device model is known to not support it.</string>
|
||||||
<string name="show_image_indicators_title">Show image indicators</string>
|
<string name="show_image_indicators_title">Show image indicators</string>
|
||||||
<string name="show_image_indicators_summary">Show Picasso colored ribbons on top of images indicating their source: red for network, blue for disk and green for memory</string>
|
<string name="show_image_indicators_summary">Show Picasso colored ribbons on top of images indicating their source: red for network, blue for disk and green for memory</string>
|
||||||
<string name="show_crash_the_player_title">Show \"Crash the player\"</string>
|
<string name="show_crash_the_player_title">Show \"Crash the player\"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user