Improve debug screen
This commit is contained in:
parent
7498fed8dc
commit
4bdd91ce20
|
@ -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<Void, Void, Void>() {
|
||||
new AsyncTask<Void, Void, CommunityDatabaseItem>() {
|
||||
@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<Void, Void, Void>() {
|
||||
@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<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>() {
|
||||
@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.<EditText>findViewById(R.id.debugPhoneNumberEditText).getText().toString();
|
||||
}
|
||||
|
||||
private void setResult(String result) {
|
||||
this.<TextView>findViewById(R.id.debugResultsTextView).setText(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
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>
|
||||
|
|
|
@ -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>
|
|
@ -46,5 +46,12 @@
|
|||
|
||||
<string name="open_debug_activity">Open debug screen</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>
|
||||
|
|
Loading…
Reference in New Issue