use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.
the class NewsFragment method onListItemClick.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
GitHubEvent event = (GitHubEvent) l.getItemAtPosition(position);
if (DownloadEvent.equals(event.type())) {
openDownload(event);
return;
}
if (PushEvent.equals(event.type())) {
openPush(event);
return;
}
if (CommitCommentEvent.equals(event.type())) {
openCommitComment(event);
return;
}
Issue issue = issueMatcher.getIssue(event);
if (issue != null) {
Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
viewIssue(issue, repo);
return;
}
Gist gist = gistMatcher.getGist(event);
if (gist != null) {
startActivity(GistsViewActivity.createIntent(gist));
return;
}
Repository repo = repoMatcher.getRepository(event);
if (repo != null) {
viewRepository(repo);
}
UserPair users = userMatcher.getUsers(event);
if (users != null) {
viewUser(users);
}
}
use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.
the class RefreshGistTask method subscribe.
@Override
public void subscribe(ObservableEmitter<FullGist> emitter) throws Exception {
try {
Gist gist = store.refreshGist(id);
List<GitHubComment> comments;
if (gist.comments() > 0) {
comments = ServiceGenerator.createService(context, GistCommentService.class).getGistComments(id, 0).blockingGet().items();
} else {
comments = Collections.emptyList();
}
for (GitHubComment comment : comments) {
imageGetter.encode(comment, comment.bodyHtml());
}
Response<Boolean> response = ServiceGenerator.createService(context, GistService.class).checkIfGistIsStarred(id).blockingGet();
boolean starred = response.code() == 204;
emitter.onNext(new FullGist(gist, starred, comments));
} catch (IOException e) {
emitter.onError(e);
}
}
use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.
the class GistsViewActivity method createIntent.
/**
* Create an intent to show gists with an initial selected Gist
*
* @param gists
* @param position
* @return intent
*/
public static Intent createIntent(List<Gist> gists, int position) {
String[] ids = new String[gists.size()];
int index = 0;
for (Gist gist : gists) {
ids[index++] = gist.id();
}
return new Builder("gists.VIEW").add(EXTRA_GIST_IDS, (Serializable) ids).add(EXTRA_POSITION, position).toIntent();
}
use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.
the class GistFileFragment method loadSource.
private void loadSource() {
store.refreshGist(gistId).map(gist -> {
Map<String, GistFile> files = gist.files();
if (files == null) {
throw new IOException();
}
GistFile loadedFile = files.get(file.filename());
if (loadedFile == null) {
throw new IOException();
}
return loadedFile;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(loadedFile -> {
file = loadedFile;
getArguments().putParcelable(EXTRA_GIST_FILE, file);
if (file.content() != null) {
showSource();
}
}, e -> ToastUtils.show(getActivity(), R.string.error_gist_file_load));
}
use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.
the class GistsPagerFragment method randomGist.
private void randomGist() {
GistService service = ServiceGenerator.createService(getActivity(), GistService.class);
service.getPublicGists(1).flatMap(response -> {
Page<Gist> firstPage = response.body();
int randomPage = (int) (Math.random() * (firstPage.last() - 1));
randomPage = Math.max(1, randomPage);
return service.getPublicGists(randomPage);
}).flatMap(response -> {
Page<Gist> gistPage = response.body();
if (gistPage.items().isEmpty()) {
int randomPage = (int) (Math.random() * (gistPage.last() - 1));
randomPage = Math.max(1, randomPage);
return service.getPublicGists(randomPage);
}
return Single.just(response);
}).map(response -> {
Page<Gist> gistPage = response.body();
if (response.isSuccessful()) {
int size = gistPage.items().size();
if (size > 0) {
return store.addGist(gistPage.items().get(rand.nextInt(size)));
} else {
throw new IllegalArgumentException(getContext().getString(R.string.no_gists_found));
}
} else {
ToastUtils.show(getActivity(), R.string.error_gist_load);
return null;
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(RxProgress.bindToLifecycle(getActivity(), R.string.random_gist)).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(gist -> getActivity().startActivityForResult(GistsViewActivity.createIntent(gist), GIST_VIEW), e -> {
Log.d(TAG, "Exception opening random Gist", e);
ToastUtils.show((Activity) getContext(), e.getMessage());
});
}
Aggregations