Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extract switch case statement and introduce a private method #2202

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions app/src/main/java/io/pslab/activity/DataLoggerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -173,32 +178,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
selectFile();
break;
case R.id.delete_all:
Context context = DataLoggerActivity.this;
if (LocalDataLog.with().getAllSensorBlocks().size() == 0) {
CustomSnackBar.showSnackBar(findViewById(android.R.id.content), context.getString(R.string.nothing_to_delete),
null, null, Snackbar.LENGTH_SHORT);
new DeleteAllTask().execute();
} else {
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);
Expand Down