From bf88d1e64f3d3ad6b2110d326484662afac6ed22 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 2 Mar 2022 10:35:23 +0100 Subject: [PATCH] Some cleaning according to code analysis --- .../net/foucry/pilldroid/CustomScannerActivity.java | 6 +++--- app/src/main/java/net/foucry/pilldroid/DBDrugs.java | 4 ++-- app/src/main/java/net/foucry/pilldroid/DBHelper.java | 10 +++++----- app/src/main/java/net/foucry/pilldroid/Drug.java | 2 +- .../java/net/foucry/pilldroid/DrugDetailActivity.java | 2 +- .../java/net/foucry/pilldroid/DrugListActivity.java | 1 - .../main/java/net/foucry/pilldroid/PrefManager.java | 4 ++-- .../foucry/pilldroid/SimpleDividerItemDecoration.java | 1 - app/src/main/java/net/foucry/pilldroid/UtilDate.java | 1 - .../java/net/foucry/pilldroid/WelcomeActivity.java | 2 +- 10 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index 6687af3..81efd5c 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -33,8 +33,8 @@ public class CustomScannerActivity extends Activity { private ImageButton switchFlashlightButton; private ViewfinderView viewfinderView; - Intent captureIntent = new Intent(); - Bundle captureIntentBundle = new Bundle(); + final Intent captureIntent = new Intent(); + final Bundle captureIntentBundle = new Bundle(); @Override public void onCreate(Bundle savedInstanceState) { @@ -88,7 +88,7 @@ public class CustomScannerActivity extends Activity { scanResult.putExtra("returnCode", captureIntentBundle.getInt("returnCode")); scanResult.putExtra("resultCode", 1); CustomScannerActivity.this.setResult(RESULT_OK, scanResult); - Log.d(TAG, "scanResult == " + scanResult.toString()); + Log.d(TAG, "scanResult == " + scanResult); finish(); } }); diff --git a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java index 7dc1047..226fa4d 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java +++ b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java @@ -155,7 +155,7 @@ class DBDrugs extends SQLiteOpenHelper { drug.setAlertThreshold(7); // Log - Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString()); + Log.d(TAG, "getDrug(" + cip13 + ")" + drug); // Return drug @@ -223,7 +223,7 @@ class DBDrugs extends SQLiteOpenHelper { drug.setAlertThreshold(7); // Log - Log.d(TAG, "getDrug(" + cip7 + ")" + drug.toString()); + Log.d(TAG, "getDrug(" + cip7 + ")" + drug); // Return drug diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index 5d9954e..01252d7 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -161,7 +161,7 @@ class DBHelper extends SQLiteOpenHelper { drug.setDateLastUpdate(Long.parseLong(cursor.getString(10))); } // Log - Log.d(TAG, "getDrug("+id+")" + drug.toString()); + Log.d(TAG, "getDrug("+id+")" + drug); assert cursor != null; cursor.close(); @@ -212,7 +212,7 @@ class DBHelper extends SQLiteOpenHelper { assert cursor != null; cursor.close(); - Log.d(TAG, "getDrug(" + cip13 + ")" + drug.toString()); + Log.d(TAG, "getDrug(" + cip13 + ")" + drug); return drug; } @@ -274,7 +274,7 @@ class DBHelper extends SQLiteOpenHelper { - Log.d(TAG, "Before sort == " + drugs.toString()); + Log.d(TAG, "Before sort == " + drugs); /*drugs.sort(Comparator.comparing(Drug::getDateEndOfStock) .thenComparing(Drug::getStock));*/ @@ -288,7 +288,7 @@ class DBHelper extends SQLiteOpenHelper { return (int) (lhs.getStock() - rhs.getStock()); } }); - Log.d(TAG, "After sort " + drugs.toString()); + Log.d(TAG, "After sort " + drugs); // Move drug with prise = 0 at the end of the list // todo: If some drug moved, must redo all the loop @@ -343,7 +343,7 @@ class DBHelper extends SQLiteOpenHelper { // Close DB db.close(); - Log.d(TAG, "values == " + values.toString()); + Log.d(TAG, "values == " + values); } /** diff --git a/app/src/main/java/net/foucry/pilldroid/Drug.java b/app/src/main/java/net/foucry/pilldroid/Drug.java index 54a1686..5c5b011 100644 --- a/app/src/main/java/net/foucry/pilldroid/Drug.java +++ b/app/src/main/java/net/foucry/pilldroid/Drug.java @@ -165,7 +165,7 @@ public class Drug implements Serializable { } void newStock() { - Log.d(TAG, "current drug = " + this.toString()); + Log.d(TAG, "current drug = " + this); Date lastUpdate = new Date(getDateLastUpdate()); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index f39b211..1d2c208 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -42,7 +42,7 @@ public class DrugDetailActivity extends AppCompatActivity { drug = (Drug) extras.getSerializable("drug"); assert drug != null; - Log.d(TAG, "drug == " + drug.toString()); + Log.d(TAG, "drug == " + drug); setContentView(R.layout.activity_drug_detail); Toolbar toolbar = findViewById(detail_toolbar); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index f8815e4..1414958 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -8,7 +8,6 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; diff --git a/app/src/main/java/net/foucry/pilldroid/PrefManager.java b/app/src/main/java/net/foucry/pilldroid/PrefManager.java index cbd6736..352df03 100644 --- a/app/src/main/java/net/foucry/pilldroid/PrefManager.java +++ b/app/src/main/java/net/foucry/pilldroid/PrefManager.java @@ -8,11 +8,11 @@ import android.content.SharedPreferences; * Created by Lincoln on 05/05/16. */ public class PrefManager { - SharedPreferences pref; + final SharedPreferences pref; SharedPreferences.Editor editor; // shared pref mode - int PRIVATE_MODE = 0; + final int PRIVATE_MODE = 0; // Shared preferences file name private static final String PREF_NAME = "Pildroid-Prefs"; diff --git a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java index 86a5bcf..ea424b5 100644 --- a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java +++ b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java @@ -6,7 +6,6 @@ import android.graphics.drawable.Drawable; import android.view.View; import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; /** diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 1213256..bafb822 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -5,7 +5,6 @@ import android.util.Log; import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; -import java.time.LocalTime; import java.util.Calendar; import java.util.Date; import java.util.Locale; diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index 624efd4..7761e90 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -132,7 +132,7 @@ public class WelcomeActivity extends AppCompatActivity { } // viewpager change listener - ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { + final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) {