Giter Club home page Giter Club logo

prefs's Introduction

profile

prefs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

prefs's Issues

Static methods versus class

Hi,

I used below code for shared prefs. My friend suggested not use static methods. He advised me to use the class like you have implemented. Can you please suggest with which way we can improve performance.

    public static void saveStringPref(Context context, String key, String value) {

        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static String getStringPref(Context context, String key,
                                       String defaultValue) {
        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        return sharedPref.getString(key, defaultValue);
    }

    public static void saveIntPref(Context context, String key, int value) {

        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static int getIntPerf(Context context, String key,
                                 int defaultValue) {
        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        return sharedPref.getInt(key, defaultValue);
    }

    public static void saveBooleanPref(Context context, String key, boolean value) {

        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static boolean getBooleanPerf(Context context, String key,
                                         boolean defaultValue) {
        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        return sharedPref.getBoolean(key, defaultValue);
    }

    public static void deletePref(Context context, String key) {
        SharedPreferences sharedPref = context.getSharedPreferences(
                "Pref-Values", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.remove(key);
        editor.commit();
    }

Customize preferences file name

I notice by default this library handles preferences with the name 'preferences' but I think it would be cool to specify the name of the Shared Preference file the user wants to access.

Basically creating a call like:
Prefs.with(yourContext, "FILE NAME").readInt(YOUR_KEY_VALUE); having the second parameter optional, defaulting to the what the library does now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.