diff --git a/app/src/main/java/org/mian/gitnex/actions/PullRequestActions.java b/app/src/main/java/org/mian/gitnex/actions/PullRequestActions.java new file mode 100644 index 00000000..61c2e687 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/actions/PullRequestActions.java @@ -0,0 +1,62 @@ +package org.mian.gitnex.actions; + +import android.content.Context; +import androidx.annotation.NonNull; +import com.google.gson.JsonElement; +import org.mian.gitnex.R; +import org.mian.gitnex.clients.RetrofitClient; +import org.mian.gitnex.helpers.AlertDialogs; +import org.mian.gitnex.helpers.Authorization; +import org.mian.gitnex.helpers.Toasty; +import retrofit2.Call; +import retrofit2.Callback; + +/** + * Author qwerty287 + */ + +public class PullRequestActions { + + public static void deleteHeadBranch(Context context, String repoOwner, String repoName, String headBranch, boolean showToasts) { + Call call = RetrofitClient + .getApiInterface(context) + .deleteBranch(Authorization.get(context), repoOwner, repoName, headBranch); + + call.enqueue(new Callback() { + + @Override + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + + if(response.code() == 204) { + + if(showToasts) Toasty.success(context, context.getString(R.string.deleteBranchSuccess)); + } + else if(response.code() == 401) { + + AlertDialogs + .authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle), context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton)); + } + else if(response.code() == 403) { + + if(showToasts) Toasty.error(context, context.getString(R.string.authorizeError)); + } + else if(response.code() == 404) { + + if(showToasts) Toasty.warning(context, context.getString(R.string.deleteBranchErrorNotFound)); + } + else { + + if(showToasts) Toasty.error(context, context.getString(R.string.genericError)); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + + if(showToasts) Toasty.error(context, context.getString(R.string.deleteBranchError)); + } + + }); + } + +} diff --git a/app/src/main/java/org/mian/gitnex/activities/MergePullRequestActivity.java b/app/src/main/java/org/mian/gitnex/activities/MergePullRequestActivity.java index 12b5d48a..e7f53cf7 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MergePullRequestActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MergePullRequestActivity.java @@ -12,6 +12,7 @@ import com.google.gson.JsonElement; import org.gitnex.tea4j.models.MergePullRequest; import org.gitnex.tea4j.models.MergePullRequestSpinner; import org.mian.gitnex.R; +import org.mian.gitnex.actions.PullRequestActions; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.databinding.ActivityMergePullRequestBinding; import org.mian.gitnex.helpers.AlertDialogs; @@ -187,7 +188,7 @@ public class MergePullRequestActivity extends BaseActivity { final String repoOwner = parts[0]; final String repoName = parts[1]; - deleteBranchFunction(repoOwner, repoName); + PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false); Toasty.success(ctx, getString(R.string.mergePRSuccessMsg)); tinyDB.putBoolean("prMerged", true); @@ -201,7 +202,7 @@ public class MergePullRequestActivity extends BaseActivity { final String repoOwner = parts[0]; final String repoName = parts[1]; - deleteBranchFunction(repoOwner, repoName); + PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false); Toasty.success(ctx, getString(R.string.mergePRSuccessMsg)); tinyDB.putBoolean("prMerged", true); @@ -253,36 +254,6 @@ public class MergePullRequestActivity extends BaseActivity { } - private void deleteBranchFunction(String repoOwner, String repoName) { - - String branchName = tinyDB.getString("prHeadBranch"); - - Call call = RetrofitClient - .getApiInterface(ctx) - .deleteBranch(Authorization.get(ctx), repoOwner, repoName, branchName); - - call.enqueue(new Callback() { - - @Override - public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { - - if(response.code() == 204) { - - Log.i("deleteBranch", "Branch deleted successfully"); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - - Log.e("onFailure", t.toString()); - enableProcessButton(); - } - - }); - - } - private void disableProcessButton() { viewBinding.mergeButton.setEnabled(false); diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsSecurityActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsSecurityActivity.java index 0e81ccb0..1573198b 100644 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsSecurityActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/SettingsSecurityActivity.java @@ -31,10 +31,10 @@ public class SettingsSecurityActivity extends BaseActivity { private View.OnClickListener onClickListener; - private static final String[] cacheSizeDataList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"}; + private static String[] cacheSizeDataList; private static int cacheSizeDataSelectedChoice = 0; - private static final String[] cacheSizeImagesList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"}; + private static String[] cacheSizeImagesList; private static int cacheSizeImagesSelectedChoice = 0; @Override @@ -61,6 +61,9 @@ public class SettingsSecurityActivity extends BaseActivity { SwitchMaterial switchBiometric = activitySettingsSecurityBinding.switchBiometric; + cacheSizeDataList = getResources().getStringArray(R.array.cacheSizeList); + cacheSizeImagesList = getResources().getStringArray(R.array.cacheSizeList); + if(!tinyDB.getString("cacheSizeStr").isEmpty()) { cacheSizeDataSelected.setText(tinyDB.getString("cacheSizeStr")); diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java index a0e5778d..b678c96a 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java @@ -13,17 +13,24 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.google.gson.JsonElement; import org.mian.gitnex.R; import org.mian.gitnex.actions.IssueActions; +import org.mian.gitnex.actions.PullRequestActions; import org.mian.gitnex.activities.EditIssueActivity; import org.mian.gitnex.activities.FileDiffActivity; import org.mian.gitnex.activities.MergePullRequestActivity; +import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.databinding.BottomSheetSingleIssueBinding; +import org.mian.gitnex.helpers.AlertDialogs; +import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; import org.mian.gitnex.helpers.Version; import org.mian.gitnex.views.ReactionSpinner; import java.util.Objects; +import retrofit2.Call; +import retrofit2.Callback; /** * Author M M Arif @@ -50,6 +57,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment { TextView copyIssueUrl = bottomSheetSingleIssueBinding.copyIssueUrl; TextView openFilesDiff = bottomSheetSingleIssueBinding.openFilesDiff; TextView mergePullRequest = bottomSheetSingleIssueBinding.mergePullRequest; + TextView deletePullRequestBranch = bottomSheetSingleIssueBinding.deletePrHeadBranch; TextView shareIssue = bottomSheetSingleIssueBinding.shareIssue; TextView subscribeIssue = bottomSheetSingleIssueBinding.subscribeIssue; TextView unsubscribeIssue = bottomSheetSingleIssueBinding.unsubscribeIssue; @@ -85,9 +93,11 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment { if(tinyDB.getBoolean("prMerged") || tinyDB.getString("repoPrState").equals("closed")) { mergePullRequest.setVisibility(View.GONE); + deletePullRequestBranch.setVisibility(View.VISIBLE); } else { mergePullRequest.setVisibility(View.VISIBLE); + deletePullRequestBranch.setVisibility(View.GONE); } if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.13.0")) { @@ -104,6 +114,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment { else { mergePullRequest.setVisibility(View.GONE); + deletePullRequestBranch.setVisibility(View.GONE); } mergePullRequest.setOnClickListener(v13 -> { @@ -112,6 +123,12 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment { dismiss(); }); + deletePullRequestBranch.setOnClickListener(v -> { + + PullRequestActions.deleteHeadBranch(ctx, parts[0], parts[1], tinyDB.getString("prHeadBranch"), true); + dismiss(); + }); + openFilesDiff.setOnClickListener(v14 -> { startActivity(new Intent(ctx, FileDiffActivity.class)); diff --git a/app/src/main/res/layout/bottom_sheet_single_issue.xml b/app/src/main/res/layout/bottom_sheet_single_issue.xml index 3eb32ac8..e6278303 100644 --- a/app/src/main/res/layout/bottom_sheet_single_issue.xml +++ b/app/src/main/res/layout/bottom_sheet_single_issue.xml @@ -58,6 +58,21 @@ android:textSize="16sp" app:drawableStartCompat="@drawable/ic_pull_request" /> + + @string/pageTitleNotifications @string/navExplore + + + 50 MB + 100 MB + 250 MB + 500 MB + 1 GB + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a78d08ae..dd9c69f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -556,6 +556,10 @@ %1$s File Changed Files Changed Merge Pull Request + Delete head branch + Branch deleted successfully + Could not delete branch + Branch does not exist Merge Delete branch after merge Merge may fail if you are not authorized to merge this Pull Request.