Commit 13469d6c authored by Geoffrey Métais's avatar Geoffrey Métais

Use settings cache to avoid I/O accesses

parent 493b173e
......@@ -43,7 +43,6 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.preference.PreferenceManager;
import android.text.TextUtils;
import org.videolan.libvlc.util.AndroidUtil;
......@@ -53,6 +52,7 @@ import org.videolan.vlc.gui.helpers.hf.OtgAccess;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.LiveDataset;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
......@@ -97,7 +97,7 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
private static void checkNewStorages(final Context ctx) {
if (VLCApplication.getMLInstance().isInitiated()) {
final int scanOpt = AndroidDevices.showTvUi(ctx) ? Constants.ML_SCAN_ON
: PreferenceManager.getDefaultSharedPreferences(ctx).getInt(Constants.KEY_MEDIALIBRARY_SCAN, -1);
: Settings.INSTANCE.getInstance(ctx).getInt(Constants.KEY_MEDIALIBRARY_SCAN, -1);
if (scanOpt == Constants.ML_SCAN_ON) new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
......@@ -174,7 +174,7 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
final String path = ((Uri) msg.obj).getPath();
removeMessages(ACTION_MEDIA_UNMOUNTED);
if (!TextUtils.isEmpty(uuid)
&& !PreferenceManager.getDefaultSharedPreferences(appCtx).getBoolean("ignore_" + uuid, false)) {
&& !Settings.INSTANCE.getInstance(appCtx).getBoolean("ignore_" + uuid, false)) {
final Medialibrary ml = VLCApplication.getMLInstance();
final String[] knownDevices = ml.getDevices();
if (!containsDevice(knownDevices, path) && ml.addDevice(uuid, path, true)) {
......
......@@ -36,7 +36,6 @@ import android.os.PowerManager
import android.support.v4.app.NotificationManagerCompat
import android.support.v4.content.ContextCompat
import android.support.v4.content.LocalBroadcastManager
import android.support.v7.preference.PreferenceManager
import android.text.TextUtils
import android.util.Log
import kotlinx.coroutines.experimental.*
......@@ -70,7 +69,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
private var notificationJob: Job? = null
@Volatile private var scanActivated = false
private val settings by lazy { PreferenceManager.getDefaultSharedPreferences(this) }
private val settings by lazy { Settings.getInstance(this) }
private var scanPaused = false
......
......@@ -28,7 +28,6 @@ import android.media.AudioManager
import android.media.audiofx.AudioEffect
import android.net.Uri
import android.os.*
import android.preference.PreferenceManager
import android.support.annotation.MainThread
import android.support.v4.app.NotificationManagerCompat
import android.support.v4.app.ServiceCompat
......@@ -448,7 +447,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
override fun onCreate() {
super.onCreate()
settings = PreferenceManager.getDefaultSharedPreferences(this)
settings = Settings.getInstance(this)
playlistManager = PlaylistManager(this)
Util.checkCpuCompatibility(this)
......
......@@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
......@@ -44,6 +43,7 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import videolan.org.commontools.TvChannelUtilsKt;
......@@ -80,7 +80,7 @@ public class StartActivity extends FragmentActivity implements StoragePermission
// Start application
/* Get the current version from package */
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences settings = Settings.INSTANCE.getInstance(this);
final int currentVersionNumber = BuildConfig.VERSION_CODE;
final int savedVersionNumber = settings.getInt(Constants.PREF_FIRST_RUN, -1);
/* Check if it's the first run */
......@@ -125,7 +125,7 @@ public class StartActivity extends FragmentActivity implements StoragePermission
private boolean showTvUi() {
return AndroidDevices.isAndroidTv || (!AndroidDevices.isChromeBook && !AndroidDevices.hasTsp) ||
PreferenceManager.getDefaultSharedPreferences(this).getBoolean("tv_ui", false);
Settings.INSTANCE.getInstance(this).getBoolean("tv_ui", false);
}
@Override
......
......@@ -11,7 +11,6 @@ import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
......@@ -19,6 +18,7 @@ import android.view.MenuItem;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.util.Settings;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -79,7 +79,7 @@ public class ExtensionsManager {
}
}
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences settings = Settings.INSTANCE.getInstance(context);
deleteUnusedExtensionPreferences(extensions, settings);
if (context instanceof MainActivity && ((MainActivity)context).getNavigator().currentIdIsExtension()) {
......@@ -113,7 +113,7 @@ public class ExtensionsManager {
}
public boolean previousExtensionIsEnabled(Context context) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences settings = Settings.INSTANCE.getInstance(context);
String key = EXTENSION_PREFIX + "_" + settings.getString("current_extension_name", null);
return settings.contains(key) && settings.getBoolean(key, false);
}
......@@ -183,9 +183,9 @@ public class ExtensionsManager {
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key, true).apply();
Settings.INSTANCE.getInstance(activity.getApplication()).edit().putBoolean(key, true).apply();
for (int i=0; i<extraTitles.size(); i++)
PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(extraKeys.get(i), extraCheckedStates[i]).apply();
Settings.INSTANCE.getInstance(activity.getApplication()).edit().putBoolean(extraKeys.get(i), extraCheckedStates[i]).apply();
displayPlugin(activity, id, extension, true);
activity.findViewById(R.id.navigation).postInvalidate();
}
......@@ -199,9 +199,9 @@ public class ExtensionsManager {
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key, false).apply();
Settings.INSTANCE.getInstance(activity.getApplication()).edit().putBoolean(key, false).apply();
for (int i=0; i<extraTitles.size(); i++)
PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(extraKeys.get(i), false).apply();
Settings.INSTANCE.getInstance(activity.getApplication()).edit().putBoolean(extraKeys.get(i), false).apply();
}
})
.show();
......
......@@ -2,7 +2,6 @@ package org.videolan.vlc.gui;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
......@@ -10,12 +9,12 @@ import android.support.v7.app.AppCompatDelegate;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Settings;
public class BaseActivity extends AppCompatActivity {
static {
AppCompatDelegate.setDefaultNightMode(VLCApplication.getAppContext() != null && PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("daynight", false) ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(VLCApplication.getAppContext() != null && Settings.INSTANCE.getInstance(VLCApplication.getAppContext()).getBoolean("daynight", false) ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
}
protected SharedPreferences mSettings;
......@@ -23,7 +22,7 @@ public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
/* Get settings */
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mSettings = Settings.INSTANCE.getInstance(this);
/* Theme must be applied before super.onCreate */
applyTheme();
super.onCreate(savedInstanceState);
......
......@@ -7,7 +7,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
......@@ -31,6 +30,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.SearchActivityBinding;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.WorkersKt;
public class SearchActivity extends AppCompatActivity implements TextWatcher, TextView.OnEditorActionListener {
......@@ -44,7 +44,7 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_black_theme", false))
if (Settings.INSTANCE.getInstance(this).getBoolean("enable_black_theme", false))
setTheme(R.style.Theme_VLC_Black);
final Intent intent = getIntent();
mBinding = DataBindingUtil.setContentView(this, R.layout.search_activity);
......
......@@ -29,7 +29,6 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.preference.PreferenceManager
import android.support.annotation.MainThread
import android.support.annotation.RequiresPermission
import android.support.constraint.ConstraintSet
......@@ -112,7 +111,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
super.onCreate(savedInstanceState)
savedInstanceState?.let { playerState = it.getInt("player_state")}
playlistAdapter = PlaylistAdapter(this)
settings = PreferenceManager.getDefaultSharedPreferences(activity)
settings = Settings.getInstance(requireContext())
helper = PlaybackServiceActivity.Helper(activity, this)
}
......
......@@ -24,7 +24,6 @@ import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableInt;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
......@@ -55,6 +54,7 @@ import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.EqualizerBar;
import org.videolan.vlc.interfaces.OnEqualizerBarChangeListener;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.VLCOptions;
import java.util.ArrayList;
......@@ -132,7 +132,7 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
allSets = new ArrayList<>();
allSets.addAll(Arrays.asList(getEqualizerPresets()));
presetCount = allSets.size();
for (Map.Entry<String, ?> entry : PreferenceManager.getDefaultSharedPreferences(context).getAll().entrySet()) {
for (Map.Entry<String, ?> entry : Settings.INSTANCE.getInstance(context).getAll().entrySet()) {
if (entry.getKey().startsWith("custom_equalizer_")) {
allSets.add(entry.getKey().replace("custom_equalizer_", "").replace("_", " "));
customCount++;
......
......@@ -41,6 +41,7 @@ import org.videolan.vlc.gui.helpers.ThreeStatesCheckbox
import org.videolan.vlc.repository.DirectoryRepository
import org.videolan.vlc.util.KEY_MEDIALIBRARY_SCAN
import org.videolan.vlc.util.ML_SCAN_ON
import org.videolan.vlc.util.Settings
internal class StorageBrowserAdapter(fragment: BaseBrowserFragment) : BaseBrowserAdapter(fragment) {
......@@ -97,7 +98,7 @@ internal class StorageBrowserAdapter(fragment: BaseBrowserFragment) : BaseBrowse
val state = tscb.state
if (state == ThreeStatesCheckbox.STATE_CHECKED) {
MedialibraryUtils.addDir(mrl)
val prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext().applicationContext)
val prefs = Settings.getInstance(v.getContext())
if (prefs.getInt(KEY_MEDIALIBRARY_SCAN, -1) != ML_SCAN_ON) prefs.edit().putInt(KEY_MEDIALIBRARY_SCAN, ML_SCAN_ON).apply()
} else
MedialibraryUtils.removeDir(mrl)
......
......@@ -38,7 +38,6 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateFormat;
......@@ -524,7 +523,7 @@ public class AdvOptionsDialog extends DismissDialogFragment implements View.OnCl
}
private void togglePassthrough() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AdvOptionsDialog.this.getContext());
final SharedPreferences prefs = Settings.INSTANCE.getInstance(AdvOptionsDialog.this.getContext());
boolean enabled = !VLCOptions.isAudioDigitalOutputEnabled(prefs);
if (mService.setAudioDigitalOutputEnabled(enabled)) {
mPassThrough.setCompoundDrawablesWithIntrinsicBounds(0,
......@@ -562,7 +561,7 @@ public class AdvOptionsDialog extends DismissDialogFragment implements View.OnCl
mService = service;
boolean tvUi = AndroidDevices.showTvUi(service);
int large_items = 0;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AdvOptionsDialog.this.getContext());
final SharedPreferences prefs = Settings.INSTANCE.getInstance(AdvOptionsDialog.this.getContext());
mAdapter.addOption(new Option(ID_SLEEP, R.attr.ic_sleep_normal_style, getString(R.string.sleep_title)));
mAdapter.addOption(new Option(ID_PLAYBACK_SPEED, R.attr.ic_speed_normal_style, getString(R.string.playback_speed)));
......@@ -657,7 +656,7 @@ public class AdvOptionsDialog extends DismissDialogFragment implements View.OnCl
private int mSelection = 0;
AdvOptionsAdapter() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AdvOptionsDialog.this.getContext());
final SharedPreferences prefs = Settings.INSTANCE.getInstance(AdvOptionsDialog.this.getContext());
if (!(prefs.getBoolean("enable_volume_gesture",false) || prefs.getBoolean("enable_volume_gesture",false)))
mSelection = 0;
}
......
......@@ -30,7 +30,6 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.preference.PreferenceManager;
import android.view.View;
import android.widget.EditText;
......@@ -40,6 +39,7 @@ import org.videolan.vlc.databinding.VlcLoginDialogBinding;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Settings;
public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding> implements View.OnFocusChangeListener {
......@@ -64,7 +64,7 @@ public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialog
@Override
public void onAttach(Context context) {
super.onAttach(context);
mSettings = PreferenceManager.getDefaultSharedPreferences(context);
mSettings = Settings.INSTANCE.getInstance(context);
}
public void onLogin(View v) {
......
......@@ -23,7 +23,6 @@ package org.videolan.vlc.gui.preferences;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.AppBarLayout;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
......@@ -32,6 +31,7 @@ import android.view.MenuItem;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.util.Settings;
@SuppressWarnings("deprecation")
public class PreferencesActivity extends AppCompatActivity implements PlaybackService.Client.Callback {
......@@ -110,7 +110,7 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
}
private void applyTheme() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences pref = Settings.INSTANCE.getInstance(this);
boolean enableBlackTheme = pref.getBoolean("enable_black_theme", false);
if (enableBlackTheme) {
setTheme(R.style.Theme_VLC_Black);
......
......@@ -3,7 +3,6 @@ package org.videolan.vlc.gui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.AppBarLayout;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
......@@ -14,6 +13,7 @@ import android.support.v7.preference.TwoStatePreference;
import org.videolan.vlc.R;
import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionsManager;
import org.videolan.vlc.util.Settings;
import java.util.ArrayList;
import java.util.List;
......@@ -33,7 +33,7 @@ public class PreferencesExtensionFragment extends BasePreferenceFragment {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mSettings = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplication());
mSettings = Settings.INSTANCE.getInstance(requireActivity());
setHasOptionsMenu(true);
if (bundle == null)
bundle = getArguments();
......
......@@ -5,7 +5,6 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.AppBarLayout;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
......@@ -17,6 +16,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.extensions.ExtensionListing;
import org.videolan.vlc.extensions.ExtensionsManager;
import org.videolan.vlc.gui.view.ClickableSwitchPreference;
import org.videolan.vlc.util.Settings;
import java.util.ArrayList;
import java.util.List;
......@@ -32,7 +32,7 @@ public class PreferencesExtensions extends BasePreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSettings = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplication());
mSettings = Settings.INSTANCE.getInstance(requireContext());
mExtensions = ExtensionsManager.getInstance().getExtensions(getActivity().getApplication(), false);
preferenceScreen = this.getPreferenceScreen();
}
......
......@@ -29,7 +29,6 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.support.v4.content.ContextCompat;
......@@ -46,6 +45,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.ImageLoaderKt;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import java.util.List;
......@@ -66,7 +66,7 @@ public class CardPresenter extends Presenter {
mContext = context;
mRes = mContext.getResources();
sDefaultCardImage = ContextCompat.getDrawable(mContext, R.drawable.ic_default_cone);
mIsSeenMediaMarkerVisible = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("media_seen", true);
mIsSeenMediaMarkerVisible = Settings.INSTANCE.getInstance(context).getBoolean("media_seen", true);
}
......
......@@ -29,7 +29,6 @@ import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v17.leanback.app.BackgroundManager
import android.support.v17.leanback.app.BrowseSupportFragment
import android.support.v17.leanback.widget.*
......@@ -93,7 +92,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
settings = PreferenceManager.getDefaultSharedPreferences(requireContext())
settings = Settings.getInstance(requireContext())
// Set display parameters for the BrowseFragment
headersState = BrowseSupportFragment.HEADERS_ENABLED
title = getString(R.string.app_name)
......
......@@ -28,7 +28,6 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
......@@ -50,6 +49,7 @@ import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.WorkersKt;
import org.videolan.vlc.viewmodels.PlaylistModel;
......@@ -138,7 +138,7 @@ public class AudioPlayerActivity extends BaseTvActivity implements PlaybackServi
public void update() {
if (mService == null || !mService.hasMedia()) return;
mBinding.buttonPlay.setImageResource(mService.isPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
final SharedPreferences mSettings= PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences mSettings= Settings.INSTANCE.getInstance(this);
if (mSettings.getBoolean(PreferencesActivity.VIDEO_RESTORE, false)) {
mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false).apply();
mService.getCurrentMediaWrapper().removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
......
......@@ -30,7 +30,6 @@ import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.widget.TextView;
......@@ -46,6 +45,7 @@ import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.tv.SearchActivity;
import org.videolan.vlc.gui.tv.TimeUpdaterKt;
import org.videolan.vlc.util.Settings;
import java.util.List;
......@@ -64,7 +64,7 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
if (savedInstanceState != null) MediaParsingServiceKt.startMedialibrary(this, false, false, true);
super.onCreate(savedInstanceState);
mMediaLibrary = VLCApplication.getMLInstance();
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mSettings = Settings.INSTANCE.getInstance(this);
registerLiveData();
new Handler().post(new Runnable() {
@Override
......
......@@ -35,7 +35,6 @@ import android.support.v17.leanback.widget.OnItemViewSelectedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v7.preference.PreferenceManager;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
......@@ -46,6 +45,7 @@ import org.videolan.vlc.gui.tv.TvUtil;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.gui.tv.browser.interfaces.DetailsFragment;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.viewmodels.browser.NetworkModel;
import java.util.List;
......@@ -60,7 +60,7 @@ public class BrowserGridFragment extends GridFragment implements OnItemViewSelec
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setOnItemViewSelectedListener(this);
setOnItemViewClickedListener(this); mShowHiddenFiles = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("browser_show_hidden_files", false);
setOnItemViewClickedListener(this); mShowHiddenFiles = Settings.INSTANCE.getInstance(requireContext()).getBoolean("browser_show_hidden_files", false);
provider = ViewModelProviders.of(this, new NetworkModel.Factory(requireContext(), null, mShowHiddenFiles)).get(NetworkModel.class);
provider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
......
......@@ -25,7 +25,6 @@ package org.videolan.vlc.gui.tv.browser
import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v17.leanback.app.BackgroundManager
import android.support.v17.leanback.app.BrowseSupportFragment
import android.support.v17.leanback.widget.*
......@@ -41,6 +40,7 @@ import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface
import org.videolan.vlc.interfaces.Sortable
import org.videolan.vlc.util.HEADER_DIRECTORIES
import org.videolan.vlc.util.HEADER_NETWORK
import org.videolan.vlc.util.Settings
import org.videolan.vlc.viewmodels.BaseModel
private const val TAG = "VLC/CategoriesFragment"
......@@ -53,7 +53,7 @@ open class CategoriesFragment<T : BaseModel<out MediaLibraryItem>> : BrowseSuppo
private lateinit var categoryRows: Map<String, ListRow>
lateinit var viewModel: T
private var restart = false
protected val preferences: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(requireContext()) }
protected val preferences: SharedPreferences by lazy { Settings.getInstance(requireContext()) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......
......@@ -28,7 +28,6 @@ import android.content.SharedPreferences
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.preference.PreferenceManager
import android.support.annotation.RequiresApi
import android.support.v17.leanback.app.BackgroundManager
import android.support.v17.leanback.widget.*
......@@ -39,6 +38,7 @@ import org.videolan.vlc.R
import org.videolan.vlc.gui.tv.TvUtil
import org.videolan.vlc.interfaces.Sortable
import org.videolan.vlc.util.AUDIO_ITEM
import org.videolan.vlc.util.Settings
import org.videolan.vlc.viewmodels.BaseModel
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
......@@ -47,7 +47,7 @@ abstract class MediaLibBrowserFragment<T : BaseModel<out MediaLibraryItem>> : Gr
private var mSelectedItem: Any? = null
lateinit var model: T
protected var currentItem: MediaLibraryItem? = null
protected val preferences: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(requireContext()) }
protected val preferences: SharedPreferences by lazy { Settings.getInstance(requireContext()) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......
......@@ -29,11 +29,11 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.viewmodels.BaseModel;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
......@@ -56,7 +56,7 @@ public abstract class MediaSortedFragment<T extends BaseModel<? extends MediaLib
if (intent != null)
mUri = intent.getData();
}
mShowHiddenFiles = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("browser_show_hidden_files", false);
mShowHiddenFiles = Settings.INSTANCE.getInstance(requireContext()).getBoolean("browser_show_hidden_files", false);
}
public void onPause(){
......
......@@ -28,12 +28,12 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.util.Settings;
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
......@@ -84,7 +84,7 @@ public class PreferencesActivity extends FragmentActivity implements PlaybackSer
}
private void applyTheme() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences pref = Settings.INSTANCE.getInstance(this);
boolean enableBlackTheme = pref.getBoolean("enable_black_theme", false);
if (enableBlackTheme) {
setTheme(R.style.Theme_VLC_Black);
......
......@@ -32,7 +32,6 @@ import android.os.Looper;
import android.os.Message;
import android.support.v4.app.NotificationCompat;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
......@@ -50,6 +49,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.view.PopupLayout;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
public class PopupManager implements PlaybackService.Callback, GestureDetector.OnDoubleTapListener,
View.OnClickListener, GestureDetector.OnGestureListener, IVLCVout.OnNewVideoLayoutListener, IVLCVout.Callback {
......@@ -72,7 +72,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
public PopupManager(PlaybackService service) {
mService = service;
mAlwaysOn = PreferenceManager.getDefaultSharedPreferences(service).getBoolean("popup_keepscreen", false);
mAlwaysOn = Settings.INSTANCE.getInstance(service).getBoolean("popup_keepscreen", false);
}