mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-07-15 21:25:46 -05:00
Minor improvements
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package org.mian.gitnex.viewmodels;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import org.gitnex.tea4j.models.Branches;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import java.util.List;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class BranchesViewModel extends ViewModel {
|
||||
|
||||
private static MutableLiveData<List<Branches>> branchesList;
|
||||
|
||||
public LiveData<List<Branches>> getBranchesList(String token, String owner, String repo, Context ctx) {
|
||||
|
||||
branchesList = new MutableLiveData<>();
|
||||
loadBranchesList(token, owner, repo, ctx);
|
||||
|
||||
return branchesList;
|
||||
}
|
||||
|
||||
public static void loadBranchesList(String token, String owner, String repo, Context ctx) {
|
||||
|
||||
Call<List<Branches>> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getBranches(token, owner, repo);
|
||||
|
||||
call.enqueue(new Callback<List<Branches>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull Response<List<Branches>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
branchesList.postValue(response.body());
|
||||
} else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Branches>> call, Throwable t) {
|
||||
Log.i("onFailure", t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,17 +7,19 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import org.gitnex.tea4j.models.Issues;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.BaseActivity;
|
||||
import org.mian.gitnex.adapters.ExploreIssuesAdapter;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.List;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesViewModel extends ViewModel {
|
||||
@@ -45,21 +47,22 @@ public class IssuesViewModel extends ViewModel {
|
||||
.getApiInterface(ctx)
|
||||
.queryIssues(token, searchKeyword, type, created, state, resultLimit, 1);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
if(response.isSuccessful()) {
|
||||
issuesList.postValue(response.body());
|
||||
}
|
||||
else {
|
||||
Log.e("onResponse", String.valueOf(response.code()));
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, Throwable t) {
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
@@ -90,7 +93,7 @@ public class IssuesViewModel extends ViewModel {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.e("onResponse", String.valueOf(response.code()));
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user