mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
Move to https://codeberg.org/GitNex/tea4j-autodeploy as Retrofit interfaces. Closes #907 closes #1084 Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1088 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
77 lines
2.2 KiB
Java
77 lines
2.2 KiB
Java
package org.mian.gitnex.actions;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.NonNull;
|
|
import org.gitnex.tea4j.v2.models.EditMilestoneOption;
|
|
import org.gitnex.tea4j.v2.models.Milestone;
|
|
import org.mian.gitnex.R;
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
|
import retrofit2.Call;
|
|
import retrofit2.Callback;
|
|
|
|
/**
|
|
* Author M M Arif
|
|
*/
|
|
|
|
public class MilestoneActions {
|
|
|
|
static final private String TAG = "MilestoneActions : ";
|
|
|
|
public static void closeMilestone(final Context ctx, int milestoneId_, RepositoryContext repository) {
|
|
updateMilestoneState(ctx, milestoneId_, repository, "closed");
|
|
}
|
|
|
|
public static void openMilestone(final Context ctx, int milestoneId_, RepositoryContext repository) {
|
|
updateMilestoneState(ctx, milestoneId_, repository, "open");
|
|
}
|
|
|
|
private static void updateMilestoneState(final Context ctx, int milestoneId_, RepositoryContext repository, String state) {
|
|
|
|
EditMilestoneOption milestoneStateJson = new EditMilestoneOption();
|
|
milestoneStateJson.setState(state);
|
|
Call<Milestone> call = RetrofitClient
|
|
.getApiInterface(ctx)
|
|
.issueEditMilestone(repository.getOwner(), repository.getName(), String.valueOf(milestoneId_), milestoneStateJson);
|
|
|
|
call.enqueue(new Callback<>() {
|
|
|
|
@Override
|
|
public void onResponse(@NonNull Call<Milestone> call, @NonNull retrofit2.Response<Milestone> response) {
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
Toasty.success(ctx, ctx.getString(R.string.milestoneStatusUpdate));
|
|
|
|
}
|
|
else if(response.code() == 401) {
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage), ctx.getResources().getString(R.string.cancelButton),
|
|
ctx.getResources().getString(R.string.navLogout));
|
|
|
|
}
|
|
else {
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(@NonNull Call<Milestone> call, @NonNull Throwable t) {
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|