added stargazers and other fixes and enhancements

This commit is contained in:
M M Arif
2019-09-13 20:56:30 +05:00
parent d24e7ffc3b
commit df260f05d2
23 changed files with 734 additions and 67 deletions

View File

@@ -0,0 +1,60 @@
package org.mian.gitnex.viewmodels;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.models.UserInfo;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
*/
public class RepoStargazersViewModel extends ViewModel {
private static MutableLiveData<List<UserInfo>> stargazersList;
public LiveData<List<UserInfo>> getRepoStargazers(String instanceUrl, String token, String repoOwner, String repoName) {
stargazersList = new MutableLiveData<>();
loadRepoStargazers(instanceUrl, token, repoOwner, repoName);
return stargazersList;
}
public static void loadRepoStargazers(String instanceUrl, String token, String repoOwner, String repoName) {
Call<List<UserInfo>> call = RetrofitClient
.getInstance(instanceUrl)
.getApiInterface()
.getRepoStargazers(token, repoOwner, repoName);
call.enqueue(new Callback<List<UserInfo>>() {
@Override
public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
if(response.isSuccessful()) {
if(response.code() == 200) {
stargazersList.postValue(response.body());
}
}
}
@Override
public void onFailure(@NonNull Call<List<UserInfo>> call, Throwable t) {
Log.i("onFailure", t.toString());
}
});
}
}