mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-11-12 14:39:35 -06:00
Add to org list
This commit is contained in:
@@ -22,119 +22,179 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class OrganizationsListAdapter extends RecyclerView.Adapter<OrganizationsListAdapter.OrganizationsViewHolder> implements Filterable {
|
||||
public class OrganizationsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Filterable {
|
||||
|
||||
private final List<UserOrganizations> orgList;
|
||||
private final Context context;
|
||||
private final List<UserOrganizations> orgListFull;
|
||||
private final Context context;
|
||||
private final int TYPE_LOAD = 0;
|
||||
private List<UserOrganizations> orgList;
|
||||
private final List<UserOrganizations> orgListFull;
|
||||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
|
||||
static class OrganizationsViewHolder extends RecyclerView.ViewHolder {
|
||||
public OrganizationsListAdapter(List<UserOrganizations> orgListMain, Context ctx) {
|
||||
this.context = ctx;
|
||||
this.orgList = orgListMain;
|
||||
orgListFull = new ArrayList<>(orgList);
|
||||
}
|
||||
|
||||
private UserOrganizations userOrganizations;
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
if(viewType == TYPE_LOAD) {
|
||||
return new OrganizationsListAdapter.OrgHolder(inflater.inflate(R.layout.list_organizations, parent, false));
|
||||
}
|
||||
else {
|
||||
return new OrganizationsListAdapter.LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
private final ImageView image;
|
||||
private final TextView orgName;
|
||||
private final TextView orgDescription;
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
}
|
||||
|
||||
private OrganizationsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
orgName = itemView.findViewById(R.id.orgName);
|
||||
orgDescription = itemView.findViewById(R.id.orgDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
if(getItemViewType(position) == TYPE_LOAD) {
|
||||
((OrganizationsListAdapter.OrgHolder) holder).bindData(orgList.get(position));
|
||||
}
|
||||
}
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||
intent.putExtra("orgName", userOrganizations.getUsername());
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if(orgList.get(position).getUsername() != null) {
|
||||
return TYPE_LOAD;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public OrganizationsListAdapter(Context ctx, List<UserOrganizations> orgsListMain) {
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return orgList.size();
|
||||
}
|
||||
|
||||
this.context = ctx;
|
||||
this.orgList = orgsListMain;
|
||||
orgListFull = new ArrayList<>(orgList);
|
||||
}
|
||||
class OrgHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public OrganizationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
private UserOrganizations userOrganizations;
|
||||
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_organizations, parent, false);
|
||||
return new OrganizationsViewHolder(v);
|
||||
}
|
||||
private final ImageView image;
|
||||
private final TextView orgName;
|
||||
private final TextView orgDescription;
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull OrganizationsViewHolder holder, int position) {
|
||||
OrgHolder(View itemView) {
|
||||
|
||||
UserOrganizations currentItem = orgList.get(position);
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||
super(itemView);
|
||||
orgName = itemView.findViewById(R.id.orgName);
|
||||
orgDescription = itemView.findViewById(R.id.orgDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
|
||||
holder.userOrganizations = currentItem;
|
||||
holder.orgName.setText(currentItem.getUsername());
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||
intent.putExtra("orgName", userOrganizations.getUsername());
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
PicassoService.getInstance(context).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
void bindData(UserOrganizations org) {
|
||||
|
||||
if(!currentItem.getDescription().equals("")) {
|
||||
holder.orgDescription.setVisibility(View.VISIBLE);
|
||||
holder.orgDescription.setText(currentItem.getDescription());
|
||||
}
|
||||
else {
|
||||
holder.orgDescription.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return orgList.size();
|
||||
}
|
||||
this.userOrganizations = org;
|
||||
orgName.setText(org.getUsername());
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return orgFilter;
|
||||
}
|
||||
PicassoService.getInstance(context).get().load(org.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(image);
|
||||
|
||||
private final Filter orgFilter = new Filter() {
|
||||
if(!org.getDescription().equals("")) {
|
||||
orgDescription.setVisibility(View.VISIBLE);
|
||||
orgDescription.setText(org.getDescription());
|
||||
}
|
||||
else {
|
||||
orgDescription.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
}
|
||||
|
||||
List<UserOrganizations> filteredList = new ArrayList<>();
|
||||
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||
LoadHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
if(!isMoreDataAvailable) {
|
||||
loadMoreListener.onLoadFinished();
|
||||
}
|
||||
}
|
||||
|
||||
filteredList.addAll(orgListFull);
|
||||
}
|
||||
else {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void notifyDataChanged() {
|
||||
notifyDataSetChanged();
|
||||
isLoading = false;
|
||||
loadMoreListener.onLoadFinished();
|
||||
}
|
||||
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
public interface OnLoadMoreListener {
|
||||
void onLoadMore();
|
||||
void onLoadFinished();
|
||||
}
|
||||
|
||||
for (UserOrganizations item : orgListFull) {
|
||||
if (item.getUsername().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
||||
this.loadMoreListener = loadMoreListener;
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
public void updateList(List<UserOrganizations> list) {
|
||||
orgList = list;
|
||||
notifyDataChanged();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return orgFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
private final Filter orgFilter = new Filter() {
|
||||
|
||||
orgList.clear();
|
||||
orgList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
||||
List<UserOrganizations> filteredList = new ArrayList<>();
|
||||
|
||||
if(constraint == null || constraint.length() == 0) {
|
||||
|
||||
filteredList.addAll(orgListFull);
|
||||
}
|
||||
else {
|
||||
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for(UserOrganizations item : orgListFull) {
|
||||
if(item.getUsername().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
|
||||
orgList.clear();
|
||||
orgList.addAll((List) results.values);
|
||||
notifyDataChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MyRepositoriesFragment extends Fragment {
|
||||
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
|
||||
private ReposListAdapter adapter;
|
||||
private int page = 1;
|
||||
private final int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@@ -11,128 +11,112 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.BaseActivity;
|
||||
import org.mian.gitnex.activities.CreateOrganizationActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.OrganizationsListAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentOrganizationsBinding;
|
||||
import org.mian.gitnex.viewmodels.OrganizationListViewModel;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.viewmodels.OrganizationsViewModel;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class OrganizationsFragment extends Fragment {
|
||||
|
||||
public static boolean orgCreated = false;
|
||||
private FragmentOrganizationsBinding fragmentOrganizationsBinding;
|
||||
private OrganizationsListAdapter adapter;
|
||||
private int page = 1;
|
||||
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private OrganizationsListAdapter adapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private ExtendedFloatingActionButton createNewOrganization;
|
||||
private TextView noDataOrg;
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
fragmentOrganizationsBinding = FragmentOrganizationsBinding.inflate(inflater, container, false);
|
||||
|
||||
FragmentOrganizationsBinding fragmentOrganizationsBinding = FragmentOrganizationsBinding.inflate(inflater, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
setHasOptionsMenu(true);
|
||||
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navOrg));
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = fragmentOrganizationsBinding.pullToRefresh;
|
||||
fragmentOrganizationsBinding.addNewOrganization.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(view.getContext(), CreateOrganizationActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navOrg));
|
||||
fragmentOrganizationsBinding.recyclerView.setHasFixedSize(true);
|
||||
fragmentOrganizationsBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(fragmentOrganizationsBinding.recyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
fragmentOrganizationsBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
mProgressBar = fragmentOrganizationsBinding.progressBar;
|
||||
noDataOrg = fragmentOrganizationsBinding.noDataOrg;
|
||||
mRecyclerView = fragmentOrganizationsBinding.recyclerView;
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
fragmentOrganizationsBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
page = 1;
|
||||
fragmentOrganizationsBinding.pullToRefresh.setRefreshing(false);
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization());
|
||||
fragmentOrganizationsBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
}, 50));
|
||||
|
||||
createNewOrganization = fragmentOrganizationsBinding.addNewOrganization;
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization());
|
||||
|
||||
createNewOrganization.setOnClickListener(view -> {
|
||||
return fragmentOrganizationsBinding.getRoot();
|
||||
};
|
||||
|
||||
Intent intent = new Intent(view.getContext(), CreateOrganizationActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
private void fetchDataAsync(String instanceToken) {
|
||||
|
||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
if (dy > 0 && createNewOrganization.isShown()) {
|
||||
createNewOrganization.setVisibility(View.GONE);
|
||||
} else if (dy < 0 ) {
|
||||
createNewOrganization.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
OrganizationsViewModel orgModel = new ViewModelProvider(this).get(OrganizationsViewModel.class);
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
}
|
||||
});
|
||||
orgModel.getUserOrg(instanceToken, page, resultLimit, getContext()).observe(getViewLifecycleOwner(), orgListMain -> {
|
||||
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
adapter = new OrganizationsListAdapter(orgListMain, getContext());
|
||||
adapter.setLoadMoreListener(new OrganizationsListAdapter.OnLoadMoreListener() {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
OrganizationListViewModel.loadOrgsList(((BaseActivity) requireActivity()).getAccount().getAuthorization(), getContext());
|
||||
@Override
|
||||
public void onLoadMore() {
|
||||
|
||||
}, 50));
|
||||
page += 1;
|
||||
OrganizationsViewModel.loadMoreOrgList(instanceToken, page, resultLimit, getContext(), adapter);
|
||||
fragmentOrganizationsBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization());
|
||||
@Override
|
||||
public void onLoadFinished() {
|
||||
|
||||
return fragmentOrganizationsBinding.getRoot();
|
||||
fragmentOrganizationsBinding.progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if(adapter.getItemCount() > 0) {
|
||||
fragmentOrganizationsBinding.recyclerView.setAdapter(adapter);
|
||||
fragmentOrganizationsBinding.noDataOrg.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
adapter.notifyDataChanged();
|
||||
fragmentOrganizationsBinding.recyclerView.setAdapter(adapter);
|
||||
fragmentOrganizationsBinding.noDataOrg.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
fragmentOrganizationsBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
|
||||
if(orgCreated) {
|
||||
OrganizationListViewModel.loadOrgsList(((BaseActivity) requireActivity()).getAccount().getAuthorization(), getContext());
|
||||
OrganizationsViewModel.loadOrgList(((BaseActivity) requireActivity()).getAccount().getAuthorization(), page, resultLimit, getContext());
|
||||
orgCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceToken) {
|
||||
|
||||
OrganizationListViewModel orgModel = new ViewModelProvider(this).get(OrganizationListViewModel.class);
|
||||
|
||||
orgModel.getUserOrgs(instanceToken, getContext()).observe(getViewLifecycleOwner(), orgsListMain -> {
|
||||
adapter = new OrganizationsListAdapter(getContext(), orgsListMain);
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noDataOrg.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noDataOrg.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
@@ -142,11 +126,6 @@ public class OrganizationsFragment extends Fragment {
|
||||
MenuItem searchItem = menu.findItem(R.id.action_search);
|
||||
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
|
||||
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
//searchView.setQueryHint(getContext().getString(R.string.strFilter));
|
||||
|
||||
/*if(!connToInternet) {
|
||||
return;
|
||||
}*/
|
||||
|
||||
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
@@ -156,13 +135,11 @@ public class OrganizationsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if(mRecyclerView.getAdapter() != null) {
|
||||
if(fragmentOrganizationsBinding.recyclerView.getAdapter() != null) {
|
||||
adapter.getFilter().filter(newText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RepositoriesByOrgFragment extends Fragment {
|
||||
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
|
||||
private ReposListAdapter adapter;
|
||||
private int page = 1;
|
||||
private final int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||
private static final String getOrgName = null;
|
||||
private String orgName;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.mian.gitnex.activities.CreateRepoActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.ReposListAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentRepositoriesBinding;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.viewmodels.RepositoriesViewModel;
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,7 @@ public class RepositoriesFragment extends Fragment {
|
||||
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
|
||||
private ReposListAdapter adapter;
|
||||
private int page = 1;
|
||||
private final int resultLimit = 5;
|
||||
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class StarredRepositoriesFragment extends Fragment {
|
||||
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
|
||||
private ReposListAdapter adapter;
|
||||
private int page = 1;
|
||||
private final int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@@ -1,63 +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.UserOrganizations;
|
||||
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 OrganizationListViewModel extends ViewModel {
|
||||
|
||||
private static MutableLiveData<List<UserOrganizations>> orgsList;
|
||||
|
||||
public LiveData<List<UserOrganizations>> getUserOrgs(String token, Context ctx) {
|
||||
|
||||
//if (orgsList == null) {
|
||||
orgsList = new MutableLiveData<>();
|
||||
loadOrgsList(token, ctx);
|
||||
//}
|
||||
|
||||
return orgsList;
|
||||
}
|
||||
|
||||
public static void loadOrgsList(String token, Context ctx) {
|
||||
|
||||
Call<List<UserOrganizations>> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getUserOrgs(token, 1, 50);
|
||||
|
||||
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,95 @@
|
||||
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.UserOrganizations;
|
||||
import org.mian.gitnex.adapters.OrganizationsListAdapter;
|
||||
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 OrganizationsViewModel extends ViewModel {
|
||||
|
||||
private static MutableLiveData<List<UserOrganizations>> orgList;
|
||||
|
||||
public LiveData<List<UserOrganizations>> getUserOrg(String token, int page, int resultLimit, Context ctx) {
|
||||
|
||||
orgList = new MutableLiveData<>();
|
||||
loadOrgList(token, page, resultLimit, ctx);
|
||||
|
||||
return orgList;
|
||||
}
|
||||
|
||||
public static void loadOrgList(String token, int page, int resultLimit, Context ctx) {
|
||||
|
||||
Call<List<UserOrganizations>> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getUserOrgs(token, page, resultLimit);
|
||||
|
||||
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) {
|
||||
orgList.postValue(response.body());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<UserOrganizations>> call, @NonNull Throwable t) {
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static void loadMoreOrgList(String token, int page, int resultLimit, Context ctx, OrganizationsListAdapter adapter) {
|
||||
|
||||
Call<List<UserOrganizations>> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getUserOrgs(token, page, resultLimit);
|
||||
|
||||
call.enqueue(new Callback<List<UserOrganizations>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<UserOrganizations>> call, @NonNull Response<List<UserOrganizations>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
List<UserOrganizations> list = orgList.getValue();
|
||||
assert list != null;
|
||||
assert response.body() != null;
|
||||
|
||||
if(response.body().size() != 0) {
|
||||
list.addAll(response.body());
|
||||
adapter.updateList(list);
|
||||
}
|
||||
else {
|
||||
adapter.setMoreDataAvailable(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.e("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<UserOrganizations>> call, @NonNull Throwable t) {
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user