optimize import and clean dead code

This commit is contained in:
jacques 2022-03-12 21:43:30 +01:00
parent 2f2c31b1c9
commit dc71f57a73
6 changed files with 11 additions and 121 deletions

View file

@ -1,5 +1,7 @@
package net.foucry.pilldroid; package net.foucry.pilldroid;
import static net.foucry.pilldroid.R.id.detail_toolbar;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -13,14 +15,11 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import java.io.Serializable;
import java.util.Date;
import static net.foucry.pilldroid.R.id.detail_toolbar;
import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.dao.MedicDAO;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Medic;
import java.util.Date;
/** /**
* An activity representing a single Drug detail screen. This * An activity representing a single Drug detail screen. This
* activity is only used narrow width devices. On tablet-size devices, * activity is only used narrow width devices. On tablet-size devices,
@ -81,9 +80,6 @@ public class DrugDetailActivity extends AppCompatActivity {
if (savedInstanceState == null) { if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity // Create the detail fragment and add it to the activity
// using a fragment transaction. // using a fragment transaction.
/*Bundle arguments = new Bundle();
arguments.putSerializable("medic",
getIntent().getExtras());*/
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putSerializable("medic", aMedic); arguments.putSerializable("medic", aMedic);
DrugDetailFragment fragment = new DrugDetailFragment(); DrugDetailFragment fragment = new DrugDetailFragment();
@ -114,7 +110,6 @@ public class DrugDetailActivity extends AppCompatActivity {
Log.d(TAG, "Time to save new values"); Log.d(TAG, "Time to save new values");
PilldroidDatabase prescriptions = null; PilldroidDatabase prescriptions = null;
DBHelper dbHelper = new DBHelper(this);
assert false; assert false;
MedicDAO medicDAO = prescriptions.getMedicDAO(); MedicDAO medicDAO = prescriptions.getMedicDAO();

View file

@ -36,15 +36,14 @@ import androidx.room.Room;
import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.ScanOptions; import com.journeyapps.barcodescanner.ScanOptions;
import java.io.Serializable; import net.foucry.pilldroid.dao.MedicDAO;
import net.foucry.pilldroid.models.Medic;
import java.text.SimpleDateFormat; 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 net.foucry.pilldroid.dao.MedicDAO;
import net.foucry.pilldroid.models.Medic;
/** /**
* An activity representing a list of Drugs is activity * An activity representing a list of Drugs is activity
* has different presentations for handset and tablet-size devices. On * has different presentations for handset and tablet-size devices. On
@ -65,7 +64,6 @@ public class DrugListActivity extends AppCompatActivity {
private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher; private ActivityResultLauncher<ScanOptions> mBarcodeScannerLauncher;
private static final String TAG = DrugListActivity.class.getName(); private static final String TAG = DrugListActivity.class.getName();
private DBHelper dbHelper;
private DBDrugs dbDrug; private DBDrugs dbDrug;
public PilldroidDatabase prescriptions; public PilldroidDatabase prescriptions;
public PilldroidDatabase medications; public PilldroidDatabase medications;
@ -114,7 +112,7 @@ public class DrugListActivity extends AppCompatActivity {
// Set view content // Set view content
setContentView(R.layout.activity_drug_list); setContentView(R.layout.activity_drug_list);
dbHelper = new DBHelper(this); DBHelper dbHelper = new DBHelper(this);
dbDrug = new DBDrugs(this); dbDrug = new DBDrugs(this);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
@ -157,49 +155,6 @@ public class DrugListActivity extends AppCompatActivity {
System.out.println(prescriptions); System.out.println(prescriptions);
Log.d(TAG, "prescriptions ==" + prescriptions); Log.d(TAG, "prescriptions ==" + prescriptions);
} }
/*
if (dbHelper.getCount() == 0) {
// String cis, String cip13, String nom, String mode_administration,
// String presentation,double stock, double prise, int warn, int alert
// Limit for randoms generator
final int min_stock = 5;
final int max_stock = 50;
final int min_prise = 0;
final int max_prise = 3;
dbHelper.addDrug(new Drug("60000011", "3400930000011", "Médicament test 01", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000012", "3400930000012", "Médicament test 02", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000013", "3400930000013", "Médicament test 03", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000014", "3400930000014", "Médicament test 04", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000015", "3400930000015", "Médicament test 05", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000016", "3400930000016", "Médicament test 06", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000017", "3400930000017", "Médicament test 07", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000018", "3400930000018", "Médicament test 08", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000019", "3400930000019", "Médicament test 09", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
dbHelper.addDrug(new Drug("60000010", "3400930000010", "Médicament test 10", "orale",
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
intRandomExclusive(min_stock, max_stock), intRandomExclusive(min_prise, max_prise), 14, 7, UtilDate.dateAtNoon(new Date()).getTime()));
}*/
} }
mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(), mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(),
@ -274,15 +229,6 @@ public class DrugListActivity extends AppCompatActivity {
MedicDAO medicDAO = prescriptions.getMedicDAO(); MedicDAO medicDAO = prescriptions.getMedicDAO();
medics = medicDAO.getAllMedics(); medics = medicDAO.getAllMedics();
/*dbHelper = new DBHelper(getApplicationContext());
if (!(drugs == null)) {
if (!drugs.isEmpty()) {
drugs.clear();
}
}
drugs = dbHelper.getAllDrugs();*/
View mRecyclerView = findViewById(R.id.drug_list); View mRecyclerView = findViewById(R.id.drug_list);
assert mRecyclerView != null; assert mRecyclerView != null;
setupRecyclerView((RecyclerView) mRecyclerView); setupRecyclerView((RecyclerView) mRecyclerView);
@ -312,11 +258,6 @@ public class DrugListActivity extends AppCompatActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
/*if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
return;
}*/
if (requestCode == CUSTOMIZED_REQUEST_CODE) { if (requestCode == CUSTOMIZED_REQUEST_CODE) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Toast.makeText(this, "REQUEST_CODE = " + requestCode + Toast.makeText(this, "REQUEST_CODE = " + requestCode +

View file

@ -3,8 +3,6 @@ package net.foucry.pilldroid;
import androidx.room.AutoMigration; import androidx.room.AutoMigration;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import net.foucry.pilldroid.dao.MedicDAO; import net.foucry.pilldroid.dao.MedicDAO;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Medic;
@ -15,8 +13,7 @@ import net.foucry.pilldroid.models.Medic;
autoMigrations = { autoMigrations = {
@AutoMigration(from = 1, to = 2), @AutoMigration(from = 1, to = 2),
@AutoMigration(from = 2, to = 3), @AutoMigration(from = 2, to = 3),
}, }
exportSchema = true
) )
public abstract class PilldroidDatabase extends RoomDatabase { public abstract class PilldroidDatabase extends RoomDatabase {

View file

@ -1,41 +1,11 @@
package net.foucry.pilldroid; package net.foucry.pilldroid;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
public class Utils { public class Utils {
private static final String TAG = Utils.class.getName(); private static final String TAG = Utils.class.getName();
public static final int SELECT_BARCODE_REQUEST = 2;
public static final int BARCODE_SCAN = 3;
public static void CopyStream(InputStream is, OutputStream os)
{
final int buffer_size=1024;
try
{
byte[] bytes=new byte[buffer_size];
for(;;)
{
int count=is.read(bytes, 0, buffer_size);
if(count==-1)
break;
os.write(bytes, 0, count);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/** /**
* Return a random number between twovalues - use to gənerate a false demo DB * Return a random number between twovalues - use to gənerate a false demo DB
* @param min minimal value accepted * @param min minimal value accepted

View file

@ -1,7 +1,5 @@
package net.foucry.pilldroid.dao; package net.foucry.pilldroid.dao;
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
import androidx.room.Dao; import androidx.room.Dao;
import androidx.room.Delete; import androidx.room.Delete;
import androidx.room.Insert; import androidx.room.Insert;
@ -10,8 +8,6 @@ import androidx.room.Update;
import net.foucry.pilldroid.models.Medic; import net.foucry.pilldroid.models.Medic;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
@Dao @Dao

View file

@ -25,11 +25,7 @@ public class Medic implements Serializable {
private Long last_update; private Long last_update;
/* public Medic(@NonNull Integer id) { public void setCis(@NonNull String cis)
this.id = id;
}*/
public void setCis(String cis)
{ {
this.cis = cis; this.cis = cis;
} }
@ -69,12 +65,7 @@ public class Medic implements Serializable {
this.last_update = last_update; this.last_update = last_update;
} }
//@NonNull @NonNull
/*public Integer getId() {
return this.id;
}*/
@NonNull
public String getCis() { public String getCis() {
return this.cis; return this.cis;
} }