From 639cf51027e071bd48003ef7a247a28a1074e588 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Thu, 5 Nov 2020 13:10:17 +0100 Subject: [PATCH] Org level labels in issue labels (#763) Adding null checks. Minor cleanups. Merge branch 'master' into org-labels-in-issue Fix repo size Add new instances Merge branch 'master' into org-labels-in-issue Add org level labels to issue labels Co-authored-by: opyale Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/763 Reviewed-by: opyale --- app/src/main/AndroidManifest.xml | 2 + .../mian/gitnex/actions/LabelsActions.java | 49 +++++++++++++------ .../gitnex/fragments/RepoInfoFragment.java | 2 +- .../mian/gitnex/interfaces/ApiInterface.java | 5 +- .../gitnex/viewmodels/LabelsViewModel.java | 2 +- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2fc3c044..c03c9b95 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -179,6 +179,8 @@ + + diff --git a/app/src/main/java/org/mian/gitnex/actions/LabelsActions.java b/app/src/main/java/org/mian/gitnex/actions/LabelsActions.java index 70a740ba..72c48521 100644 --- a/app/src/main/java/org/mian/gitnex/actions/LabelsActions.java +++ b/app/src/main/java/org/mian/gitnex/actions/LabelsActions.java @@ -63,7 +63,7 @@ public class LabelsActions { Call> call = RetrofitClient .getApiInterface(ctx) - .getlabels(Authorization.get(ctx), repoOwner, repoName); + .getLabels(Authorization.get(ctx), repoOwner, repoName); call.enqueue(new Callback>() { @@ -71,26 +71,45 @@ public class LabelsActions { public void onResponse(@NonNull Call> call, @NonNull retrofit2.Response> response) { labelsList.clear(); - List labelsList_ = response.body(); - - labelsBinding.progressBar.setVisibility(View.GONE); - labelsBinding.dialogFrame.setVisibility(View.VISIBLE); if (response.code() == 200) { - assert labelsList_ != null; + if(response.body() != null) { - if(labelsList_.size() > 0) { - - labelsList.addAll(labelsList_); - } - else { - - dialogLabels.dismiss(); - Toasty.warning(ctx, ctx.getResources().getString(R.string.noLabelsFound)); + labelsList.addAll(response.body()); } - labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter); + // Load organization labels + Call> callOrgLabels = RetrofitClient + .getApiInterface(ctx) + .getOrganizationLabels(Authorization.get(ctx), repoOwner); + + callOrgLabels.enqueue(new Callback>() { + + @Override + public void onResponse(@NonNull Call> call, @NonNull retrofit2.Response> responseOrg) { + + labelsBinding.progressBar.setVisibility(View.GONE); + labelsBinding.dialogFrame.setVisibility(View.VISIBLE); + + if(responseOrg.body() != null) { + + labelsList.addAll(responseOrg.body()); + } + + if(labelsList.isEmpty()) { + + dialogLabels.dismiss(); + Toasty.warning(ctx, ctx.getResources().getString(R.string.noLabelsFound)); + + } + + labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter); + } + + @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) {} + + }); } else { diff --git a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java index 9ebd43ae..7dd76b90 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java @@ -262,7 +262,7 @@ public class RepoInfoFragment extends Fragment { repoMetaForks.setText(repoInfo.getForks_count()); repoMetaWatchers.setText(repoInfo.getWatchers_count()); - repoMetaSize.setText(FileUtils.byteCountToDisplaySize((int) repoInfo.getSize())); + repoMetaSize.setText(FileUtils.byteCountToDisplaySize((int) (repoInfo.getSize() * 1024))); repoMetaCreatedAt.setText(TimeHelper.formatTime(repoInfo.getCreated_at(), new Locale(locale), timeFormat, ctx)); if(timeFormat.equals("pretty")) { diff --git a/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java b/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java index e37722b2..d07f58f7 100644 --- a/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java +++ b/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java @@ -176,7 +176,10 @@ public interface ApiInterface { Call createNewIssue(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Body CreateIssue jsonStr); @GET("repos/{owner}/{repo}/labels") // get labels list - Call> getlabels(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName); + Call> getLabels(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName); + + @GET("orgs/{owner}/labels") // get org labels list + Call> getOrganizationLabels(@Header("Authorization") String token, @Path("owner") String ownerName); @GET("users/{username}/repos") // get current logged in user repositories Call> getCurrentUserRepositories(@Header("Authorization") String token, @Path("username") String username, @Query("page") int page, @Query("limit") int limit); diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/LabelsViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/LabelsViewModel.java index c42455f9..c83c4df5 100644 --- a/app/src/main/java/org/mian/gitnex/viewmodels/LabelsViewModel.java +++ b/app/src/main/java/org/mian/gitnex/viewmodels/LabelsViewModel.java @@ -33,7 +33,7 @@ public class LabelsViewModel extends ViewModel { Call> call = RetrofitClient .getApiInterface(ctx) - .getlabels(token, owner, repo); + .getLabels(token, owner, repo); call.enqueue(new Callback>() {