com.f2prateek.rx.preferences.Preference Java Examples

The following examples show how to use com.f2prateek.rx.preferences.Preference. 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: MatchResultController.java    From android with Apache License 2.0 6 votes vote down vote up
/** Updates the current user club based on the provided match result */
public void updateWithResult(MatchResult result) {
  JsonPreference<Club> userClubPref = userPreferences.clubPreference();
  Preference<Long> userCoinsPref = userPreferences.coinsPreference();
  int goalDiff = Math.abs(result.homeGoals().size() - result.awayGoals().size());
  if (!result.isDraw()) {
    if (userClub.nameEquals(result.winner())) {
      // user is winner
      userClubPref.set(userClub.newWithWin(goalDiff));
      userCoinsPref.set(userPreferences.coins() + UserPreferences.COINS_PRIZE_WIN);
    } else {
      // computer is winner
      userClubPref.set(userClub.newWithLoss(-goalDiff));
    }
  } else {
    // match result is draw
    userClubPref.set(userClub.newWithDraw());
    userCoinsPref.set(userPreferences.coins() + UserPreferences.COINS_PRIZE_DRAW);
  }
}
 
Example #2
Source File: ApplicationTest.java    From Favor with Apache License 2.0 6 votes vote down vote up
public void testRxSharePreference() {
    Preference<String> name = profile.name();
    assertNotNull(name);
    assertEquals("No Name", name.get());
    Preference<Boolean> gender = profile.gender();

    remove("gender");

    assertNotNull(gender);
    gender.set(true);
    sleep(2000);
    assertTrue(gender.get());
    assertTrue(sp().getBoolean("gender", false));

    gender.delete();
    sleep(2000);
    assertNull(gender.get());
}
 
Example #3
Source File: DebugApiModule.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
@Provides
@ApplicationScope
NetworkBehavior provideBehavior(@NetworkDelay Preference<Long> networkDelay,
                                @NetworkFailurePercent Preference<Integer> networkFailurePercent,
                                @NetworkVariancePercent Preference<Integer> networkVariancePercent) {
    NetworkBehavior behavior = NetworkBehavior.create();
    behavior.setDelay(networkDelay.get(), MILLISECONDS);
    behavior.setFailurePercent(networkFailurePercent.get());
    behavior.setVariancePercent(networkVariancePercent.get());
    return behavior;
}
 
Example #4
Source File: ProxyAdapter.java    From u2020 with Apache License 2.0 5 votes vote down vote up
ProxyAdapter(Context context, Preference<InetSocketAddress> proxyAddress) {
  super(context);
  if (proxyAddress == null) {
    throw new IllegalStateException("proxy == null");
  }
  this.proxyAddress = proxyAddress;
}
 
Example #5
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton OkHttpClient provideOkHttpClient(Application app,
    Preference<InetSocketAddress> networkProxyAddress) {
  return DataModule.createOkHttpClient(app)
      .sslSocketFactory(createBadSslSocketFactory())
      .proxy(InetSocketAddressPreferenceAdapter.createProxy(networkProxyAddress.get()))
      .build();
}
 
Example #6
Source File: DebugApiModule.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton NetworkBehavior provideBehavior(@NetworkDelay Preference<Long> networkDelay,
    @NetworkVariancePercent Preference<Integer> networkVariancePercent,
    @NetworkFailurePercent Preference<Integer> networkFailurePercent,
    @NetworkErrorPercent Preference<Integer> networkErrorPercent,
    Preference<NetworkErrorCode> networkErrorCode) {
  NetworkBehavior behavior = NetworkBehavior.create();
  behavior.setDelay(networkDelay.get(), MILLISECONDS);
  behavior.setVariancePercent(networkVariancePercent.get());
  behavior.setFailurePercent(networkFailurePercent.get());
  behavior.setErrorPercent(networkErrorPercent.get());
  behavior.setErrorFactory(
      () -> Response.error(networkErrorCode.get().code, ResponseBody.create(null, new byte[0])));
  return behavior;
}
 
Example #7
Source File: OauthManager.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Inject public OauthManager(IntentFactory intentFactory, OkHttpClient client, Moshi moshi,
    @AccessToken Preference<String> accessToken) {
  this.intentFactory = intentFactory;
  this.client = client;
  this.moshi = moshi;
  this.accessToken = accessToken;
}
 
Example #8
Source File: DebugViewContainer.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
@Inject
public DebugViewContainer(@SeenDebugDrawer Preference<Boolean> seenDebugDrawer,
                          @PixelGridEnabled Preference<Boolean> pixelGridEnabled,
                          @PixelRatioEnabled Preference<Boolean> pixelRatioEnabled,
                          @ScalpelEnabled Preference<Boolean> scalpelEnabled,
                          @ScalpelWireframeEnabled Preference<Boolean> scalpelWireframeEnabled) {
    this.seenDebugDrawer = seenDebugDrawer;
    this.pixelGridEnabled = pixelGridEnabled;
    this.pixelRatioEnabled = pixelRatioEnabled;
    this.scalpelEnabled = scalpelEnabled;
    this.scalpelWireframeEnabled = scalpelWireframeEnabled;
}
 
Example #9
Source File: DebugViewContainer.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Inject public DebugViewContainer(LumberYard lumberYard,
    @SeenDebugDrawer Preference<Boolean> seenDebugDrawer,
    @PixelGridEnabled Preference<Boolean> pixelGridEnabled,
    @PixelRatioEnabled Preference<Boolean> pixelRatioEnabled,
    @ScalpelEnabled Preference<Boolean> scalpelEnabled,
    @ScalpelWireframeEnabled Preference<Boolean> scalpelWireframeEnabled) {
  this.lumberYard = lumberYard;
  this.seenDebugDrawer = seenDebugDrawer;
  this.pixelGridEnabled = pixelGridEnabled;
  this.pixelRatioEnabled = pixelRatioEnabled;
  this.scalpelEnabled = scalpelEnabled;
  this.scalpelWireframeEnabled = scalpelWireframeEnabled;
}
 
Example #10
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
@Provides
@ApplicationScope
@IsMockMode
boolean provideIsMockMode(@ApiEndpoint Preference<String> endpoint,
                          @IsInstrumentationTest boolean isInstrumentationTest) {
    // Running in an instrumentation forces mock mode.
    return isInstrumentationTest || ApiEndpoints.isMockMode(endpoint.get());
}
 
Example #11
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
@Provides
@ApplicationScope
OkHttpClient provideOkHttpClient(Application app,
                                 Preference<InetSocketAddress> networkProxyAddress) {
    return DataModule.createOkHttpClient(app)
            .sslSocketFactory(createBadSslSocketFactory())
            .proxy(InetSocketAddressPreferenceAdapter.createProxy(networkProxyAddress.get()))
            .build();
}
 
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 @NetworkErrorPercent
Preference<Integer> provideNetworkErrorPercent(RxSharedPreferences preferences) {
  return preferences.getInteger("debug_network_error_percent", 0);
}
 
Example #14
Source File: DebugDataModule.java    From u2020 with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton IntentFactory provideIntentFactory(@IsMockMode boolean isMockMode,
    @CaptureIntents Preference<Boolean> captureIntents) {
  return new CapturingIntentFactory(IntentFactory.REAL, () -> isMockMode && captureIntents.get());
}
 
Example #15
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 #16
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 #17
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@PixelGridEnabled
Preference<Boolean> providePixelGridEnabled(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_pixel_grid_enabled", DEFAULT_PIXEL_GRID_ENABLED);
}
 
Example #18
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@PicassoDebugging
Preference<Boolean> providePicassoDebugging(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_picasso_debugging", DEFAULT_PICASSO_DEBUGGING);
}
 
Example #19
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@AnimationSpeed
Preference<Integer> provideAnimationSpeed(RxSharedPreferences prefs) {
    return prefs.getInteger("debug_animation_speed", DEFAULT_ANIMATION_SPEED);
}
 
Example #20
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@CaptureIntents
Preference<Boolean> provideCaptureIntentsPreference(RxSharedPreferences prefs) {
    return prefs.getBoolean("debug_capture_intents", DEFAULT_CAPTURE_INTENTS);
}
 
Example #21
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
Preference<InetSocketAddress> provideNetworkProxyAddress(RxSharedPreferences preferences) {
    return preferences.getObject("debug_network_proxy", InetSocketAddressPreferenceAdapter.INSTANCE);
}
 
Example #22
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 #23
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@NetworkFailurePercent
Preference<Integer> provideNetworkFailurePercent(RxSharedPreferences prefs) {
    return prefs.getInteger("debug_network_failure_percent", 3);
}
 
Example #24
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@NetworkDelay
Preference<Long> provideNetworkDelay(RxSharedPreferences prefs) {
    return prefs.getLong("debug_network_delay", 2000L);
}
 
Example #25
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 #26
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
@ApiEndpoint
Preference<String> provideEndpointPreference(RxSharedPreferences prefs) {
    return prefs.getString("debug_endpoint", ApiEndpoints.MOCK_MODE.url);
}
 
Example #27
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 #28
Source File: DebugDataModule.java    From u2020-mvp with Apache License 2.0 4 votes vote down vote up
@Provides
@ApplicationScope
IntentFactory provideIntentFactory(@IsMockMode boolean isMockMode,
                                   @CaptureIntents Preference<Boolean> captureIntents) {
    return new DebugIntentFactory(IntentFactory.REAL, isMockMode, captureIntents);
}
 
Example #29
Source File: UserPreferences.java    From android with Apache License 2.0 4 votes vote down vote up
public Preference<String> coachPreference() {
  return coachPreference;
}
 
Example #30
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);
}