fully offline CP
This commit is contained in:
parent
fb2271e758
commit
937872e80c
1 changed files with 15 additions and 12 deletions
|
@ -30,14 +30,6 @@ public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
DBAccessReceiver.class.getSimpleName());
|
DBAccessReceiver.class.getSimpleName());
|
||||||
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
|
|
||||||
if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (SP.getBoolean(R.string.key_ns_noupload, false)) {
|
|
||||||
log.debug("Upload disabled. Message dropped");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
try {
|
try {
|
||||||
Bundle bundles = intent.getExtras();
|
Bundle bundles = intent.getExtras();
|
||||||
|
@ -83,16 +75,22 @@ public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equals("dbRemove")) {
|
if (action.equals("dbRemove")) {
|
||||||
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
|
if (shouldUpload()) {
|
||||||
UploadQueue.add(dbr);
|
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
|
||||||
|
UploadQueue.add(dbr);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
|
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
|
||||||
// this is not used as mongo _id but only for searching in UploadQueue database
|
// this is not used as mongo _id but only for searching in UploadQueue database
|
||||||
// if record has to be removed from queue before upload
|
// if record has to be removed from queue before upload
|
||||||
dbr._id = nsclientid.toString();
|
dbr._id = nsclientid.toString();
|
||||||
UploadQueue.add(dbr);
|
|
||||||
if (collection.equals("treatments"))
|
if (shouldUpload()) {
|
||||||
|
UploadQueue.add(dbr);
|
||||||
|
}
|
||||||
|
if (collection.equals("treatments")) {
|
||||||
genereateTreatmentOfflineBroadcast(dbr);
|
genereateTreatmentOfflineBroadcast(dbr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -101,6 +99,11 @@ public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldUpload() {
|
||||||
|
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
|
||||||
|
return nsClientInternalPlugin.isEnabled(PluginBase.GENERAL) && !SP.getBoolean(R.string.key_ns_noupload, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void genereateTreatmentOfflineBroadcast(DbRequest request) {
|
public void genereateTreatmentOfflineBroadcast(DbRequest request) {
|
||||||
if (request.action.equals("dbAdd")) {
|
if (request.action.equals("dbAdd")) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue