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,9 +57,7 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV
//changeMaskColor(null); //changeMaskColor(null);
changeLaserVisibility(true); changeLaserVisibility(true);
barcodeScannerView.decodeSingle(new BarcodeCallback() { barcodeScannerView.decodeSingle(result -> {
@Override
public void barcodeResult(BarcodeResult result) {
Intent scanResult = new Intent(); Intent scanResult = new Intent();
//Bundle scanResultBundle = new Bundle(); //Bundle scanResultBundle = new Bundle();
scanResult.putExtra("Barcode Content", result.getText()); scanResult.putExtra("Barcode Content", result.getText());
@ -69,7 +67,6 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV
CustomScannerActivity.this.setResult(RESULT_OK, scanResult); CustomScannerActivity.this.setResult(RESULT_OK, scanResult);
Log.d(TAG, "scanResult == " + scanResult); Log.d(TAG, "scanResult == " + scanResult);
finish(); 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
public int compare(Drug lhs, Drug rhs) {
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
else else
return (int) (lhs.getStock() - rhs.getStock()); 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
public void onClick(View view) {
Log.d(TAG, "Click on save icon"); 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
public void onClick(View v) {
dialog.cancel(); dialog.cancel();
Log.i(TAG, "dismiss dialog"); 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
public void onClick(View v) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
dlg.dismiss(); dlg.dismiss();
finish(); finish();
addDrugToList(Utils.medicine2prescription(aMedicine)); 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
public void onClick(View v) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
dlg.dismiss(); dlg.dismiss();
finish(); finish();
}
}); });
} }
dlg.show(); dlg.show();
@ -521,12 +510,9 @@ 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
public void onClick(View v) {
prescriptionList.add(position, prescription); prescriptionList.add(position, prescription);
mAdapter.notifyItemInserted(position); mAdapter.notifyItemInserted(position);
}
}).show(); }).show();
} }
@ -654,9 +640,7 @@ 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
public void onClick(View v) {
Prescription aPrescription = mValues.get(position); Prescription aPrescription = mValues.get(position);
Context context = v.getContext(); Context context = v.getContext();
Intent intent = new Intent(context, DrugDetailActivity.class); Intent intent = new Intent(context, DrugDetailActivity.class);
@ -664,7 +648,6 @@ 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());
@ -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
public void onClick(View v) {
Prescription prescription = mValues.get(position); Prescription prescription = mValues.get(position);
Context context = v.getContext(); Context context = v.getContext();
Intent intent = new Intent(context, DrugDetailActivity.class); Intent intent = new Intent(context, DrugDetailActivity.class);
intent.putExtra("prescription", prescription); intent.putExtra("prescription", prescription);
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);
}
}); });
} }
} }

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
public int compare(Prescription lhs, Prescription rhs) {
if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0)
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
else else
return (int) (lhs.getStock() - rhs.getStock()); 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
public void onClick(View v) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
dlg.dismiss(); dlg.dismiss();
finish(); finish();
}
}); });
} }