mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-07 16:06:18 +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:
parent
a554462ff8
commit
9b5a1f5bf6
@ -40,7 +40,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".sync_adapters.SmsSyncService"
|
android:name=".sync_adapters.SmsSyncService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":sync" >
|
android:process=":sync">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.content.SyncAdapter" />
|
<action android:name="android.content.SyncAdapter" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@ -52,7 +52,27 @@
|
|||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".providers.SmsDataProvider"
|
android:name=".providers.SmsDataProvider"
|
||||||
android:authorities="fr.unix_experience.owncloud_sms.datasync.provider">
|
android:label="@string/pref_title_slow_sync"
|
||||||
|
android:authorities="@string/account_authority">
|
||||||
|
</provider>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".sync_adapters.SmsSlowSyncService"
|
||||||
|
android:exported="true"
|
||||||
|
android:process=":sync">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.content.SyncAdapter" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.content.SyncAdapter"
|
||||||
|
android:resource="@xml/slow_sync_adapter" />
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name=".providers.SmsDataProvider"
|
||||||
|
android:label="@string/pref_title_sync"
|
||||||
|
android:authorities="@string/slowsync_account_authority">
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<!-- Related to Login -->
|
<!-- Related to Login -->
|
||||||
|
@ -26,7 +26,10 @@
|
|||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<string name="pref_title_sync_frequency">Sync frequency</string>
|
<string name="pref_title_sync">Fast Sync</string>
|
||||||
|
<string name="pref_title_sync_frequency">Fast Sync frequency</string>
|
||||||
|
<string name="pref_title_slow_sync">Secure Slow Sync</string>
|
||||||
|
<string name="pref_title_slow_sync_frequency">Secure Slow Sync frequency</string>
|
||||||
|
|
||||||
<!-- Translations must begin there -->
|
<!-- Translations must begin there -->
|
||||||
<!-- Preferences -->
|
<!-- Preferences -->
|
||||||
@ -43,6 +46,7 @@
|
|||||||
<string name="title_activity_general_settings">General Settings</string>
|
<string name="title_activity_general_settings">General Settings</string>
|
||||||
|
|
||||||
<string-array name="pref_sync_frequency_titles">
|
<string-array name="pref_sync_frequency_titles">
|
||||||
|
<item>5 minutes</item>
|
||||||
<item>15 minutes</item>
|
<item>15 minutes</item>
|
||||||
<item>30 minutes</item>
|
<item>30 minutes</item>
|
||||||
<item>1 hour</item>
|
<item>1 hour</item>
|
||||||
@ -53,6 +57,7 @@
|
|||||||
<item>Never</item>
|
<item>Never</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="pref_sync_frequency_values">
|
<string-array name="pref_sync_frequency_values">
|
||||||
|
<item>5</item>
|
||||||
<item>15</item>
|
<item>15</item>
|
||||||
<item>30</item>
|
<item>30</item>
|
||||||
<item>60</item>
|
<item>60</item>
|
||||||
@ -63,6 +68,24 @@
|
|||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_slow_sync_frequency_titles">
|
||||||
|
<item>1 hour</item>
|
||||||
|
<item>3 hours</item>
|
||||||
|
<item>6 hours</item>
|
||||||
|
<item>12 hours</item>
|
||||||
|
<item>24 hours</item>
|
||||||
|
<item>Never</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_slow_sync_frequency_values">
|
||||||
|
<item>60</item>
|
||||||
|
<item>180</item>
|
||||||
|
<item>360</item>
|
||||||
|
<item>720</item>
|
||||||
|
<item>1440</item>
|
||||||
|
<item>-1</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="title_activity_login">Sign in</string>
|
<string name="title_activity_login">Sign in</string>
|
||||||
|
|
||||||
<!-- Login -->
|
<!-- Login -->
|
||||||
|
@ -31,13 +31,17 @@
|
|||||||
<string name="app_name">ownCloud-SMS</string>
|
<string name="app_name">ownCloud-SMS</string>
|
||||||
<string name="account_type">fr.unix_experience.owncloud_sms</string>
|
<string name="account_type">fr.unix_experience.owncloud_sms</string>
|
||||||
<string name="account_authority">fr.unix_experience.owncloud_sms.datasync.provider</string>
|
<string name="account_authority">fr.unix_experience.owncloud_sms.datasync.provider</string>
|
||||||
|
<string name="slowsync_account_authority">fr.unix_experience.owncloud_sms.datasync.slowsync_provider</string>
|
||||||
|
|
||||||
<string name="target_package">fr.unix_experience.owncloud_sms</string>
|
<string name="target_package">fr.unix_experience.owncloud_sms</string>
|
||||||
<string name="login_logo">Login logo</string>
|
<string name="login_logo">Login logo</string>
|
||||||
|
|
||||||
<!-- Translations must begin there -->
|
<!-- Translations must begin there -->
|
||||||
<!-- Preferences -->
|
<!-- Preferences -->
|
||||||
<string name="pref_title_sync_frequency">Sync frequency</string>
|
<string name="pref_title_sync">Fast Sync</string>
|
||||||
|
<string name="pref_title_sync_frequency">Fast Sync frequency</string>
|
||||||
|
<string name="pref_title_slow_sync">Secure Slow Sync</string>
|
||||||
|
<string name="pref_title_slow_sync_frequency">Secure Slow Sync frequency</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="sync_now">Synchronize now</string>
|
<string name="sync_now">Synchronize now</string>
|
||||||
<string name="pref_category_sync">Synchronization</string>
|
<string name="pref_category_sync">Synchronization</string>
|
||||||
@ -51,6 +55,7 @@
|
|||||||
<string name="title_activity_general_settings">General Settings</string>
|
<string name="title_activity_general_settings">General Settings</string>
|
||||||
|
|
||||||
<string-array name="pref_sync_frequency_titles">
|
<string-array name="pref_sync_frequency_titles">
|
||||||
|
<item>5 minutes</item>
|
||||||
<item>15 minutes</item>
|
<item>15 minutes</item>
|
||||||
<item>30 minutes</item>
|
<item>30 minutes</item>
|
||||||
<item>1 hour</item>
|
<item>1 hour</item>
|
||||||
@ -61,6 +66,7 @@
|
|||||||
<item>Never</item>
|
<item>Never</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="pref_sync_frequency_values">
|
<string-array name="pref_sync_frequency_values">
|
||||||
|
<item>5</item>
|
||||||
<item>15</item>
|
<item>15</item>
|
||||||
<item>30</item>
|
<item>30</item>
|
||||||
<item>60</item>
|
<item>60</item>
|
||||||
@ -71,6 +77,24 @@
|
|||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_slow_sync_frequency_titles">
|
||||||
|
<item>1 hour</item>
|
||||||
|
<item>3 hours</item>
|
||||||
|
<item>6 hours</item>
|
||||||
|
<item>12 hours</item>
|
||||||
|
<item>24 hours</item>
|
||||||
|
<item>Never</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_slow_sync_frequency_values">
|
||||||
|
<item>60</item>
|
||||||
|
<item>180</item>
|
||||||
|
<item>360</item>
|
||||||
|
<item>720</item>
|
||||||
|
<item>1440</item>
|
||||||
|
<item>-1</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="title_activity_login">Sign in</string>
|
<string name="title_activity_login">Sign in</string>
|
||||||
|
|
||||||
<!-- Login -->
|
<!-- Login -->
|
||||||
|
16
res/xml/global_preferences.xml
Normal file
16
res/xml/global_preferences.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:key="global_settings"
|
||||||
|
android:title="Global Preferences"
|
||||||
|
android:summary="Global preferences">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="general_prefs"
|
||||||
|
android:summary="@string/summary_global_pref_to_general_prefs"
|
||||||
|
android:title="@string/title_global_pref_to_general_prefs" >
|
||||||
|
<intent android:targetPackage="fr.unix_experience.owncloud_sms"
|
||||||
|
android:targetClass="fr.unix_experience.owncloud_sms.activities.GeneralSettingsActivity"
|
||||||
|
android:action="ACTION_VIEW" />
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
6
res/xml/owncloud_account_authenticator.xml
Normal file
6
res/xml/owncloud_account_authenticator.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:accountType="@string/account_type"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:smallIcon="@drawable/ic_launcher"
|
||||||
|
android:accountPreferences="@xml/global_preferences"/>
|
21
res/xml/pref_data_sync.xml
Normal file
21
res/xml/pref_data_sync.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/summary_global_pref_to_general_prefs">
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="10"
|
||||||
|
android:entries="@array/pref_sync_frequency_titles"
|
||||||
|
android:entryValues="@array/pref_sync_frequency_values"
|
||||||
|
android:key="sync_frequency"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="@string/pref_title_sync_frequency" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="60"
|
||||||
|
android:entries="@array/pref_slow_sync_frequency_titles"
|
||||||
|
android:entryValues="@array/pref_slow_sync_frequency_values"
|
||||||
|
android:key="slow_sync_frequency"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="@string/pref_title_slow_sync_frequency" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
</PreferenceScreen>
|
9
res/xml/slow_sync_adapter.xml
Normal file
9
res/xml/slow_sync_adapter.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<sync-adapter
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:contentAuthority="@string/slowsync_account_authority"
|
||||||
|
android:accountType="@string/account_type"
|
||||||
|
android:userVisible="true"
|
||||||
|
android:supportsUploading="true"
|
||||||
|
android:allowParallelSyncs="false"
|
||||||
|
android:isAlwaysSyncable="true" />
|
9
res/xml/sync_adapter.xml
Normal file
9
res/xml/sync_adapter.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<sync-adapter
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:contentAuthority="@string/account_authority"
|
||||||
|
android:accountType="@string/account_type"
|
||||||
|
android:userVisible="true"
|
||||||
|
android:supportsUploading="true"
|
||||||
|
android:allowParallelSyncs="false"
|
||||||
|
android:isAlwaysSyncable="true" />
|
@ -39,6 +39,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
private static final boolean ALWAYS_SIMPLE_PREFS = false;
|
private static final boolean ALWAYS_SIMPLE_PREFS = false;
|
||||||
static AccountManager mAccountMgr;
|
static AccountManager mAccountMgr;
|
||||||
static String mAccountAuthority;
|
static String mAccountAuthority;
|
||||||
|
static String mSlowSyncAccountAuthority;
|
||||||
static String mAccountType;
|
static String mAccountType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -47,6 +48,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
mAccountMgr = AccountManager.get(getBaseContext());
|
mAccountMgr = AccountManager.get(getBaseContext());
|
||||||
mAccountAuthority = getString(R.string.account_authority);
|
mAccountAuthority = getString(R.string.account_authority);
|
||||||
|
mSlowSyncAccountAuthority = getString(R.string.slowsync_account_authority);
|
||||||
mAccountType = getString(R.string.account_type);
|
mAccountType = getString(R.string.account_type);
|
||||||
setupSimplePreferencesScreen();
|
setupSimplePreferencesScreen();
|
||||||
}
|
}
|
||||||
@ -69,6 +71,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
// their values. When their values change, their summaries are updated
|
// their values. When their values change, their summaries are updated
|
||||||
// to reflect the new value, per the Android Design guidelines.
|
// to reflect the new value, per the Android Design guidelines.
|
||||||
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
|
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
|
||||||
|
bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@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 {
|
} else {
|
||||||
// For all other preferences, set the summary to the value's
|
// 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
|
// updated to reflect the new value, per the Android Design
|
||||||
// guidelines.
|
// guidelines.
|
||||||
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user