From b852801fd53d8d8070bed96cf8e2e20ab4e72b35 Mon Sep 17 00:00:00 2001 From: Giorgos Seimenis Date: Thu, 30 Mar 2023 01:38:03 +0300 Subject: [PATCH] changed themes --- .../benzinapp/ActivityAddRecord.java | 15 ++++++++++ .../benzinapp/DatabaseManager.java | 28 +++++++++++++------ app/src/main/res/values-el-rGR/strings.xml | 5 ++++ app/src/main/res/values-night/themes.xml | 12 ++++---- app/src/main/res/values/strings.xml | 5 ++++ app/src/main/res/values/themes.xml | 8 +++--- 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/georgemc2610/benzinapp/ActivityAddRecord.java b/app/src/main/java/com/georgemc2610/benzinapp/ActivityAddRecord.java index fafcad08..1afee895 100644 --- a/app/src/main/java/com/georgemc2610/benzinapp/ActivityAddRecord.java +++ b/app/src/main/java/com/georgemc2610/benzinapp/ActivityAddRecord.java @@ -2,9 +2,11 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.motion.widget.Debug; +import androidx.core.app.NavUtils; import android.app.DatePickerDialog; import android.os.Bundle; +import android.view.MenuItem; import android.view.View; import android.widget.DatePicker; import android.widget.EditText; @@ -53,6 +55,19 @@ protected void onCreate(Bundle savedInstanceState) } } + @Override + public boolean onOptionsItemSelected(MenuItem item) + { + switch (item.getItemId()) + { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + public void OnButtonAddClicked(View v) { int validation_counter = 0; diff --git a/app/src/main/java/com/georgemc2610/benzinapp/DatabaseManager.java b/app/src/main/java/com/georgemc2610/benzinapp/DatabaseManager.java index 866972b1..2f5998d9 100644 --- a/app/src/main/java/com/georgemc2610/benzinapp/DatabaseManager.java +++ b/app/src/main/java/com/georgemc2610/benzinapp/DatabaseManager.java @@ -79,15 +79,20 @@ public void AddRecord(float liters, float cost, float kilometers, LocalDate date */ public void DisplayCards(LinearLayout layout, LayoutInflater inflater) { + // first, remove all views. layout.removeAllViews(); + // initialize db query. String query = "SELECT * FROM BENZINAPP ORDER BY timestamp DESC;"; Cursor cursor = DB.rawQuery(query, null); + // go through all queries while (cursor.moveToNext()) { + // inflate the card View v = inflater.inflate(R.layout.cardview_fill, null); + // initialize all text views TextView petrolType = v.findViewById(R.id.card_filled_petrol); petrolType.setText(cursor.getString(8)); @@ -103,16 +108,21 @@ public void DisplayCards(LinearLayout layout, LayoutInflater inflater) TextView date = v.findViewById(R.id.card_date); date.setText(cursor.getString(7)); + // give life to the buttons FloatingActionButton deleteButton = v.findViewById(R.id.card_buttonDelete); deleteButton.setOnClickListener(new DeleteButtonListener(layout.getContext(), cursor.getInt(0), inflater, layout)); + // and add the layout layout.addView(v); } cursor.close(); - } + /** + * Deletes a record from the database, based on the primary key. + * @param id The primary key (ID). + */ public void DeleteRecord(int id) { String query = "DELETE FROM BENZINAPP WHERE id = ?"; @@ -122,6 +132,9 @@ public void DeleteRecord(int id) } } +/** + * Internal class to handle most of the click listeners + */ class DeleteButtonListener implements View.OnClickListener { private Context context; @@ -142,27 +155,26 @@ public void onClick(View v) { AlertDialog.Builder dialog = new AlertDialog.Builder(this.context); - // TODO: Make these string not hardcoded. - dialog.setTitle("RECORD DELETION"); - dialog.setMessage("Do you really want to delete this record?"); + dialog.setTitle(layout.getContext().getResources().getString(R.string.dialog_delete_title)); + dialog.setMessage(layout.getContext().getResources().getString(R.string.dialog_delete_confirmation)); - dialog.setPositiveButton("YES", new DialogInterface.OnClickListener() + dialog.setPositiveButton(layout.getContext().getResources().getString(R.string.dialog_yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatabaseManager.getInstance(null).DeleteRecord(id); DatabaseManager.getInstance(null).DisplayCards(layout, inflater); - Toast.makeText(layout.getContext(), "", Toast.LENGTH_LONG).show(); + Toast.makeText(layout.getContext(), layout.getContext().getResources().getString(R.string.toast_record_deleted), Toast.LENGTH_LONG).show(); } }); - dialog.setNegativeButton("NO", new DialogInterface.OnClickListener() + dialog.setNegativeButton(layout.getContext().getResources().getString(R.string.dialog_no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - + // foo } }); diff --git a/app/src/main/res/values-el-rGR/strings.xml b/app/src/main/res/values-el-rGR/strings.xml index 515a2375..ebc233bc 100644 --- a/app/src/main/res/values-el-rGR/strings.xml +++ b/app/src/main/res/values-el-rGR/strings.xml @@ -17,4 +17,9 @@ Ημερομηνία: Πατήστε εδώ για να επιλέξετε... Πατήστε σε μία εγγραφή για να δείτε περισσότερα. + ΔΙΑΓΡΑΦΗ + Είστε σίγουροι ότι θέλετε να διαγράψετε αυτήν την εγγραφή; + ΝΑΙ + ΟΧΙ + Η εγγραφή διεγράφη επιτυχώς. \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 58fa3e8e..f8b662c3 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -2,13 +2,13 @@