From adc658961459a2e0e838c345eeab16446e1eb42a Mon Sep 17 00:00:00 2001 From: Souma Date: Fri, 19 Mar 2021 13:03:42 +0530 Subject: [PATCH 1/2] extract switch case statement from onCreate and introduce a private method --- .../java/io/pslab/activity/DataLoggerActivity.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/DataLoggerActivity.java b/app/src/main/java/io/pslab/activity/DataLoggerActivity.java index c7e87b621..60c96c058 100644 --- a/app/src/main/java/io/pslab/activity/DataLoggerActivity.java +++ b/app/src/main/java/io/pslab/activity/DataLoggerActivity.java @@ -86,9 +86,16 @@ protected void onCreate(Bundle savedInstanceState) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } - if (caller == null) caller = ""; + + if (caller == null) + caller = getResources().getString(R.string.logged_data); getSupportActionBar().setTitle(caller); + setCategoryData(); + fillData(); + } + + private void setCategoryData() { switch (caller) { case "Lux Meter": categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.lux_meter)); @@ -137,9 +144,7 @@ protected void onCreate(Bundle savedInstanceState) { break; default: categoryData = LocalDataLog.with().getAllSensorBlocks(); - getSupportActionBar().setTitle(getString(R.string.logged_data)); } - fillData(); } private void fillData() { From 436541a1734321edcb2cdd4b3912136aece33a21 Mon Sep 17 00:00:00 2001 From: Souma Date: Fri, 19 Mar 2021 23:03:24 +0530 Subject: [PATCH 2/2] extract alert dialog in a seperate method --- .../io/pslab/activity/DataLoggerActivity.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/DataLoggerActivity.java b/app/src/main/java/io/pslab/activity/DataLoggerActivity.java index 60c96c058..fec402888 100644 --- a/app/src/main/java/io/pslab/activity/DataLoggerActivity.java +++ b/app/src/main/java/io/pslab/activity/DataLoggerActivity.java @@ -178,26 +178,22 @@ public boolean onOptionsItemSelected(MenuItem item) { selectFile(); break; case R.id.delete_all: - Context context = DataLoggerActivity.this; - new AlertDialog.Builder(context) - .setTitle(context.getString(R.string.delete)) - .setMessage(context.getString(R.string.delete_all_message)) - .setPositiveButton(context.getString(R.string.delete), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - deleteAllProgressBar.setVisibility(View.VISIBLE); - new DeleteAllTask().execute(); - } - }).setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }).create().show(); + displayAlertDialog(DataLoggerActivity.this); break; } return super.onOptionsItemSelected(item); } + private void displayAlertDialog(Context context) { + new AlertDialog.Builder(context) + .setTitle(context.getString(R.string.delete)) + .setMessage(context.getString(R.string.delete_all_message)) + .setPositiveButton(context.getString(R.string.delete), (dialog, which) -> { + deleteAllProgressBar.setVisibility(View.VISIBLE); + new DeleteAllTask().execute(); + }).setNegativeButton(context.getString(R.string.cancel), (dialog, which) -> dialog.dismiss()).create().show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.log_activity_menu, menu);