From e5f79751097d24d788d10b5cd2690ea44f6215b9 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Mon, 15 Aug 2022 09:57:07 +0200 Subject: [PATCH] Wiki link handler (#1186) Closes #1163 Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1186 Reviewed-by: qwerty287 --- .../gitnex/activities/DeepLinksActivity.java | 47 ++++++++++++++----- .../gitnex/activities/RepoDetailActivity.java | 19 ++++++-- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java b/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java index d90cf865..9198cc14 100644 --- a/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java @@ -84,16 +84,25 @@ public class DeepLinksActivity extends BaseActivity { String hostUri = userAccount.getInstanceUrl(); - String host = data.getHost(); - if (host == null) host = ""; + String hostExternal = data.getHost(); + int portExternal = data.getPort(); - if(hostUri.toLowerCase().contains(host.toLowerCase())) { + String hostUrlExternal; + if(portExternal > 0) { + hostUrlExternal = hostExternal + ":" + portExternal; + } + else { + hostUrlExternal = hostExternal; + } + + if (hostUrlExternal == null) hostUrlExternal = ""; + + if(hostUri.toLowerCase().contains(hostUrlExternal.toLowerCase())) { accountFound = true; AppUtil.switchToAccount(ctx, userAccount, true); break; - } } @@ -303,6 +312,17 @@ public class DeepLinksActivity extends BaseActivity { getFile(data.getPathSegments().get(0), data.getPathSegments().get(1), filePath.toString(), data.getPathSegments().get(4)), 500); } + else if(data.getPathSegments().get(2).equals("wiki")) { // wiki + + if(data.getQueryParameter("action") != null && data.getQueryParameter("action").equalsIgnoreCase("_new")) { + new Handler(Looper.getMainLooper()).postDelayed(() -> + goToRepoSection(data.getPathSegments().get(0), data.getPathSegments().get(1), "wikiNew"), 500); + } + else { + new Handler(Looper.getMainLooper()).postDelayed( + () -> goToRepoSection(data.getPathSegments().get(0), data.getPathSegments().get(1), "wiki"), 500); + } + } else { // no action, show options showNoActionButtons(); } @@ -355,14 +375,14 @@ public class DeepLinksActivity extends BaseActivity { .getApiInterface(ctx) .repoGetPullRequest(repoOwner, repoName, (long) index); - call.enqueue(new Callback() { + call.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { PullRequest prInfo = response.body(); - if (response.code() == 200) { + if(response.code() == 200) { assert prInfo != null; @@ -401,13 +421,13 @@ public class DeepLinksActivity extends BaseActivity { .getApiInterface(ctx) .repoGet(repoOwner, repoName); - call.enqueue(new Callback() { + call.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { Repository repoInfo = response.body(); - if (response.code() == 200) { + if(response.code() == 200) { assert repoInfo != null; RepositoryContext repo = new RepositoryContext(repoInfo, ctx); @@ -420,10 +440,11 @@ public class DeepLinksActivity extends BaseActivity { ctx.startActivity(repoIntent); finish(); - } else { + } + else { ctx.startActivity(mainIntent); finish(); - Log.e("onFailure-goToRepo", String.valueOf(response.code())); + Log.e("error-goToRepo", response.message()); } } @@ -441,7 +462,7 @@ public class DeepLinksActivity extends BaseActivity { private void getUserOrOrg(String userOrgName) { Call call = RetrofitClient.getApiInterface(ctx).orgGet(userOrgName); - call.enqueue(new Callback() { + call.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { @@ -474,7 +495,7 @@ public class DeepLinksActivity extends BaseActivity { private void getUser(String userName) { Call call = RetrofitClient.getApiInterface(ctx).userGet(userName); - call.enqueue(new Callback() { + call.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { @@ -502,7 +523,7 @@ public class DeepLinksActivity extends BaseActivity { private void getFile(String owner, String repo, String filePath, String branch) { Call call = RetrofitClient.getApiInterface(ctx).repoGetContents(owner, repo, filePath, branch); - call.enqueue(new Callback() { + call.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java index 731ecc1f..81734c40 100644 --- a/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java @@ -86,6 +86,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe private MaterialAlertDialogBuilder materialAlertDialogBuilder; + private Intent intentWiki; + private final ActivityResultLauncher createReleaseLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { if(result.getResultCode() == 201) { @@ -141,6 +143,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert); + intentWiki = new Intent(ctx, WikiActivity.class); + TextView toolbarTitle = findViewById(R.id.toolbar_title); toolbarTitle.setText(repository.getFullName()); @@ -762,15 +766,24 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe viewPager.setCurrentItem(4); createReleaseLauncher.launch(repository.getIntent(ctx, CreateReleaseActivity.class)); break; - case "milestones": + case "wiki": viewPager.setCurrentItem(5); break; - case "milestonesNew": + case "wikiNew": viewPager.setCurrentItem(5); + intentWiki.putExtra("action", "add"); + intentWiki.putExtra(RepositoryContext.INTENT_EXTRA, ((RepoDetailActivity) ctx).repository); + ctx.startActivity(intentWiki); + break; + case "milestones": + viewPager.setCurrentItem(6); + break; + case "milestonesNew": + viewPager.setCurrentItem(6); createMilestoneLauncher.launch(repository.getIntent(ctx, CreateMilestoneActivity.class)); break; case "labels": - viewPager.setCurrentItem(6); + viewPager.setCurrentItem(7); break; case "settings": settingsLauncher.launch(repository.getIntent(ctx, RepositorySettingsActivity.class));