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

Prepare a new sync adapter. This permit to create slow sync and fast sync queries. At this time it's same

* Also added missing XML files
This commit is contained in:
Loïc Blot (@U-Exp)
2014-11-30 19:59:05 +01:00
parent a554462ff8
commit 9b5a1f5bf6
10 changed files with 233 additions and 4 deletions
@@ -39,6 +39,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
private static final boolean ALWAYS_SIMPLE_PREFS = false;
static AccountManager mAccountMgr;
static String mAccountAuthority;
static String mSlowSyncAccountAuthority;
static String mAccountType;
@Override
@@ -47,6 +48,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
mAccountMgr = AccountManager.get(getBaseContext());
mAccountAuthority = getString(R.string.account_authority);
mSlowSyncAccountAuthority = getString(R.string.slowsync_account_authority);
mAccountType = getString(R.string.account_type);
setupSimplePreferencesScreen();
}
@@ -69,6 +71,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
// their values. When their values change, their summaries are updated
// to reflect the new value, per the Android Design guidelines.
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
}
/** {@inheritDoc} */
@@ -151,6 +154,35 @@ public class GeneralSettingsActivity extends PreferenceActivity {
}
}
} else if (prefKey.equals(new String("slow_sync_frequency"))) {
long syncFreq = Long.parseLong((String)value);
// Get ownCloud SMS account list
Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType);
for (int i = 0; i < myAccountList.length; i++) {
// And get all authorities for this account
List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mSlowSyncAccountAuthority);
boolean foundSameSyncCycle = false;
for (int j = 0; j < syncList.size(); j++) {
PeriodicSync ps = syncList.get(i);
if (ps.period == syncFreq && ps.extras.getInt("synctype") == 2) {
foundSameSyncCycle = true;
}
}
if (foundSameSyncCycle == false) {
Bundle b = new Bundle();
b.putInt("synctype", 2);
ContentResolver.removePeriodicSync(myAccountList[i],
mSlowSyncAccountAuthority, b);
ContentResolver.addPeriodicSync(myAccountList[i],
mSlowSyncAccountAuthority, b, syncFreq * 60);
}
}
}
} else {
// For all other preferences, set the summary to the value's
@@ -203,6 +235,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
}
}
}
@@ -0,0 +1,68 @@
package fr.unix_experience.owncloud_sms.sync_adapters;
/*
* Copyright (c) 2014, Loic Blot <loic.blot@unix-experience.fr>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class SmsSlowSyncService extends Service {
// Storage for an instance of the sync adapter
private static SmsSyncAdapter _adapter = null;
// Object to use as a thread-safe lock
private static final Object sSyncAdapterLock = new Object();
/*
* Instantiate the sync adapter object.
*/
@Override
public void onCreate() {
/*
* Create the sync adapter as a singleton.
* Set the sync adapter as syncable
* Disallow parallel syncs
*/
synchronized (sSyncAdapterLock) {
if (_adapter == null) {
_adapter = new SmsSyncAdapter(getApplicationContext(), true);
}
}
}
/**
* Return an object that allows the system to invoke
* the sync adapter.
*
*/
@Override
public IBinder onBind(Intent intent) {
/*
* Get the object that allows external processes
* to call onPerformSync(). The object is created
* in the base class code when the SyncAdapter
* constructors call super()
*/
return _adapter.getSyncAdapterBinder();
}
}