From 9ba7054d1455b7eb9a6e9e72a32d19b2f29232ec Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Tue, 23 Jun 2015 18:59:48 +0200 Subject: [PATCH] Use disable push_on_receive mechanism and comment new feature to prepare next release --- .../fragment_mainactivity_gotosettings.xml | 7 +-- res/values-en/strings.xml | 3 +- res/values-fr/strings.xml | 3 +- res/values/strings.xml | 3 +- .../activities/GeneralSettingsActivity.java | 5 +++ .../ConnectivityChanged.java | 43 +++++++++++-------- .../owncloud_sms/prefs/OCSMSSharedPrefs.java | 4 ++ 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/res/layout/fragment_mainactivity_gotosettings.xml b/res/layout/fragment_mainactivity_gotosettings.xml index 7e754e9..e4c2ebe 100644 --- a/res/layout/fragment_mainactivity_gotosettings.xml +++ b/res/layout/fragment_mainactivity_gotosettings.xml @@ -103,7 +103,7 @@ style="@style/StandardButton" android:text="@string/ma_button_sync_accounts_now" /> - - + --> + \ No newline at end of file diff --git a/res/values-en/strings.xml b/res/values-en/strings.xml index 41ddf80..450bc71 100644 --- a/res/values-en/strings.xml +++ b/res/values-en/strings.xml @@ -27,7 +27,7 @@ --> - 6 + 7 @@ -91,6 +91,7 @@ -1 + Push SMS on reception Synchronize in Wi-Fi Synchronize in 4G Synchronize in 3G diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index 5ea2462..d779817 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -27,7 +27,7 @@ --> - 6 + 7 @@ -71,6 +71,7 @@ -1 + Pousser le SMS à la réception Synchroniser en Wi-Fi Synchroniser en 4G Synchroniser en 3G diff --git a/res/values/strings.xml b/res/values/strings.xml index e19c586..41f2fb3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -28,7 +28,7 @@ - 6 + 7 ownCloud-SMS @@ -96,6 +96,7 @@ -1 + Push SMS on reception Synchronize in Wi-Fi Synchronize in 4G Synchronize in 3G diff --git a/src/fr/unix_experience/owncloud_sms/activities/GeneralSettingsActivity.java b/src/fr/unix_experience/owncloud_sms/activities/GeneralSettingsActivity.java index 1d6c418..0f7a0bd 100644 --- a/src/fr/unix_experience/owncloud_sms/activities/GeneralSettingsActivity.java +++ b/src/fr/unix_experience/owncloud_sms/activities/GeneralSettingsActivity.java @@ -25,12 +25,15 @@ import android.content.ContentResolver; import android.content.PeriodicSync; import android.os.Bundle; import android.preference.ListPreference; +import android.util.Log; import fr.nrz.androidlib.activities.NrzSettingsActivity; import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.defines.DefaultPrefs; import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; public class GeneralSettingsActivity extends NrzSettingsActivity { + private static final String TAG = GeneralSettingsActivity.class.getSimpleName(); + private static AccountManager _accountMgr; private static String _accountAuthority; private static String _accountType; @@ -65,6 +68,8 @@ public class GeneralSettingsActivity extends NrzSettingsActivity { key.equals(new String("sync_3g")) || key.equals("sync_gprs") || key.equals("sync_4g") || key.equals("sync_others")) { final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context); + Log.d(TAG,"GeneralSettingsActivity.handleCheckboxPreference: set " + key + " to " + + value.toString()); prefs.putBoolean(key, value); } else { diff --git a/src/fr/unix_experience/owncloud_sms/broadcast_receivers/ConnectivityChanged.java b/src/fr/unix_experience/owncloud_sms/broadcast_receivers/ConnectivityChanged.java index e6d18a4..a25efe3 100644 --- a/src/fr/unix_experience/owncloud_sms/broadcast_receivers/ConnectivityChanged.java +++ b/src/fr/unix_experience/owncloud_sms/broadcast_receivers/ConnectivityChanged.java @@ -12,28 +12,35 @@ package fr.unix_experience.owncloud_sms.broadcast_receivers; * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import org.json.JSONArray; -import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync; -import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor; -import fr.unix_experience.owncloud_sms.engine.SmsFetcher; -import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; +import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync; +import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor; +import fr.unix_experience.owncloud_sms.engine.SmsFetcher; +import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; public class ConnectivityChanged extends BroadcastReceiver implements ASyncSMSSync { @Override - public void onReceive(Context context, Intent intent) { - ConnectivityMonitor cMon = new ConnectivityMonitor(context); - + public void onReceive(final Context context, final Intent intent) { + final ConnectivityMonitor cMon = new ConnectivityMonitor(context); + + final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(context); + + if (!prefs.pushOnReceive()) { + Log.d(TAG,"ConnectivityChanges.onReceive: pushOnReceive is disabled"); + return; + } + // If data is available and previous dataConnectionState was false, then we need to sync if (cMon.isValid() && dataConnectionAvailable == false) { dataConnectionAvailable = true; @@ -46,24 +53,24 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncSMSSy Log.d(TAG,"ConnectivityChanges.onReceive: data conn is off"); } } - - private void checkMessagesAndSend(Context context) { + + private void checkMessagesAndSend(final Context context) { // Get last message synced from preferences - Long lastMessageSynced = (new OCSMSSharedPrefs(context)).getLastMessageDate(); + final Long lastMessageSynced = (new OCSMSSharedPrefs(context)).getLastMessageDate(); Log.d(TAG,"Synced Last:" + lastMessageSynced); - + // Now fetch messages since last stored date - JSONArray smsList = new SmsFetcher(context).bufferizeMessagesSinceDate(lastMessageSynced); - - ConnectivityMonitor cMon = new ConnectivityMonitor(context); - + final JSONArray smsList = new SmsFetcher(context).bufferizeMessagesSinceDate(lastMessageSynced); + + final ConnectivityMonitor cMon = new ConnectivityMonitor(context); + // Synchronize if network is valid and there are SMS if (cMon.isValid() && smsList != null) { new SyncTask(context, smsList).execute(); } } - + private static boolean dataConnectionAvailable = false; - + private static final String TAG = ConnectivityChanged.class.getSimpleName(); } diff --git a/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java b/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java index 75251d1..2c6df03 100644 --- a/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java +++ b/src/fr/unix_experience/owncloud_sms/prefs/OCSMSSharedPrefs.java @@ -39,6 +39,10 @@ public class OCSMSSharedPrefs extends SharedPrefs { return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0); } + public Boolean pushOnReceive() { + return _sPrefs.getBoolean("push_on_receive", DefaultPrefs.pushOnReceive); + } + public Boolean syncInWifi() { return _sPrefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi); }