From 0edfcde8da759c14e41808266f859fc65e7d2ae8 Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Tue, 7 Aug 2018 18:13:19 +0200 Subject: [PATCH 1/4] Add support for deleting crashes in database. --- .../src/main/java/com/singhajit/sherlock/core/Sherlock.java | 2 ++ .../java/com/singhajit/sherlock/core/database/CrashTable.java | 1 + .../sherlock/core/database/SherlockDatabaseHelper.java | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java b/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java index 9e61c0c..507188b 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java @@ -58,6 +58,8 @@ public List getAllCrashes() { return getInstance().database.getCrashes(); } + public void clearAllCrashes() { return getInstance().database.clearCrashes(); } + private static void analyzeAndReportCrash(Throwable throwable) { Log.d(TAG, "Analyzing Crash..."); CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable); diff --git a/sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashTable.java b/sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashTable.java index 18e09fb..691d4b9 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashTable.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashTable.java @@ -19,6 +19,7 @@ public class CrashTable implements BaseColumns { public static final String DROP_QUERY = "drop table " + TABLE_NAME; public static final String TRUNCATE_QUERY = "delete from " + TABLE_NAME; public static final String SELECT_ALL = "SELECT * FROM " + TABLE_NAME + " ORDER BY " + _ID + " DESC"; + public static final String DELETE_ALL = "DELETE FROM " + TABLE_NAME; public static String selectById(int id) { return "SELECT * FROM " + TABLE_NAME + " WHERE " + _ID + " = " + id; diff --git a/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java b/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java index 1abbb1f..dd7691e 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java @@ -61,6 +61,10 @@ public List getCrashes() { return crashes; } + public void clearCrashes() { + sqLiteDatabase.execSQL(CrashTable.DELETE_ALL); + } + public Crash getCrashById(int id) { SQLiteDatabase readableDatabase = getReadableDatabase(); Cursor cursor = readableDatabase.rawQuery(CrashTable.selectById(id), null); From d5c20e8a48c36c4db062743511c79160f22380aa Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Tue, 7 Aug 2018 18:24:47 +0200 Subject: [PATCH 2/4] Remove useless instance based operation, while a static interface is used internally anyway. --- .../src/main/java/com/singhajit/sherlock/core/Sherlock.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java b/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java index 507188b..ee7fee7 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java @@ -54,11 +54,11 @@ public static Sherlock getInstance() { return instance; } - public List getAllCrashes() { + public static List getAllCrashes() { return getInstance().database.getCrashes(); } - public void clearAllCrashes() { return getInstance().database.clearCrashes(); } + public static void clearAllCrashes() { getInstance().database.clearCrashes(); } private static void analyzeAndReportCrash(Throwable throwable) { Log.d(TAG, "Analyzing Crash..."); From 693dbf3b7de3026a68b933f497df597aedc53ac9 Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Tue, 7 Aug 2018 18:25:42 +0200 Subject: [PATCH 3/4] Remove useless instance based operation, while a static interface is used internally anyway. --- .../sherlock/core/database/SherlockDatabaseHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java b/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java index dd7691e..073a9d8 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java @@ -62,7 +62,7 @@ public List getCrashes() { } public void clearCrashes() { - sqLiteDatabase.execSQL(CrashTable.DELETE_ALL); + getWritableDatabase().execSQL(CrashTable.DELETE_ALL); } public Crash getCrashById(int id) { From 66b7a6f516c068f77ef710c92c4f94aa2720988e Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Mon, 13 Aug 2018 16:01:09 +0200 Subject: [PATCH 4/4] Add button in the CrashListActivity allowing to clear all crashes when requested to do so. --- .../crashes/activity/CrashListActivity.java | 24 +++++++++++++++++-- .../main/res/layout/crash_list_activity.xml | 13 +++++++++- sherlock/src/main/res/values/strings.xml | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashListActivity.java b/sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashListActivity.java index 705f2d1..6ff2a0f 100644 --- a/sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashListActivity.java +++ b/sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashListActivity.java @@ -9,6 +9,7 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.widget.CheckBox; import android.widget.LinearLayout; import com.singhajit.sherlock.R; @@ -18,8 +19,11 @@ import com.singhajit.sherlock.crashes.presenter.CrashListPresenter; import com.singhajit.sherlock.crashes.viewmodel.CrashesViewModel; -public class CrashListActivity extends BaseActivity implements CrashListActions { +import static com.singhajit.sherlock.crashes.activity.CrashActivity.CRASH_ID; + +public class CrashListActivity extends BaseActivity implements CrashListActions { + public static final String CLEAR_CRASHES = "com.singhajit.sherlock.CLEAR_CRASHES"; private CrashListPresenter presenter; @Override @@ -27,6 +31,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crash_list_activity); + Intent intent = getIntent(); + boolean clearCrashes = intent.getBooleanExtra(CLEAR_CRASHES, false); + ((CheckBox) findViewById(R.id.erase_crashes)).setChecked(clearCrashes); + enableHomeButton((Toolbar) findViewById(R.id.toolbar)); setTitle(R.string.app_name); @@ -35,6 +43,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { presenter.render(database); } + @Override + protected void onDestroy() + { + CheckBox eraseAll = (CheckBox) findViewById(R.id.erase_crashes); + if (eraseAll != null && eraseAll.isChecked()) + { + SherlockDatabaseHelper dbHelper = new SherlockDatabaseHelper(this); + dbHelper.clearCrashes(); + } + super.onDestroy(); + } + @Override public void render(CrashesViewModel viewModel) { RecyclerView crashList = (RecyclerView) findViewById(R.id.crash_list); @@ -66,7 +86,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override public void openCrashDetails(int crashId) { Intent intent = new Intent(this, CrashActivity.class); - intent.putExtra(CrashActivity.CRASH_ID, crashId); + intent.putExtra(CRASH_ID, crashId); startActivity(intent); } diff --git a/sherlock/src/main/res/layout/crash_list_activity.xml b/sherlock/src/main/res/layout/crash_list_activity.xml index 22db841..092d411 100644 --- a/sherlock/src/main/res/layout/crash_list_activity.xml +++ b/sherlock/src/main/res/layout/crash_list_activity.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent" android:orientation="vertical"> + + + + android:scrollbars="vertical"> + + + \ No newline at end of file diff --git a/sherlock/src/main/res/values/strings.xml b/sherlock/src/main/res/values/strings.xml index eaafa92..8284fba 100644 --- a/sherlock/src/main/res/values/strings.xml +++ b/sherlock/src/main/res/values/strings.xml @@ -12,4 +12,5 @@ Version 404 https://github.com/ajitsing/Sherlock + Clear all crashes upon leaving