Search in sources :

Example 1 with ReleaseAsset

use of com.meisolsson.githubsdk.model.ReleaseAsset in project gh4a by slapperwan.

the class EventListFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) item.getMenuInfo();
    if (info.position >= mAdapter.getItemCount()) {
        return false;
    }
    int id = item.getItemId();
    GitHubEvent event = mAdapter.getItemFromAdapterPosition(info.position);
    if (id >= MENU_DOWNLOAD_START && id <= MENU_DOWNLOAD_END) {
        if (event.type() == GitHubEventType.ReleaseEvent) {
            ReleasePayload payload = (ReleasePayload) event.payload();
            ReleaseAsset asset = payload.release().assets().get(id - MENU_DOWNLOAD_START);
            UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), asset.url(), asset.contentType(), asset.name(), asset.label(), null);
        } else if (event.type() == GitHubEventType.DownloadEvent) {
            DownloadPayload payload = (DownloadPayload) event.payload();
            Download download = payload.download();
            UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
        }
        return true;
    }
    return false;
}
Also used : ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) ReleaseAsset(com.meisolsson.githubsdk.model.ReleaseAsset) BaseActivity(com.gh4a.BaseActivity) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload) Download(com.meisolsson.githubsdk.model.Download) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView)

Aggregations

BaseActivity (com.gh4a.BaseActivity)1 ContextMenuAwareRecyclerView (com.gh4a.widget.ContextMenuAwareRecyclerView)1 Download (com.meisolsson.githubsdk.model.Download)1 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)1 ReleaseAsset (com.meisolsson.githubsdk.model.ReleaseAsset)1 DownloadPayload (com.meisolsson.githubsdk.model.payload.DownloadPayload)1 ReleasePayload (com.meisolsson.githubsdk.model.payload.ReleasePayload)1