use of com.gh4a.Gh4Application in project gh4a by slapperwan.
the class Github4AndroidActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Gh4Application app = Gh4Application.get();
if (app.isAuthorized()) {
if (!handleIntent(getIntent())) {
goToToplevelActivity();
}
finish();
} else {
setContentView(R.layout.main);
AppBarLayout abl = findViewById(R.id.header);
abl.setEnabled(false);
FrameLayout contentContainer = (FrameLayout) findViewById(R.id.content).getParent();
contentContainer.setForeground(null);
findViewById(R.id.oauth_login_button).setOnClickListener(this);
findViewById(R.id.user_pw_login_button).setOnClickListener(this);
mContent = findViewById(R.id.welcome_container);
mProgress = findViewById(R.id.login_progress_container);
handleIntent(getIntent());
}
}
use of com.gh4a.Gh4Application in project gh4a by slapperwan.
the class CommitFragment method fillHeader.
private void fillHeader() {
final Activity activity = getActivity();
final Gh4Application app = Gh4Application.get();
ImageView ivGravatar = mContentView.findViewById(R.id.iv_gravatar);
User author = mCommit.author();
if (author != null) {
AvatarHandler.assignAvatar(ivGravatar, author);
} else {
GitUser commitAuthor = mCommit.commit().author();
String email = commitAuthor != null ? commitAuthor.email() : null;
ivGravatar.setImageDrawable(new AvatarHandler.DefaultAvatarDrawable(null, email));
}
String login = ApiHelpers.getAuthorLogin(mCommit);
if (login != null) {
ivGravatar.setOnClickListener(this);
ivGravatar.setTag(login);
}
TextView tvMessage = mContentView.findViewById(R.id.tv_message);
TextView tvTitle = mContentView.findViewById(R.id.tv_title);
String message = mCommit.commit().message();
int pos = message.indexOf('\n');
String title = pos > 0 ? message.substring(0, pos) : message;
title = EmojiParser.parseToUnicode(title);
int length = message.length();
while (pos > 0 && pos < length && Character.isWhitespace(message.charAt(pos))) {
pos++;
}
message = pos > 0 && pos < length ? message.substring(pos) : null;
if (message != null) {
message = EmojiParser.parseToUnicode(message);
}
tvTitle.setText(title);
tvMessage.setText(message);
tvTitle.setVisibility(StringUtils.isBlank(title) ? View.GONE : View.VISIBLE);
tvMessage.setVisibility(StringUtils.isBlank(message) ? View.GONE : View.VISIBLE);
tvMessage.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
GitCommit commit = mCommit.commit();
TextView tvAuthor = mContentView.findViewById(R.id.tv_author);
tvAuthor.setText(ApiHelpers.getAuthorName(app, mCommit));
TextView tvTimestamp = mContentView.findViewById(R.id.tv_timestamp);
tvTimestamp.setText(StringUtils.formatRelativeTime(activity, commit.author().date(), true));
View committerContainer = mContentView.findViewById(R.id.committer);
if (!ApiHelpers.authorEqualsCommitter(mCommit)) {
ImageView commitGravatar = mContentView.findViewById(R.id.iv_commit_gravatar);
StyleableTextView commitExtra = mContentView.findViewById(R.id.tv_commit_extra);
AvatarHandler.assignAvatar(commitGravatar, mCommit.committer());
String committerText = getString(R.string.commit_details, ApiHelpers.getCommitterName(app, mCommit), StringUtils.formatRelativeTime(activity, commit.committer().date(), true));
StringUtils.applyBoldTagsAndSetText(commitExtra, committerText);
committerContainer.setVisibility(View.VISIBLE);
} else {
committerContainer.setVisibility(View.GONE);
}
}
use of com.gh4a.Gh4Application in project gh4a by slapperwan.
the class NewsFeedFactory method loadOrganizations.
private void loadOrganizations(boolean force) {
final Gh4Application app = Gh4Application.get();
final OrganizationService service = ServiceFactory.get(OrganizationService.class, force);
mOrganizationSubscription = ApiHelpers.PageIterator.toSingle(page -> ApiHelpers.loginEquals(mUserLogin, app.getAuthLogin()) ? service.getMyOrganizations(page) : service.getUserPublicOrganizations(mUserLogin, page)).compose(mActivity.makeLoaderSingle(ID_LOADER_ORGS, force)).subscribe(result -> {
mUserScopes = result.isEmpty() ? null : result;
mActivity.supportInvalidateOptionsMenu();
}, mActivity::handleLoadFailure);
}
use of com.gh4a.Gh4Application in project gh4a by slapperwan.
the class SingleFactory method isAppUserRepoCollaborator.
public static Single<Boolean> isAppUserRepoCollaborator(String repoOwner, String repoName, boolean bypassCache) {
Gh4Application app = Gh4Application.get();
RepositoryCollaboratorService service = ServiceFactory.get(RepositoryCollaboratorService.class, bypassCache);
if (!app.isAuthorized()) {
return Single.just(false);
}
return service.isUserCollaborator(repoOwner, repoName, app.getAuthLogin()).map(ApiHelpers::throwOnFailure).compose(RxUtils.mapFailureToValue(403, false)).map(result -> true);
}
use of com.gh4a.Gh4Application in project gh4a by slapperwan.
the class PullRequestActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.pullrequest_menu, menu);
Gh4Application app = Gh4Application.get();
boolean authorized = app.isAuthorized();
boolean isCreator = mPullRequest != null && ApiHelpers.loginEquals(mPullRequest.user(), app.getAuthLogin());
boolean isClosed = mPullRequest != null && mPullRequest.state() == IssueState.Closed;
boolean isCollaborator = mIsCollaborator != null && mIsCollaborator;
boolean closerIsCreator = mIssue != null && ApiHelpers.userEquals(mIssue.user(), mIssue.closedBy());
boolean canClose = mPullRequest != null && authorized && (isCreator || isCollaborator);
boolean canOpen = canClose && (isCollaborator || closerIsCreator);
boolean canMerge = canClose && isCollaborator;
if (!canClose || isClosed) {
menu.removeItem(R.id.pull_close);
}
if (!canOpen || !isClosed) {
menu.removeItem(R.id.pull_reopen);
} else if (isClosed && mPullRequest.merged()) {
menu.findItem(R.id.pull_reopen).setEnabled(false);
}
if (!canMerge) {
menu.removeItem(R.id.pull_merge);
} else if (mPullRequest.merged() || mPullRequest.mergeable() == null || !mPullRequest.mergeable()) {
MenuItem mergeItem = menu.findItem(R.id.pull_merge);
mergeItem.setEnabled(false);
}
if (mPullRequest == null) {
menu.removeItem(R.id.share);
menu.removeItem(R.id.browser);
menu.removeItem(R.id.copy_number);
}
if (!mPendingReviewLoaded || mPullRequest == null || isClosed) {
menu.removeItem(R.id.pull_review);
}
return super.onCreateOptionsMenu(menu);
}
Aggregations