Skip to content

Commit 6b10de7

Browse files
committed
response wrapped.
1 parent ad6a8bc commit 6b10de7

File tree

4 files changed

+103
-36
lines changed

4 files changed

+103
-36
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.syslogic.github.model;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
import androidx.databinding.Bindable;
6+
7+
import com.google.gson.annotations.SerializedName;
8+
9+
import java.util.ArrayList;
10+
11+
/**
12+
* Model: Workflows Response
13+
*
14+
* @author Martin Zeitler
15+
*/
16+
public class WorkflowsResponse {
17+
18+
@SerializedName("total_count")
19+
private Long totalCount;
20+
21+
@SerializedName("workflows")
22+
private ArrayList<Workflow> workflows;
23+
24+
@SuppressWarnings("unused")
25+
public void setTotalCount(@NonNull Long value) {
26+
this.totalCount = value;
27+
}
28+
29+
public void setWorkflows(@NonNull ArrayList<Workflow> value) {
30+
this.workflows = value;
31+
}
32+
33+
@NonNull
34+
public Long getTotalCount() {
35+
return this.totalCount;
36+
}
37+
38+
@Nullable
39+
public ArrayList<Workflow> getWorkflows() {
40+
return this.workflows;
41+
}
42+
}

mobile/src/main/java/io/syslogic/github/recyclerview/WorkflowsAdapter.java

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.syslogic.github.databinding.FragmentWorkflowsBinding;
3636
import io.syslogic.github.model.Repository;
3737
import io.syslogic.github.model.Workflow;
38+
import io.syslogic.github.model.WorkflowsResponse;
3839
import io.syslogic.github.network.TokenHelper;
3940
import io.syslogic.github.retrofit.GithubClient;
4041

@@ -62,8 +63,6 @@ public class WorkflowsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
6263

6364
private WeakReference<Context> mContext;
6465

65-
private long totalItemCount = 0;
66-
6766
public WorkflowsAdapter(@NonNull Context context) {
6867
this.mContext = new WeakReference<>(context);
6968
}
@@ -89,15 +88,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int po
8988
binding.setItem(item);
9089
}
9190

92-
private Repository getItem(int index) {
93-
return this.mItems.get(index);
94-
}
95-
96-
@Override
97-
public int getItemCount() {
98-
return this.mItems.size();
99-
}
100-
10191
public void fetchPage(final int pageNumber) {
10292

10393
/* It may add the account and therefore must be called first */
@@ -119,10 +109,41 @@ public void fetchPage(final int pageNumber) {
119109
api.enqueue(new Callback<>() {
120110
@Override
121111
public void onResponse(@NonNull Call<ArrayList<Repository>> call, @NonNull Response<ArrayList<Repository>> response) {
112+
int positionStart = getItemCount();
122113
if (response.code() == 200) { // OK
123114
if (response.body() != null) {
115+
124116
ArrayList<Repository> items = response.body();
125-
int positionStart = getItemCount();
117+
for (Repository item : items) {
118+
119+
Call<WorkflowsResponse> api2 = GithubClient.getWorkflows(accessToken, username,item.getName());
120+
// if (BuildConfig.DEBUG) {Log.w(LOG_TAG, api2.request().url() + "");}
121+
api2.enqueue(new Callback<>() {
122+
@Override
123+
public void onResponse(@NonNull Call<WorkflowsResponse> call, @NonNull Response<WorkflowsResponse> response) {
124+
if (response.code() == 200) { // OK
125+
if (response.body() != null) {
126+
WorkflowsResponse items = response.body();
127+
assert items.getWorkflows() != null;
128+
for (Workflow item : items.getWorkflows()) {
129+
if (BuildConfig.DEBUG) {Log.d(LOG_TAG, "has workflow: " + item.getName());}
130+
}
131+
}
132+
} else {
133+
/* "bad credentials" means that the provided access-token is invalid. */
134+
if (response.errorBody() != null) {
135+
logError(response.errorBody());
136+
}
137+
}
138+
}
139+
140+
@Override
141+
public void onFailure(@NonNull Call<WorkflowsResponse> call, @NonNull Throwable t) {
142+
if (BuildConfig.DEBUG) {Log.e(LOG_TAG, "onFailure: " + t.getMessage());}
143+
}
144+
});
145+
}
146+
126147
getItems().addAll(items);
127148
notifyItemRangeChanged(positionStart, getItemCount());
128149
}
@@ -141,6 +162,16 @@ public void onFailure(@NonNull Call<ArrayList<Repository>> call, @NonNull Throwa
141162
});
142163
}
143164

165+
/** Getters */
166+
private Repository getItem(int index) {
167+
return this.mItems.get(index);
168+
}
169+
170+
@Override
171+
public int getItemCount() {
172+
return this.mItems.size();
173+
}
174+
144175
ArrayList<Repository> getItems() {
145176
return this.mItems;
146177
}
@@ -167,27 +198,11 @@ private String getAccessToken() {
167198
}
168199
}
169200

170-
void clearItems() {
171-
this.mItems.clear();
172-
notifyItemRangeChanged(0, getItemCount());
173-
}
174-
175201
@NonNull
176202
protected Context getContext() {
177203
return this.mContext.get();
178204
}
179205

180-
/** Setters */
181-
void setTotalItemCount(long value) {
182-
this.totalItemCount = value;
183-
}
184-
185-
/** Getters */
186-
@SuppressWarnings("unused")
187-
private long getTotalItemCount() {
188-
return this.totalItemCount;
189-
}
190-
191206
void logError(@NonNull ResponseBody responseBody) {
192207
try {
193208
String errors = responseBody.string();

mobile/src/main/java/io/syslogic/github/retrofit/GithubClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
1010

11+
import io.syslogic.github.Constants;
1112
import io.syslogic.github.model.Branch;
1213
import io.syslogic.github.model.RateLimits;
1314
import io.syslogic.github.model.RepositorySearch;
1415
import io.syslogic.github.model.Repository;
1516
import io.syslogic.github.model.User;
16-
import io.syslogic.github.model.WorkflowJobs;
17+
import io.syslogic.github.model.WorkflowsResponse;
1718

1819
import okhttp3.OkHttpClient;
1920
import okhttp3.ResponseBody;
@@ -22,8 +23,6 @@
2223
import retrofit2.Retrofit;
2324
import retrofit2.converter.gson.GsonConverterFactory;
2425

25-
import io.syslogic.github.Constants;
26-
2726
/**
2827
* GitHub API Client
2928
*
@@ -94,9 +93,8 @@ private static GithubService getService() {
9493
return getService().getBranch(owner, repo, branch);
9594
}
9695

97-
@SuppressWarnings("unused")
98-
public static @NonNull Call<WorkflowJobs> getWorkflowRuns(@Nullable String token, @NonNull String owner, @NonNull String repo, @NonNull Integer jobId) {
99-
return getService().getWorkflowRuns("token " + token, owner, repo, jobId);
96+
public static @NonNull Call<WorkflowsResponse> getWorkflows(@Nullable String token, @NonNull String owner, @NonNull String repo) {
97+
return getService().getWorkflows("token " + token, owner, repo);
10098
}
10199

102100
public static @NonNull Call<ResponseBody> getArchiveLink(@NonNull String token, @NonNull String owner, @NonNull String repo, @NonNull String format, @NonNull String ref) {

mobile/src/main/java/io/syslogic/github/retrofit/GithubService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.syslogic.github.model.Repository;
1212
import io.syslogic.github.model.User;
1313
import io.syslogic.github.model.WorkflowJobs;
14+
import io.syslogic.github.model.WorkflowsResponse;
1415

1516
import okhttp3.ResponseBody;
1617

@@ -150,10 +151,21 @@ Call<RepositorySearch> getRepositories(
150151
@NonNull @Header("Authorization") String token
151152
);
152153

153-
/** GitHub Actions: Workflow Runs */
154+
/**
155+
* GitHub Actions: Workflows
156+
*/
157+
@NonNull
158+
@GET("/repos/{owner}/{repo}/actions/workflows")
159+
Call<WorkflowsResponse> getWorkflows(
160+
@NonNull @Header("Authorization") String token,
161+
@NonNull @Path(value = "owner") String owner,
162+
@NonNull @Path(value = "repo") String repo
163+
);
164+
165+
/** GitHub Actions: Workflow Run */
154166
@NonNull
155167
@GET("/repos/{owner}/{repo}/actions/jobs/{jobId}")
156-
Call<WorkflowJobs> getWorkflowRuns(
168+
Call<WorkflowJobs> getWorkflowRun(
157169
@NonNull @Header("Authorization") String token,
158170
@NonNull @Path(value = "owner") String owner,
159171
@NonNull @Path(value = "repo") String repo,

0 commit comments

Comments
 (0)