Skip to content

Instantly share code, notes, and snippets.

View krupalshah's full-sized avatar
🎯
Focusing

krupal krupalshah

🎯
Focusing
View GitHub Profile
@krupalshah
krupalshah / PreferenceHelper.java
Last active August 12, 2018 10:01
helper for shared prefs - java version - Refactoring Step 1
public static void setStringPreference(Context context, String key, String value) {
edit(context, (editor) -> editor.putString(key, value));
}
@krupalshah
krupalshah / PreferenceHelper.java
Last active June 7, 2017 15:58
helper for shared prefs - java version - Refactoring step 1
private static void edit(Context context, Performer<SharedPreferences.Editor> performer) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
performer.performOperation(editor);
editor.apply();
}
public interface Performer<T> {
void performOperation(T victim);
}
@krupalshah
krupalshah / PreferenceHelper.java
Last active June 7, 2017 15:58
helper for shared prefs - java version
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
/**
* helper for shared prefs - java version
*/