Use lambda everywhere (#23)

This commit is contained in:
Jean-Baptiste 2024-03-26 21:17:58 +01:00 committed by GitHub
parent d11048d679
commit 2f54326206
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 101 deletions

View file

@ -57,19 +57,16 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV
//changeMaskColor(null); //changeMaskColor(null);
changeLaserVisibility(true); changeLaserVisibility(true);
barcodeScannerView.decodeSingle(new BarcodeCallback() { barcodeScannerView.decodeSingle(result -> {
@Override Intent scanResult = new Intent();
public void barcodeResult(BarcodeResult result) { //Bundle scanResultBundle = new Bundle();
Intent scanResult = new Intent(); scanResult.putExtra("Barcode Content", result.getText());
//Bundle scanResultBundle = new Bundle(); scanResult.putExtra("Barcode Format name", result.getBarcodeFormat().name());
scanResult.putExtra("Barcode Content", result.getText()); scanResult.putExtra("returnCode", captureIntentBundle.getInt("returnCode"));
scanResult.putExtra("Barcode Format name", result.getBarcodeFormat().name()); scanResult.putExtra("resultCode", 1);
scanResult.putExtra("returnCode", captureIntentBundle.getInt("returnCode")); CustomScannerActivity.this.setResult(RESULT_OK, scanResult);
scanResult.putExtra("resultCode", 1); Log.d(TAG, "scanResult == " + scanResult);
CustomScannerActivity.this.setResult(RESULT_OK, scanResult); finish();
Log.d(TAG, "scanResult == " + scanResult);
finish();
}
}); });
} }

View file

@ -270,14 +270,11 @@ class DBHelper extends SQLiteOpenHelper {
Log.d(TAG, "Before sort == " + drugs); Log.d(TAG, "Before sort == " + drugs);
drugs.sort(new Comparator<Drug>() { drugs.sort((lhs, rhs) -> {
@Override if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
public int compare(Drug lhs, Drug rhs) { return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) else
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); return (int) (lhs.getStock() - rhs.getStock());
else
return (int) (lhs.getStock() - rhs.getStock());
}
}); });
Log.d(TAG, "After sort " + drugs); Log.d(TAG, "After sort " + drugs);

View file

@ -47,16 +47,13 @@ public class DrugDetailActivity extends AppCompatActivity {
} }
ImageButton fab = findViewById(R.id.fab); ImageButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(v -> {
@Override Log.d(TAG, "Click on save icon");
public void onClick(View view) {
Log.d(TAG, "Click on save icon");
getDrugChanges(); getDrugChanges();
setResult(1); setResult(1);
finish(); finish();
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right); overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);
}
}); });
// Show the Up button in the action bar. // Show the Up button in the action bar.

View file

@ -375,21 +375,16 @@ public class DrugListActivity extends AppCompatActivity {
} }
} }
}); });
ok.setOnClickListener(new View.OnClickListener() { ok.setOnClickListener(v -> {
public void onClick(View v) { dialog.cancel();
dialog.cancel(); Log.i("EditText Value",editText.getEditableText().toString());
Log.i("EditText Value",editText.getEditableText().toString()); MedicinesDAO medicinesDAO = medicines.getMedicinesDAO();
MedicinesDAO medicinesDAO = medicines.getMedicinesDAO(); Medicine aMedicine = medicinesDAO.getMedicineByCIP13(cip13);
Medicine aMedicine = medicinesDAO.getMedicineByCIP13(cip13); askToAddInDB(aMedicine);
askToAddInDB(aMedicine);
}
}); });
cancel.setOnClickListener(new View.OnClickListener() { cancel.setOnClickListener(v -> {
@Override dialog.cancel();
public void onClick(View v) { Log.i(TAG, "dismiss dialog");
dialog.cancel();
Log.i(TAG, "dismiss dialog");
}
}); });
dialog.show(); dialog.show();
@ -423,27 +418,21 @@ public class DrugListActivity extends AppCompatActivity {
cpl.setEnabled(false); cpl.setEnabled(false);
} }
icon.setImageResource(R.drawable.tickmark); icon.setImageResource(R.drawable.tickmark);
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(v -> {
@Override // TODO Auto-generated method stub
public void onClick(View v) { dlg.dismiss();
// TODO Auto-generated method stub finish();
dlg.dismiss(); addDrugToList(Utils.medicine2prescription(aMedicine));
finish();
addDrugToList(Utils.medicine2prescription(aMedicine));
}
}); });
} else { } else {
msgString = getString(R.string.msgNotFound); msgString = getString(R.string.msgNotFound);
msg.setText(msgString); msg.setText(msgString);
cpl.setText(""); cpl.setText("");
icon.setImageResource(R.drawable.tickcross); icon.setImageResource(R.drawable.tickcross);
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(v -> {
@Override // TODO Auto-generated method stub
public void onClick(View v) { dlg.dismiss();
// TODO Auto-generated method stub finish();
dlg.dismiss();
finish();
}
}); });
} }
dlg.show(); dlg.show();
@ -521,13 +510,10 @@ public class DrugListActivity extends AppCompatActivity {
} }
Snackbar.make(recyclerView, prescription.getName(), Snackbar.make(recyclerView, prescription.getName(),
Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() { Snackbar.LENGTH_LONG).setAction(R.string.Undo, v -> {
@Override prescriptionList.add(position, prescription);
public void onClick(View v) { mAdapter.notifyItemInserted(position);
prescriptionList.add(position, prescription); }).show();
mAdapter.notifyItemInserted(position);
}
}).show();
} }
@Override @Override
@ -654,17 +640,14 @@ public class DrugListActivity extends AppCompatActivity {
holder.mView.setBackgroundResource(R.drawable.gradient_bg); holder.mView.setBackgroundResource(R.drawable.gradient_bg);
holder.mIconView.setImageResource(R.drawable.ic_suspended_pill); holder.mIconView.setImageResource(R.drawable.ic_suspended_pill);
holder.mView.setOnClickListener(new View.OnClickListener() { holder.mView.setOnClickListener(v -> {
@Override Prescription aPrescription = mValues.get(position);
public void onClick(View v) { Context context = v.getContext();
Prescription aPrescription = mValues.get(position); Intent intent = new Intent(context, DrugDetailActivity.class);
Context context = v.getContext(); intent.putExtra("prescription", aPrescription);
Intent intent = new Intent(context, DrugDetailActivity.class); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
intent.putExtra("prescription", aPrescription); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
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());
@ -680,16 +663,13 @@ public class DrugListActivity extends AppCompatActivity {
holder.mIconView.setImageResource(R.drawable.ok_stock_vect); holder.mIconView.setImageResource(R.drawable.ok_stock_vect);
} }
holder.mView.setOnClickListener(new View.OnClickListener() { holder.mView.setOnClickListener(v -> {
@Override Prescription prescription = mValues.get(position);
public void onClick(View v) { Context context = v.getContext();
Prescription prescription = mValues.get(position); Intent intent = new Intent(context, DrugDetailActivity.class);
Context context = v.getContext(); intent.putExtra("prescription", prescription);
Intent intent = new Intent(context, DrugDetailActivity.class); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
intent.putExtra("prescription", prescription); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
}); });
} }
} }

View file

@ -49,14 +49,11 @@ public class Utils {
} }
public static void sortPrescriptionList(List<Prescription> prescriptionList) { public static void sortPrescriptionList(List<Prescription> prescriptionList) {
prescriptionList.sort(new Comparator<>() { prescriptionList.sort((lhs, rhs) -> {
@Override if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
public int compare(Prescription lhs, Prescription rhs) { return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) else
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); return (int) (lhs.getStock() - rhs.getStock());
else
return (int) (lhs.getStock() - rhs.getStock());
}
}); });
} }

View file

@ -156,13 +156,10 @@ public class WelcomeActivity extends AppCompatActivity {
} }
//icon.setImageResource(R.drawable.pilldroid_icon); //icon.setImageResource(R.drawable.pilldroid_icon);
btn.setText(R.string.Yes); btn.setText(R.string.Yes);
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(v -> {
@Override // TODO Auto-generated method stub
public void onClick(View v) { dlg.dismiss();
// TODO Auto-generated method stub finish();
dlg.dismiss();
finish();
}
}); });
} }