2020-10-09 17:47:52 +02:00
|
|
|
package org.mian.gitnex.actions;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.View;
|
2022-08-07 21:34:02 +02:00
|
|
|
import android.widget.ProgressBar;
|
2020-10-09 17:47:52 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-08-07 21:34:02 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.Label;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
|
|
import java.util.List;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
2022-04-06 17:27:02 +02:00
|
|
|
* @author M M Arif
|
2020-10-09 17:47:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class LabelsActions {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
public static void getCurrentIssueLabels(Context ctx, String repoOwner, String repoName, int issueIndex, List<Integer> currentLabelsIds) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<List<Label>> callSingleIssueLabels = RetrofitClient.getApiInterface(ctx).issueGetLabels(repoOwner, repoName, (long) issueIndex);
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
callSingleIssueLabels.enqueue(new Callback<>() {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<Label>> call, @NonNull retrofit2.Response<List<Label>> response) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
if(response.isSuccessful()) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
List<Label> issueLabelsList = response.body();
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
assert issueLabelsList != null;
|
|
|
|
|
|
|
|
if(issueLabelsList.size() > 0) {
|
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
for(int i = 0; i < issueLabelsList.size(); i++) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
currentLabelsIds.add(Math.toIntExact(issueLabelsList.get(i).getId()));
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-06 17:27:02 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<List<Label>> call, @NonNull Throwable t) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
public static void getRepositoryLabels(Context ctx, String repoOwner, String repoName, List<Label> labelsList, MaterialAlertDialogBuilder materialAlertDialogBuilder, LabelsListAdapter labelsAdapter,
|
|
|
|
CustomLabelsSelectionDialogBinding labelsBinding, ProgressBar progressBar) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<List<Label>> call = RetrofitClient.getApiInterface(ctx).issueListLabels(repoOwner, repoName, null, null);
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<Label>> call, @NonNull retrofit2.Response<List<Label>> response) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
|
|
|
labelsList.clear();
|
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
if(response.isSuccessful()) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2020-11-05 13:10:17 +01:00
|
|
|
if(response.body() != null) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2020-11-05 13:10:17 +01:00
|
|
|
labelsList.addAll(response.body());
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:10:17 +01:00
|
|
|
// Load organization labels
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<List<Label>> callOrgLabels = RetrofitClient.getApiInterface(ctx).orgListLabels(repoOwner, null, null);
|
2020-11-05 13:10:17 +01:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
callOrgLabels.enqueue(new Callback<>() {
|
2020-11-05 13:10:17 +01:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<Label>> call, @NonNull retrofit2.Response<List<Label>> responseOrg) {
|
2020-11-05 13:10:17 +01:00
|
|
|
|
|
|
|
if(responseOrg.body() != null) {
|
|
|
|
|
|
|
|
labelsList.addAll(responseOrg.body());
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.show();
|
2020-11-05 13:10:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(labelsList.isEmpty()) {
|
|
|
|
|
2022-03-18 09:56:49 +01:00
|
|
|
Toasty.warning(ctx, ctx.getResources().getString(R.string.noDataFound));
|
2020-11-05 13:10:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter);
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:27:02 +02:00
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<List<Label>> call, @NonNull Throwable t) {
|
2022-04-06 17:27:02 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
|
|
|
}
|
2020-11-05 13:10:17 +01:00
|
|
|
});
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericError));
|
|
|
|
}
|
2022-08-07 21:34:02 +02:00
|
|
|
if(progressBar != null) {
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
}
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<List<Label>> call, @NonNull Throwable t) {
|
2020-10-09 17:47:52 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
if(progressBar != null) {
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
}
|
2020-10-09 17:47:52 +02:00
|
|
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
}
|