use of com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase in project noChange by Khalidtoak.
the class AddChangeOrDebt method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_change_or_debt);
// find all the views
customerName = findViewById(R.id.edit_text_name);
ItemBought = findViewById(R.id.itemBought);
HowMuch = findViewById(R.id.edit_text_Amount);
save = findViewById(R.id.fab_for_save);
addImage = findViewById(R.id.add_profileImage);
AddPhoneNumber = findViewById(R.id.phone_no);
ChangeradButton = findViewById(R.id.radButton1);
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(this);
DebtRadButton = findViewById(R.id.radButton2);
// set default checked rad button to the one for change
ChangeradButton.setChecked(true);
ChangeOrDebit = "Change";
// when you click on the floating action button for taking a picture
addImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// use an implicit intent to launch camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// startActivity
startActivityForResult(intent, REQUEST_CAPTURE_IMAGE);
}
});
// when we click save
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// we get the text from each of the edit Text
String customersname = customerName.getText().toString();
String boughtStuff = ItemBought.getText().toString();
String howMuch = HowMuch.getText().toString();
// get the change or debt rad button
String debtOrChange = ChangeOrDebit;
// get the text of the phone number editText
String phoneNumber = AddPhoneNumber.getText().toString();
// editText length is not 11
if (!(phoneNumber.substring(0, 2).equals("080") || phoneNumber.substring(0, 2).equals("090") || phoneNumber.substring(0, 2).equals("070") || phoneNumber.length() == 11)) {
// you tell the user his phone number is invalid and don't go futher by calling return
Toast.makeText(getApplicationContext(), "Invalid phone Number", Toast.LENGTH_LONG).show();
return;
}
// if any of the editTexts are empty... we also tell the user and do not go further
if (customersname.length() == 0 || boughtStuff.length() == 0 || howMuch.length() == 0 || debtOrChange.length() == 0) {
Toast.makeText(getApplicationContext(), "please fill in all fields", Toast.LENGTH_LONG).show();
return;
}
// now we save the customer's details
creditorsAndDebtorsDataBase.SaveLecturesAdded(customersname, boughtStuff, howMuch, debtOrChange, getPathForImage(), phoneNumber);
Log.d("ContentVals: ", "onClick: " + customersname + boughtStuff + howMuch + debtOrChange);
Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show();
// start the DashBoard Activity
Intent intent = new Intent(AddChangeOrDebt.this, DashBoard.class);
startActivity(intent);
}
});
}
use of com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase 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.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase 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.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase 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;
}
use of com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.CreditorsAndDebtorsDataBase in project noChange by Khalidtoak.
the class Adapters method onBindViewHolder.
@Override
public void onBindViewHolder(final AdapterViewHolder holder, int position) {
// here the views are binded to the view holder
// we move our cursor to the position on the recycler view adapter
mCursor.moveToPosition(position);
// get the values in our table that we have queried
// by calling get column Index
// and passing the column name
final String customerName = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_CUSTOMER_NAME));
String boughtStuff = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_ITEM_BOUGHT));
String howMuch = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_HOW_MUCH));
String Time = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_TIME_STAMP));
String DebtOrChange = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_DEBT_OR_CHANGE));
final String phoneNo = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_PHONE_NUMBER));
// display this data on our recyclerview
holder.CustomerName.setText(customerName);
holder.ItemBought.setText("bought Item: " + boughtStuff);
holder.amount.setText(howMuch + "Naira");
holder.time.setText(Time);
holder.itemView.setTag(mCursor.getLong(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase._ID)));
// for the Image ..we made use of glide Image loading library and using the Circle transform class created
// in the utils package... we display the circuilar version of the image
Glide.with(context).load(mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_IMAGE))).transform(new CircleTransform(context)).crossFade().into(holder.imageProfile);
// an image button is a clickable image
// we create a pop up menu and set a listener for it so that we click it...
// we will bw able to perform a certain action
holder.callOrTextessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popupMenu = new PopupMenu(context, holder.callOrTextessage);
// we always inflate menus in android or else the menu won't show
// A menu resource defines an application menu
// (Options Menu, Context Menu, or submenu) that can be inflated with MenuInflater
popupMenu.inflate(R.menu.menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
popupMenu.setGravity(Gravity.CENTER);
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// get the id of the item that was clicked in the menu
switch(menuItem.getItemId()) {
// if call is clicked
case R.id.call:
// open the dialer using an implicit intent
/**
* An intent is an abstract description of an operation to be performed.
* It can be used with startActivity to launch an Activity,
* broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent)
* or bindService(Intent, ServiceConnection, int) to communicate with a Background Service.
* Explicit intent launches an intent in your app while implicit intents launches another app
* from your app
* here we are launching the dialer app from our app *
*/
openDialer(phoneNo);
break;
case R.id.send_text_message:
// here we will launch the sms app from our app
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNo));
context.startActivity(intent);
break;
}
return false;
}
});
// show the popup menu
popupMenu.show();
}
});
}
Aggregations