mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-14 01:21:35 +01:00
refactor a lot of code to make it cleaner and remove debug and test code.
This commit is contained in:
parent
c82b1266b6
commit
bd4fe6774f
1 changed files with 71 additions and 152 deletions
|
@ -274,93 +274,39 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
super.onActivityResult(requestCode, resultCode, data);
|
||||
return;
|
||||
}
|
||||
switch (requestCode) {
|
||||
case CUSTOMIZED_REQUEST_CODE: {
|
||||
Toast.makeText(this, "REQUEST_CODE = " + requestCode +"RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode +" RESULT_CODE = " + resultCode);
|
||||
switch (resultCode) {
|
||||
case 1: {
|
||||
if (requestCode == CUSTOMIZED_REQUEST_CODE) {
|
||||
Toast.makeText(this, "REQUEST_CODE = " + requestCode + "RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||
if (resultCode == 1) {
|
||||
constructMedsList();
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
Toast.makeText(this, "Cancelled scan", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Cancelled Scan");
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
Toast.makeText(this, "Keyboard input", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Keyboard Input");
|
||||
String cip13_input = showInputDialog();
|
||||
|
||||
final Medicament medoc = dbMedoc.getMedocByCIP13(cip13_input);
|
||||
if ( medoc != null ) {
|
||||
medoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(medoc);
|
||||
mAdapter.addItem(medoc);
|
||||
} else {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to do to just dismiss dialog
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Toast.makeText(this, "What are you doing here?", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "What are you doing here?");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
} else {
|
||||
IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
|
||||
|
||||
Toast.makeText(this, "REQUEST_CODE = " + requestCode, Toast.LENGTH_LONG).show();
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + "resultCode = " + resultCode);
|
||||
if(result.getContents() == null) {
|
||||
if (result.getContents() == null) {
|
||||
Intent originalIntent = result.getOriginalIntent();
|
||||
if (originalIntent == null) {
|
||||
Log.d(TAG, "Cancelled scan"); // Todo: put here resultCode =3 test
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode +" RESULT_CODE = " + resultCode);
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else if(originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
|
||||
Log.d(TAG,"Cancelled scan due to missing camera permission");
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode +" RESULT_CODE = " + resultCode);
|
||||
Toast.makeText(this, "Cancelled due to missing camera permission", Toast.LENGTH_LONG).show();
|
||||
} else if (resultCode == 3) {
|
||||
if (resultCode == 3) { // TODO: Should call showInputDialog and have keyboardInput back
|
||||
Toast.makeText(this, "Keyboard input", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Keyboard Input");
|
||||
String cip13_input = showInputDialog();
|
||||
|
||||
final Medicament medoc = dbMedoc.getMedocByCIP13(cip13_input);
|
||||
if ( medoc != null ) {
|
||||
medoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(medoc);
|
||||
mAdapter.addItem(medoc);
|
||||
} else {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to do to just dismiss dialog
|
||||
Log.d(TAG, "Cancelled scan"); // Todo: put here resultCode =3 test
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
}
|
||||
break;
|
||||
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||
} else if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
|
||||
Log.d(TAG, "Cancelled scan due to missing camera permission");
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||
Toast.makeText(this, "Cancelled due to missing camera permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Scanned");
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode +" RESULT_CODE = " + resultCode);
|
||||
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
|
||||
Log.d(TAG, "result.getContents = " + result.getContents());
|
||||
Log.d(TAG, "format = " + result.getFormatName());
|
||||
|
||||
|
@ -368,29 +314,6 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
|
||||
String cip13;
|
||||
|
||||
if (resultCode == 3) {
|
||||
Toast.makeText(this, "Keyboard input", Toast.LENGTH_SHORT).show();
|
||||
Log.d(TAG, "Keyboard Input");
|
||||
cip13= showInputDialog();
|
||||
|
||||
final Medicament medoc = dbMedoc.getMedocByCIP13(cip13);
|
||||
if ( medoc != null ) {
|
||||
medoc.setDateEndOfStock();
|
||||
dbHelper.addDrug(medoc);
|
||||
mAdapter.addItem(medoc);
|
||||
} else {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
dlg.setMessage(getString(R.string.msgNotFound));
|
||||
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to do to just dismiss dialog
|
||||
}
|
||||
});
|
||||
dlg.show();
|
||||
}
|
||||
} else {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||
dlg.setTitle(getString(R.string.app_name));
|
||||
|
||||
|
@ -430,12 +353,9 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String showInputDialog() {
|
||||
protected void showInputDialog() {
|
||||
|
||||
// get prompts.xml view
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(MedicamentListActivity.this);
|
||||
|
@ -461,7 +381,6 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
// create an alert dialog
|
||||
AlertDialog alert = alertDialogBuilder.create();
|
||||
alert.show();
|
||||
return editText.toString();
|
||||
}
|
||||
|
||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
|
|
Loading…
Reference in a new issue