Change part of code according to AndroidStudio suggestions.

Add debug dialog code for the menu.
This commit is contained in:
jacques 2024-06-02 21:56:57 +02:00
parent b0c738e017
commit d3bbfbbdc8

View file

@ -38,11 +38,6 @@ import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.room.Room; import androidx.room.Room;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textview.MaterialTextView; import com.google.android.material.textview.MaterialTextView;
import com.google.zxing.client.android.BuildConfig; import com.google.zxing.client.android.BuildConfig;
@ -60,6 +55,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
/** /**
* An activity representing a list of Drugs is activity * An activity representing a list of Drugs is activity
@ -225,6 +221,7 @@ public class DrugListActivity extends AppCompatActivity {
Log.d(TAG, "Missing camera permission"); Log.d(TAG, "Missing camera permission");
Toast.makeText(this, R.string.missing_camera_permission, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.missing_camera_permission, Toast.LENGTH_LONG).show();
} else { } else {
assert bundle != null;
Log.d(TAG, "bundle == " + bundle.getInt("returnCode")); Log.d(TAG, "bundle == " + bundle.getInt("returnCode"));
int returnCode = bundle.getInt("returnCode"); int returnCode = bundle.getInt("returnCode");
int resultCode = bundle.getInt("resultCode"); int resultCode = bundle.getInt("resultCode");
@ -248,13 +245,13 @@ public class DrugListActivity extends AppCompatActivity {
} }
String cip13; String cip13;
switch (bundle.getString(BARCODE_FORMAT_NAME)) { switch (Objects.requireNonNull(bundle.getString(BARCODE_FORMAT_NAME))) {
case "CODE_128": case "CODE_128":
case "EAN_13": //CODE_128 || EAN 13 case "EAN_13": //CODE_128 || EAN 13
cip13 = bundle.getString(BARCODE_CONTENT); cip13 = bundle.getString(BARCODE_CONTENT);
break; break;
case "DATA_MATRIX": case "DATA_MATRIX":
cip13 = bundle.getString(BARCODE_CONTENT).substring(4, 17); cip13 = Objects.requireNonNull(bundle.getString(BARCODE_CONTENT)).substring(4, 17);
break; break;
default: default:
scanNotOK(); scanNotOK();
@ -304,6 +301,44 @@ public class DrugListActivity extends AppCompatActivity {
startActivity(new Intent(this, WelcomeActivity.class)); startActivity(new Intent(this, WelcomeActivity.class));
return true; return true;
} }
else if (id == R.id.export_prescription) {
final Dialog dlg = new Dialog(this);
dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
Objects.requireNonNull(dlg.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dlg.setContentView(R.layout.custom_dialog_layout_one_button);
dlg.setCancelable(false);
TextView msg = dlg.findViewById(R.id.msg);
msg.setText("Demande de Backup");
TextView cpl = dlg.findViewById(R.id.cpl);
ImageView icon = dlg.findViewById(R.id.image);
Button btn = dlg.findViewById(R.id.txtClose);
btn.setText(R.string.button_ok);
btn.setOnClickListener(v -> {
dlg.dismiss();
finish();
});
dlg.show();
} else if (id == R.id.import_prescription) {
final Dialog dlg = new Dialog(this);
dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
Objects.requireNonNull(dlg.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dlg.setContentView(R.layout.custom_dialog_layout_one_button);
dlg.setCancelable(false);
TextView msg = dlg.findViewById(R.id.msg);
msg.setText("Demande de Restauration");
TextView cpl = dlg.findViewById(R.id.cpl);
String cplString;
ImageView icon = dlg.findViewById(R.id.image);
Button btn = dlg.findViewById(R.id.txtClose);
btn.setText(R.string.button_ok);
btn.setOnClickListener(v -> {
dlg.dismiss();
finish();
});
dlg.show();
}
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -318,7 +353,7 @@ public class DrugListActivity extends AppCompatActivity {
} }
// Launch scan // Launch scan
public void onButtonClick() { public void onButtonClick(View v) {
Log.d(TAG, "add medication"); Log.d(TAG, "add medication");
ScanOptions options = new ScanOptions(); ScanOptions options = new ScanOptions();
options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_128); options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_128);
@ -340,7 +375,7 @@ public class DrugListActivity extends AppCompatActivity {
protected void showInputDialog() { protected void showInputDialog() {
final Dialog dialog = new Dialog(this); final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true); dialog.setCanceledOnTouchOutside(true);
@ -401,7 +436,7 @@ public class DrugListActivity extends AppCompatActivity {
private void askToAddInDB(Medicine aMedicine) { private void askToAddInDB(Medicine aMedicine) {
final Dialog dlg = new Dialog(this); final Dialog dlg = new Dialog(this);
dlg.requestWindowFeature(Window.FEATURE_NO_TITLE); dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
dlg.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); Objects.requireNonNull(dlg.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dlg.setContentView(R.layout.custom_dialog_layout_one_button); dlg.setContentView(R.layout.custom_dialog_layout_one_button);
dlg.setCancelable(true); dlg.setCancelable(true);
MaterialTextView msg = dlg.findViewById(R.id.msg); MaterialTextView msg = dlg.findViewById(R.id.msg);
@ -414,8 +449,17 @@ public class DrugListActivity extends AppCompatActivity {
if (aMedicine != null) { if (aMedicine != null) {
msgString = aMedicine.getName() + " " + getString(R.string.msgFound); msgString = aMedicine.getName() + " " + getString(R.string.msgFound);
msg.setText(msgString); msg.setText(msgString);
cplString = getString(R.string.addInList);
if (cplString.isEmpty()) {
cpl.setEnabled(false);
}
cpl.setText(getString(R.string.addInList)); cpl.setText(getString(R.string.addInList));
icon.setImageResource(R.drawable.tickmark); icon.setImageResource(R.drawable.tickmark);
btn.setOnClickListener(v -> {
// TODO Auto-generated method stub
dlg.dismiss();
finish();
addDrugToList(Utils.medicine2prescription(aMedicine));
btn.setText(getString(R.string.Yes)); btn.setText(getString(R.string.Yes));
btn.setOnClickListener(v -> { btn.setOnClickListener(v -> {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -429,6 +473,11 @@ public class DrugListActivity extends AppCompatActivity {
cpl.setText(""); cpl.setText("");
icon.setImageResource(R.drawable.tickcross); icon.setImageResource(R.drawable.tickcross);
btn.setText(getString(R.string.button_close)); btn.setText(getString(R.string.button_close));
btn.setOnClickListener(v -> {
// TODO Auto-generated method stub
dlg.dismiss();
finish();
icon.setImageResource(R.drawable.tickcross); //TODO: Exception imageResource null Object reference
btn.setOnClickListener(v -> { btn.setOnClickListener(v -> {
// TODO Auto-generated method stub // TODO Auto-generated method stub
dlg.dismiss(); dlg.dismiss();
@ -515,6 +564,10 @@ public class DrugListActivity extends AppCompatActivity {
mAdapter.notifyItemInserted(position); mAdapter.notifyItemInserted(position);
}).setActionTextColor(getResources().getColor(R.color.bg_screen1)) }).setActionTextColor(getResources().getColor(R.color.bg_screen1))
.show(); .show();
Snackbar.LENGTH_LONG).setAction(R.string.Undo, v -> {
prescriptionList.add(position, prescription);
mAdapter.notifyItemInserted(position);
}).show();
} }
@Override @Override
@ -649,6 +702,7 @@ public class DrugListActivity extends AppCompatActivity {
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
}); });
} else { } else {
int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getTake()); int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getTake());