Search in sources :

Example 1 with GistFile

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;
}
Also used : Bundle(android.os.Bundle) GistFile(com.meisolsson.githubsdk.model.GistFile) Fragment(android.support.v4.app.Fragment)

Example 2 with GistFile

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());
    });
}
Also used : HashMap(java.util.HashMap) CreateGist(com.meisolsson.githubsdk.model.request.gist.CreateGist) GistFile(com.meisolsson.githubsdk.model.GistFile)

Example 3 with GistFile

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));
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) BaseFragment(com.github.pockethub.android.ui.base.BaseFragment) PreferenceUtils(com.github.pockethub.android.util.PreferenceUtils) OnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener) NonNull(android.support.annotation.NonNull) EXTRA_GIST_FILE(com.github.pockethub.android.Intents.EXTRA_GIST_FILE) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) BindView(butterknife.BindView) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) GistStore(com.github.pockethub.android.core.gist.GistStore) MenuInflater(android.view.MenuInflater) Gist(com.meisolsson.githubsdk.model.Gist) Map(java.util.Map) Menu(android.view.Menu) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) ToastUtils(com.github.pockethub.android.util.ToastUtils) WebView(android.webkit.WebView) SourceEditor(com.github.pockethub.android.util.SourceEditor) GistFile(com.meisolsson.githubsdk.model.GistFile) LayoutInflater(android.view.LayoutInflater) IOException(java.io.IOException) WRAP(com.github.pockethub.android.util.PreferenceUtils.WRAP) ViewGroup(android.view.ViewGroup) EXTRA_GIST_ID(com.github.pockethub.android.Intents.EXTRA_GIST_ID) SharedPreferences(android.content.SharedPreferences) R(com.github.pockethub.android.R) IOException(java.io.IOException) GistFile(com.meisolsson.githubsdk.model.GistFile) Map(java.util.Map)

Example 4 with GistFile

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);
}
Also used : GistFileItem(com.github.pockethub.android.ui.item.gist.GistFileItem) ArrayList(java.util.ArrayList) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) GistFile(com.meisolsson.githubsdk.model.GistFile)

Example 5 with GistFile

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));
}
Also used : Context(android.content.Context) PocketHub(com.github.pockethub.android.PocketHub) ArrayMap(android.support.v4.util.ArrayMap) GistFile(com.meisolsson.githubsdk.model.GistFile)

Aggregations

GistFile (com.meisolsson.githubsdk.model.GistFile)7 Context (android.content.Context)2 Bundle (android.os.Bundle)2 LayoutInflater (android.view.LayoutInflater)2 ViewGroup (android.view.ViewGroup)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1 OnSharedPreferenceChangeListener (android.content.SharedPreferences.OnSharedPreferenceChangeListener)1 NonNull (android.support.annotation.NonNull)1 Fragment (android.support.v4.app.Fragment)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 ArrayMap (android.support.v4.util.ArrayMap)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 WebView (android.webkit.WebView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1