Skip to content

Commit

Permalink
editing a record is now possible!
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMC2610 committed Aug 9, 2023
1 parent 489acf2 commit 98ffcae
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.Response;
import com.georgemc2610.benzinapp.classes.FuelFillRecord;
import com.georgemc2610.benzinapp.classes.RequestHandler;

public class ActivityEditRecord extends AppCompatActivity
import java.time.LocalDate;

public class ActivityEditRecord extends AppCompatActivity implements Response.Listener<String>
{
private FuelFillRecord record;
private EditText editTextLiters, editTextCost, editTextKilometers, editTextDate, editTextPetrolType, editTextStation, editTextNotes;
Expand Down Expand Up @@ -54,8 +59,8 @@ record = (FuelFillRecord) getIntent().getSerializableExtra("record");
editTextLiters .setText(String.valueOf(record.getLiters()));
editTextCost .setText(String.valueOf(record.getCost_eur()));
editTextKilometers.setText(String.valueOf(record.getKilometers()));
editTextPetrolType.setText(String.valueOf(record.getFuelType()));
editTextDate .setText(String.valueOf(record.getDate()));
editTextPetrolType.setText(record.getFuelType());
editTextStation .setText(record.getStation());
editTextNotes .setText(record.getNotes());

Expand All @@ -81,7 +86,44 @@ public boolean onOptionsItemSelected(MenuItem item)

public void OnButtonApplyEditsClicked(View v)
{
// get floats (that will be nulled if empty)
Float newLiters = getFloatFromEditText(editTextLiters);
Float newCost = getFloatFromEditText(editTextCost);
Float newKilometers = getFloatFromEditText(editTextKilometers);

// get strings (that will be nulled if empty)
String newPetrolType = getStringFromEditText(editTextPetrolType);
String newStation = getStringFromEditText(editTextStation);
String newNotes = getStringFromEditText(editTextNotes);

// send the request.
RequestHandler.getInstance().EditFuelFillRecord(this, this, record.getId(), newKilometers, newLiters, newCost, newPetrolType, newStation, newNotes);
}

/**
* From any "EditText" view, takes the text and gets the Float type from it. If it's empty, it nullifies it.
* @param editText Any EditText view that contains a floating point number.
* @return An object of type Float.
*/
private Float getFloatFromEditText(EditText editText)
{
return editText.getText().toString().trim().isEmpty() ? null : Float.parseFloat(editText.getText().toString().trim());
}

/**
* From any "EditText" view, takes the text and trims it. If the text is empty it nullifies it.
* @param editText Any EditText view that contains text.
* @return An object of type String.
*/
private String getStringFromEditText(EditText editText)
{
return editText.getText().toString().trim().isEmpty() ? null : editText.getText().toString().trim();
}

@Override
public void onResponse(String response)
{
Toast.makeText(this, "Record Successfully Edited.", Toast.LENGTH_LONG).show();
finish();
}

}

0 comments on commit 98ffcae

Please sign in to comment.