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

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/util/SharedPrefsUtils.java

Issue 29760569: Issue 6238 - Download/store notifications.json (Closed)
Patch Set: Created May 15, 2018, 9:57 a.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 try 57 try
58 { 58 {
59 return preferences.getInt(context.getString(keyResId), defValue); 59 return preferences.getInt(context.getString(keyResId), defValue);
60 } 60 }
61 catch (ClassCastException e) 61 catch (ClassCastException e)
62 { 62 {
63 return defValue; 63 return defValue;
64 } 64 }
65 } 65 }
66 66
67 public static void putLong(final Context context, final int keyResId, final lo ng value)
68 {
69 final SharedPreferences.Editor editor = getDefaultSharedPreferences(context) .edit();
70 editor.putLong(context.getString(keyResId), value).apply();
71 }
72
73 public static long getLong(final Context context, final int keyResId, final lo ng defValue)
74 {
75 final SharedPreferences preferences = getDefaultSharedPreferences(context);
76 try
77 {
78 return preferences.getLong(context.getString(keyResId), defValue);
79 }
80 catch (final ClassCastException e)
81 {
82 return defValue;
83 }
84 }
85
67 public static void putString(Context context, int keyResId, String value) 86 public static void putString(Context context, int keyResId, String value)
68 { 87 {
69 final SharedPreferences.Editor editor = getDefaultSharedPreferences(context) .edit(); 88 final SharedPreferences.Editor editor = getDefaultSharedPreferences(context) .edit();
70 editor.putString(context.getString(keyResId), value).apply(); 89 editor.putString(context.getString(keyResId), value).apply();
71 } 90 }
72 91
73 public static String getString(Context context, int keyResId, String defValue) 92 public static String getString(Context context, int keyResId, String defValue)
74 { 93 {
75 final SharedPreferences preferences = getDefaultSharedPreferences(context); 94 final SharedPreferences preferences = getDefaultSharedPreferences(context);
76 try 95 try
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 144
126 @Override 145 @Override
127 public final void onSharedPreferenceChanged(SharedPreferences sharedPreferen ces, String key) 146 public final void onSharedPreferenceChanged(SharedPreferences sharedPreferen ces, String key)
128 { 147 {
129 this.onSharedPreferenceChanged(key); 148 this.onSharedPreferenceChanged(key);
130 } 149 }
131 150
132 protected abstract void onSharedPreferenceChanged(String key); 151 protected abstract void onSharedPreferenceChanged(String key);
133 } 152 }
134 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld