Improve debug screen

This commit is contained in:
xynngh 2019-06-09 20:35:30 +04:00
parent 7498fed8dc
commit 4bdd91ce20
5 changed files with 105 additions and 52 deletions

View File

@ -3,9 +3,9 @@ package dummydomain.yetanothercallblocker;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.View;
import android.view.MenuItem; import android.widget.EditText;
import android.widget.Toast; import android.widget.TextView;
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton; import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem; import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
@ -19,37 +19,53 @@ public class DebugActivity extends AppCompatActivity {
setContentView(R.layout.activity_debug); setContentView(R.layout.activity_debug);
} }
@Override public void onQueryDbButtonClick(View view) {
public boolean onCreateOptionsMenu(Menu menu) { setResult("");
getMenuInflater().inflate(R.menu.activity_debug, menu);
return true;
}
public void onQueryDb(MenuItem item) { new AsyncTask<Void, Void, CommunityDatabaseItem>() {
new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected CommunityDatabaseItem doInBackground(Void... voids) {
CommunityDatabaseItem item = DatabaseSingleton.getCommunityDatabase() CommunityDatabaseItem item = DatabaseSingleton.getCommunityDatabase()
.getDbItemByNumber("74995861192"); .getDbItemByNumber(getNumber());
return null; return item;
} }
}.execute();
}
public void onQueryFeaturedDb(MenuItem item) {
new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected void onPostExecute(CommunityDatabaseItem item) {
FeaturedDatabaseItem item = DatabaseSingleton.getFeaturedDatabase() setResult(item != null ? item.toString()
.getDbItemByNumber("74995861192"); : DebugActivity.this.getString(R.string.debug_not_found));
return null;
} }
}.execute(); }.execute();
} }
public void onUpdateDb(MenuItem item) { public void onQueryFeaturedDbButtonClick(View view) {
setResult("");
new AsyncTask<Void, Void, FeaturedDatabaseItem>() {
@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<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
@ -60,15 +76,18 @@ public class DebugActivity extends AppCompatActivity {
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
Toast.makeText(DebugActivity.this, "Update finished; DB ver: " setResult(DebugActivity.this.getString(R.string.debug_update_result,
+ DatabaseSingleton.getCommunityDatabase().getEffectiveDbVersion(), DatabaseSingleton.getCommunityDatabase().getEffectiveDbVersion()));
Toast.LENGTH_SHORT).show();
} }
}.execute(); }.execute();
} }
public void onTestLoadReviews(MenuItem item) { private String getNumber() {
ReviewsActivity.startForNumber(this, "74995861192"); return this.<EditText>findViewById(R.id.debugPhoneNumberEditText).getText().toString();
}
private void setResult(String result) {
this.<TextView>findViewById(R.id.debugResultsTextView).setText(result);
} }
} }

View File

@ -1,5 +1,7 @@
package dummydomain.yetanothercallblocker.sia.model.database; package dummydomain.yetanothercallblocker.sia.model.database;
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
public class CommunityDatabaseItem { public class CommunityDatabaseItem {
private long number; private long number;
@ -72,7 +74,7 @@ public class CommunityDatabaseItem {
", negativeRatingsCount=" + negativeRatingsCount + ", negativeRatingsCount=" + negativeRatingsCount +
", neutralRatingsCount=" + neutralRatingsCount + ", neutralRatingsCount=" + neutralRatingsCount +
", unknownData=" + unknownData + ", unknownData=" + unknownData +
", category=" + category + ", category=" + NumberCategory.getById(category) +
'}'; '}';
} }

View File

@ -1,9 +1,54 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".DebugActivity"> tools:context=".DebugActivity">
</android.support.constraint.ConstraintLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/text_margin">
<EditText
android:id="@+id/debugPhoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="12"
android:inputType="number"
android:text="@string/debug_default_test_number" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onQueryDbButtonClick"
android:text="@string/debug_query_db" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onQueryFeaturedDbButtonClick"
android:text="@string/debug_query_featured_db" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onLoadReviewsButtonClick"
android:text="@string/debug_load_reviews" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onUpdateDbButtonClick"
android:text="@string/debug_update_db" />
<TextView
android:id="@+id/debugResultsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="Test DB query"
android:onClick="onQueryDb"/>
<item
android:title="Test featured DB query "
android:onClick="onQueryFeaturedDb"/>
<item
android:title="Update DB"
android:onClick="onUpdateDb"/>
<item
android:title="Test reviews loading"
android:onClick="onTestLoadReviews"/>
</menu>

View File

@ -46,5 +46,12 @@
<string name="open_debug_activity">Open debug screen</string> <string name="open_debug_activity">Open debug screen</string>
<string name="debug_activity_label">Debug</string> <string name="debug_activity_label">Debug</string>
<string name="debug_query_db">Query DB</string>
<string name="debug_query_featured_db">Query featured DB</string>
<string name="debug_load_reviews">Load reviews (online)</string>
<string name="debug_default_test_number">74995861192</string>
<string name="debug_update_db">Manually update DB</string>
<string name="debug_not_found">Not found</string>
<string name="debug_update_result">Update finished; DB ver: %d</string>
</resources> </resources>