1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

introduced SyncOperations class

This commit is contained in:
Nikolay Pultsin 2014-08-09 18:57:20 +01:00
parent 8f0379cd8e
commit c8daf85889
4 changed files with 50 additions and 23 deletions

View file

@ -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() {

View file

@ -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);

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2010-2014 Geometer Plus <contact@geometerplus.com>
*
* 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));
}
}

View file

@ -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);
}