forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dribbble team API methods & data manager.
- Loading branch information
1 parent
84b256a
commit 1e8142f
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/main/java/io/plaidapp/data/api/dribbble/TeamMembersDataManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.data.api.dribbble; | ||
|
||
import android.content.Context; | ||
|
||
import java.util.List; | ||
|
||
import io.plaidapp.data.PaginatedDataManager; | ||
import io.plaidapp.data.api.dribbble.model.User; | ||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
/** | ||
* Loads the members of a given dribbble team. | ||
*/ | ||
public abstract class TeamMembersDataManager extends PaginatedDataManager<List<User>> { | ||
|
||
private final String teamName; | ||
private Call teamMembersCall; | ||
|
||
public TeamMembersDataManager(Context context, String teamName) { | ||
super(context); | ||
this.teamName = teamName; | ||
} | ||
|
||
@Override | ||
public void cancelLoading() { | ||
if (teamMembersCall != null) teamMembersCall.cancel(); | ||
} | ||
|
||
@Override | ||
protected void loadData(int page) { | ||
teamMembersCall = getDribbbleApi() | ||
.getTeamMembers(teamName, page, DribbbleService.PER_PAGE_DEFAULT); | ||
teamMembersCall.enqueue(new Callback<List<User>>() { | ||
|
||
@Override | ||
public void onResponse(Call<List<User>> call, Response<List<User>> response) { | ||
if (response.isSuccessful()) { | ||
loadFinished(); | ||
final List<User> teamMembers = response.body(); | ||
moreDataAvailable = teamMembers.size() == DribbbleService.PER_PAGE_DEFAULT; | ||
onDataLoaded(teamMembers); | ||
teamMembersCall = null; | ||
} else { | ||
failure(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<List<User>> call, Throwable t) { | ||
failure(); | ||
} | ||
|
||
private void failure() { | ||
loadFinished(); | ||
moreDataAvailable = false; | ||
teamMembersCall = null; | ||
} | ||
}); | ||
} | ||
} |