Search in sources :

Example 6 with Gist

use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.

the class GistsViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pager);
    gists = getStringArrayExtra(EXTRA_GIST_IDS);
    gist = getParcelableExtra(EXTRA_GIST);
    initialPosition = getIntExtra(EXTRA_POSITION);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // in the intent but not currently present in the store
    if (gists == null && gist != null) {
        if (gist.createdAt() != null) {
            Gist stored = store.getGist(gist.id());
            if (stored == null) {
                store.addGist(gist);
            }
        }
        gists = new String[] { gist.id() };
    }
    adapter = new GistsPagerAdapter(this, gists);
    pager.setAdapter(adapter);
    pager.addOnPageChangeListener(this);
    pager.scheduleSetItem(initialPosition, this);
    onPageSelected(initialPosition);
}
Also used : Gist(com.meisolsson.githubsdk.model.Gist)

Example 7 with Gist

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 items
 * @param position
 * @return intent
 */
public static Intent createIntent(List<Item> items, int position) {
    String[] ids = new String[items.size()];
    int index = 0;
    for (Item item : items) {
        Gist gist = ((GistItem) item).getGist();
        ids[index++] = gist.id();
    }
    return new Builder("gists.VIEW").add(EXTRA_GIST_IDS, (Serializable) ids).add(EXTRA_POSITION, position).toIntent();
}
Also used : GistItem(com.github.pockethub.android.ui.item.gist.GistItem) MenuItem(android.view.MenuItem) Item(com.xwray.groupie.Item) Gist(com.meisolsson.githubsdk.model.Gist) GistItem(com.github.pockethub.android.ui.item.gist.GistItem) Builder(com.github.pockethub.android.Intents.Builder)

Example 8 with Gist

use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.

the class GistUriMatcherTest method testPublicGist.

/**
 * Verify public Gist id
 */
public void testPublicGist() {
    Gist gist = GistUriMatcher.getGist(Uri.parse("https://gist.github.com/1234"));
    assertNotNull(gist);
    assertEquals("1234", gist.id());
}
Also used : Gist(com.meisolsson.githubsdk.model.Gist)

Example 9 with Gist

use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.

the class GistUriMatcherTest method testPrivateGist.

/**
 * Verify public Gist id
 */
public void testPrivateGist() {
    Gist gist = GistUriMatcher.getGist(Uri.parse("https://gist.github.com/abcd1234abcd1234abcd"));
    assertNotNull(gist);
    assertEquals("abcd1234abcd1234abcd", gist.id());
}
Also used : Gist(com.meisolsson.githubsdk.model.Gist)

Example 10 with Gist

use of com.meisolsson.githubsdk.model.Gist in project PocketHub by pockethub.

the class NewsFragment method onItemClick.

@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
    if (!(item instanceof NewsItem)) {
        return;
    }
    GitHubEvent event = ((NewsItem) item).getGitHubEvent();
    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 = IssueEventMatcher.getIssue(event);
    if (issue != null) {
        Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
        viewIssue(issue, repo);
        return;
    }
    Gist gist = GistEventMatcher.getGist(event);
    if (gist != null) {
        startActivity(GistsViewActivity.createIntent(gist));
        return;
    }
    Repository repo = RepositoryEventMatcher.getRepository(event);
    if (repo != null) {
        viewRepository(repo);
    }
    UserPair users = UserEventMatcher.getUsers(event);
    if (users != null) {
        viewUser(users);
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Gist(com.meisolsson.githubsdk.model.Gist) Issue(com.meisolsson.githubsdk.model.Issue) UserPair(com.github.pockethub.android.core.user.UserEventMatcher.UserPair) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) NewsItem(com.github.pockethub.android.ui.item.news.NewsItem)

Aggregations

Gist (com.meisolsson.githubsdk.model.Gist)17 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)4 MenuItem (android.view.MenuItem)3 GistStore (com.github.pockethub.android.core.gist.GistStore)3 Issue (com.meisolsson.githubsdk.model.Issue)3 Repository (com.meisolsson.githubsdk.model.Repository)3 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 View (android.view.View)2 Builder (com.github.pockethub.android.Intents.Builder)2 R (com.github.pockethub.android.R)2 UserPair (com.github.pockethub.android.core.user.UserEventMatcher.UserPair)2 ToastUtils (com.github.pockethub.android.util.ToastUtils)2 Single (io.reactivex.Single)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 IOException (java.io.IOException)2 Inject (javax.inject.Inject)2