1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-13 02:46:41 +00:00

Fix coding style, helped by eclipse. Also add notification when manual sync is done

This commit is contained in:
Loic Blot 2015-03-22 00:37:01 +01:00
parent 24f72073a4
commit bd26728bb5
5 changed files with 172 additions and 171 deletions

View File

@ -12,19 +12,19 @@ package fr.unix_experience.owncloud_sms.activities;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import java.util.List;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.PeriodicSync; import android.content.PeriodicSync;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -34,10 +34,6 @@ import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log;
import java.util.List;
import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs; import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
@ -51,7 +47,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
static String mAccountType; static String mAccountType;
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(final Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
mAccountMgr = AccountManager.get(getBaseContext()); mAccountMgr = AccountManager.get(getBaseContext());
@ -74,7 +70,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
// In the simplified UI, fragments are not used at all and we instead // In the simplified UI, fragments are not used at all and we instead
// use the older PreferenceActivity APIs. // use the older PreferenceActivity APIs.
addPreferencesFromResource(R.xml.pref_data_sync); addPreferencesFromResource(R.xml.pref_data_sync);
mContext = getBaseContext(); mContext = getBaseContext();
bindPreferences(); bindPreferences();
@ -90,7 +86,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
* Helper method to determine if the device has an extra-large screen. For * Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large. * example, 10" tablets are extra-large.
*/ */
private static boolean isXLargeTablet(Context context) { private static boolean isXLargeTablet(final Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
@ -101,7 +97,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
* doesn't have an extra-large screen. In these cases, a single-pane * doesn't have an extra-large screen. In these cases, a single-pane
* "simplified" settings UI should be shown. * "simplified" settings UI should be shown.
*/ */
private static boolean isSimplePreferences(Context context) { private static boolean isSimplePreferences(final Context context) {
return ALWAYS_SIMPLE_PREFS return ALWAYS_SIMPLE_PREFS
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
|| !isXLargeTablet(context); || !isXLargeTablet(context);
@ -113,52 +109,52 @@ public class GeneralSettingsActivity extends PreferenceActivity {
*/ */
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object value) { public boolean onPreferenceChange(final Preference preference, final Object value) {
if (preference instanceof ListPreference) { if (preference instanceof ListPreference) {
String prefKey = preference.getKey(); final String prefKey = preference.getKey();
String stringValue = value.toString(); final String stringValue = value.toString();
// For list preferences, look up the correct display value in // For list preferences, look up the correct display value in
// the preference's 'entries' list. // the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference; final ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue); final int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value. // Set the summary to reflect the new value.
preference preference
.setSummary(index >= 0 ? listPreference.getEntries()[index] .setSummary(index >= 0 ? listPreference.getEntries()[index]
: null); : null);
Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType); final Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType);
// Handle sync frequency change // Handle sync frequency change
if (prefKey.equals("sync_frequency")) { if (prefKey.equals("sync_frequency")) {
long syncFreq = Long.parseLong(stringValue); final long syncFreq = Long.parseLong(stringValue);
// Get ownCloud SMS account list // Get ownCloud SMS account list
for (int i = 0; i < myAccountList.length; i++) { for (int i = 0; i < myAccountList.length; i++) {
// And get all authorities for this account // And get all authorities for this account
List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mAccountAuthority); final List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mAccountAuthority);
boolean foundSameSyncCycle = false; boolean foundSameSyncCycle = false;
for (int j = 0; j < syncList.size(); j++) { for (int j = 0; j < syncList.size(); j++) {
PeriodicSync ps = syncList.get(i); final PeriodicSync ps = syncList.get(i);
if (ps.period == syncFreq && ps.extras.getInt("synctype") == 1) { if (ps.period == syncFreq && ps.extras.getInt("synctype") == 1) {
foundSameSyncCycle = true; foundSameSyncCycle = true;
} }
} }
if (foundSameSyncCycle == false) { if (foundSameSyncCycle == false) {
Bundle b = new Bundle(); final Bundle b = new Bundle();
b.putInt("synctype", 1); b.putInt("synctype", 1);
ContentResolver.removePeriodicSync(myAccountList[i], ContentResolver.removePeriodicSync(myAccountList[i],
mAccountAuthority, b); mAccountAuthority, b);
ContentResolver.addPeriodicSync(myAccountList[i], ContentResolver.addPeriodicSync(myAccountList[i],
mAccountAuthority, b, syncFreq * 60); mAccountAuthority, b, syncFreq * 60);
} }
} }
} }
// Slow Sync frequency // Slow Sync frequency
/*else if (prefKey.equals(new String("slow_sync_frequency"))) { /*else if (prefKey.equals(new String("slow_sync_frequency"))) {
long syncFreq = Long.parseLong((String)value); long syncFreq = Long.parseLong((String)value);
@ -167,21 +163,21 @@ public class GeneralSettingsActivity extends PreferenceActivity {
for (int i = 0; i < myAccountList.length; i++) { for (int i = 0; i < myAccountList.length; i++) {
// And get all authorities for this account // And get all authorities for this account
List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mSlowSyncAccountAuthority); List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], mSlowSyncAccountAuthority);
boolean foundSameSyncCycle = false; boolean foundSameSyncCycle = false;
for (int j = 0; j < syncList.size(); j++) { for (int j = 0; j < syncList.size(); j++) {
PeriodicSync ps = syncList.get(i); PeriodicSync ps = syncList.get(i);
if (ps.period == syncFreq && ps.extras.getInt("synctype") == 2) { if (ps.period == syncFreq && ps.extras.getInt("synctype") == 2) {
foundSameSyncCycle = true; foundSameSyncCycle = true;
} }
} }
if (foundSameSyncCycle == false) { if (foundSameSyncCycle == false) {
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt("synctype", 2); b.putInt("synctype", 2);
ContentResolver.removePeriodicSync(myAccountList[i], ContentResolver.removePeriodicSync(myAccountList[i],
mSlowSyncAccountAuthority, b); mSlowSyncAccountAuthority, b);
ContentResolver.addPeriodicSync(myAccountList[i], ContentResolver.addPeriodicSync(myAccountList[i],
mSlowSyncAccountAuthority, b, syncFreq * 60); mSlowSyncAccountAuthority, b, syncFreq * 60);
@ -189,15 +185,14 @@ public class GeneralSettingsActivity extends PreferenceActivity {
} }
}*/ }*/
} else if (preference instanceof CheckBoxPreference) { } else if (preference instanceof CheckBoxPreference) {
String prefKey = preference.getKey(); final String prefKey = preference.getKey();
Boolean boolValue = (Boolean)value; final Boolean boolValue = (Boolean)value;
// Network types allowed for sync // Network types allowed for sync
if(prefKey.equals(new String("sync_wifi")) || prefKey.equals("sync_2g") || if(prefKey.equals(new String("sync_wifi")) || prefKey.equals("sync_2g") ||
prefKey.equals(new String("sync_3g")) || prefKey.equals("sync_gprs") || prefKey.equals(new String("sync_3g")) || prefKey.equals("sync_gprs") ||
prefKey.equals("sync_4g") || prefKey.equals("sync_others")) { prefKey.equals("sync_4g") || prefKey.equals("sync_others")) {
Log.d("FUCK",prefKey + " " + boolValue.toString());
final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(mContext);
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(mContext);
prefs.putBoolean(prefKey, boolValue); prefs.putBoolean(prefKey, boolValue);
} }
} else { } else {
@ -218,38 +213,38 @@ public class GeneralSettingsActivity extends PreferenceActivity {
* *
* @see #sBindPreferenceSummaryToValueListener * @see #sBindPreferenceSummaryToValueListener
*/ */
private static void bindPreferenceBooleanToValue(Preference preference, Boolean defValue) { private static void bindPreferenceBooleanToValue(final Preference preference, final Boolean defValue) {
// Set the listener to watch for value changes. // Set the listener to watch for value changes.
preference preference
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); .setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's // Trigger the listener immediately with the preference's
// current value. // current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange( sBindPreferenceSummaryToValueListener.onPreferenceChange(
preference, preference,
PreferenceManager.getDefaultSharedPreferences( PreferenceManager.getDefaultSharedPreferences(
preference.getContext()).getBoolean( preference.getContext()).getBoolean(
preference.getKey(), preference.getKey(),
defValue defValue
) )
); );
} }
private static void bindPreferenceStringToValue(Preference preference) { private static void bindPreferenceStringToValue(final Preference preference) {
// Set the listener to watch for value changes. // Set the listener to watch for value changes.
preference preference
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); .setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's // Trigger the listener immediately with the preference's
// current value. // current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange( sBindPreferenceSummaryToValueListener.onPreferenceChange(
preference, preference,
PreferenceManager.getDefaultSharedPreferences( PreferenceManager.getDefaultSharedPreferences(
preference.getContext()).getString( preference.getContext()).getString(
preference.getKey(), preference.getKey(),
"" ""
) )
); );
} }
/** /**
@ -259,7 +254,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class DataSyncPreferenceFragment extends PreferenceFragment { public static class DataSyncPreferenceFragment extends PreferenceFragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_data_sync); addPreferencesFromResource(R.xml.pref_data_sync);
@ -277,7 +272,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
//bindPreferenceSummaryToValue(findPreference("slow_sync_frequency")); //bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
} }
} }
private void bindPreferences() { private void bindPreferences() {
mContext = getBaseContext(); mContext = getBaseContext();

View File

@ -30,11 +30,6 @@ import java.util.Vector;
import org.json.JSONArray; import org.json.JSONArray;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
import fr.unix_experience.owncloud_sms.engine.SmsFetcher;
import fr.unix_experience.owncloud_sms.engine.ASyncTask.SyncTask;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
@ -45,10 +40,14 @@ import android.provider.Settings;
import android.support.v13.app.FragmentPagerAdapter; import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter; import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.engine.ASyncTask.SyncTask;
import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
import fr.unix_experience.owncloud_sms.engine.SmsFetcher;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager;
public class MainActivity extends Activity { public class MainActivity extends Activity {
@ -67,23 +66,23 @@ public class MainActivity extends Activity {
ViewPager mViewPager; ViewPager mViewPager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
List<Fragment> fragments = new Vector<Fragment>(); final List<Fragment> fragments = new Vector<Fragment>();
/* /*
* Add the Main tabs here * Add the Main tabs here
*/ */
fragments.add(Fragment.instantiate(this,StarterFragment.class.getName())); fragments.add(Fragment.instantiate(this,StarterFragment.class.getName()));
fragments.add(Fragment.instantiate(this,SecondTestFragment.class.getName())); fragments.add(Fragment.instantiate(this,SecondTestFragment.class.getName()));
fragments.add(Fragment.instantiate(this,ThanksAndRateFragment.class.getName())); fragments.add(Fragment.instantiate(this,ThanksAndRateFragment.class.getName()));
mPagerAdapter = new MainPagerAdapter(getFragmentManager(), fragments); mPagerAdapter = new MainPagerAdapter(getFragmentManager(), fragments);
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
@ -98,13 +97,14 @@ public class MainActivity extends Activity {
public class MainPagerAdapter extends FragmentPagerAdapter { public class MainPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragments; private final List<Fragment> mFragments;
public MainPagerAdapter(FragmentManager fragmentManager, List<Fragment> fragments) { public MainPagerAdapter(final FragmentManager fragmentManager, final List<Fragment> fragments) {
super(fragmentManager); super(fragmentManager);
mFragments = fragments; mFragments = fragments;
} }
public Fragment getItem(int position) { @Override
public Fragment getItem(final int position) {
// getItem is called to instantiate the fragment for the given page. // getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class // Return a PlaceholderFragment (defined as a static inner class
// below). // below).
@ -123,65 +123,67 @@ public class MainActivity extends Activity {
*/ */
public static class StarterFragment extends Fragment { public static class StarterFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) { final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_mainactivity_main, container, final View rootView = inflater.inflate(R.layout.fragment_mainactivity_main, container,
false); false);
return rootView; return rootView;
} }
} }
public static class SecondTestFragment extends Fragment { public static class SecondTestFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) { final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_mainactivity_gotosettings, container, final View rootView = inflater.inflate(R.layout.fragment_mainactivity_gotosettings, container,
false); false);
return rootView; return rootView;
} }
} }
public static class ThanksAndRateFragment extends Fragment { public static class ThanksAndRateFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) { final Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_mainactivity_thanks_note, container, final View rootView = inflater.inflate(R.layout.fragment_mainactivity_thanks_note, container,
false); false);
return rootView; return rootView;
} }
} }
public void openAppSettings(View view) { public void openAppSettings(final View view) {
startActivity(new Intent(this, GeneralSettingsActivity.class)); startActivity(new Intent(this, GeneralSettingsActivity.class));
} }
public void openAddAccount(View view) { public void openAddAccount(final View view) {
startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
} }
public void syncAllMessages(View view) { public void syncAllMessages(final View view) {
ConnectivityMonitor cMon = new ConnectivityMonitor(getApplicationContext()); final ConnectivityMonitor cMon = new ConnectivityMonitor(getApplicationContext());
if (cMon.isValid()) { if (cMon.isValid()) {
// Now fetch messages since last stored date // Now fetch messages since last stored date
JSONArray smsList = new SmsFetcher(getApplicationContext()) final JSONArray smsList = new SmsFetcher(getApplicationContext())
.bufferizeMessagesSinceDate((long) 0); .bufferizeMessagesSinceDate((long) 0);
if (smsList != null) { if (smsList != null) {
final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(getApplicationContext());
nMgr.setSyncProcessMsg();
new SyncTask(getApplicationContext(), smsList).execute(); new SyncTask(getApplicationContext(), smsList).execute();
} }
} }
} }
public void openGooglePlayStore(View view) { public void openGooglePlayStore(final View view) {
Intent intent; Intent intent;
try { try {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())); intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
} catch (android.content.ActivityNotFoundException anfe) { } catch (final android.content.ActivityNotFoundException anfe) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())); intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
} }
startActivity(intent); startActivity(intent);
} }
} }

View File

@ -12,7 +12,7 @@ package fr.unix_experience.owncloud_sms.engine;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -27,39 +27,43 @@ import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager;
public interface ASyncTask { public interface ASyncTask {
class SyncTask extends AsyncTask<Void, Void, Void>{ class SyncTask extends AsyncTask<Void, Void, Void>{
public SyncTask(Context context, JSONArray smsList) { public SyncTask(final Context context, final JSONArray smsList) {
_context = context; _context = context;
_smsList = smsList; _smsList = smsList;
} }
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(final Void... params) {
final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(_context);
// Get ownCloud SMS account list // Get ownCloud SMS account list
AccountManager _accountMgr = AccountManager.get(_context); final AccountManager _accountMgr = AccountManager.get(_context);
Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type)); final Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type));
for (int i = 0; i < myAccountList.length; i++) { for (final Account element : myAccountList) {
Uri serverURI = Uri.parse(_accountMgr.getUserData(myAccountList[i], "ocURI")); final Uri serverURI = Uri.parse(_accountMgr.getUserData(element, "ocURI"));
OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context,
serverURI, _accountMgr.getUserData(myAccountList[i], "ocLogin"), serverURI, _accountMgr.getUserData(element, "ocLogin"),
_accountMgr.getPassword(myAccountList[i])); _accountMgr.getPassword(element));
try { try {
_client.doPushRequest(_smsList); _client.doPushRequest(_smsList);
} catch (OCSyncException e) { } catch (final OCSyncException e) {
Log.e(TAG, _context.getString(e.getErrorId())); Log.e(TAG, _context.getString(e.getErrorId()));
} }
} }
nMgr.dropSyncProcessMsg();
return null; return null;
} }
private Context _context; private final Context _context;
private JSONArray _smsList; private final JSONArray _smsList;
} }
static final String TAG = ASyncTask.class.getSimpleName(); static final String TAG = ASyncTask.class.getSimpleName();
} }

View File

@ -12,65 +12,65 @@ package fr.unix_experience.owncloud_sms.prefs;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
public class OCSMSSharedPrefs { public class OCSMSSharedPrefs {
public OCSMSSharedPrefs(Context context) { public OCSMSSharedPrefs(final Context context) {
_context = context; _context = context;
_sPrefs = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE); _sPrefs = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE);
} }
public void putBoolean(String prefKey, Boolean boolValue) { public void putBoolean(final String prefKey, final Boolean boolValue) {
Editor edit = _sPrefs.edit(); final Editor edit = _sPrefs.edit();
edit.putBoolean(prefKey, boolValue); edit.putBoolean(prefKey, boolValue);
edit.commit(); edit.commit();
} }
public void setLastMessageDate(Long msgDate) { public void setLastMessageDate(final Long msgDate) {
SharedPreferences.Editor editor = _sPrefs.edit(); final SharedPreferences.Editor editor = _sPrefs.edit();
editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate); editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate);
editor.commit(); editor.commit();
} }
public Long getLastMessageDate() { public Long getLastMessageDate() {
return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0); return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0);
} }
public Boolean syncInWifi() { public Boolean syncInWifi() {
return _sPrefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi); return _sPrefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi);
} }
public Boolean syncIn2G() { public Boolean syncIn2G() {
return _sPrefs.getBoolean("sync_2g", DefaultPrefs.sync2G); return _sPrefs.getBoolean("sync_2g", DefaultPrefs.sync2G);
} }
public Boolean syncInGPRS() { public Boolean syncInGPRS() {
return _sPrefs.getBoolean("sync_gprs", DefaultPrefs.syncGPRS); return _sPrefs.getBoolean("sync_gprs", DefaultPrefs.syncGPRS);
} }
public Boolean syncIn3G() { public Boolean syncIn3G() {
return _sPrefs.getBoolean("sync_3g", DefaultPrefs.sync3G); return _sPrefs.getBoolean("sync_3g", DefaultPrefs.sync3G);
} }
public Boolean syncIn4G() { public Boolean syncIn4G() {
return _sPrefs.getBoolean("sync_4g", DefaultPrefs.sync4G); return _sPrefs.getBoolean("sync_4g", DefaultPrefs.sync4G);
} }
public Boolean syncInOtherModes() { public Boolean syncInOtherModes() {
return _sPrefs.getBoolean("sync_others", DefaultPrefs.syncOthers); return _sPrefs.getBoolean("sync_others", DefaultPrefs.syncOthers);
} }
private SharedPreferences _sPrefs; private final SharedPreferences _sPrefs;
private Context _context; private final Context _context;
} }

View File

@ -12,16 +12,11 @@ package fr.unix_experience.owncloud_sms.sync_adapters;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient;
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.AbstractThreadedSyncAdapter; import android.content.AbstractThreadedSyncAdapter;
@ -31,43 +26,48 @@ import android.content.SyncResult;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient;
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager;
public class SmsSyncAdapter extends AbstractThreadedSyncAdapter { public class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
public SmsSyncAdapter(Context context, boolean autoInitialize) { public SmsSyncAdapter(final Context context, final boolean autoInitialize) {
super(context, autoInitialize); super(context, autoInitialize);
_accountMgr = AccountManager.get(context); _accountMgr = AccountManager.get(context);
} }
@Override @Override
public void onPerformSync(Account account, Bundle extras, String authority, public void onPerformSync(final Account account, final Bundle extras, final String authority,
ContentProviderClient provider, SyncResult syncResult) { final ContentProviderClient provider, final SyncResult syncResult) {
OCSMSNotificationManager nMgr = new OCSMSNotificationManager(getContext()); final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(getContext());
// Create client // Create client
String ocURI = _accountMgr.getUserData(account, "ocURI"); final String ocURI = _accountMgr.getUserData(account, "ocURI");
if (ocURI == null) { if (ocURI == null) {
nMgr.setSyncErrorMsg(getContext().getString(R.string.err_sync_account_unparsable)); nMgr.setSyncErrorMsg(getContext().getString(R.string.err_sync_account_unparsable));
return; return;
} }
Uri serverURI = Uri.parse(ocURI); final Uri serverURI = Uri.parse(ocURI);
nMgr.setSyncProcessMsg(); nMgr.setSyncProcessMsg();
OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(getContext(), final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(getContext(),
serverURI, _accountMgr.getUserData(account, "ocLogin"), serverURI, _accountMgr.getUserData(account, "ocLogin"),
_accountMgr.getPassword(account)); _accountMgr.getPassword(account));
try { try {
// getServerAPI version // getServerAPI version
Log.d(TAG,"Server API version: " + _client.getServerAPIVersion()); Log.d(TAG,"Server API version: " + _client.getServerAPIVersion());
// and push datas // and push datas
_client.doPushRequest(null); _client.doPushRequest(null);
nMgr.dropSyncErrorMsg(); nMgr.dropSyncErrorMsg();
} catch (OCSyncException e) { } catch (final OCSyncException e) {
nMgr.setSyncErrorMsg(getContext().getString(e.getErrorId())); nMgr.setSyncErrorMsg(getContext().getString(e.getErrorId()));
if (e.getErrorType() == OCSyncErrorType.IO) { if (e.getErrorType() == OCSyncErrorType.IO) {
syncResult.stats.numIoExceptions++; syncResult.stats.numIoExceptions++;
@ -82,12 +82,12 @@ public class SmsSyncAdapter extends AbstractThreadedSyncAdapter {
// UNHANDLED // UNHANDLED
} }
} }
nMgr.dropSyncProcessMsg(); nMgr.dropSyncProcessMsg();
} }
private AccountManager _accountMgr; private final AccountManager _accountMgr;
private static final String TAG = SmsSyncAdapter.class.getSimpleName(); private static final String TAG = SmsSyncAdapter.class.getSimpleName();
} }