From 4bdd91ce20d64f82430ef373eb7510f368e5beb0 Mon Sep 17 00:00:00 2001 From: xynngh Date: Sun, 9 Jun 2019 20:35:30 +0400 Subject: [PATCH] Improve debug screen --- .../yetanothercallblocker/DebugActivity.java | 75 ++++++++++++------- .../model/database/CommunityDatabaseItem.java | 4 +- app/src/main/res/layout/activity_debug.xml | 51 ++++++++++++- app/src/main/res/menu/activity_debug.xml | 20 ----- app/src/main/res/values/strings.xml | 7 ++ 5 files changed, 105 insertions(+), 52 deletions(-) delete mode 100644 app/src/main/res/menu/activity_debug.xml diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java b/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java index 11c1c50..a3c795b 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/DebugActivity.java @@ -3,9 +3,9 @@ package dummydomain.yetanothercallblocker; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; import dummydomain.yetanothercallblocker.sia.DatabaseSingleton; import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem; @@ -19,37 +19,53 @@ public class DebugActivity extends AppCompatActivity { setContentView(R.layout.activity_debug); } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_debug, menu); - return true; - } + public void onQueryDbButtonClick(View view) { + setResult(""); - public void onQueryDb(MenuItem item) { - new AsyncTask() { + new AsyncTask() { @Override - protected Void doInBackground(Void... voids) { + protected CommunityDatabaseItem doInBackground(Void... voids) { CommunityDatabaseItem item = DatabaseSingleton.getCommunityDatabase() - .getDbItemByNumber("74995861192"); + .getDbItemByNumber(getNumber()); - return null; + return item; } - }.execute(); - } - public void onQueryFeaturedDb(MenuItem item) { - new AsyncTask() { @Override - protected Void doInBackground(Void... voids) { - FeaturedDatabaseItem item = DatabaseSingleton.getFeaturedDatabase() - .getDbItemByNumber("74995861192"); - - return null; + protected void onPostExecute(CommunityDatabaseItem item) { + setResult(item != null ? item.toString() + : DebugActivity.this.getString(R.string.debug_not_found)); } }.execute(); } - public void onUpdateDb(MenuItem item) { + public void onQueryFeaturedDbButtonClick(View view) { + setResult(""); + + new AsyncTask() { + @Override + protected FeaturedDatabaseItem doInBackground(Void... voids) { + FeaturedDatabaseItem item = DatabaseSingleton.getFeaturedDatabase() + .getDbItemByNumber(getNumber()); + + return item; + } + + @Override + protected void onPostExecute(FeaturedDatabaseItem item) { + setResult(item != null ? item.toString() + : DebugActivity.this.getString(R.string.debug_not_found)); + } + }.execute(); + } + + public void onLoadReviewsButtonClick(View view) { + ReviewsActivity.startForNumber(this, getNumber()); + } + + public void onUpdateDbButtonClick(View view) { + setResult(""); + new AsyncTask() { @Override protected Void doInBackground(Void... voids) { @@ -60,15 +76,18 @@ public class DebugActivity extends AppCompatActivity { @Override protected void onPostExecute(Void aVoid) { - Toast.makeText(DebugActivity.this, "Update finished; DB ver: " - + DatabaseSingleton.getCommunityDatabase().getEffectiveDbVersion(), - Toast.LENGTH_SHORT).show(); + setResult(DebugActivity.this.getString(R.string.debug_update_result, + DatabaseSingleton.getCommunityDatabase().getEffectiveDbVersion())); } }.execute(); } - public void onTestLoadReviews(MenuItem item) { - ReviewsActivity.startForNumber(this, "74995861192"); + private String getNumber() { + return this.findViewById(R.id.debugPhoneNumberEditText).getText().toString(); + } + + private void setResult(String result) { + this.findViewById(R.id.debugResultsTextView).setText(result); } } diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabaseItem.java b/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabaseItem.java index b8d3445..67fff52 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabaseItem.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/sia/model/database/CommunityDatabaseItem.java @@ -1,5 +1,7 @@ package dummydomain.yetanothercallblocker.sia.model.database; +import dummydomain.yetanothercallblocker.sia.model.NumberCategory; + public class CommunityDatabaseItem { private long number; @@ -72,7 +74,7 @@ public class CommunityDatabaseItem { ", negativeRatingsCount=" + negativeRatingsCount + ", neutralRatingsCount=" + neutralRatingsCount + ", unknownData=" + unknownData + - ", category=" + category + + ", category=" + NumberCategory.getById(category) + '}'; } diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 3fd3b18..59694a9 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -1,9 +1,54 @@ - - + + + + +