use of com.example.first_responder_app.recyclerViews.EditRankRecyclerViewAdapter in project FirstResponse by mattpost1700.
the class EditRankFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// binding fragment with nav_map by using navHostFragment, throw this block of code in there and that allows you to switch to other fragments
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_edit_rank, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavController navController = navHostFragment.getNavController();
activeUser = AppUtil.getActiveUser(getActivity());
ranksList = new ArrayList<>();
populateRanks();
// handles edit rank by onClick
EditRankRecyclerViewAdapter.ItemClickListener editRankClickListener = ((view, position, data) -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Edit Rank").setMessage("Rank Title");
final EditText input = new EditText(getContext());
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
builder.setView(input);
builder.setPositiveButton("Confirm", (dialogInterface, i) -> {
RanksDataModel rank = ranksList.get(position);
rank.setRank_name(input.getText().toString());
db.collection("ranks").document(rank.getDocumentId()).set(rank);
editRankRecyclerViewAdapter.notifyDataSetChanged();
});
builder.setNegativeButton("Cancel", (dialogInterface, i) -> {
});
AlertDialog dialog = builder.create();
dialog.show();
});
// handles hold to delete
EditRankRecyclerViewAdapter.rankLongClickListener rankLongClickListener = (view, position) -> {
@SuppressLint("NotifyDataSetChanged") AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()).setTitle("Delete rank").setMessage("Are you sure you want to delete this rank?").setPositiveButton("Yes", (dialogInterface, i) -> {
RanksDataModel rank = ranksList.get(position);
db.collection("ranks").document(rank.getDocumentId()).delete();
ranksList.remove(position);
checkRanksListEmpty();
editRankRecyclerViewAdapter.notifyDataSetChanged();
}).setNegativeButton("No", (dialogInterface, i) -> {
});
dialog.show();
};
binding.addRankBtn.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Create Rank").setMessage("Rank Title");
final EditText input = new EditText(getContext());
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
builder.setView(input);
builder.setPositiveButton("Confirm", (dialogInterface, i) -> {
firestoreDatabase.addRank(input.getText().toString());
populateRanks();
});
builder.setNegativeButton("Cancel", (dialogInterface, i) -> {
});
AlertDialog dialog = builder.create();
dialog.show();
});
RecyclerView editRankRecyclerView = binding.editRankRecycler;
editRankRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
editRankRecyclerViewAdapter = new EditRankRecyclerViewAdapter(getContext(), ranksList);
editRankRecyclerViewAdapter.setClickListener(editRankClickListener);
editRankRecyclerViewAdapter.setLongClickListener(rankLongClickListener);
editRankRecyclerView.setAdapter(editRankRecyclerViewAdapter);
/* swipe to delete (now using hold to delete)
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
RanksDataModel deletedRank = ranksList.get(viewHolder.getAdapterPosition());
int pos = viewHolder.getAdapterPosition();
ranksList.remove(pos);
editRankRecyclerViewAdapter.notifyItemRemoved(pos);
}
}).attachToRecyclerView(editRankRecyclerView);
*/
final SwipeRefreshLayout pullToRefresh = binding.rankSwipeRefreshLayout;
pullToRefresh.setOnRefreshListener(() -> {
populateRanks();
pullToRefresh.setRefreshing(false);
});
return binding.getRoot();
}
Aggregations