mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
fbe55035f2
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>
120 lines
4.3 KiB
Java
120 lines
4.3 KiB
Java
package org.mian.gitnex.actions;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.NonNull;
|
|
import org.gitnex.tea4j.v2.models.AddCollaboratorOption;
|
|
import org.mian.gitnex.R;
|
|
import org.mian.gitnex.activities.AddCollaboratorToRepositoryActivity;
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
import org.mian.gitnex.fragments.CollaboratorsFragment;
|
|
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 CollaboratorActions {
|
|
|
|
public static void deleteCollaborator(final Context context, String userName, RepositoryContext repository) {
|
|
|
|
Call<Void> call = RetrofitClient
|
|
.getApiInterface(context)
|
|
.repoDeleteCollaborator(repository.getOwner(), repository.getName(), userName);
|
|
|
|
call.enqueue(new Callback<>() {
|
|
|
|
@Override
|
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
|
|
|
if(response.isSuccessful()) {
|
|
if(response.code() == 204) {
|
|
|
|
CollaboratorsFragment.refreshCollaborators = true;
|
|
Toasty.success(context, context.getString(R.string.removeCollaboratorToastText));
|
|
((AddCollaboratorToRepositoryActivity) context).finish();
|
|
}
|
|
}
|
|
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.cancelButton),
|
|
context.getResources().getString(R.string.navLogout));
|
|
}
|
|
else if(response.code() == 403) {
|
|
|
|
Toasty.error(context, context.getString(R.string.authorizeError));
|
|
}
|
|
else if(response.code() == 404) {
|
|
|
|
Toasty.warning(context, context.getString(R.string.apiNotFound));
|
|
}
|
|
else {
|
|
|
|
Toasty.error(context, context.getString(R.string.genericError));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
|
|
|
Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError));
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
public static void addCollaborator(final Context context, String permission, String userName, RepositoryContext repository) {
|
|
|
|
AddCollaboratorOption permissionString = new AddCollaboratorOption();
|
|
permissionString.setPermission(permission);
|
|
|
|
Call<Void> call = RetrofitClient
|
|
.getApiInterface(context)
|
|
.repoAddCollaborator(repository.getOwner(), repository.getName(), userName, permissionString);
|
|
|
|
call.enqueue(new Callback<>() {
|
|
|
|
@Override
|
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
|
|
|
if(response.isSuccessful()) {
|
|
if(response.code() == 204) {
|
|
|
|
CollaboratorsFragment.refreshCollaborators = true;
|
|
Toasty.success(context, context.getString(R.string.addCollaboratorToastText));
|
|
((AddCollaboratorToRepositoryActivity) context).finish();
|
|
}
|
|
}
|
|
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.cancelButton),
|
|
context.getResources().getString(R.string.navLogout));
|
|
}
|
|
else if(response.code() == 403) {
|
|
|
|
Toasty.error(context, context.getString(R.string.authorizeError));
|
|
}
|
|
else if(response.code() == 404) {
|
|
|
|
Toasty.warning(context, context.getString(R.string.apiNotFound));
|
|
}
|
|
else {
|
|
|
|
Toasty.error(context, context.getString(R.string.genericError));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
|
|
|
Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError));
|
|
}
|
|
});
|
|
}
|
|
}
|