use of com.group1.swepproject.user.nochange.Adapters.Adapters in project noChange by Khalidtoak.
the class ChangeRecord method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_change_record, container, false);
// find the recycler view in its xml by its id
recyclerView = rootView.findViewById(R.id.recyclcer_view_change);
// find the searView ById
searchView = rootView.findViewById(R.id.sv1);
// setLayout manager to a vertical linear layout manager
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
// setFixed size for recycler view
recyclerView.setHasFixedSize(true);
// initialize database
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
// initialize the adapter and pass in the context of the activity and retrieve by calling the method we
// created in the database and passing it in as the cursor
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"), getContext());
// /set the adapter of the recycler view
recyclerView.setAdapter(adapters);
// When the text in the search view changes .. we listen to it and re-do our querying
// by initializing the adapter and passing in the new cursor
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// get the query and convert it to a string
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewPagerAndSearchedText(query, "Change"), getContext());
// re set the adapter
recyclerView.setAdapter(adapters);
return true;
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
// get the id of the row yo want to delete
final long id1 = (long) viewHolder.itemView.getTag();
// /create a dialog message that confirms if you want to delete it or not
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if yes is selected
// delete that customer and pass in the id
// delete the News with id that was swiped off
removeCustomer(id1);
// create a snack bar that tells the user iif it has been deleted or not
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"));
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// if no is clicked... just swap cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"));
}
}).show();
Log.d(TAG, "onSwiped: did something happen here??");
}
}).attachToRecyclerView(recyclerView);
return rootView;
}
use of com.group1.swepproject.user.nochange.Adapters.Adapters in project noChange by Khalidtoak.
the class DashBoardFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootV = inflater.inflate(R.layout.fragment_dash_board, container, false);
recyclerView = rootV.findViewById(R.id.recyclcer_view_dash);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
searchView = rootV.findViewById(R.id.sv);
sqLiteDatabase = creditorsAndDebtorsDataBase.getWritableDatabase();
adapters = new Adapters(getAllSaved(), getContext());
recyclerView.setAdapter(adapters);
floatingActionButton = rootV.findViewById(R.id.fab_for_recyclcer_view_dash);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), AddChangeOrDebt.class);
startActivity(intent);
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
final long id1 = (long) viewHolder.itemView.getTag();
// delete the News with id that was swiped off
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete the Customer with id that was swiped off
removeCustomer(id1);
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(getAllSaved());
Log.d(TAG, "onSwiped: did something happen here??");
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapters.swapCursor(getAllSaved());
}
}).show();
}
}).attachToRecyclerView(recyclerView);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieve(query), getContext());
recyclerView.setAdapter(adapters);
return true;
}
});
return rootV;
}
use of com.group1.swepproject.user.nochange.Adapters.Adapters in project noChange by Khalidtoak.
the class DebtorsRecord method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_debtors_record, container, false);
recyclerView = rootView.findViewById(R.id.recyclcer_view_debtors);
searchView = rootView.findViewById(R.id.sv2);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"), getContext());
recyclerView.setAdapter(adapters);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewPagerAndSearchedText(query, "Debtors"), getContext());
recyclerView.setAdapter(adapters);
return true;
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
final long id1 = (long) viewHolder.itemView.getTag();
// delete the News with id that was swiped off
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete the News with id that was swiped off
removeCustomer(id1);
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"));
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"));
}
}).show();
Log.d(TAG, "onSwiped: did something happen here??");
Log.d(TAG, "onSwiped: did something happen here??");
}
}).attachToRecyclerView(recyclerView);
return rootView;
}
Aggregations