1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2026-08-21 13:22:55 +00:00

Add an option to disable sync notification

Fix #150
This commit is contained in:
Loic Blot
2017-06-06 23:50:20 +02:00
parent ceba0324e1
commit 1d45d0a318
10 changed files with 43 additions and 16 deletions
@@ -54,6 +54,7 @@ import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
import fr.unix_experience.owncloud_sms.enums.OCSMSNotificationType;
import fr.unix_experience.owncloud_sms.enums.PermissionID;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationUI;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
import fr.unix_experience.owncloud_sms.prefs.PermissionChecker;
import static fr.unix_experience.owncloud_sms.enums.PermissionID.REQUEST_MAX;
@@ -204,21 +205,27 @@ public class MainActivity extends AppCompatActivity
}
Context ctx = getApplicationContext();
if (_ConnectivityMonitor.isValid()) {
// Now fetch messages since last stored date
JSONArray smsList = new JSONArray();
new AndroidSmsFetcher(ctx).bufferMessagesSinceDate(smsList, (long) 0);
if (smsList.length() > 0) {
OCSMSNotificationUI.notify(ctx, ctx.getString(R.string.sync_title),
ctx.getString(R.string.sync_inprogress), OCSMSNotificationType.SYNC.ordinal());
new SyncTask(getApplicationContext(), smsList).execute();
} else {
Toast.makeText(ctx, ctx.getString(R.string.nothing_to_sync), Toast.LENGTH_SHORT).show();
}
} else {
if (!_ConnectivityMonitor.isValid()) {
Toast.makeText(ctx, ctx.getString(R.string.err_sync_no_connection_available), Toast.LENGTH_SHORT).show();
Log.v(MainActivity.TAG, "Finish syncAllMessages(): invalid connection");
return;
}
// Now fetch messages since last stored date
JSONArray smsList = new JSONArray();
new AndroidSmsFetcher(ctx).bufferMessagesSinceDate(smsList, (long) 0);
if (smsList.length() == 0) {
Toast.makeText(ctx, ctx.getString(R.string.nothing_to_sync), Toast.LENGTH_SHORT).show();
Log.v(MainActivity.TAG, "Finish syncAllMessages(): no sms");
return;
}
if (new OCSMSSharedPrefs(this).showSyncNotifications()) {
OCSMSNotificationUI.notify(ctx, ctx.getString(R.string.sync_title),
ctx.getString(R.string.sync_inprogress), OCSMSNotificationType.SYNC.ordinal());
}
new SyncTask(getApplicationContext(), smsList).execute();
Log.v(MainActivity.TAG, "Finish syncAllMessages()");
}
@@ -77,6 +77,7 @@ public class OCSMSSettingsActivity extends VirtualSettingsActivity {
// Bind our boolean preferences
VirtualSettingsActivity._boolPrefs.add(new BindObjectPref("push_on_receive", DefaultPrefs.pushOnReceive));
VirtualSettingsActivity._boolPrefs.add(new BindObjectPref("show_sync_notifications", DefaultPrefs.showSyncNotifications));
VirtualSettingsActivity._boolPrefs.add(new BindObjectPref("sync_wifi", DefaultPrefs.syncWifi));
VirtualSettingsActivity._boolPrefs.add(new BindObjectPref("sync_4g", DefaultPrefs.sync4G));
VirtualSettingsActivity._boolPrefs.add(new BindObjectPref("sync_3g", DefaultPrefs.sync3G));
@@ -95,7 +96,7 @@ public class OCSMSSettingsActivity extends VirtualSettingsActivity {
protected void handleCheckboxPreference(String key, Boolean value) {
// Network types allowed for sync
if ("push_on_receive".equals(key) ||
if ("push_on_receive".equals(key) || "show_sync_notifications".equals(key) ||
"sync_wifi".equals(key) || "sync_2g".equals(key) ||
"sync_3g".equals(key) || "sync_gprs".equals(key) ||
"sync_4g".equals(key) || "sync_others".equals(key)) {
@@ -4,6 +4,7 @@ public class DefaultPrefs {
public final static Integer syncInterval = 15;
public final static Integer minimumCharsForSync = 0;
public final static Boolean pushOnReceive = true;
public final static Boolean showSyncNotifications = true;
public final static Boolean syncWifi = true;
public final static Boolean sync2G = true;
@@ -43,6 +43,10 @@ public class OCSMSSharedPrefs extends SharedPrefs {
return _sPrefs.getBoolean("push_on_receive", DefaultPrefs.pushOnReceive);
}
public Boolean showSyncNotifications() {
return _sPrefs.getBoolean("show_sync_notifications", DefaultPrefs.showSyncNotifications);
}
public Boolean syncInWifi() {
return _sPrefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi);
}
@@ -31,6 +31,7 @@ import fr.unix_experience.owncloud_sms.enums.OCSMSNotificationType;
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationUI;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
@@ -41,8 +42,11 @@ class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
OCSMSNotificationUI.notify(getContext(), getContext().getString(R.string.sync_title),
getContext().getString(R.string.sync_inprogress), OCSMSNotificationType.SYNC.ordinal());
if (new OCSMSSharedPrefs(getContext()).showSyncNotifications()) {
OCSMSNotificationUI.notify(getContext(), getContext().getString(R.string.sync_title),
getContext().getString(R.string.sync_inprogress), OCSMSNotificationType.SYNC.ordinal());
}
try {
OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(getContext(), account);