Refresh call log only if DB actually changed

This commit is contained in:
xynngh 2020-09-30 14:22:18 +04:00
parent 8398658e12
commit 1ecb236332
4 changed files with 18 additions and 4 deletions

View File

@ -197,7 +197,7 @@ public class MainActivity extends AppCompatActivity {
@Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
public void onSecondaryDbUpdateFinished(SecondaryDbUpdateFinished event) {
reloadCallLog();
if (event.updated) reloadCallLog();
}
private void checkPermissions() {

View File

@ -1,3 +1,11 @@
package dummydomain.yetanothercallblocker.event;
public class SecondaryDbUpdateFinished {}
public class SecondaryDbUpdateFinished {
public final boolean updated;
public SecondaryDbUpdateFinished(boolean updated) {
this.updated = updated;
}
}

View File

@ -104,19 +104,22 @@ public class TaskService extends IntentService {
private void updateSecondaryDb() {
Settings settings = App.getSettings();
boolean updated = false;
SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent();
postStickyEvent(sticky);
try {
if (YacbHolder.getCommunityDatabase().updateSecondaryDb()) {
settings.setLastUpdateTime(System.currentTimeMillis());
updated = true;
}
settings.setLastUpdateCheckTime(System.currentTimeMillis());
} finally {
removeStickyEvent(sticky);
}
postEvent(new SecondaryDbUpdateFinished());
postEvent(new SecondaryDbUpdateFinished(updated));
}
}

View File

@ -34,19 +34,22 @@ public class UpdateWorker extends Worker {
Settings settings = App.getSettings();
boolean updated = false;
SecondaryDbUpdatingEvent sticky = new SecondaryDbUpdatingEvent();
postStickyEvent(sticky);
try {
if (YacbHolder.getCommunityDatabase().updateSecondaryDb()) {
settings.setLastUpdateTime(System.currentTimeMillis());
updated = true;
}
settings.setLastUpdateCheckTime(System.currentTimeMillis());
} finally {
removeStickyEvent(sticky);
}
postEvent(new SecondaryDbUpdateFinished());
postEvent(new SecondaryDbUpdateFinished(updated));
LOG.info("doWork() finished");
return Result.success();