2020-05-20 20:21:09 +02:00
|
|
|
package org.mian.gitnex.actions;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.activities.AddNewTeamMemberActivity;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
2022-04-06 17:27:02 +02:00
|
|
|
* @author M M Arif
|
2020-05-20 20:21:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class TeamActions {
|
|
|
|
|
|
|
|
public static void removeTeamMember(final Context context, String userName, int teamId) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Call<Void> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(context)
|
2022-04-18 09:10:54 +02:00
|
|
|
.orgRemoveTeamMember((long) teamId, userName);
|
2020-05-20 20:21:09 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
|
|
|
|
if(response.code() == 204) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(context, context.getString(R.string.memberRemovedMessage));
|
2022-04-06 17:27:02 +02:00
|
|
|
((AddNewTeamMemberActivity) context).finish();
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
2022-04-06 17:27:02 +02:00
|
|
|
context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.cancelButton),
|
|
|
|
context.getResources().getString(R.string.navLogout));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 403) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(context, context.getString(R.string.authorizeError));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(context, context.getString(R.string.apiNotFound));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(context, context.getString(R.string.genericError));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addTeamMember(final Context context, String userName, int teamId) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Call<Void> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(context)
|
2022-04-18 09:10:54 +02:00
|
|
|
.orgAddTeamMember((long) teamId, userName);
|
2020-05-20 20:21:09 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
|
|
|
|
if(response.code() == 204) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(context, context.getString(R.string.memberAddedMessage));
|
2022-04-06 17:27:02 +02:00
|
|
|
((AddNewTeamMemberActivity) context).finish();
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
2022-04-06 17:27:02 +02:00
|
|
|
context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.cancelButton),
|
|
|
|
context.getResources().getString(R.string.navLogout));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 403) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(context, context.getString(R.string.authorizeError));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(context, context.getString(R.string.apiNotFound));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(context, context.getString(R.string.genericError));
|
2020-05-20 20:21:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
2020-05-20 20:21:09 +02:00
|
|
|
|
|
|
|
Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|