mirror of
https://gitlab.com/xynngh/YetAnotherCallBlocker.git
synced 2025-03-13 01:50:11 +01:00
Add DB info to debug screen
This commit is contained in:
parent
146acd4483
commit
0efe3523b3
@ -7,15 +7,20 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.util.Pair;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished;
|
||||
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
|
||||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem;
|
||||
import dummydomain.yetanothercallblocker.work.TaskService;
|
||||
|
||||
@ -26,6 +31,8 @@ public class DebugActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_debug);
|
||||
hideSummary();
|
||||
|
||||
onDbInfoButtonClick(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,17 +59,23 @@ public class DebugActivity extends AppCompatActivity {
|
||||
setResult("");
|
||||
hideSummary();
|
||||
|
||||
new AsyncTask<Void, Void, CommunityDatabaseItem>() {
|
||||
new AsyncTask<Void, Void, Pair<CommunityDatabaseItem, FeaturedDatabaseItem>>() {
|
||||
@Override
|
||||
protected CommunityDatabaseItem doInBackground(Void... voids) {
|
||||
protected Pair<CommunityDatabaseItem, FeaturedDatabaseItem> doInBackground(Void... voids) {
|
||||
CommunityDatabaseItem item = DatabaseSingleton.getCommunityDatabase()
|
||||
.getDbItemByNumber(getNumber());
|
||||
|
||||
return item;
|
||||
FeaturedDatabaseItem featuredItem = DatabaseSingleton.getFeaturedDatabase()
|
||||
.getDbItemByNumber(getNumber());
|
||||
|
||||
return new Pair(item, featuredItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(CommunityDatabaseItem item) {
|
||||
protected void onPostExecute(Pair<CommunityDatabaseItem, FeaturedDatabaseItem> result) {
|
||||
CommunityDatabaseItem item = result.first;
|
||||
FeaturedDatabaseItem featuredItem = result.second;
|
||||
|
||||
String string;
|
||||
if (item != null) {
|
||||
string = item.getNumber() + "\n";
|
||||
@ -82,36 +95,55 @@ public class DebugActivity extends AppCompatActivity {
|
||||
} else {
|
||||
string = DebugActivity.this.getString(R.string.debug_not_found);
|
||||
}
|
||||
|
||||
if (featuredItem != null) {
|
||||
string += "\n" + "Featured name: " + featuredItem.getName();
|
||||
}
|
||||
|
||||
setResult(string);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public void onQueryFeaturedDbButtonClick(View view) {
|
||||
setResult("");
|
||||
hideSummary();
|
||||
|
||||
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 onDbInfoButtonClick(View view) {
|
||||
setResult("");
|
||||
hideSummary();
|
||||
|
||||
new AsyncTask<Void, Void, String>() {
|
||||
@Override
|
||||
protected String doInBackground(Void... voids) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
CommunityDatabase communityDatabase = DatabaseSingleton.getCommunityDatabase();
|
||||
|
||||
sb.append("DB info:\n");
|
||||
sb.append("Operational: ").append(communityDatabase.isOperational()).append('\n');
|
||||
sb.append("Base version: ").append(communityDatabase.getBaseDbVersion());
|
||||
sb.append(" (SIA: ").append(communityDatabase.getSiaAppVersion()).append(")\n");
|
||||
sb.append("Effective version: ").append(communityDatabase.getEffectiveDbVersion()).append('\n');
|
||||
sb.append("Last update time: ").append(new Date(App.getSettings().getLastUpdateTime())).append('\n');
|
||||
sb.append("Last update check time: ").append(new Date(App.getSettings().getLastUpdateCheckTime())).append('\n');
|
||||
|
||||
FeaturedDatabase featuredDatabase = DatabaseSingleton.getFeaturedDatabase();
|
||||
|
||||
sb.append("Featured DB info:\n");
|
||||
sb.append("Operational: ").append(featuredDatabase.isOperational()).append('\n');
|
||||
sb.append("Effective version: ").append(featuredDatabase.getBaseDbVersion()).append('\n');
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String info) {
|
||||
setResult(info);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public void onUpdateDbButtonClick(View view) {
|
||||
setResult("");
|
||||
hideSummary();
|
||||
|
@ -7,6 +7,8 @@ public class Settings {
|
||||
|
||||
private static final String PREF_INCOMING_CALL_NOTIFICATIONS = "incomingCallNotifications";
|
||||
private static final String PREF_BLOCK_CALLS = "blockCalls";
|
||||
private static final String PREF_LAST_UPDATE_TIME = "lastUpdateTime";
|
||||
private static final String PREF_LAST_UPDATE_CHECK_TIME = "lastUpdateCheckTime";
|
||||
|
||||
private final SharedPreferences pref;
|
||||
|
||||
@ -30,6 +32,22 @@ public class Settings {
|
||||
setBoolean(PREF_BLOCK_CALLS, block);
|
||||
}
|
||||
|
||||
public long getLastUpdateTime() {
|
||||
return getLong(PREF_LAST_UPDATE_TIME, 0);
|
||||
}
|
||||
|
||||
public void setLastUpdateTime(long timestamp) {
|
||||
setLong(PREF_LAST_UPDATE_TIME, timestamp);
|
||||
}
|
||||
|
||||
public long getLastUpdateCheckTime() {
|
||||
return getLong(PREF_LAST_UPDATE_CHECK_TIME, 0);
|
||||
}
|
||||
|
||||
public void setLastUpdateCheckTime(long timestamp) {
|
||||
setLong(PREF_LAST_UPDATE_CHECK_TIME, timestamp);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return getBoolean(key, false);
|
||||
}
|
||||
@ -38,8 +56,16 @@ public class Settings {
|
||||
return pref.getBoolean(key, defValue);
|
||||
}
|
||||
|
||||
private void setBoolean(String key, boolean value) {
|
||||
public void setBoolean(String key, boolean value) {
|
||||
pref.edit().putBoolean(key, value).apply();
|
||||
}
|
||||
|
||||
public long getLong(String key, long defValue) {
|
||||
return pref.getLong(key, defValue);
|
||||
}
|
||||
|
||||
public void setLong(String key, long value) {
|
||||
pref.edit().putLong(key, value).apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,11 @@ public abstract class AbstractDatabase<T extends AbstractDatabaseDataSlice<V>, V
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public int getBaseDbVersion() {
|
||||
checkLoaded();
|
||||
return baseDatabaseVersion;
|
||||
}
|
||||
|
||||
public boolean reload() {
|
||||
return load();
|
||||
}
|
||||
|
@ -219,12 +219,12 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
|
||||
FileUtils.createDirectory(getDataDir(), getSecondaryDbPathPrefix());
|
||||
}
|
||||
|
||||
public void updateSecondaryDb() {
|
||||
public boolean updateSecondaryDb() {
|
||||
LOG.info("updateSecondaryDb() started");
|
||||
|
||||
if (!isOperational()) {
|
||||
LOG.warn("updateSecondaryDb() DB is not operational, update aborted");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
long startTimestamp = System.currentTimeMillis();
|
||||
@ -249,6 +249,8 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
|
||||
}
|
||||
|
||||
LOG.info("updateSecondaryDb() finished in {} ms", System.currentTimeMillis() - startTimestamp);
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
private UpdateResult updateSecondaryDbInternal() {
|
||||
|
@ -15,8 +15,10 @@ import androidx.core.content.ContextCompat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import dummydomain.yetanothercallblocker.App;
|
||||
import dummydomain.yetanothercallblocker.NotificationHelper;
|
||||
import dummydomain.yetanothercallblocker.R;
|
||||
import dummydomain.yetanothercallblocker.Settings;
|
||||
import dummydomain.yetanothercallblocker.event.MainDbDownloadFinishedEvent;
|
||||
import dummydomain.yetanothercallblocker.event.MainDbDownloadingEvent;
|
||||
import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished;
|
||||
@ -111,11 +113,16 @@ public class TaskService extends IntentService {
|
||||
}
|
||||
|
||||
private void updateSecondaryDb() {
|
||||
Settings settings = App.getSettings();
|
||||
|
||||
SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent();
|
||||
|
||||
postStickyEvent(sticky);
|
||||
try {
|
||||
DatabaseSingleton.getCommunityDatabase().updateSecondaryDb();
|
||||
if (DatabaseSingleton.getCommunityDatabase().updateSecondaryDb()) {
|
||||
settings.setLastUpdateTime(System.currentTimeMillis());
|
||||
}
|
||||
settings.setLastUpdateCheckTime(System.currentTimeMillis());
|
||||
} finally {
|
||||
removeStickyEvent(sticky);
|
||||
}
|
||||
|
@ -6,14 +6,19 @@ import androidx.annotation.NonNull;
|
||||
import androidx.work.Worker;
|
||||
import androidx.work.WorkerParameters;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import dummydomain.yetanothercallblocker.App;
|
||||
import dummydomain.yetanothercallblocker.Settings;
|
||||
import dummydomain.yetanothercallblocker.event.SecondaryDbUpdateFinished;
|
||||
import dummydomain.yetanothercallblocker.event.SecondaryDbUpdatingEvent;
|
||||
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
|
||||
|
||||
import static dummydomain.yetanothercallblocker.EventUtils.postEvent;
|
||||
import static dummydomain.yetanothercallblocker.EventUtils.postStickyEvent;
|
||||
import static dummydomain.yetanothercallblocker.EventUtils.removeStickyEvent;
|
||||
|
||||
public class UpdateWorker extends Worker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateWorker.class);
|
||||
@ -27,18 +32,21 @@ public class UpdateWorker extends Worker {
|
||||
public Result doWork() {
|
||||
LOG.info("doWork() started");
|
||||
|
||||
EventBus bus = EventBus.getDefault();
|
||||
Settings settings = App.getSettings();
|
||||
|
||||
SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent();
|
||||
|
||||
bus.postSticky(sticky);
|
||||
postStickyEvent(sticky);
|
||||
try {
|
||||
DatabaseSingleton.getCommunityDatabase().updateSecondaryDb();
|
||||
if (DatabaseSingleton.getCommunityDatabase().updateSecondaryDb()) {
|
||||
settings.setLastUpdateTime(System.currentTimeMillis());
|
||||
}
|
||||
settings.setLastUpdateCheckTime(System.currentTimeMillis());
|
||||
} finally {
|
||||
bus.removeStickyEvent(sticky);
|
||||
removeStickyEvent(sticky);
|
||||
}
|
||||
|
||||
bus.post(new SecondaryDbUpdateFinished());
|
||||
postEvent(new SecondaryDbUpdateFinished());
|
||||
|
||||
LOG.info("doWork() finished");
|
||||
return Result.success();
|
||||
|
@ -28,14 +28,14 @@
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onQueryFeaturedDbButtonClick"
|
||||
android:text="@string/debug_query_featured_db" />
|
||||
android:onClick="onLoadReviewsButtonClick"
|
||||
android:text="@string/debug_load_reviews" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onLoadReviewsButtonClick"
|
||||
android:text="@string/debug_load_reviews" />
|
||||
android:onClick="onDbInfoButtonClick"
|
||||
android:text="@string/debug_db_info" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
|
@ -25,7 +25,6 @@
|
||||
<string name="open_debug_activity">Открыть экран отладки</string>
|
||||
<string name="debug_activity_label">Отладка</string>
|
||||
<string name="debug_query_db">Искать в общей базе</string>
|
||||
<string name="debug_query_featured_db">Искать в базе организаций</string>
|
||||
<string name="debug_load_reviews">Показать online-отзывы</string>
|
||||
<string name="debug_update_db">Обновить базы</string>
|
||||
<string name="debug_not_found">Не найдено</string>
|
||||
|
@ -75,9 +75,9 @@
|
||||
<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" translatable="false">74995861192</string>
|
||||
<string name="debug_db_info">DB info</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user