2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.viewmodels;
|
|
|
|
|
2019-11-13 16:52:49 +01:00
|
|
|
import android.content.Context;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import androidx.lifecycle.ViewModel;
|
2021-02-11 11:23:35 +01:00
|
|
|
import org.gitnex.tea4j.models.Releases;
|
2020-11-02 16:17:00 +01:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
import java.util.List;
|
2019-06-03 23:25:05 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class ReleasesViewModel extends ViewModel {
|
|
|
|
|
|
|
|
private static MutableLiveData<List<Releases>> releasesList;
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
public LiveData<List<Releases>> getReleasesList(String token, String owner, String repo, Context ctx) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
releasesList = new MutableLiveData<>();
|
2020-11-02 16:17:00 +01:00
|
|
|
loadReleasesList(token, owner, repo, ctx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
return releasesList;
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
public static void loadReleasesList(String token, String owner, String repo, Context ctx) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
Call<List<Releases>> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getReleases(token, owner, repo);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<List<Releases>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Releases>> call, @NonNull Response<List<Releases>> response) {
|
|
|
|
|
|
|
|
if (response.isSuccessful()) {
|
|
|
|
releasesList.postValue(response.body());
|
|
|
|
} else {
|
|
|
|
Log.i("onResponse", String.valueOf(response.code()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Releases>> call, Throwable t) {
|
|
|
|
Log.i("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|