Commit 9ee0d1c1 authored by Geoffrey Métais's avatar Geoffrey Métais

Use cached SharedPreferences value

parent 7463d92d
......@@ -415,7 +415,7 @@ fun reload(ctx: Context) {
fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = launch(UI.immediate) {
if (Medialibrary.getInstance().isStarted || !Permissions.canReadStorage(this@startMedialibrary)) return@launch
val prefs = withContext(VLCIO) { VLCApplication.getSettings() ?: android.preference.PreferenceManager.getDefaultSharedPreferences(this@startMedialibrary) }
val prefs = withContext(VLCIO) { Settings.getInstance(this@startMedialibrary) }
val scanOpt = if (VLCApplication.showTvUi()) Constants.ML_SCAN_ON else prefs.getInt(Constants.KEY_MEDIALIBRARY_SCAN, -1)
if (parse && scanOpt == -1) {
if (dbExists(this@startMedialibrary)) prefs.edit().putInt(Constants.KEY_MEDIALIBRARY_SCAN, Constants.ML_SCAN_ON).apply()
......
......@@ -28,7 +28,6 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
......@@ -52,6 +51,7 @@ import org.videolan.vlc.gui.view.FastScroller;
import org.videolan.vlc.gui.view.SwipeRefreshLayout;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.viewmodels.audio.AlbumModel;
import org.videolan.vlc.viewmodels.audio.ArtistModel;
......@@ -101,7 +101,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mSettings == null) mSettings = PreferenceManager.getDefaultSharedPreferences(getContext());
if (mSettings == null) mSettings = Settings.INSTANCE.getInstance(requireContext());
setupAdapters(mSettings.getInt(Constants.KEY_AUDIO_CURRENT_TAB, 0));
}
......
......@@ -31,7 +31,6 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.preference.PreferenceManager
import android.support.v7.view.ActionMode
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
......@@ -45,7 +44,6 @@ import kotlinx.coroutines.experimental.withContext
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.databinding.DirectoryBrowserBinding
import org.videolan.vlc.gui.InfoActivity
import org.videolan.vlc.gui.dialogs.CtxActionReceiver
......@@ -104,7 +102,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
mrl = requireActivity().intent.dataString
requireActivity().intent = null
}
showHiddenFiles = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("browser_show_hidden_files", false)
showHiddenFiles = Settings.getInstance(requireContext()).getBoolean("browser_show_hidden_files", false)
isRootDirectory = defineIsRoot()
browserFavRepository = BrowserFavRepository.getInstance(requireContext())
}
......
......@@ -59,6 +59,7 @@ import org.videolan.vlc.interfaces.Filterable;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.util.WorkersKt;
import org.videolan.vlc.viewmodels.BaseModel;
......@@ -251,7 +252,7 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
final T provider = getViewModel();
provider.sort(sort);
final String key = provider.getKey();
VLCApplication.getSettings().edit()
Settings.INSTANCE.getInstance(requireContext()).edit()
.putInt(key, sort)
.putBoolean(key+"_desc", provider.getDesc())
.apply();
......
......@@ -63,6 +63,7 @@ import org.videolan.vlc.media.MediaGroup;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.media.PlaylistManager;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.viewmodels.VideosModel;
import java.util.ArrayList;
......@@ -80,8 +81,9 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mAdapter == null) {
mAdapter = new VideoListAdapter(this);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
final SharedPreferences preferences = Settings.INSTANCE.getInstance(requireContext());
final boolean seenMarkVisible = preferences.getBoolean("media_seen", true);
mAdapter = new VideoListAdapter(this, seenMarkVisible);
final int minGroupLengthValue = Integer.valueOf(preferences.getString("video_min_group_length", "6"));
viewModel = ViewModelProviders.of(requireActivity(), new VideosModel.Factory(mGroup, minGroupLengthValue, Medialibrary.SORT_DEFAULT)).get(VideosModel.class);
viewModel.getDataset().observe(this, this);
......
......@@ -65,11 +65,10 @@ public class VideoListAdapter extends DiffUtilAdapter<MediaWrapper, VideoListAda
private boolean mIsSeenMediaMarkerVisible;
VideoListAdapter(IEventsHandler eventsHandler) {
VideoListAdapter(IEventsHandler eventsHandler, boolean seenMarkVisible) {
super();
mEventsHandler = eventsHandler;
final SharedPreferences settings = VLCApplication.getSettings();
mIsSeenMediaMarkerVisible = settings == null || settings.getBoolean("media_seen", true);
mIsSeenMediaMarkerVisible = seenMarkVisible;
}
@Override
......
......@@ -27,16 +27,15 @@ import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v7.app.AppCompatActivity
import android.view.View
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.databinding.MlWizardActivityBinding
import org.videolan.vlc.startMedialibrary
import org.videolan.vlc.util.Constants
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.VLCIO
......@@ -54,7 +53,7 @@ class MLWizardActivity : AppCompatActivity() {
@Suppress("UNUSED_PARAMETER")
fun apply(v: View) = launch(VLCIO) {
val parse = binding.wizardCheckScan.isChecked
val prefs = VLCApplication.getSettings() ?: PreferenceManager.getDefaultSharedPreferences(this@MLWizardActivity)
val prefs = Settings.getInstance(this@MLWizardActivity)
prefs.edit().putInt(Constants.KEY_MEDIALIBRARY_SCAN, if (parse) Constants.ML_SCAN_ON else Constants.ML_SCAN_OFF).commit()
startMedialibrary(true, true, parse)
if (!isFinishing) finish()
......
......@@ -46,7 +46,6 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.repository.ExternalSubRepository;
......@@ -106,7 +105,7 @@ public class SubtitlesDownloader {
try {
languages = Collections.singleton(Locale.getDefault().getISO3Language().toLowerCase());
} catch (MissingResourceException ignored) {}
languages = VLCApplication.getSettings().getStringSet("languages_download_list", languages);
languages = Settings.INSTANCE.getInstance(context).getStringSet("languages_download_list", languages);
if (languages == null) { // In case getDefault().getISO3Language() fails
Toast.makeText(mContext, R.string.subs_dl_lang_fail, Toast.LENGTH_SHORT).show();
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment