Skip to content

Commit

Permalink
BraveNewPipeLegacy: (Kitkat) make sure seekbar_preview_thumbnail_high…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
evermind-zz committed Apr 25, 2024
1 parent 641cd73 commit c05e38c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.schabi.newpipe.settings;

public abstract class BraveVideoAudioSettingsBaseFragment extends BraveBasePreferenceFragment {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.schabi.newpipe.settings;

public abstract class BraveVideoAudioSettingsBaseFragment extends BraveBasePreferenceFragment {
}
7 changes: 7 additions & 0 deletions app/src/braveLegacy/java/org/schabi/newpipe/BraveApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Build;

import org.conscrypt.Conscrypt;
import org.schabi.newpipe.settings.BraveVideoAudioSettingsBaseFragment;
import org.schabi.newpipe.util.BraveTLSSocketFactory;

import java.security.Security;
Expand All @@ -24,6 +25,8 @@ public void onCreate() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
BraveTLSSocketFactory.setAsDefault();
}

makeConfigOptionsSuitableForFlavor();
}

/**
Expand All @@ -41,4 +44,8 @@ public void onCreate() {
public static Context getAppContext() {
return appContext;
}

private void makeConfigOptionsSuitableForFlavor() {
BraveVideoAudioSettingsBaseFragment.makeConfigOptionsSuitableForFlavor(getAppContext());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.LinkedList;
import java.util.List;

public class VideoAudioSettingsFragment extends BasePreferenceFragment {
public class VideoAudioSettingsFragment extends BraveVideoAudioSettingsBaseFragment {
private SharedPreferences.OnSharedPreferenceChangeListener listener;

@Override
Expand Down

0 comments on commit c05e38c

Please sign in to comment.