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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.sbrowser.contentblocker; 18 package org.adblockplus.sbrowser.contentblocker;
19 19
20 import java.io.File; 20 import java.io.File;
21 import java.io.FileNotFoundException; 21 import java.io.FileNotFoundException;
22 import java.io.IOException; 22 import java.io.IOException;
23 23
24 import org.adblockplus.adblockplussbrowser.R; 24 import org.adblockplus.adblockplussbrowser.R;
25 import org.adblockplus.sbrowser.contentblocker.engine.Engine; 25 import org.adblockplus.sbrowser.contentblocker.engine.Engine;
26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; 26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
27 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
27 28
28 import android.content.ContentProvider; 29 import android.content.ContentProvider;
29 import android.content.ContentValues; 30 import android.content.ContentValues;
30 import android.content.Intent; 31 import android.content.Intent;
31 import android.content.SharedPreferences;
32 import android.database.Cursor; 32 import android.database.Cursor;
33 import android.net.Uri; 33 import android.net.Uri;
34 import android.os.Bundle; 34 import android.os.Bundle;
35 import android.os.ParcelFileDescriptor; 35 import android.os.ParcelFileDescriptor;
36 import android.preference.PreferenceManager;
37 import android.util.Log; 36 import android.util.Log;
38 37
39 public class ContentBlockerContentProvider extends ContentProvider 38 public class ContentBlockerContentProvider extends ContentProvider
40 { 39 {
41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl eName(); 40 private static final String TAG = ContentBlockerContentProvider.class.getSimpl eName();
42 41
43 @Override 42 @Override
44 public Bundle call(String method, String arg, Bundle extras) 43 public Bundle call(String method, String arg, Bundle extras)
45 { 44 {
46 // As of SBC interface v1.4 we return `null` here to signal that we do not 45 // As of SBC interface v1.4 we return `null` here to signal that we do not
47 // use encryption 46 // use encryption
48 return null; 47 return null;
49 } 48 }
50 49
51 private static boolean getBooleanPref(final SharedPreferences prefs, final Str ing key,
52 final boolean defValue)
53 {
54 try
55 {
56 return prefs.getBoolean(key, defValue);
57 }
58 catch (final Throwable t)
59 {
60 return defValue;
61 }
62 }
63
64 private void setApplicationActivated() 50 private void setApplicationActivated()
65 { 51 {
66 final SharedPreferences prefs = PreferenceManager 52 final boolean applicationActivated = SharedPrefsUtils.getBoolean(
67 .getDefaultSharedPreferences(this.getContext().getApplicationContext()); 53 this.getContext(), R.string.key_application_activated, false);
68 final String key = this.getContext().getString(R.string.key_application_acti vated); 54
69 final boolean applicationActived = getBooleanPref(prefs, key, false); 55 if (!applicationActivated)
70 if (!applicationActived)
71 { 56 {
72 prefs.edit() 57 SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_ac tivated, true);
73 .putBoolean(key, true)
74 .commit();
75 } 58 }
76 } 59 }
77 60
78 @Override 61 @Override
79 public ParcelFileDescriptor openFile(final Uri uri, final String mode) 62 public ParcelFileDescriptor openFile(final Uri uri, final String mode)
80 throws FileNotFoundException 63 throws FileNotFoundException
81 { 64 {
82 try 65 try
83 { 66 {
84 this.setApplicationActivated(); 67 this.setApplicationActivated();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return 0; 111 return 0;
129 } 112 }
130 113
131 @Override 114 @Override
132 public int update(final Uri uri, final ContentValues values, final String sele ction, 115 public int update(final Uri uri, final ContentValues values, final String sele ction,
133 final String[] selectionArgs) 116 final String[] selectionArgs)
134 { 117 {
135 return 0; 118 return 0;
136 } 119 }
137 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld