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 androidx.annotation.NonNull;
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import androidx.lifecycle.ViewModel;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.List;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.User;
|
2022-04-06 17:27:02 +02:00
|
|
|
import org.mian.gitnex.R;
|
2020-11-02 16:17:00 +01:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2022-04-06 17:27:02 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2019-06-03 23:25:05 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
/**
|
2022-04-06 17:27:02 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
|
|
|
public class MembersByOrgViewModel extends ViewModel {
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private MutableLiveData<List<User>> membersList;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
public LiveData<List<User>> getMembersList(String owner, Context ctx) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
membersList = new MutableLiveData<>();
|
|
|
|
loadMembersList(owner, ctx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
return membersList;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void loadMembersList(String owner, Context ctx) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<List<User>> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx).orgListMembers(owner, null, null);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<List<User>> call,
|
|
|
|
@NonNull Response<List<User>> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
membersList.postValue(response.body());
|
|
|
|
} else {
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
2024-03-28 13:02:17 +01:00
|
|
|
public void onFailure(@NonNull Call<List<User>> call, @NonNull Throwable t) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|