PreferncesUtils.java
package com.crosspayments.crosspay.crosspayments.Utils;
import android.content.Context;
import android.content.SharedPreferences;
public class PreferncesUtils {
public static final String PREFERENCE_NAME = "crosspay";
public static final String USER_ID = "userid";
public static final String EMAIL_ID = "emailid";
public static final String FIRST_NAME = "firstname";
public static final String LAST_NAME = "lastname";
public static final String PHONE_NUMBER = "phonenumber";
public static final String INTRO_ACTIVITY = "introactivity";
public static final String FROM_CODE = "fromcode";
public static final String TO_CODE = "tocode";
public static final String FROM_COUNTRY = "fromcountry";
public static final String TO_COUNTRY = "tocountry";
public static final String FROM_AMOUNT = "fromamount";
public static final String TO_AMOUNT = "toamount";
public static final String CASHCOMMISSION_FEE = "Cashcommissionfee";
public static final String ACCOUNTCREDIT_FEE = "AccountCreditFee";
public static final String RATE = "rate";
public static final String DISPLAY_USERID = "displayuserid";
public static final String PAYMENT_STATUS = "paymentstatus";
public static final String CHECK_STATUS = "checkstatus";
public static final String FCM_ID = "fcmid";
public static final String REF_CODE = "refcode";
public static final String SOURCE_ISO_CODE = "sourcecountryisocode";
public static final String DESTINATION_ISO_CODE = "destinationcountryisocode";
public static final String PROMO_CODE = "promocode";
public static final String PROMO_CODE_BALANCE = "promocodebalance";
public static final String RATE_US_POPUP = "rateuspopup";
public static final String USER_CATEGORY = "user_category";
public static final String CHARITYCOUNTRY_CODE = "Charitycountry_code";
public static final String CHARITY_MinAmount = "MinAmount";
public static final String CHARITY_MaxAmount = "MaxAmount";
public static final String COUNTRY = "COUNTRY";
public static final String customer_id = "customer_id";
public static void saveFloatValue(Context context, String key, float value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
editor.putFloat(key, value);
editor.apply();
}
public static float loadFloatValue(Context mContext, String from, float defValue) {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).getFloat(from, defValue);
}
public static void saveLongValue(Context context, String key, long value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
editor.putLong(key, value);
editor.apply();
}
public static long loadLongValue(Context mContext, String from, long defValue) {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).getLong(from, defValue);
}
//SharedPreferences String
public static void saveStringValue(Context context, String key, String value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
editor.putString(key, value);
editor.apply();
}
// PreferncesUtils.saveStringValue(LoginActivity.this,PreferncesUtils.PHONE_NUMBER,phonenumber);
// String phonenumber = PreferncesUtils.loadStringValue(LoginActivity.this,PreferncesUtils.PHONE_NUMBER,"");
public static String loadStringValue(Context mContext, String from, String defValue) {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).getString(from, defValue);
}
//SharedPreferences Integer
public static void saveIntegerValue(Context context, String key, int value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
editor.putInt(key, value);
editor.apply();
}
// PreferncesUtils.saveIntegerValue(IntroActivity.this,PreferncesUtils.INTRO_ACTIVITY,01);
// int intro_value=PreferncesUtils.loadIntegerValue(SplashActivity.this,PreferncesUtils.INTRO_ACTIVITY,0);
public static int loadIntegerValue(Context mContext, String from, int defValue) {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).getInt(from, defValue);
}
//SharedPreferences Boolean
public static void saveBooleanValue(Context context, String key, boolean value) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
editor.putBoolean(key, value);
editor.apply();
}
// PreferncesUtils.saveBooleanValue(IntroActivity.this,PreferncesUtils.INTRO_ACTIVITY,true);
// Boolean intro_value=PreferncesUtils.loadBooleanValue(IntroActivity.this,PreferncesUtils.INTRO_ACTIVITY,false);
public static boolean loadBooleanValue(Context mContext, String from, boolean defValue) {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).getBoolean(from, defValue);
}
}