use of com.meisolsson.githubsdk.model.GistFile in project PocketHub by pockethub.
the class GistFilesPagerAdapter method getItem.
@Override
public Fragment getItem(final int position) {
GistFile file = files[position];
Fragment fragment = new GistFileFragment();
Bundle args = new Bundle();
args.putParcelable(EXTRA_GIST_FILE, file);
fragment.setArguments(args);
return fragment;
}
use of com.meisolsson.githubsdk.model.GistFile in project PocketHub by pockethub.
the class CreateGistActivity method createGist.
private void createGist() {
final boolean isPublic = publicCheckBox.isChecked();
String enteredDescription = descriptionText.getText().toString().trim();
final String description = enteredDescription.length() > 0 ? enteredDescription : getString(R.string.gist_description_hint);
String enteredName = nameText.getText().toString().trim();
final String name = enteredName.length() > 0 ? enteredName : getString(R.string.gist_file_name_hint);
final String content = contentText.getText().toString();
Map<String, GistFile> map = new HashMap<>();
map.put(name, GistFile.builder().filename(name).content(content).build());
CreateGist createGist = CreateGist.builder().files(map).description(description).isPublic(isPublic).build();
ServiceGenerator.createService(this, GistService.class).createGist(createGist).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(RxProgress.bindToLifecycle(this, R.string.creating_gist)).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> {
startActivity(GistsViewActivity.createIntent(response.body()));
setResult(RESULT_OK);
finish();
}, e -> {
Log.d(TAG, "Exception creating Gist", e);
ToastUtils.show(this, e.getMessage());
});
}
use of com.meisolsson.githubsdk.model.GistFile 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.GistFile in project PocketHub by pockethub.
the class GistFragment method updateFiles.
private void updateFiles(Gist gist) {
final Activity activity = getActivity();
if (activity == null) {
return;
}
Map<String, GistFile> files = gist.files();
if (files == null || files.isEmpty()) {
filesSection.update(Collections.emptyList());
return;
}
List<GistFileItem> fileItems = new ArrayList<>();
for (GistFile file : files.values()) {
fileItems.add(new GistFileItem(file));
}
filesSection.update(fileItems);
}
use of com.meisolsson.githubsdk.model.GistFile in project PocketHub by pockethub.
the class GistFilesViewActivityTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Context context = getInstrumentation().getTargetContext();
PocketHub pocketHub = (PocketHub) context.getApplicationContext();
store = pocketHub.applicationComponent().gistStore();
Map<String, GistFile> files = new ArrayMap<>();
GistFile a = GistFile.builder().content("aa").filename("a").build();
GistFile b = GistFile.builder().content("bb").filename("b").build();
files.put("a", a);
files.put("b", b);
gist = Gist.builder().id("abcd").files(files).build();
store.addGist(gist);
setActivityIntent(GistFilesViewActivity.createIntent(gist, 0));
}
Aggregations