com.f2prateek.rx.preferences.RxSharedPreferences Java Examples

The following examples show how to use com.f2prateek.rx.preferences.RxSharedPreferences. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserPreferences.java    From android with Apache License 2.0 5 votes vote down vote up
public UserPreferences(SharedPreferences preferences, Moshi moshi) {
  RxSharedPreferences rxSharedPreferences = RxSharedPreferences.create(preferences);
  JsonAdapter<Nation> nationAdapter = moshi.adapter(Nation.class);
  JsonAdapter<Club> clubAdapter = moshi.adapter(Club.class);
  JsonAdapter<League> leagueAdapter = moshi.adapter(League.class);
  nationPreference = new JsonPreference<>(rxSharedPreferences, nationAdapter, KEY_USER_NATION);
  clubPreference = new JsonPreference<>(rxSharedPreferences, clubAdapter, KEY_USER_CLUB);
  leaguePreference = new JsonPreference<>(rxSharedPreferences, leagueAdapter, KEY_USER_LEAGUE);
  coachPreference = rxSharedPreferences.getString(KEY_COACH_NAME);
  coinsPreference = rxSharedPreferences.getLong(KEY_COINS);
  gameSpeedPreference = rxSharedPreferences.getInteger(KEY_GAME_SPEED, DEFAULT_GAME_SPEED);
}
 
Example #2
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@PixelRatioEnabled
Preference<Boolean> providePixelRatioEnabled(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_pixel_ratio_enabled", DEFAULT_PIXEL_RATIO_ENABLED);
}
 
Example #3
Source File: TelescopeViewContainer.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Inject public TelescopeViewContainer(LumberYard lumberYard, RxSharedPreferences preferences) {
  this.lumberYard = lumberYard;
  this.seenTelescopeDialog = preferences.getBoolean("internal-seen-telescope-dialog", false);
}
 
Example #4
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@SeenDebugDrawer
Preference<Boolean> provideSeenDebugDrawer(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_seen_debug_drawer", DEFAULT_SEEN_DEBUG_DRAWER);
}
 
Example #5
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@ScalpelEnabled
Preference<Boolean> provideScalpelEnabled(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_scalpel_enabled", DEFAULT_SCALPEL_ENABLED);
}
 
Example #6
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@ScalpelWireframeEnabled
Preference<Boolean> provideScalpelWireframeEnabled(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_scalpel_wireframe_drawer", DEFAULT_SCALPEL_WIREFRAME_ENABLED);
}
 
Example #7
Source File: InternalReleaseDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
RxSharedPreferences provideRxSharedPreferences(SharedPreferences preferences) {
    return RxSharedPreferences.create(preferences);
}
 
Example #8
Source File: TelescopeViewContainer.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Inject public TelescopeViewContainer(LumberYard lumberYard, RxSharedPreferences preferences) {
    this.lumberYard = lumberYard;
    this.seenTelescopeDialog = preferences.getBoolean("internal-seen-telescope-dialog", false);
}
 
Example #9
Source File: DataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton RxSharedPreferences provideRxSharedPreferences(SharedPreferences prefs) {
  return RxSharedPreferences.create(prefs);
}
 
Example #10
Source File: DataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @AccessToken
Preference<String> provideAccessToken(RxSharedPreferences prefs) {
  return prefs.getString("access-token");
}
 
Example #11
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton RxSharedPreferences provideRxSharedPreferences(SharedPreferences prefs) {
  return RxSharedPreferences.create(prefs);
}
 
Example #12
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @AccessToken Preference<String> provideAccessToken(RxSharedPreferences prefs,
    @ApiEndpoint Preference<String> endpoint) {
  // Return an endpoint-specific preference.
  return prefs.getString("access-token-" + endpoint.get());
}
 
Example #13
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @ApiEndpoint
Preference<String> provideEndpointPreference(RxSharedPreferences preferences) {
  return preferences.getString("debug_endpoint", ApiEndpoints.MOCK_MODE.url);
}
 
Example #14
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @NetworkDelay
Preference<Long> provideNetworkDelay(RxSharedPreferences preferences) {
  return preferences.getLong("debug_network_delay", 2000l);
}
 
Example #15
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @NetworkFailurePercent
Preference<Integer> provideNetworkFailurePercent(RxSharedPreferences preferences) {
  return preferences.getInteger("debug_network_failure_percent", 3);
}
 
Example #16
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @NetworkErrorPercent
Preference<Integer> provideNetworkErrorPercent(RxSharedPreferences preferences) {
  return preferences.getInteger("debug_network_error_percent", 0);
}
 
Example #17
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton
Preference<NetworkErrorCode> provideNetworkErrorCode(RxSharedPreferences preferences) {
  return preferences.getEnum("debug_network_error_code", NetworkErrorCode.HTTP_500,
      NetworkErrorCode.class);
}
 
Example #18
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @NetworkVariancePercent
Preference<Integer> provideNetworkVariancePercent(RxSharedPreferences preferences) {
  return preferences.getInteger("debug_network_variance_percent", 40);
}
 
Example #19
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton
Preference<InetSocketAddress> provideNetworkProxyAddress(RxSharedPreferences preferences) {
  return preferences.getObject("debug_network_proxy",
      InetSocketAddressPreferenceAdapter.INSTANCE);
}
 
Example #20
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @CaptureIntents
Preference<Boolean> provideCaptureIntentsPreference(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_capture_intents", DEFAULT_CAPTURE_INTENTS);
}
 
Example #21
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @AnimationSpeed
Preference<Integer> provideAnimationSpeed(RxSharedPreferences preferences) {
  return preferences.getInteger("debug_animation_speed", DEFAULT_ANIMATION_SPEED);
}
 
Example #22
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @PicassoDebugging
Preference<Boolean> providePicassoDebugging(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_picasso_debugging", DEFAULT_PICASSO_DEBUGGING);
}
 
Example #23
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @PixelGridEnabled
Preference<Boolean> providePixelGridEnabled(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_pixel_grid_enabled", DEFAULT_PIXEL_GRID_ENABLED);
}
 
Example #24
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @PixelRatioEnabled
Preference<Boolean> providePixelRatioEnabled(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_pixel_ratio_enabled", DEFAULT_PIXEL_RATIO_ENABLED);
}
 
Example #25
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @SeenDebugDrawer
Preference<Boolean> provideSeenDebugDrawer(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_seen_debug_drawer", DEFAULT_SEEN_DEBUG_DRAWER);
}
 
Example #26
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @ScalpelEnabled
Preference<Boolean> provideScalpelEnabled(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_scalpel_enabled", DEFAULT_SCALPEL_ENABLED);
}
 
Example #27
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @ScalpelWireframeEnabled
Preference<Boolean> provideScalpelWireframeEnabled(RxSharedPreferences preferences) {
  return preferences.getBoolean("debug_scalpel_wireframe_drawer",
      DEFAULT_SCALPEL_WIREFRAME_ENABLED);
}
 
Example #28
Source File: JsonPreference.java    From android with Apache License 2.0 4 votes vote down vote up
JsonPreference(RxSharedPreferences rxSharedPreferences, JsonAdapter<T> adapter, String key) {
  this.adapter = adapter;
  this.rxPreference = rxSharedPreferences.getString(key);
}
 
Example #29
Source File: ApplicationModule.java    From ViewInspector with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @ViewFilter Preference<Set<String>> provideViewFilterSet(
    RxSharedPreferences prefs) {
  return prefs.getStringSet("viewFilter", new HashSet<String>());
}
 
Example #30
Source File: MethodInfo.java    From Favor with Apache License 2.0 4 votes vote down vote up
private void parseMethodAnnotations() {
        for (Annotation methodAnnotation : method.getAnnotations()) {
            Class<? extends Annotation> annotationType = methodAnnotation.annotationType();

            if (annotationType == Favor.class) {
                key = ((Favor) methodAnnotation).value();
                if (key.trim().length() == 0) {
                    key = getKeyFromMethod(method);
                }
                if (!TextUtils.isEmpty(prefix)) {
                    key = prefix + key;
                }
            } else if (annotationType == Default.class) {
                defaultValues = ((Default) methodAnnotation).value();
            } else if (annotationType == Commit.class) {
                commit = true;
            }
        }

        if (allFavor && key == null) {
            key = getKeyFromMethod(method);
            if (!TextUtils.isEmpty(prefix)) {
                key = prefix + key;
            }
        }

        if (responseType == ResponseType.OBSERVABLE) {
            checkDefaultValueType(responseObjectType, defaultValues);
            if (commit) {
                Log.w(TAG, "@Commit will be ignored for RxReference");
            }
            RxSharedPreferences rx = RxSharedPreferences.create(sp);
            if (responseObjectType == String.class) {
                rxPref = rx.getString(key, defaultValues[0]);
            } else if (responseObjectType == Integer.class) {
                rxPref = rx.getInteger(key, defaultValues[0] == null ? null : Integer.valueOf(defaultValues[0]));
            } else if (responseObjectType == Float.class) {
                rxPref = rx.getFloat(key, defaultValues[0] == null ? null : Float.valueOf(defaultValues[0]));
            } else if (responseObjectType == Long.class) {
                rxPref = rx.getLong(key, defaultValues[0] == null ? null : Long.valueOf(defaultValues[0]));
            } else if (responseObjectType == Boolean.class) {
                rxPref = rx.getBoolean(key, defaultValues[0] == null ? null : Boolean.valueOf(defaultValues[0]));
            } else if (Serializable.class.isAssignableFrom(Types.getRawType(responseObjectType))) {
                rxPref = rx.getObject(key, new SerializableAdapter<>());
            } else {
//                        Class returnTypeClass = Types.getRawType(returnType);
//                        if (returnTypeClass == Set.class) {
//                            rxPref = rx.getStringSet(key,new HashSet<String>(defaultValues))
//                        }
            }
        } else {
            if (FavorType == String.class) {
                taste = new Taste.StringTaste(sp, key, defaultValues);
            } else if (FavorType == boolean.class) {
                taste = new Taste.BoolTaste(sp, key, defaultValues);
            } else if (FavorType == int.class) {
                taste = new Taste.IntTaste(sp, key, defaultValues);
            } else if (FavorType == float.class) {
                taste = new Taste.FloatTaste(sp, key, defaultValues);
            } else if (FavorType == long.class) {
                taste = new Taste.LongTaste(sp, key, defaultValues);
            } else if (Types.getRawType(FavorType) == Set.class) {
                taste = new Taste.StringSetTaste(sp, key, defaultValues);
            } else if (Serializable.class.isAssignableFrom(Types.getRawType(FavorType))) {
                taste = new Taste.SerializableTaste(sp, key, defaultValues);
            } else {
                taste = new Taste.EmptyTaste(sp, key, defaultValues);
                throw methodError("Unsupported type " + FavorType.toString());
            }
        }
    }