Wiki link handler (#1186)

Closes #1163

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1186
Reviewed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
M M Arif 2022-08-15 09:57:07 +02:00
parent 9fa2e3f506
commit e5f7975109
2 changed files with 50 additions and 16 deletions

View File

@ -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<PullRequest>() {
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<PullRequest> call, @NonNull retrofit2.Response<PullRequest> 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<Repository>() {
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<Repository> call, @NonNull retrofit2.Response<Repository> 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<Organization> call = RetrofitClient.getApiInterface(ctx).orgGet(userOrgName);
call.enqueue(new Callback<Organization>() {
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<Organization> call, @NonNull Response<Organization> response) {
@ -474,7 +495,7 @@ public class DeepLinksActivity extends BaseActivity {
private void getUser(String userName) {
Call<User> call = RetrofitClient.getApiInterface(ctx).userGet(userName);
call.enqueue(new Callback<User>() {
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<User> call, @NonNull Response<User> response) {
@ -502,7 +523,7 @@ public class DeepLinksActivity extends BaseActivity {
private void getFile(String owner, String repo, String filePath, String branch) {
Call<ContentsResponse> call = RetrofitClient.getApiInterface(ctx).repoGetContents(owner, repo, filePath, branch);
call.enqueue(new Callback<ContentsResponse>() {
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<ContentsResponse> call, @NonNull Response<ContentsResponse> response) {

View File

@ -86,6 +86,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe
private MaterialAlertDialogBuilder materialAlertDialogBuilder;
private Intent intentWiki;
private final ActivityResultLauncher<Intent> 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));