Skip to content

Commit

Permalink
changed themes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMC2610 committed Mar 29, 2023
1 parent af3f303 commit b852801
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 20 additions & 8 deletions app/src/main/java/com/georgemc2610/benzinapp/DatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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 = ?";
Expand All @@ -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;
Expand All @@ -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
}
});

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-el-rGR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
<string name="text_view_datetime">Ημερομηνία:</string>
<string name="edit_text_datetime_hint">Πατήστε εδώ για να επιλέξετε...</string>
<string name="text_view_click_cards_message">Πατήστε σε μία εγγραφή για να δείτε περισσότερα.</string>
<string name="dialog_delete_title">ΔΙΑΓΡΑΦΗ</string>
<string name="dialog_delete_confirmation">Είστε σίγουροι ότι θέλετε να διαγράψετε αυτήν την εγγραφή;</string>
<string name="dialog_yes">ΝΑΙ</string>
<string name="dialog_no">ΟΧΙ</string>
<string name="toast_record_deleted">Η εγγραφή διεγράφη επιτυχώς.</string>
</resources>
12 changes: 6 additions & 6 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<!-- Base application theme. -->
<style name="Theme.BenzinApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorSecondary">#ff9900</item>
<item name="colorSecondaryVariant">#bb6600</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorPrimary">#009900</item>
<item name="colorPrimaryVariant">#004400</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
<string name="text_view_datetime">Date:</string>
<string name="edit_text_datetime_hint">Tap to select date...</string>
<string name="text_view_click_cards_message">Click on a card to see more info.</string>
<string name="dialog_delete_title">RECORD DELETION</string>
<string name="dialog_delete_confirmation">Are you sure you want to delete this record?</string>
<string name="dialog_yes">YES</string>
<string name="dialog_no">NO</string>
<string name="toast_record_deleted">Record deleted successfully.</string>
</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<!-- Base application theme. -->
<style name="Theme.BenzinApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">#ff9900</item>
<item name="colorPrimaryVariant">#bb6600</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorSecondary">#009900</item>
<item name="colorSecondaryVariant">#004400</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
Expand Down

0 comments on commit b852801

Please sign in to comment.