Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java

Issue 29449601: Issue 5235 - Refactoring on SharedPrefs (Closed)
Patch Set: Fixing unregisterOnSharedPreferenceChangeListener using wrapper Created May 31, 2017, 2:33 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
===================================================================
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
@@ -19,64 +19,47 @@ package org.adblockplus.sbrowser.content
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.adblockplus.adblockplussbrowser.R;
import org.adblockplus.sbrowser.contentblocker.engine.Engine;
import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
+import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
-import android.preference.PreferenceManager;
import android.util.Log;
public class ContentBlockerContentProvider extends ContentProvider
{
private static final String TAG = ContentBlockerContentProvider.class.getSimpleName();
@Override
public Bundle call(String method, String arg, Bundle extras)
{
// As of SBC interface v1.4 we return `null` here to signal that we do not
// use encryption
return null;
}
- private static boolean getBooleanPref(final SharedPreferences prefs, final String key,
- final boolean defValue)
- {
- try
- {
- return prefs.getBoolean(key, defValue);
- }
- catch (final Throwable t)
- {
- return defValue;
- }
- }
-
private void setApplicationActivated()
{
- final SharedPreferences prefs = PreferenceManager
- .getDefaultSharedPreferences(this.getContext().getApplicationContext());
- final String key = this.getContext().getString(R.string.key_application_activated);
- final boolean applicationActived = getBooleanPref(prefs, key, false);
- if (!applicationActived)
+ final boolean applicationActivated = SharedPrefsUtils.getBoolean(
+ this.getContext(), R.string.key_application_activated, false);
+
+ if (!applicationActivated)
{
- prefs.edit()
- .putBoolean(key, true)
- .commit();
+ SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_activated, true);
}
}
@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode)
throws FileNotFoundException
{
try

Powered by Google App Engine
This is Rietveld