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);
changeLaserVisibility(true);
barcodeScannerView.decodeSingle(new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
barcodeScannerView.decodeSingle(result -> {
Intent scanResult = new Intent();
//Bundle scanResultBundle = new Bundle();
scanResult.putExtra("Barcode Content", result.getText());
@ -69,7 +67,6 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV
CustomScannerActivity.this.setResult(RESULT_OK, scanResult);
Log.d(TAG, "scanResult == " + scanResult);
finish();
}
});
}

View file

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

View file

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

View file

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

View file

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