2020-10-23 20:13:13 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-07-23 17:41:19 +02:00
|
|
|
import org.gitnex.tea4j.models.Files;
|
|
|
|
import org.gitnex.tea4j.models.Organization;
|
2021-02-11 11:23:35 +01:00
|
|
|
import org.gitnex.tea4j.models.PullRequests;
|
2021-08-11 14:47:31 +02:00
|
|
|
import org.gitnex.tea4j.models.UserInfo;
|
2021-02-11 11:23:35 +01:00
|
|
|
import org.gitnex.tea4j.models.UserRepositories;
|
2021-07-23 17:41:19 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-10-23 20:13:13 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-04-13 20:56:50 +02:00
|
|
|
import org.mian.gitnex.database.api.BaseApi;
|
2020-10-23 20:13:13 +02:00
|
|
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
|
|
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
|
|
|
import org.mian.gitnex.database.models.Repository;
|
|
|
|
import org.mian.gitnex.database.models.UserAccount;
|
|
|
|
import org.mian.gitnex.databinding.ActivityDeeplinksBinding;
|
2021-04-13 20:56:50 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2021-07-23 17:41:19 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
2020-10-23 20:13:13 +02:00
|
|
|
import org.mian.gitnex.helpers.UrlHelper;
|
|
|
|
import java.net.URI;
|
2021-07-23 17:41:19 +02:00
|
|
|
import java.util.ArrayList;
|
2020-10-23 20:13:13 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
import io.mikael.urlbuilder.UrlBuilder;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2021-07-23 17:41:19 +02:00
|
|
|
import retrofit2.Response;
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class DeepLinksActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private ActivityDeeplinksBinding viewBinding;
|
|
|
|
private String currentInstance;
|
|
|
|
private String instanceToken;
|
2020-11-02 18:01:06 +01:00
|
|
|
private boolean accountFound = false;
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
private Intent mainIntent;
|
|
|
|
private Intent issueIntent;
|
|
|
|
private Intent repoIntent;
|
2021-07-23 17:41:19 +02:00
|
|
|
private Intent orgIntent;
|
|
|
|
private Intent userIntent;
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
viewBinding = ActivityDeeplinksBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(viewBinding.getRoot());
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
mainIntent = new Intent(ctx, MainActivity.class);
|
|
|
|
issueIntent = new Intent(ctx, IssueDetailActivity.class);
|
|
|
|
repoIntent = new Intent(ctx, RepoDetailActivity.class);
|
2021-07-23 17:41:19 +02:00
|
|
|
orgIntent = new Intent(ctx, OrganizationDetailActivity.class);
|
2021-08-11 14:47:31 +02:00
|
|
|
userIntent = new Intent(ctx, ProfileActivity.class);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
Uri data = intent.getData();
|
|
|
|
assert data != null;
|
|
|
|
|
|
|
|
// check for login
|
2020-11-02 16:17:00 +01:00
|
|
|
if(!tinyDB.getBoolean("loggedInMode")) {
|
2021-07-23 17:41:19 +02:00
|
|
|
Intent loginIntent = new Intent(ctx, LoginActivity.class);
|
|
|
|
loginIntent.putExtra("instanceUrl", data.getHost());
|
|
|
|
ctx.startActivity(loginIntent);
|
2020-10-23 20:13:13 +02:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for the links(URI) to be in the db
|
2021-04-13 20:56:50 +02:00
|
|
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
2020-10-23 20:13:13 +02:00
|
|
|
List<UserAccount> userAccounts = userAccountsApi.usersAccounts();
|
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
for(UserAccount userAccount : userAccounts) {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
String hostUri = userAccount.getInstanceUrl();
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
currentInstance = userAccount.getInstanceUrl();
|
|
|
|
instanceToken = userAccount.getToken();
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
if(hostUri.toLowerCase().contains(Objects.requireNonNull(data.getHost().toLowerCase()))) {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
accountFound = true;
|
2021-02-25 00:22:11 +01:00
|
|
|
|
2021-04-13 20:56:50 +02:00
|
|
|
AppUtil.switchToAccount(ctx, userAccount);
|
2020-11-02 18:01:06 +01:00
|
|
|
break;
|
2021-04-13 20:56:50 +02:00
|
|
|
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
if(accountFound) {
|
2020-10-29 00:21:47 +01:00
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
// redirect to proper fragment/activity, if no action is there, show options where user to want to go like repos, profile, notifications etc
|
|
|
|
if(data.getPathSegments().size() == 1) {
|
|
|
|
if(data.getLastPathSegment().equals("notifications")) { // notifications
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals("explore")) { // explore
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals(tinyDB.getString("userLogin"))) { // your user profile
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "profile");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals("admin")) {
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
getUserOrOrg(currentInstance, instanceToken, data.getLastPathSegment()), 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().size() == 2) {
|
|
|
|
if(data.getPathSegments().get(0).equals("explore")) { // specific explore tab
|
|
|
|
if(data.getPathSegments().get(1).equals("organizations")) { // orgs
|
|
|
|
mainIntent.putExtra("exploreOrgs", true);
|
|
|
|
}
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(0).equals("user") && data.getPathSegments().get(1).equals("login")) { // open login
|
|
|
|
Intent loginIntent = new Intent(ctx, AddNewAccountActivity.class);
|
|
|
|
loginIntent.putExtra("instanceUrl", data.getHost());
|
|
|
|
loginIntent.putExtra("instanceProtocol", data.getScheme());
|
|
|
|
ctx.startActivity(loginIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(0).equals("admin")) {
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
|
|
|
mainIntent.putExtra("giteaAdminAction", data.getLastPathSegment());
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(!data.getPathSegments().get(0).equals("") & !data.getLastPathSegment().equals("")) { // go to repo
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getLastPathSegment(), "repo"), 500);
|
|
|
|
}
|
|
|
|
else { // no action, show options
|
|
|
|
showNoActionButtons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().size() >= 3) {
|
|
|
|
if(data.getPathSegments().get(2).equals("issues")) { // issue
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("issues") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
issueIntent.putExtra("issueNumber", data.getLastPathSegment());
|
2021-07-09 17:36:59 +02:00
|
|
|
issueIntent.putExtra("openedFromLink", "true");
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
String[] urlSplitted = data.toString().split("#");
|
|
|
|
if (urlSplitted.length == 2) {
|
|
|
|
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
tinyDB.putString("issueNumber", data.getLastPathSegment());
|
|
|
|
tinyDB.putString("issueType", "Issue");
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
tinyDB.putString("repoFullName", data.getPathSegments().get(0) + "/" + data.getPathSegments().get(1));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
final String repoOwner = data.getPathSegments().get(0);
|
|
|
|
final String repoName = data.getPathSegments().get(1);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
2021-04-13 20:56:50 +02:00
|
|
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
if(count == 0) {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
|
|
|
tinyDB.putLong("repositoryId", id);
|
|
|
|
}
|
|
|
|
else {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
|
|
|
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
|
|
|
}
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
ctx.startActivity(issueIntent);
|
|
|
|
finish();
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
2020-11-02 18:01:06 +01:00
|
|
|
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("issues")) {
|
2021-07-23 17:41:19 +02:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issue"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals("new")) {
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issueNew"), 500);
|
2020-11-02 18:01:06 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
2021-07-23 17:41:19 +02:00
|
|
|
else if(data.getPathSegments().get(2).equals("pulls")) { // pr
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("pulls") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
String[] urlSplitted = data.toString().split("#");
|
|
|
|
if (urlSplitted.length == 2) {
|
|
|
|
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getLastPathSegment()));
|
2020-11-02 18:01:06 +01:00
|
|
|
}, 500);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
}
|
|
|
|
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("pulls")) {
|
2021-07-23 17:41:19 +02:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals("files")) { // pr diff
|
2020-11-02 18:01:06 +01:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2021-07-23 17:41:19 +02:00
|
|
|
issueIntent.putExtra("openPrDiff", "true");
|
|
|
|
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getPathSegments().get(3)));
|
2020-11-02 18:01:06 +01:00
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
2020-11-13 16:04:14 +01:00
|
|
|
}
|
|
|
|
|
2021-07-23 17:41:19 +02:00
|
|
|
else if(data.getPathSegments().get(2).equals("compare")) { // new pull request
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pullNew"), 500);
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
2021-07-23 17:41:19 +02:00
|
|
|
else if(data.getPathSegments().get(2).equals("commit")) { // commits (no API yet to properly implement)
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
2021-07-23 17:41:19 +02:00
|
|
|
else if(data.getPathSegments().get(2).equals("commits")) { // commits list
|
|
|
|
String branch = data.getLastPathSegment();
|
|
|
|
repoIntent.putExtra("branchName", branch);
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "commitsList"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("milestones") && data.getLastPathSegment().equals("new")) { // new milestone
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestonesNew"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("milestones")) { // milestones
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("milestone")) { // milestone
|
|
|
|
repoIntent.putExtra("milestoneId", data.getLastPathSegment());
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("releases") && data.getLastPathSegment().equals("new")) { // new release
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "newRelease"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("releases") && data.getPathSegments().get(3).equals("tag") && data.getPathSegments().size() == 5) { // release
|
|
|
|
repoIntent.putExtra("releaseTagName", data.getLastPathSegment());
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("releases")) { // releases
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("labels")) { // labels
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "labels"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("settings")) { // repo settings
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "settings"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getLastPathSegment().equals("branches")) { // branches list
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branchesList"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().size() == 5 && data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // branch
|
|
|
|
repoIntent.putExtra("selectedBranch", data.getLastPathSegment());
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branch"), 500);
|
|
|
|
}
|
|
|
|
else if(data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // file/dir
|
|
|
|
StringBuilder filePath = new StringBuilder();
|
|
|
|
ArrayList<String> segments = new ArrayList<>(data.getPathSegments());
|
|
|
|
segments.subList(0, 5).clear();
|
|
|
|
for (String item : segments) {
|
|
|
|
filePath.append(item);
|
|
|
|
filePath.append("/");
|
2020-11-02 18:01:06 +01:00
|
|
|
}
|
2021-07-23 17:41:19 +02:00
|
|
|
filePath.deleteCharAt(filePath.toString().length() - 1);
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
|
|
|
getFile(currentInstance, instanceToken, data.getPathSegments().get(0),
|
|
|
|
data.getPathSegments().get(1), filePath.toString(), data.getPathSegments().get(4)), 500);
|
|
|
|
}
|
|
|
|
else { // no action, show options
|
|
|
|
showNoActionButtons();
|
2020-11-02 18:01:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
viewBinding.progressBar.setVisibility(View.GONE);
|
|
|
|
viewBinding.addNewAccountFrame.setVisibility(View.VISIBLE);
|
|
|
|
viewBinding.noActionFrame.setVisibility(View.GONE);
|
|
|
|
viewBinding.addAccountText.setText(String.format(getResources().getString(R.string.accountDoesNotExist), data.getHost()));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
viewBinding.addNewAccount.setOnClickListener(addNewAccount -> {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
Intent accountIntent = new Intent(ctx, AddNewAccountActivity.class);
|
2021-07-23 17:41:19 +02:00
|
|
|
accountIntent.putExtra("instanceUrl", data.getHost());
|
2020-11-02 18:01:06 +01:00
|
|
|
startActivity(accountIntent);
|
|
|
|
finish();
|
|
|
|
});
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
viewBinding.openInBrowser.setOnClickListener(addNewAccount -> {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
Integer port = data.getPort() >= 0 ? data.getPort() : null;
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
URI host = UrlBuilder.fromString(UrlHelper.fixScheme(data.getHost(), "https"))
|
|
|
|
.withPort(port)
|
|
|
|
.toUri();
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
Intent intentBrowser = new Intent();
|
2020-10-29 00:21:47 +01:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
intentBrowser.setAction(Intent.ACTION_VIEW);
|
|
|
|
intentBrowser.addCategory(Intent.CATEGORY_BROWSABLE);
|
|
|
|
intentBrowser.setData(Uri.parse(String.valueOf(host)));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
startActivity(intentBrowser);
|
|
|
|
finish();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
viewBinding.launchApp.setOnClickListener(launchApp -> {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 18:01:06 +01:00
|
|
|
startActivity(mainIntent);
|
2020-10-23 20:13:13 +02:00
|
|
|
finish();
|
2020-11-02 18:01:06 +01:00
|
|
|
});
|
|
|
|
}
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void getPullRequest(String url, String token, String repoOwner, String repoName, int index) {
|
|
|
|
|
|
|
|
Call<PullRequests> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx, url)
|
2020-10-23 20:13:13 +02:00
|
|
|
.getPullRequestByIndex(token, repoOwner, repoName, index);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<PullRequests>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<PullRequests> call, @NonNull retrofit2.Response<PullRequests> response) {
|
|
|
|
|
|
|
|
PullRequests prInfo = response.body();
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
|
|
|
assert prInfo != null;
|
|
|
|
|
|
|
|
issueIntent.putExtra("issueNumber", index);
|
|
|
|
issueIntent.putExtra("prMergeable", prInfo.isMergeable());
|
2021-07-09 17:36:59 +02:00
|
|
|
issueIntent.putExtra("openedFromLink", "true");
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
if(prInfo.getHead() != null) {
|
|
|
|
|
|
|
|
issueIntent.putExtra("prHeadBranch", prInfo.getHead().getRef());
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("prHeadBranch", prInfo.getHead().getRef());
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
if(prInfo.getHead().getRepo() != null) {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("prIsFork", String.valueOf(prInfo.getHead().getRepo().isFork()));
|
|
|
|
tinyDB.putString("prForkFullName", prInfo.getHead().getRepo().getFull_name());
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
// pull was done from a deleted fork
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("prIsFork", "true");
|
2021-02-13 20:31:38 +01:00
|
|
|
tinyDB.putString("prForkFullName", ctx.getString(R.string.prDeletedFork));
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("issueNumber", String.valueOf(index));
|
|
|
|
tinyDB.putString("prMergeable", String.valueOf(prInfo.isMergeable()));
|
|
|
|
tinyDB.putString("issueType", "Pull");
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("repoFullName", repoOwner + "/" + repoName);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
2021-04-13 20:56:50 +02:00
|
|
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
|
|
|
|
|
|
|
if(count == 0) {
|
|
|
|
|
|
|
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putLong("repositoryId", id);
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.startActivity(issueIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
2020-11-13 16:04:14 +01:00
|
|
|
ctx.startActivity(issueIntent);
|
|
|
|
finish();
|
2020-10-23 20:13:13 +02:00
|
|
|
Log.e("onFailure-links-pr", String.valueOf(response.code()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<PullRequests> call, @NonNull Throwable t) {
|
|
|
|
|
2020-11-13 16:04:14 +01:00
|
|
|
ctx.startActivity(issueIntent);
|
|
|
|
finish();
|
2020-10-23 20:13:13 +02:00
|
|
|
Log.e("onFailure-links-pr", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void goToRepoSection(String url, String token, String repoOwner, String repoName, String type) {
|
|
|
|
|
|
|
|
Call<UserRepositories> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx, url)
|
2020-10-23 20:13:13 +02:00
|
|
|
.getUserRepository(token, repoOwner, repoName);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<UserRepositories>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
|
|
|
|
|
|
|
UserRepositories repoInfo = response.body();
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
|
|
|
assert repoInfo != null;
|
|
|
|
|
|
|
|
repoIntent.putExtra("repoFullName", repoInfo.getFullName());
|
|
|
|
repoIntent.putExtra("goToSection", "yes");
|
|
|
|
repoIntent.putExtra("goToSectionType", type);
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("repoFullName", repoInfo.getFullName());
|
2020-10-23 20:13:13 +02:00
|
|
|
if(repoInfo.getPrivateFlag()) {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("repoType", getResources().getString(R.string.strPrivate));
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putString("repoType", getResources().getString(R.string.strPublic));
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putBoolean("isRepoAdmin", repoInfo.getPermissions().isAdmin());
|
|
|
|
tinyDB.putString("repoBranch", repoInfo.getDefault_branch());
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
2021-04-13 20:56:50 +02:00
|
|
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
|
|
|
|
|
|
|
if(count == 0) {
|
|
|
|
|
|
|
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putLong("repositoryId", id);
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putLong("repositoryId", data.getRepositoryId());
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.startActivity(repoIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
2020-11-13 16:04:14 +01:00
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
Log.e("onFailure-goToRepo", String.valueOf(response.code()));
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
|
|
|
|
2020-11-13 16:04:14 +01:00
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
Log.e("onFailure-goToRepo", t.toString());
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-07-23 17:41:19 +02:00
|
|
|
|
|
|
|
private void getUserOrOrg(String url, String instanceToken, String userOrgName) {
|
|
|
|
Call<Organization> call = RetrofitClient.getApiInterface(ctx, url).getOrganization(instanceToken, userOrgName);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<Organization>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NotNull Call<Organization> call, @NotNull Response<Organization> response) {
|
|
|
|
if(response.code() == 404) { // org doesn't exist or it's a user user
|
|
|
|
Log.d("getUserOrOrg-404", String.valueOf(response.code()));
|
|
|
|
getUser(url, instanceToken, userOrgName);
|
|
|
|
}
|
|
|
|
else if(response.code() == 200) { // org
|
|
|
|
assert response.body() != null;
|
|
|
|
orgIntent.putExtra("orgName", response.body().getUsername());
|
|
|
|
|
|
|
|
|
|
|
|
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
|
|
|
tinyDb.putString("orgName", response.body().getUsername());
|
|
|
|
tinyDb.putString("organizationId", String.valueOf(response.body().getId()));
|
|
|
|
tinyDb.putBoolean("organizationAction", true);
|
|
|
|
ctx.startActivity(orgIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Log.e("getUserOrOrg-code", String.valueOf(response.code()));
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NotNull Call<Organization> call, @NotNull Throwable t) {
|
|
|
|
Log.e("onFailure-getUserOrOrg", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getUser(String url, String instanceToken, String userName) {
|
2021-08-11 14:47:31 +02:00
|
|
|
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx, url).getUserProfile(instanceToken, userName);
|
2021-07-23 17:41:19 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<UserInfo>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NotNull Call<UserInfo> call, @NotNull Response<UserInfo> response) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
assert response.body() != null;
|
|
|
|
userIntent.putExtra("username", response.body().getLogin());
|
|
|
|
ctx.startActivity(userIntent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Log.e("getUser-code", String.valueOf(response.code()));
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
}
|
2021-08-11 14:47:31 +02:00
|
|
|
finish();
|
2021-07-23 17:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NotNull Call<UserInfo> call, @NotNull Throwable t) {
|
|
|
|
Log.e("onFailure-getUser", t.toString());
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
2021-08-11 14:47:31 +02:00
|
|
|
});
|
2021-07-23 17:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void getFile(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
|
|
|
Call<Files> call = RetrofitClient.getApiInterface(ctx, url).getSingleFileContents(instanceToken, owner, repo, filePath, branch);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<Files>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NotNull Call<Files> call, @NotNull Response<Files> response) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
// check if file and open file/dir
|
|
|
|
Files file = response.body();
|
|
|
|
assert file != null;
|
|
|
|
if(file.getType().equals("file")) {
|
|
|
|
repoIntent.putExtra("file", file);
|
|
|
|
repoIntent.putExtra("branch", branch);
|
|
|
|
goToRepoSection(url, instanceToken, owner, repo, "file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Log.e("getFile-onFailure", String.valueOf(response.code()));
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NotNull Call<Files> call, @NotNull Throwable t) {
|
|
|
|
Log.e("getFile-onFailure", t.toString());
|
|
|
|
// maybe it's a directory
|
|
|
|
getDir(url, instanceToken, owner, repo, filePath, branch);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getDir(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
|
|
|
repoIntent.putExtra("branch", branch);
|
|
|
|
repoIntent.putExtra("dir", filePath);
|
|
|
|
goToRepoSection(url, instanceToken, owner, repo, "dir");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showNoActionButtons() {
|
|
|
|
viewBinding.progressBar.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if(tinyDB.getInt("defaultScreenId") == 1) { // repos
|
|
|
|
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(tinyDB.getInt("defaultScreenId") == 2) { // org
|
|
|
|
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(tinyDB.getInt("defaultScreenId") == 3) { // notifications
|
|
|
|
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(tinyDB.getInt("defaultScreenId") == 4) { // explore
|
|
|
|
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(tinyDB.getInt("defaultScreenId") == 0) { // show options
|
|
|
|
|
|
|
|
viewBinding.noActionFrame.setVisibility(View.VISIBLE);
|
|
|
|
viewBinding.addNewAccountFrame.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
viewBinding.repository.setOnClickListener(repository -> {
|
|
|
|
|
|
|
|
tinyDB.putInt("defaultScreenId", 1);
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
viewBinding.organization.setOnClickListener(organization -> {
|
|
|
|
|
|
|
|
tinyDB.putInt("defaultScreenId", 2);
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
viewBinding.notification.setOnClickListener(notification -> {
|
|
|
|
|
|
|
|
tinyDB.putInt("defaultScreenId", 3);
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
viewBinding.explore.setOnClickListener(explore -> {
|
|
|
|
|
|
|
|
tinyDB.putInt("defaultScreenId", 4);
|
|
|
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
viewBinding.launchApp2.setOnClickListener(launchApp2 -> {
|
|
|
|
|
|
|
|
tinyDB.putInt("defaultScreenId", 0);
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|