From 35a8aedc2c89d09236e36b6a3471c7fc5901b4d1 Mon Sep 17 00:00:00 2001 From: George Kankava Date: Fri, 15 Apr 2016 15:20:19 +0400 Subject: [PATCH] Multiple code improvements - squid:S1148, squid:HiddenFieldCheck, squid:S1066, squid:S1172 --- .../refresh/pos/domain/DateTimeStrategy.java | 12 +++++-- .../pos/domain/inventory/ProductLot.java | 2 +- .../pos/techicalservices/AndroidDatabase.java | 33 +++++++++---------- .../refresh/pos/techicalservices/Demo.java | 4 ++- .../ui/inventory/ProductDetailActivity.java | 4 +-- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/refresh/pos/domain/DateTimeStrategy.java b/app/src/main/java/com/refresh/pos/domain/DateTimeStrategy.java index ddb1c7d..405f5ab 100644 --- a/app/src/main/java/com/refresh/pos/domain/DateTimeStrategy.java +++ b/app/src/main/java/com/refresh/pos/domain/DateTimeStrategy.java @@ -28,14 +28,22 @@ public static void setLocale(String lang, String reg) { locale = new Locale(lang, reg); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", locale); } - + + /** + * Sets current time format. + * @return current time format. + */ + public static String format() { + return dateFormat.format(Calendar.getInstance(locale).getTime()); + } + /** * Sets current time format. * @param date date of this format. * @return current time format. */ public static String format(String date) { - return dateFormat.format(Calendar.getInstance(locale).getTime()); + return dateFormat.format(date); } /** diff --git a/app/src/main/java/com/refresh/pos/domain/inventory/ProductLot.java b/app/src/main/java/com/refresh/pos/domain/inventory/ProductLot.java index 2b25cda..9a1444b 100644 --- a/app/src/main/java/com/refresh/pos/domain/inventory/ProductLot.java +++ b/app/src/main/java/com/refresh/pos/domain/inventory/ProductLot.java @@ -87,7 +87,7 @@ public Product getProduct() { public Map toMap() { Map map = new HashMap(); map.put("id", id + ""); - map.put("dateAdded", DateTimeStrategy.format(dateAdded)); + map.put("dateAdded", DateTimeStrategy.format()); map.put("quantity", quantity + ""); map.put("productName", product.getName()); map.put("cost", unitCost + ""); diff --git a/app/src/main/java/com/refresh/pos/techicalservices/AndroidDatabase.java b/app/src/main/java/com/refresh/pos/techicalservices/AndroidDatabase.java index 5b94154..ffbb933 100644 --- a/app/src/main/java/com/refresh/pos/techicalservices/AndroidDatabase.java +++ b/app/src/main/java/com/refresh/pos/techicalservices/AndroidDatabase.java @@ -19,6 +19,7 @@ */ public class AndroidDatabase extends SQLiteOpenHelper implements Database { + private static final String TAG = "AndroidDatabase"; private static final int DATABASE_VERSION = 1; /** @@ -112,25 +113,23 @@ public List select(String queryString) { List list = new ArrayList(); Cursor cursor = database.rawQuery(queryString, null); - if (cursor != null) { - if (cursor.moveToFirst()) { - do { - ContentValues content = new ContentValues(); - String[] columnNames = cursor.getColumnNames(); - for (String columnName : columnNames) { - content.put(columnName, cursor.getString(cursor - .getColumnIndex(columnName))); - } - list.add(content); - } while (cursor.moveToNext()); - } + if (cursor != null && cursor.moveToFirst()) { + do { + ContentValues content = new ContentValues(); + String[] columnNames = cursor.getColumnNames(); + for (String columnName : columnNames) { + content.put(columnName, cursor.getString(cursor + .getColumnIndex(columnName))); + } + list.add(content); + } while (cursor.moveToNext()); } cursor.close(); database.close(); return list; } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return null; } } @@ -144,7 +143,7 @@ public int insert(String tableName, Object content) { database.close(); return id; } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return -1; } @@ -161,7 +160,7 @@ public boolean update(String tableName, Object content) { return true; } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return false; } } @@ -174,7 +173,7 @@ public boolean delete(String tableName, int id) { return true; } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return false; } } @@ -186,7 +185,7 @@ public boolean execute(String query) { database.execSQL(query); return true; }catch(Exception e){ - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return false; } } diff --git a/app/src/main/java/com/refresh/pos/techicalservices/Demo.java b/app/src/main/java/com/refresh/pos/techicalservices/Demo.java index fb8b22b..02f50c9 100644 --- a/app/src/main/java/com/refresh/pos/techicalservices/Demo.java +++ b/app/src/main/java/com/refresh/pos/techicalservices/Demo.java @@ -19,6 +19,8 @@ */ public class Demo { + private static final String TAG = "Demo"; + /** * Adds the demo product to inventory. * @param context The current stage of the application. @@ -35,7 +37,7 @@ public static void testProduct(Context context) { catalog.addProduct(contents[1], contents[0], Double.parseDouble(contents[2])); } } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); } } diff --git a/app/src/main/java/com/refresh/pos/ui/inventory/ProductDetailActivity.java b/app/src/main/java/com/refresh/pos/ui/inventory/ProductDetailActivity.java index 7fc4f4c..3915954 100644 --- a/app/src/main/java/com/refresh/pos/ui/inventory/ProductDetailActivity.java +++ b/app/src/main/java/com/refresh/pos/ui/inventory/ProductDetailActivity.java @@ -72,8 +72,8 @@ public class ProductDetailActivity extends Activity { @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.detail_menu, menu); + MenuInflater menuInflater = getMenuInflater(); + menuInflater.inflate(R.menu.detail_menu, menu); return true; }