Skip to content

Commit ad6a8bc

Browse files
committed
missing model.
1 parent 5bfd204 commit ad6a8bc

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.syslogic.github.model;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.databinding.Bindable;
5+
6+
import com.google.gson.annotations.SerializedName;
7+
8+
import java.util.ArrayList;
9+
10+
/**
11+
* Model: Repository Listing
12+
*
13+
* @author Martin Zeitler
14+
*/
15+
public class Repositories extends BaseModel {
16+
17+
@SerializedName("items")
18+
private ArrayList<Repository> mItems;
19+
20+
@SerializedName("total_count")
21+
private Long totalCount;
22+
23+
public void setRepositories(@NonNull ArrayList<Repository> items) {
24+
this.mItems = items;
25+
}
26+
27+
@SuppressWarnings("unused")
28+
public void setTotalCount(@NonNull Long value) {
29+
this.totalCount = value;
30+
}
31+
32+
@NonNull
33+
public ArrayList<Repository> getRepositories() {
34+
return this.mItems;
35+
}
36+
37+
@NonNull
38+
@Bindable
39+
public Long getTotalCount() {
40+
return this.totalCount;
41+
}
42+
43+
@NonNull
44+
@Bindable
45+
public Long getPageCount() {
46+
Long recordsPerPage = 30L;
47+
return (this.totalCount + recordsPerPage -1) / recordsPerPage;
48+
}
49+
}

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,23 @@ public void fetchPage(final int pageNumber) {
113113
return;
114114
}
115115

116-
Call<ArrayList<Repository>> api = GithubClient.getUserRepositories(accessToken, username,"public", "full_name","desc", 100, pageNumber);
116+
Call<ArrayList<Repository>> api = GithubClient.getUserRepositories(accessToken, username,"owner", "full_name","desc", 100, pageNumber);
117117
if (BuildConfig.DEBUG) {Log.w(LOG_TAG, api.request().url() + "");}
118-
api.enqueue(new Callback<>() {
119118

119+
api.enqueue(new Callback<>() {
120120
@Override
121121
public void onResponse(@NonNull Call<ArrayList<Repository>> call, @NonNull Response<ArrayList<Repository>> response) {
122-
switch (response.code()) {
123-
124-
// OK
125-
case 200 -> {
126-
if (response.body() != null) {
127-
ArrayList<Repository> items = response.body();
128-
int positionStart = getItemCount();
129-
getItems().addAll(items);
130-
notifyItemRangeChanged(positionStart, getItemCount());
131-
}
122+
if (response.code() == 200) { // OK
123+
if (response.body() != null) {
124+
ArrayList<Repository> items = response.body();
125+
int positionStart = getItemCount();
126+
getItems().addAll(items);
127+
notifyItemRangeChanged(positionStart, getItemCount());
132128
}
133-
default -> {
134-
/* "bad credentials" means that the provided access-token is invalid. */
135-
if (response.errorBody() != null) {
136-
logError(response.errorBody());
137-
}
129+
} else {
130+
/* "bad credentials" means that the provided access-token is invalid. */
131+
if (response.errorBody() != null) {
132+
logError(response.errorBody());
138133
}
139134
}
140135
}

0 commit comments

Comments
 (0)