use of com.gh4a.BaseActivity 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;
}
use of com.gh4a.BaseActivity in project gh4a by slapperwan.
the class EventListFragment method onItemClick.
@Override
public void onItemClick(GitHubEvent event) {
if (EventAdapter.hasInvalidPayload(event)) {
return;
}
GitHubEvent.RepoIdentifier eventRepo = event.repo();
String repoOwner = "";
String repoName = "";
Intent intent = null;
Single<Optional<Intent>> intentSingle = null;
if (eventRepo != null) {
String[] repoNamePart = eventRepo.repoWithUserName().split("/");
if (repoNamePart.length == 2) {
repoOwner = repoNamePart[0];
repoName = repoNamePart[1];
}
}
if (Arrays.binarySearch(REPO_EVENTS, event.type()) >= 0 && eventRepo == null) {
Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
return;
}
switch(event.type()) {
case CommitCommentEvent:
{
CommitCommentPayload payload = (CommitCommentPayload) event.payload();
GitComment comment = payload.comment();
if (comment != null) {
intentSingle = CommitCommentLoadTask.load(getActivity(), repoOwner, repoName, comment.commitId(), new IntentUtils.InitialCommentMarker(comment.id()));
}
break;
}
case CreateEvent:
{
CreatePayload payload = (CreatePayload) event.payload();
String ref = null;
if (payload.refType() == ReferenceType.Branch || payload.refType() == ReferenceType.Tag) {
ref = payload.ref();
}
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName, ref);
break;
}
case DeleteEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case DownloadEvent:
{
DownloadPayload payload = (DownloadPayload) event.payload();
Download download = payload.download();
UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
break;
}
case FollowEvent:
{
FollowPayload payload = (FollowPayload) event.payload();
intent = UserActivity.makeIntent(getActivity(), payload.target());
break;
}
case ForkEvent:
{
ForkPayload payload = (ForkPayload) event.payload();
Repository forkee = payload.forkee();
if (forkee != null) {
intent = RepositoryActivity.makeIntent(getActivity(), forkee);
} else {
Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
}
break;
}
case ForkApplyEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case GistEvent:
{
GistPayload payload = (GistPayload) event.payload();
intent = GistActivity.makeIntent(getActivity(), payload.gist().id());
break;
}
case GollumEvent:
{
GollumPayload payload = (GollumPayload) event.payload();
intent = WikiListActivity.makeIntent(getActivity(), repoOwner, repoName, payload.pages().isEmpty() ? null : payload.pages().get(0));
break;
}
case IssueCommentEvent:
{
IssueCommentPayload payload = (IssueCommentPayload) event.payload();
Issue issue = payload.issue();
PullRequest request = issue != null ? issue.pullRequest() : null;
IntentUtils.InitialCommentMarker initialComment = payload.comment() != null ? new IntentUtils.InitialCommentMarker(payload.comment().id()) : null;
if (request != null && request.htmlUrl() != null) {
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment != null ? PullRequestActivity.PAGE_CONVERSATION : -1, initialComment);
} else if (issue != null) {
intent = IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment);
}
break;
}
case IssuesEvent:
{
IssuesPayload payload = (IssuesPayload) event.payload();
startActivity(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, payload.issue().number()));
break;
}
case MemberEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case PublicEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
case PullRequestEvent:
{
PullRequestPayload payload = (PullRequestPayload) event.payload();
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number());
break;
}
case PullRequestReviewCommentEvent:
{
PullRequestReviewCommentPayload payload = (PullRequestReviewCommentPayload) event.payload();
PullRequest pr = payload.pullRequest();
ReviewComment comment = payload.comment();
IntentUtils.InitialCommentMarker initialComment = comment != null ? new IntentUtils.InitialCommentMarker(comment.id()) : null;
if (pr != null) {
if (initialComment != null) {
intentSingle = PullRequestReviewCommentLoadTask.load(getActivity(), repoOwner, repoName, pr.number(), initialComment);
} else {
intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, pr.number(), -1, null);
}
} else if (comment != null) {
intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, comment.commitId(), initialComment);
}
break;
}
case PushEvent:
{
PushPayload payload = (PushPayload) event.payload();
List<GitCommit> commits = payload.commits();
if (commits != null && !commits.isEmpty()) {
if (commits.size() > 1) {
// if commit > 1, then show compare activity
intent = CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head());
} else {
// only 1 commit, then show the commit details
intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, commits.get(0).sha());
}
} else {
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
}
break;
}
case ReleaseEvent:
{
ReleasePayload payload = (ReleasePayload) event.payload();
Release release = payload.release();
if (release != null) {
intent = ReleaseInfoActivity.makeIntent(getActivity(), repoOwner, repoName, release.id());
}
break;
}
case WatchEvent:
intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
break;
}
if (intent != null) {
startActivity(intent);
} else if (intentSingle != null) {
intentSingle.compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(getActivity(), R.string.loading_msg)).subscribe(result -> {
if (result.isPresent() && isAdded()) {
startActivity(result.get());
}
}, error -> Log.d(Gh4Application.LOG_TAG, "Loading click intent failed", error));
}
}
use of com.gh4a.BaseActivity in project gh4a by slapperwan.
the class CommitNoteFragment method onToggleAdvancedMode.
@Override
public void onToggleAdvancedMode(boolean advancedMode) {
BaseActivity activity = getBaseActivity();
if (activity != null) {
activity.collapseAppBar();
activity.setAppBarLocked(advancedMode);
}
mBottomSheet.resetPeekHeight(0);
}
use of com.gh4a.BaseActivity in project gh4a by slapperwan.
the class CommitNoteFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getBaseActivity().addAppBarOffsetListener(mBottomSheet);
mBottomSheet.post(() -> {
// Fix an issue where the bottom sheet is initially located outside of the visible
// screen area
final BaseActivity activity = getBaseActivity();
if (activity != null) {
mBottomSheet.resetPeekHeight(activity.getAppBarTotalScrollRange());
}
});
}
use of com.gh4a.BaseActivity in project gh4a by slapperwan.
the class ContentListContainerFragment method loadModuleMap.
private void loadModuleMap() {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
service.getContents(repoOwner, repoName, ".gitmodules", mSelectedRef).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<Content>absent())).map(contentOpt -> contentOpt.map(content -> StringUtils.fromBase64(content.content()))).map(this::parseModuleMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(mRxLoader.makeSingleTransformer(ID_LOADER_MODULEMAP, true)).subscribe(resultOpt -> {
mGitModuleMap = resultOpt.orNull();
if (mContentListFragment != null) {
mContentListFragment.onSubModuleNamesChanged(getSubModuleNames(mContentListFragment));
}
}, ((BaseActivity) getActivity())::handleLoadFailure);
}
Aggregations