com.google.android.agera.Repository Java Examples

The following examples show how to use com.google.android.agera.Repository. 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: Okhttp3AgeraGsonActivity.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Override protected void initData() {
    SaveVolley saveVolley = SaveVolleys
        .<GankData>request(TEST_URL)
        .method(Method.GET)
        .parseStyle(GSON)
        .classOf(GankData.class)
        .createRequest()
        .context(this)
        .compile();

    final Repository<GankResultData> repository = Repositories.repositoryWithInitialValue(
        INITIAL_VALUE)
        .observe(saveVolley.getReservoir())
        .onUpdatesPerLoop()
        .goTo(executor)
        .attemptGetFrom(saveVolley.getReservoir())
        .orSkip()
        .thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
            /**
             * Returns the result of applying this function to {@code input}.
             */
            @NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
                if (input instanceof GankData) {
                    return Result.success(((GankData) input).results.get(0));
                } else if (input instanceof VolleyError) {
                    return Result.failure((VolleyError) input);
                }
                return Result.failure();
            }
        })
        .orSkip()
        .compile();

    repository.addUpdatable(new Updatable() {
        @Override public void update() {
            getContentText.setText(repository.get().toString());
        }
    });
}
 
Example #2
Source File: HurlAgeraGsonActivity.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Override protected void initData() {
    SaveVolley saveVolley = SaveVolleys
        .<GankData>request(TEST_URL)
        .method(Method.GET)
        .parseStyle(GSON)
        .classOf(GankData.class)
        .createRequest()
        .context(this)
        .compile();

    final Repository<GankResultData> repository = Repositories
        .repositoryWithInitialValue(INITIAL_VALUE)
        .observe(saveVolley.getReservoir())
        .onUpdatesPerLoop()
        .goTo(executor)
        .attemptGetFrom(saveVolley.getReservoir())
        .orSkip()
        .thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
            /**
             * Returns the result of applying this function to {@code input}.
             */
            @NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
                if (input instanceof GankData) {
                    return Result.success(((GankData) input).results.get(0));
                } else if (input instanceof VolleyError) {
                    return Result.failure((VolleyError) input);
                }
                return Result.failure();
            }
        })
        .orSkip()
        .compile();

    repository.addUpdatable(new Updatable() {
        @Override public void update() {
            getContentText.setText(repository.get().toString());
        }
    });
}
 
Example #3
Source File: HurlAgeraFastjsonActivity.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Override protected void initData() {
    SaveVolley saveVolley = SaveVolleys
        .<GankData>request(TEST_URL)
        .method(Method.GET)
        .parseStyle(FASTJSON)
        .classOf(GankData.class)
        .createRequest()
        .context(this)
        .compile();

    final Repository<GankResultData> repository = Repositories
        .repositoryWithInitialValue(INITIAL_VALUE)
        .observe(saveVolley.getReservoir())
        .onUpdatesPerLoop()
        .goTo(executor)
        .attemptGetFrom(saveVolley.getReservoir())
        .orSkip()
        .thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
            /**
             * Returns the result of applying this function to {@code input}.
             */
            @NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
                if (input instanceof GankData) {
                    return Result.success(((GankData) input).results.get(0));
                } else if (input instanceof VolleyError) {
                    return Result.failure((VolleyError) input);
                }
                return Result.failure();
            }
        })
        .orSkip()
        .compile();

    repository.addUpdatable(new Updatable() {
        @Override public void update() {
            getContentText.setText(repository.get().toString());
        }
    });
}
 
Example #4
Source File: Okhttp3AgeraFastjsonActivity.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Override protected void initData() {
    SaveVolley saveVolley = SaveVolleys
        .<GankData>request(TEST_URL)
        .method(Method.GET)
        .parseStyle(FASTJSON)
        .classOf(GankData.class)
        .createRequest()
        .context(this)
        .compile();

    final Repository<GankResultData> repository = Repositories
        .repositoryWithInitialValue(INITIAL_VALUE)
        .observe(saveVolley.getReservoir())
        .onUpdatesPerLoop()
        .goTo(executor)
        .attemptGetFrom(saveVolley.getReservoir())
        .orSkip()
        .thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
            /**
             * Returns the result of applying this function to {@code input}.
             */
            @NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
                if (input instanceof GankData) {
                    return Result.success(((GankData) input).results.get(0));
                } else if (input instanceof VolleyError) {
                    return Result.failure((VolleyError) input);
                }
                return Result.failure();
            }
        })
        .orSkip()
        .compile();

    repository.addUpdatable(new Updatable() {
        @Override public void update() {
            getContentText.setText(repository.get().toString());
        }
    });
}
 
Example #5
Source File: NotesStore.java    From agera with Apache License 2.0 5 votes vote down vote up
private NotesStore(@NonNull final Repository<List<NoteGroup>> notesRepository,
    @NonNull final Receiver<SqlInsertRequest> insert,
    @NonNull final Receiver<SqlUpdateRequest> update,
    @NonNull final Receiver<SqlDeleteRequest> delete,
    @NonNull final SqlDatabaseSupplier databaseSupplier) {
  this.insert = insert;
  this.update = update;
  this.delete = delete;
  this.notesRepository = notesRepository;
  this.databaseSupplier = databaseSupplier;
}
 
Example #6
Source File: RepositoryAdapter.java    From agera with Apache License 2.0 5 votes vote down vote up
private RepositoryPart(
    @NonNull final Repository repository,
    @NonNull final RepositoryPresenter presenter) {
  this.repository = repository;
  this.presenter = presenter;
  this.data = repository.get();
}
 
Example #7
Source File: NotesStore.java    From agera with Apache License 2.0 4 votes vote down vote up
@NonNull
Repository<List<NoteGroup>> getNotesRepository() {
  return notesRepository;
}
 
Example #8
Source File: RepositoryAdapter.java    From agera with Apache License 2.0 3 votes vote down vote up
/**
 * Specifies that the {@link RepositoryAdapter} being built should present the given
 * {@code repository} next (after all previously added repositories, items and static layouts),
 * using the given {@code presenter} for any presentation logic.
 *
 * <p>When the {@code RepositoryAdapter} is active (between {@link #startObserving()} and
 * {@link #stopObserving()}), updates from the {@code repository} will cause the data to be
 * reloaded, and the {@code presenter} may be asked to produce a sequence of fine-grained events
 * capturing the change of data. For mor details, see {@link RepositoryPresenter#getUpdates}.
 *
 * @param repository The repository to be presented. This can be the same as a previously added
 *     repository; this makes the resulting {@link RepositoryAdapter} present the same data in
 *     different positions and/or different ways.
 * @param presenter The repository presenter associated with the {@code repository} at this
 *     position of the {@link RepositoryAdapter}.
 * @return This instance, for chaining.
 */
@NonNull
public <T> Builder add(@NonNull final Repository<T> repository,
    @NonNull final RepositoryPresenter<T> presenter) {
  parts.add(new RepositoryPart(repository, presenter));
  return this;
}