diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java index 6832b7095..6ffcd2ea0 100644 --- a/src/org/geometerplus/android/fbreader/FBReader.java +++ b/src/org/geometerplus/android/fbreader/FBReader.java @@ -58,7 +58,7 @@ import org.geometerplus.android.fbreader.api.*; import org.geometerplus.android.fbreader.httpd.DataService; import org.geometerplus.android.fbreader.library.BookInfoActivity; import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow; -import org.geometerplus.android.fbreader.sync.SyncService; +import org.geometerplus.android.fbreader.sync.SyncOperations; import org.geometerplus.android.fbreader.tips.TipsActivity; import org.geometerplus.android.util.*; @@ -488,7 +488,7 @@ public final class FBReader extends Activity implements ZLApplicationWindow { protected void onResume() { super.onResume(); - SyncService.enableSync(this, true); + SyncOperations.enableSync(this, true); myStartTimer = true; Config.Instance().runOnConnect(new Runnable() { diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index 5c689ade4..c0f065a54 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -50,7 +50,7 @@ import org.geometerplus.android.fbreader.FBReader; import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow; import org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext; import org.geometerplus.android.fbreader.preferences.fileChooser.FileChooserCollection; -import org.geometerplus.android.fbreader.sync.SyncService; +import org.geometerplus.android.fbreader.sync.SyncOperations; import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.util.DeviceType; @@ -158,8 +158,8 @@ public class PreferenceActivity extends ZLPreferenceActivity { } } - private void enableSyncService() { - SyncService.enableSync(PreferenceActivity.this, syncOptions.Enabled.getValue()); + private void enableSynchronisation() { + SyncOperations.enableSync(PreferenceActivity.this, syncOptions.Enabled.getValue()); } @Override @@ -171,7 +171,7 @@ public class PreferenceActivity extends ZLPreferenceActivity { if (!isChecked()) { syncOptions.Enabled.setValue(false); - enableSyncService(); + enableSynchronisation(); syncPreferences.run(); return; } @@ -185,7 +185,7 @@ public class PreferenceActivity extends ZLPreferenceActivity { public void processResponse(Object response) { final String account = (String)((Map)response).get("user"); syncOptions.Enabled.setValue(account != null); - enableSyncService(); + enableSynchronisation(); runOnUiThread(new Runnable() { public void run() { setOnSummary(account); diff --git a/src/org/geometerplus/android/fbreader/sync/SyncOperations.java b/src/org/geometerplus/android/fbreader/sync/SyncOperations.java new file mode 100644 index 000000000..e233317da --- /dev/null +++ b/src/org/geometerplus/android/fbreader/sync/SyncOperations.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2010-2014 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.android.fbreader.sync; + +import java.io.*; +import java.util.*; + +import android.content.Context; +import android.content.Intent; + +public abstract class SyncOperations { + interface Action { + String START = "android.fbreader.action.sync.START"; + String STOP = "android.fbreader.action.sync.STOP"; + String SYNC = "android.fbreader.action.sync.SYNC"; + } + + public static void enableSync(Context context, boolean enable) { + final String action = enable ? Action.START : Action.STOP; + context.startService(new Intent(context, SyncService.class).setAction(action)); + } +} diff --git a/src/org/geometerplus/android/fbreader/sync/SyncService.java b/src/org/geometerplus/android/fbreader/sync/SyncService.java index d585858eb..ff07447e3 100644 --- a/src/org/geometerplus/android/fbreader/sync/SyncService.java +++ b/src/org/geometerplus/android/fbreader/sync/SyncService.java @@ -23,7 +23,6 @@ import java.io.*; import java.util.*; import android.app.*; -import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.os.SystemClock; @@ -44,17 +43,6 @@ public class SyncService extends Service implements IBookCollection.Listener, Ru Log.d("FBReader.Sync", message); } - public static void enableSync(Context context, boolean enable) { - final String action = enable ? Action.START : Action.STOP; - context.startService(new Intent(context, SyncService.class).setAction(action)); - } - - private interface Action { - String START = "android.fbreader.action.sync.START"; - String STOP = "android.fbreader.action.sync.STOP"; - String SYNC = "android.fbreader.action.sync.SYNC"; - } - private enum Status { AlreadyUploaded(Book.SYNCHRONISED_LABEL), Uploaded(Book.SYNCHRONISED_LABEL), @@ -96,14 +84,14 @@ public class SyncService extends Service implements IBookCollection.Listener, Ru private PendingIntent syncIntent() { return PendingIntent.getService( - this, 0, new Intent(this, getClass()).setAction(Action.SYNC), 0 + this, 0, new Intent(this, getClass()).setAction(SyncOperations.Action.SYNC), 0 ); } @Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent.getAction(); - if (Action.START.equals(action)) { + if (SyncOperations.Action.START.equals(action)) { final AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); alarmManager.cancel(syncIntent()); Config.Instance().runOnConnect(new Runnable() { @@ -121,11 +109,11 @@ public class SyncService extends Service implements IBookCollection.Listener, Ru ); } }); - } else if (Action.STOP.equals(action)) { + } else if (SyncOperations.Action.STOP.equals(action)) { final AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); alarmManager.cancel(syncIntent()); log("stopped"); - } else if (Action.SYNC.equals(action)) { + } else if (SyncOperations.Action.SYNC.equals(action)) { SQLiteCookieDatabase.init(this); myCollection.bindToService(this, this); }