@@ -0,0 +1,86 @@
 | 
			
		||||
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.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.helpers.AlertDialogs;
 | 
			
		||||
import org.mian.gitnex.helpers.Toasty;
 | 
			
		||||
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 AdminGetUsersViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> usersList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getUsersList(Context ctx, String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        usersList = new MutableLiveData<>();
 | 
			
		||||
        loadUsersList(ctx, instanceUrl, token);
 | 
			
		||||
 | 
			
		||||
        return usersList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadUsersList(final Context ctx, String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .adminGetUsers(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.code() == 200) {
 | 
			
		||||
                    usersList.postValue(response.body());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                else if(response.code() == 401) {
 | 
			
		||||
 | 
			
		||||
                    AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
 | 
			
		||||
                            ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
 | 
			
		||||
                            ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
 | 
			
		||||
                            ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else if(response.code() == 403) {
 | 
			
		||||
 | 
			
		||||
                    Toasty.info(ctx, ctx.getString(R.string.authorizeError));
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else if(response.code() == 404) {
 | 
			
		||||
 | 
			
		||||
                    Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
 | 
			
		||||
                    Toasty.info(ctx, ctx.getString(R.string.genericError));
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, @NonNull Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Branches;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
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 instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        branchesList = new MutableLiveData<>();
 | 
			
		||||
        loadBranchesList(instanceUrl, token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        return branchesList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadBranchesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Branches>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .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());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Collaborators;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class CollaboratorsViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Collaborators>> collaboratorsList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Collaborators>> getCollaboratorsList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        collaboratorsList = new MutableLiveData<>();
 | 
			
		||||
        loadCollaboratorsListList(instanceUrl, token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        return collaboratorsList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void loadCollaboratorsListList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Collaborators>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getCollaborators(token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<Collaborators>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    collaboratorsList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<Collaborators>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,63 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.IssueComments;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class IssueCommentsViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<IssueComments>> issueComments;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<IssueComments>> getIssueCommentList(String instanceUrl, String token, String owner, String repo, int index) {
 | 
			
		||||
 | 
			
		||||
        issueComments = new MutableLiveData<>();
 | 
			
		||||
        loadIssueComments(instanceUrl, token, owner, repo, index);
 | 
			
		||||
 | 
			
		||||
        return issueComments;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadIssueComments(String instanceUrl, String token, String owner, String repo, int index) {
 | 
			
		||||
 | 
			
		||||
        Call<List<IssueComments>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getIssueComments(token, owner, repo, index);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<IssueComments>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<IssueComments>> call, @NonNull Response<List<IssueComments>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
 | 
			
		||||
                    issueComments.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<IssueComments>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Labels;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class LabelsViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Labels>> labelsList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Labels>> getLabelsList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        labelsList = new MutableLiveData<>();
 | 
			
		||||
        loadLabelsList(instanceUrl, token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        return labelsList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadLabelsList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Labels>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getlabels(token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<Labels>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Labels>> call, @NonNull Response<List<Labels>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    labelsList.postValue(response.body());
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<Labels>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class MembersByOrgViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> membersList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getMembersList(String instanceUrl, String token, String owner) {
 | 
			
		||||
 | 
			
		||||
        membersList = new MutableLiveData<>();
 | 
			
		||||
        loadMembersList(instanceUrl, token, owner);
 | 
			
		||||
 | 
			
		||||
        return membersList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void loadMembersList(String instanceUrl, String token, String owner) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getMembersByOrg(token, owner);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    membersList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Milestones;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class MilestonesViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Milestones>> milestonesList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Milestones>> getMilestonesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        milestonesList = new MutableLiveData<>();
 | 
			
		||||
        loadMilestonesList(instanceUrl, token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        return milestonesList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadMilestonesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Milestones>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getMilestones(token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<Milestones>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull Response<List<Milestones>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    milestonesList.postValue(response.body());
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<Milestones>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,63 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class MyRepositoriesViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserRepositories>> myReposList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserRepositories>> getCurrentUserRepositories(String instanceUrl, String token, String username) {
 | 
			
		||||
 | 
			
		||||
        //if (myReposList == null) {
 | 
			
		||||
        myReposList = new MutableLiveData<>();
 | 
			
		||||
        loadMyReposList(instanceUrl, token, username);
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        return myReposList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadMyReposList(String instanceUrl, String token, String username) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserRepositories>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getCurrentUserRepositories(token, username);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserRepositories>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        myReposList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserRepositories>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,63 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserOrganizations;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class OrganizationListViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserOrganizations>> orgsList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserOrganizations>> getUserOrgs(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        //if (orgsList == null) {
 | 
			
		||||
            orgsList = new MutableLiveData<>();
 | 
			
		||||
            loadOrgsList(instanceUrl, token);
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        return orgsList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadOrgsList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserOrganizations>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getUserOrgs(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserOrganizations>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserOrganizations>> call, @NonNull Response<List<UserOrganizations>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        orgsList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserOrganizations>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Emails;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class ProfileEmailsViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Emails>> emailsList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Emails>> getEmailsList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        emailsList = new MutableLiveData<>();
 | 
			
		||||
        loadEmailsList(instanceUrl, token);
 | 
			
		||||
 | 
			
		||||
        return emailsList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadEmailsList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Emails>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getUserEmails(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<Emails>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Emails>> call, @NonNull Response<List<Emails>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    emailsList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<Emails>> call, @NonNull Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class ProfileFollowersViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> followersList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getFollowersList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        followersList = new MutableLiveData<>();
 | 
			
		||||
        loadFollowersList(instanceUrl, token);
 | 
			
		||||
 | 
			
		||||
        return followersList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadFollowersList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getFollowers(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    followersList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, @NonNull Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class ProfileFollowingViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> followingList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getFollowingList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        followingList = new MutableLiveData<>();
 | 
			
		||||
        loadFollowingList(instanceUrl, token);
 | 
			
		||||
 | 
			
		||||
        return followingList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadFollowingList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getFollowing(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    followingList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, @NonNull Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Releases;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class ReleasesViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Releases>> releasesList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Releases>> getReleasesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        releasesList = new MutableLiveData<>();
 | 
			
		||||
        loadReleasesList(instanceUrl, token, owner, repo);
 | 
			
		||||
 | 
			
		||||
        return releasesList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadReleasesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Releases>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .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());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class RepositoriesByOrgViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserRepositories>> orgReposList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserRepositories>> getRepositoriesByOrg(String instanceUrl, String token, String orgName) {
 | 
			
		||||
 | 
			
		||||
        orgReposList = new MutableLiveData<>();
 | 
			
		||||
        loadOrgRepos(instanceUrl, token, orgName);
 | 
			
		||||
 | 
			
		||||
        return orgReposList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadOrgRepos(String instanceUrl, String token, String orgName) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserRepositories>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getReposByOrg(token, orgName);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserRepositories>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        orgReposList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserRepositories>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,63 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class RepositoriesListViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserRepositories>> reposList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserRepositories>> getUserRepositories(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        //if (reposList == null) {
 | 
			
		||||
            reposList = new MutableLiveData<>();
 | 
			
		||||
            loadReposList(instanceUrl, token);
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        return reposList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadReposList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserRepositories>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getUserRepositories(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserRepositories>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        reposList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserRepositories>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class StarredRepositoriesViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserRepositories>> reposList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserRepositories>> getUserStarredRepositories(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        reposList = new MutableLiveData<>();
 | 
			
		||||
        loadStarredReposList(instanceUrl, token);
 | 
			
		||||
 | 
			
		||||
        return reposList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadStarredReposList(String instanceUrl, String token) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserRepositories>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getUserStarredRepos(token);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserRepositories>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        reposList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserRepositories>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class TeamMembersByOrgViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> teamMembersList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getMembersByOrgList(String instanceUrl, String token, int teamId) {
 | 
			
		||||
 | 
			
		||||
        teamMembersList = new MutableLiveData<>();
 | 
			
		||||
        loadMembersByOrgList(instanceUrl, token, teamId);
 | 
			
		||||
 | 
			
		||||
        return teamMembersList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void loadMembersByOrgList(String instanceUrl, String token, int teamId) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getTeamMembersByOrg(token, teamId);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    teamMembersList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,61 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.Teams;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class TeamsByOrgViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<Teams>> teamsList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Teams>> getTeamsByOrg(String instanceUrl, String token, String orgName) {
 | 
			
		||||
 | 
			
		||||
        teamsList = new MutableLiveData<>();
 | 
			
		||||
        loadTeamsByOrgList(instanceUrl, token, orgName);
 | 
			
		||||
 | 
			
		||||
        return teamsList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadTeamsByOrgList(String instanceUrl, String token, String orgName) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Teams>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getTeamsByOrg(token, orgName);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<Teams>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Teams>> call, @NonNull Response<List<Teams>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        teamsList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<Teams>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user