BraveNewPipeLegacy: (Kitkat) make sure seekbar_preview_thumbnail_high_quality is not set

OutOfMemoryError will be triggered as the seekbar_preview_thumbnail generation is
allocating too much memory. This patch only allows low resolution until there
might be a better solution
This commit is contained in:
evermind 2024-04-09 08:38:10 +02:00
parent 641cd7366c
commit c05e38ca48
5 changed files with 86 additions and 1 deletions

View file

@ -0,0 +1,4 @@
package org.schabi.newpipe.settings;
public abstract class BraveVideoAudioSettingsBaseFragment extends BraveBasePreferenceFragment {
}

View file

@ -0,0 +1,4 @@
package org.schabi.newpipe.settings;
public abstract class BraveVideoAudioSettingsBaseFragment extends BraveBasePreferenceFragment {
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.os.Build; import android.os.Build;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;
import org.schabi.newpipe.settings.BraveVideoAudioSettingsBaseFragment;
import org.schabi.newpipe.util.BraveTLSSocketFactory; import org.schabi.newpipe.util.BraveTLSSocketFactory;
import java.security.Security; import java.security.Security;
@ -24,6 +25,8 @@ public class BraveApp extends MultiDexApplication {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
BraveTLSSocketFactory.setAsDefault(); BraveTLSSocketFactory.setAsDefault();
} }
makeConfigOptionsSuitableForFlavor();
} }
/** /**
@ -41,4 +44,8 @@ public class BraveApp extends MultiDexApplication {
public static Context getAppContext() { public static Context getAppContext() {
return appContext; return appContext;
} }
private void makeConfigOptionsSuitableForFlavor() {
BraveVideoAudioSettingsBaseFragment.makeConfigOptionsSuitableForFlavor(getAppContext());
}
} }

View file

@ -0,0 +1,70 @@
package org.schabi.newpipe.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import org.schabi.newpipe.R;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceManager;
public abstract class BraveVideoAudioSettingsBaseFragment extends BraveBasePreferenceFragment {
public static void makeConfigOptionsSuitableForFlavor(final Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return;
}
final SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(context);
// make sure seekbar thumbnail stuff is *not* set to high quality as it
// consumes to much memory which gives OutOfMemoryError Exception on Kitkat
// -> so default to low quality
// -> TODO long run fix the bug of the seekbar_preview_thumbnail implementation
final String seekBarOption = prefs.getString(context.getString(
R.string.seekbar_preview_thumbnail_key), null
);
if ((null == seekBarOption) || (seekBarOption.equals(
context.getString(R.string.seekbar_preview_thumbnail_high_quality)))) {
prefs.edit().putString(
context.getString(R.string.seekbar_preview_thumbnail_key),
context.getString(R.string.seekbar_preview_thumbnail_low_quality)).apply();
}
}
@Override
protected void manipulateCreatedPreferenceOptions() {
super.manipulateCreatedPreferenceOptions();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return;
}
setListPreferenceData();
}
private void setListPreferenceData() {
final ListPreference lp = (ListPreference) findPreference(
getString(R.string.seekbar_preview_thumbnail_key));
final CharSequence[] entries = {
getString(R.string.low_quality_smaller),
getString(R.string.dont_show)
};
final CharSequence[] entryValues = {
getString(R.string.seekbar_preview_thumbnail_low_quality),
getString(R.string.seekbar_preview_thumbnail_none)
};
lp.setEntries(entries);
lp.setEntryValues(entryValues);
// default value has to be set in BraveApp via the static
// method makeConfigOptionsSuitableForFlavor()
//lp.setDefaultValue(getString(R.string.seekbar_preview_thumbnail_low_quality));
//lp.setValueIndex(0);
}
}

View file

@ -19,7 +19,7 @@ import org.schabi.newpipe.util.PermissionHelper;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
public class VideoAudioSettingsFragment extends BasePreferenceFragment { public class VideoAudioSettingsFragment extends BraveVideoAudioSettingsBaseFragment {
private SharedPreferences.OnSharedPreferenceChangeListener listener; private SharedPreferences.OnSharedPreferenceChangeListener listener;
@Override @Override