added a way to navigate to repo when clicking on notification or a link from comments, webview to close #163

This commit is contained in:
Kosh 2017-03-18 18:52:48 +08:00
parent ee5a29b5b6
commit 7166e5bc81
15 changed files with 119 additions and 43 deletions

View File

@ -25,8 +25,6 @@ import com.fastaccess.ui.modules.user.UserPagerView;
import java.util.List;
import static android.content.Intent.ACTION_VIEW;
/**
* Created by Kosh on 09 Dec 2016, 4:44 PM
*/
@ -38,14 +36,12 @@ public class SchemeParser {
private static final String API_AUTHORITY = "api.github.com";
private static final String PROTOCOL_HTTPS = "https";
public static void launchUri(@NonNull Context context, @NonNull Intent data) {
if (data.getData() != null) {
launchUri(context, data.getData());
}
public static void launchUri(@NonNull Context context, @NonNull Uri data) {
launchUri(context, data, false);
}
public static void launchUri(@NonNull Context context, @NonNull Uri data) {
Intent intent = convert(context, data);
public static void launchUri(@NonNull Context context, @NonNull Uri data, boolean showRepoBtn) {
Intent intent = convert(context, data, showRepoBtn);
if (intent != null) {
context.startActivity(intent);
} else {
@ -58,14 +54,7 @@ public class SchemeParser {
}
}
@Nullable private static Intent convert(@NonNull Context context, final Intent intent) {
if (intent == null) return null;
if (!ACTION_VIEW.equals(intent.getAction())) return null;
Uri data = intent.getData();
return convert(context, data);
}
@Nullable private static Intent convert(@NonNull Context context, Uri data) {
@Nullable private static Intent convert(@NonNull Context context, Uri data, boolean showRepoBtn) {
if (data == null) return null;
if (InputHelper.isEmpty(data.getHost()) || InputHelper.isEmpty(data.getScheme())) {
String host = data.getHost();
@ -85,10 +74,10 @@ public class SchemeParser {
}
}
return getIntentForURI(context, data);
return getIntentForURI(context, data, showRepoBtn);
}
@Nullable private static Intent getIntentForURI(@NonNull Context context, @NonNull Uri data) {
@Nullable private static Intent getIntentForURI(@NonNull Context context, @NonNull Uri data, boolean showRepoBtn) {
if (HOST_GISTS.equals(data.getHost())) {
String gist = getGistId(data);
if (gist != null) {
@ -99,12 +88,12 @@ public class SchemeParser {
if (TextUtils.equals(authority, HOST_DEFAULT) || TextUtils.equals(authority, RAW_AUTHORITY) ||
TextUtils.equals(authority, API_AUTHORITY)) {
Intent userIntent = getUser(context, data);
Intent pullRequestIntent = getPullRequestIntent(context, data);
Intent pullRequestIntent = getPullRequestIntent(context, data, showRepoBtn);
Intent createIssueIntent = getCreateIssueIntent(context, data);
Intent issueIntent = getIssueIntent(context, data);
Intent issueIntent = getIssueIntent(context, data, showRepoBtn);
Intent repoIntent = getRepo(context, data);
Intent commit = getCommit(context, data);
Intent commits = getCommits(context, data);
Intent commit = getCommit(context, data, showRepoBtn);
Intent commits = getCommits(context, data, showRepoBtn);
Intent blob = getBlob(context, data);
Optional<Intent> intentOptional = returnNonNull(userIntent, pullRequestIntent, commit, commits,
createIssueIntent, issueIntent, repoIntent, blob);
@ -119,7 +108,7 @@ public class SchemeParser {
return null;
}
@Nullable private static Intent getPullRequestIntent(@NonNull Context context, @NonNull Uri uri) {
@Nullable private static Intent getPullRequestIntent(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
List<String> segments = uri.getPathSegments();
if (segments == null || segments.size() < 4) return null;
String owner;
@ -145,10 +134,10 @@ public class SchemeParser {
return null;
}
if (issueNumber < 1) return null;
return PullRequestPagerView.createIntent(context, repo, owner, issueNumber);
return PullRequestPagerView.createIntent(context, repo, owner, issueNumber, showRepoBtn);
}
@Nullable private static Intent getIssueIntent(@NonNull Context context, @NonNull Uri uri) {
@Nullable private static Intent getIssueIntent(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
List<String> segments = uri.getPathSegments();
if (segments == null || segments.size() < 4) return null;
String owner;
@ -174,7 +163,7 @@ public class SchemeParser {
return null;
}
if (issueNumber < 1) return null;
return IssuePagerView.createIntent(context, repo, owner, issueNumber);
return IssuePagerView.createIntent(context, repo, owner, issueNumber, showRepoBtn);
}
@Nullable private static Intent getRepo(@NonNull Context context, @NonNull Uri uri) {
@ -204,25 +193,25 @@ public class SchemeParser {
return null;
}
@Nullable private static Intent getCommits(@NonNull Context context, @NonNull Uri uri) {
@Nullable private static Intent getCommits(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
List<String> segments = uri.getPathSegments();
if (segments == null || segments.isEmpty() || segments.size() < 4) return null;
if (segments.get(3).equals("commits")) {
String login = segments.get(1);
String repoId = segments.get(2);
String sha = segments.get(4);
return CommitPagerView.createIntent(context, repoId, login, sha);
return CommitPagerView.createIntent(context, repoId, login, sha, showRepoBtn);
}
return null;
}
@Nullable private static Intent getCommit(@NonNull Context context, @NonNull Uri uri) {
@Nullable private static Intent getCommit(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
List<String> segments = uri.getPathSegments();
if (segments == null || segments.size() < 4 || !"commit".equals(segments.get(2))) return null;
String login = segments.get(0);
String repoId = segments.get(1);
String sha = segments.get(3);
return CommitPagerView.createIntent(context, repoId, login, sha);
return CommitPagerView.createIntent(context, repoId, login, sha, showRepoBtn);
}
@Nullable private static String getGistId(@NonNull Uri uri) {

View File

@ -75,7 +75,7 @@ public class NotificationsView extends BaseFragment<NotificationsMvp.View, Notif
if (getActivity().isTaskRoot()) {
StackBuilderSchemeParser.launchUri(getContext(), Uri.parse(url));
} else {
SchemeParser.launchUri(getContext(), Uri.parse(url));
SchemeParser.launchUri(getContext(), Uri.parse(url), true);
}
}

View File

@ -30,6 +30,8 @@ interface CommitPagerMvp {
String getRepoId();
boolean showToRepoBtn();
}
}

View File

@ -20,6 +20,7 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
private String sha;
private String login;
private String repoId;
private boolean showToRepoBtn;
@Nullable @Override public Commit getCommit() {
return commitModel;
@ -35,6 +36,7 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
sha = intent.getExtras().getString(BundleConstant.ID);
login = intent.getExtras().getString(BundleConstant.EXTRA);
repoId = intent.getExtras().getString(BundleConstant.EXTRA_TWO);
showToRepoBtn = intent.getExtras().getBoolean(BundleConstant.EXTRA_THREE);
if (commitModel != null) {
sendToView(CommitPagerMvp.View::onSetup);
return;
@ -69,4 +71,8 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
return repoId;
}
@Override public boolean showToRepoBtn() {
return showToRepoBtn;
}
}

View File

@ -56,11 +56,17 @@ public class CommitPagerView extends BaseActivity<CommitPagerMvp.View, CommitPag
@BindView(R.id.detailsIcon) View detailsIcon;
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login, @NonNull String sha) {
return createIntent(context, repoId, login, sha, false);
}
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login,
@NonNull String sha, boolean showRepoBtn) {
Intent intent = new Intent(context, CommitPagerView.class);
intent.putExtras(Bundler.start()
.put(BundleConstant.ID, sha)
.put(BundleConstant.EXTRA, login)
.put(BundleConstant.EXTRA_TWO, repoId)
.put(BundleConstant.EXTRA_THREE, showRepoBtn)
.end());
return intent;
@ -125,6 +131,11 @@ public class CommitPagerView extends BaseActivity<CommitPagerMvp.View, CommitPag
return super.onOptionsItemSelected(item);
}
@Override public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.toRepo).setVisible(getPresenter().showToRepoBtn());
return super.onPrepareOptionsMenu(menu);
}
@Override public void onSetup() {
hideProgress();
if (getPresenter().getCommit() == null) {

View File

@ -5,9 +5,9 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.fastaccess.data.dao.model.Issue;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.MilestoneModel;
import com.fastaccess.data.dao.model.Issue;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.modules.repos.extras.assignees.AssigneesMvp;
@ -55,6 +55,8 @@ interface IssuePagerMvp {
boolean isCollaborator();
boolean showToRepoBtn();
void onHandleConfirmDialog(@Nullable Bundle bundle);
void onOpenCloseIssue();

View File

@ -10,15 +10,15 @@ import com.annimon.stream.Collectors;
import com.annimon.stream.Stream;
import com.fastaccess.R;
import com.fastaccess.data.dao.AssigneesRequestModel;
import com.fastaccess.data.dao.model.Issue;
import com.fastaccess.data.dao.IssueRequestModel;
import com.fastaccess.data.dao.LabelListModel;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.model.Login;
import com.fastaccess.data.dao.MilestoneModel;
import com.fastaccess.data.dao.PullsIssuesParser;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.data.dao.UsersListModel;
import com.fastaccess.data.dao.model.Issue;
import com.fastaccess.data.dao.model.Login;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.data.dao.types.IssueState;
import com.fastaccess.data.service.IssueService;
import com.fastaccess.helper.BundleConstant;
@ -43,6 +43,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
private String login;
private String repoId;
private boolean isCollaborator;
private boolean showToRepoBtn;
@Nullable @Override public Issue getIssue() {
return issueModel;
@ -59,6 +60,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
issueNumber = intent.getExtras().getInt(BundleConstant.ID);
login = intent.getExtras().getString(BundleConstant.EXTRA);
repoId = intent.getExtras().getString(BundleConstant.EXTRA_TWO);
showToRepoBtn = intent.getExtras().getBoolean(BundleConstant.EXTRA_THREE);
if (issueModel != null) {
issueNumber = issueModel.getNumber();
sendToView(IssuePagerMvp.View::onSetupIssue);
@ -120,6 +122,10 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
return isCollaborator;
}
@Override public boolean showToRepoBtn() {
return showToRepoBtn;
}
@Override public void onHandleConfirmDialog(@Nullable Bundle bundle) {
if (bundle != null) {
boolean proceedCloseIssue = bundle.getBoolean(BundleConstant.EXTRA);

View File

@ -16,6 +16,7 @@ import com.fastaccess.R;
import com.fastaccess.data.dao.FragmentPagerAdapterModel;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.MilestoneModel;
import com.fastaccess.data.dao.NameParser;
import com.fastaccess.data.dao.model.Issue;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.data.dao.types.IssueState;
@ -28,6 +29,7 @@ import com.fastaccess.helper.ParseDateFormat;
import com.fastaccess.helper.ViewHelper;
import com.fastaccess.ui.adapter.FragmentsPagerAdapter;
import com.fastaccess.ui.base.BaseActivity;
import com.fastaccess.ui.modules.repos.RepoPagerView;
import com.fastaccess.ui.modules.repos.extras.assignees.AssigneesView;
import com.fastaccess.ui.modules.repos.extras.labels.LabelsView;
import com.fastaccess.ui.modules.repos.extras.milestone.create.MilestoneActivityView;
@ -65,11 +67,17 @@ public class IssuePagerView extends BaseActivity<IssuePagerMvp.View, IssuePagerP
@BindView(R.id.detailsIcon) View detailsIcon;
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login, int number) {
return createIntent(context, repoId, login, number, false);
}
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login, int number, boolean showToRepoBtn) {
Intent intent = new Intent(context, IssuePagerView.class);
intent.putExtras(Bundler.start()
.put(BundleConstant.ID, number)
.put(BundleConstant.EXTRA, login)
.put(BundleConstant.EXTRA_TWO, repoId)
.put(BundleConstant.EXTRA_THREE, showToRepoBtn)
.end());
return intent;
@ -177,6 +185,13 @@ public class IssuePagerView extends BaseActivity<IssuePagerMvp.View, IssuePagerP
} else if (item.getItemId() == R.id.assignees) {
getPresenter().onLoadAssignees();
return true;
} else if (item.getItemId() == R.id.toRepo) {
NameParser nameParser = new NameParser("");
nameParser.setName(getPresenter().getRepoId());
nameParser.setUsername(getPresenter().getLogin());
RepoPagerView.startRepoPager(this, nameParser);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@ -189,6 +204,7 @@ public class IssuePagerView extends BaseActivity<IssuePagerMvp.View, IssuePagerP
MenuItem assignees = menu.findItem(R.id.assignees);
MenuItem edit = menu.findItem(R.id.edit);
MenuItem editMenu = menu.findItem(R.id.editMenu);
menu.findItem(R.id.toRepo).setVisible(getPresenter().showToRepoBtn());
boolean isOwner = getPresenter().isOwner();
boolean isLocked = getPresenter().isLocked();
boolean isCollaborator = getPresenter().isCollaborator();

View File

@ -59,6 +59,8 @@ interface PullRequestPagerMvp {
boolean isMergeable();
boolean showToRepoBtn();
void onHandleConfirmDialog(@Nullable Bundle bundle);
void onOpenCloseIssue();

View File

@ -45,6 +45,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
private String login;
private String repoId;
private boolean isCollaborator;
private boolean showToRepoBtn;
@Nullable @Override public PullRequest getPullRequest() {
return pullRequest;
@ -60,6 +61,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
issueNumber = intent.getExtras().getInt(BundleConstant.ID);
login = intent.getExtras().getString(BundleConstant.EXTRA);
repoId = intent.getExtras().getString(BundleConstant.EXTRA_TWO);
showToRepoBtn = intent.getExtras().getBoolean(BundleConstant.EXTRA_THREE);
if (pullRequest != null) {
sendToView(PullRequestPagerMvp.View::onSetupIssue);
return;
@ -119,6 +121,10 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
return getPullRequest() != null && getPullRequest().isMergeable() && !getPullRequest().isMerged();
}
@Override public boolean showToRepoBtn() {
return showToRepoBtn;
}
@Override public void onHandleConfirmDialog(@Nullable Bundle bundle) {
if (bundle != null) {
boolean proceedCloseIssue = bundle.getBoolean(BundleConstant.EXTRA);

View File

@ -16,6 +16,7 @@ import com.fastaccess.R;
import com.fastaccess.data.dao.FragmentPagerAdapterModel;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.MilestoneModel;
import com.fastaccess.data.dao.NameParser;
import com.fastaccess.data.dao.model.PullRequest;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.data.dao.types.IssueState;
@ -27,6 +28,7 @@ import com.fastaccess.helper.Logger;
import com.fastaccess.helper.ViewHelper;
import com.fastaccess.ui.adapter.FragmentsPagerAdapter;
import com.fastaccess.ui.base.BaseActivity;
import com.fastaccess.ui.modules.repos.RepoPagerView;
import com.fastaccess.ui.modules.repos.extras.assignees.AssigneesView;
import com.fastaccess.ui.modules.repos.extras.labels.LabelsView;
import com.fastaccess.ui.modules.repos.extras.milestone.create.MilestoneActivityView;
@ -65,11 +67,17 @@ public class PullRequestPagerView extends BaseActivity<PullRequestPagerMvp.View,
@BindView(R.id.detailsIcon) View detailsIcon;
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login, int number) {
return createIntent(context, repoId, login, number, false);
}
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login, int number, boolean showRepoBtn) {
Intent intent = new Intent(context, PullRequestPagerView.class);
intent.putExtras(Bundler.start()
.put(BundleConstant.ID, number)
.put(BundleConstant.EXTRA, login)
.put(BundleConstant.EXTRA_TWO, repoId)
.put(BundleConstant.EXTRA_THREE, showRepoBtn)
.end());
return intent;
@ -178,6 +186,13 @@ public class PullRequestPagerView extends BaseActivity<PullRequestPagerMvp.View,
String msg = getPresenter().getPullRequest().getTitle();
MergePullRequestView.newInstance(msg).show(getSupportFragmentManager(), "MergePullRequestView");
}
} else if (item.getItemId() == R.id.toRepo) {
NameParser nameParser = new NameParser("");
nameParser.setName(getPresenter().getRepoId());
nameParser.setUsername(getPresenter().getLogin());
RepoPagerView.startRepoPager(this, nameParser);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@ -191,6 +206,7 @@ public class PullRequestPagerView extends BaseActivity<PullRequestPagerMvp.View,
MenuItem edit = menu.findItem(R.id.edit);
MenuItem editMenu = menu.findItem(R.id.editMenu);
MenuItem merge = menu.findItem(R.id.merge);
menu.findItem(R.id.toRepo).setVisible(getPresenter().showToRepoBtn());
boolean isOwner = getPresenter().isOwner();
boolean isLocked = getPresenter().isLocked();
boolean isCollaborator = getPresenter().isCollaborator();

View File

@ -153,19 +153,19 @@ public class PrettifyWebView extends NestedWebView {
}
}
private void startActivity(Uri url) {
private void startActivity(@Nullable Uri url) {
if (url == null) return;
Logger.e(url);
if (MarkDownProvider.isImage(url.toString())) {
CodeViewerView.startActivity(getContext(), url.toString());
} else {
String lastSegment = url.getEncodedFragment();
Logger.e(lastSegment);
if (lastSegment != null) {
loadUrl("javascript:scrollTo(\"" + lastSegment + "\")");
String anchorLink = url.getEncodedFragment();
Logger.e(anchorLink);
if (anchorLink != null) {
loadUrl("javascript:scrollTo(\"" + anchorLink + "\")");
return;
}
SchemeParser.launchUri(getContext(), url);
SchemeParser.launchUri(getContext(), url, true);
}
}

View File

@ -44,11 +44,17 @@
</menu>
</item>
<item
android:id="@+id/toRepo"
android:icon="@drawable/ic_home"
android:title="@string/repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
app:showAsAction="never"/>
</menu>

View File

@ -49,10 +49,16 @@
</item>
<item
android:id="@+id/toRepo"
android:icon="@drawable/ic_home"
android:title="@string/repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
app:showAsAction="never"/>
</menu>

View File

@ -7,4 +7,12 @@
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="always"/>
<item
android:id="@+id/toRepo"
android:icon="@drawable/ic_home"
android:title="@string/repo"
android:visible="false"
app:showAsAction="ifRoom"/>
</menu>