Remove SyncAction

pull/189/head
Alex Baker 10 years ago
parent 584fdefe47
commit 1b6c7eaa69

@ -105,13 +105,6 @@ public class AstridApiConstants {
*/
public static final String BROADCAST_REQUEST_SYNC_ACTIONS = API_PACKAGE + ".REQUEST_SYNC_ACTIONS";
/**
* Action name for broadcast intent sending sync provider information back to Astrid
* <li> EXTRAS_ADDON your add-on identifier
* <li> EXTRAS_RESPONSE a {@link SyncAction} to invoke synchronization
*/
public static final String BROADCAST_SEND_SYNC_ACTIONS = API_PACKAGE + ".SEND_SYNC_ACTIONS";
// --- Actions API
/**

@ -1,112 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.api;
import android.app.PendingIntent;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Represents an intent that can be called to perform synchronization
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class SyncAction implements Parcelable {
/**
* Label
*/
public String label = null;
/**
* Intent to call when invoking this operation
*/
public PendingIntent intent = null;
/**
* Create an EditOperation object
*
* @param label
* label to display
* @param intent
* intent to invoke
*/
public SyncAction(String label, PendingIntent intent) {
super();
this.label = label;
this.intent = intent;
}
/**
* Returns the label of this action
*/
@Override
public String toString() {
return label;
}
@Override
public int hashCode() {
return label.hashCode() ^ intent.getTargetPackage().hashCode();
}
/**
* We consider two sync actions equal if target package is identical
* and the labels are the same. This prevents duplicate pendingIntents
* from creating multiple SyncAction objects.
*/
@Override
public boolean equals(Object o) {
if(!(o instanceof SyncAction)) {
return false;
}
SyncAction other = (SyncAction) o;
return label.equals(other.label) && intent.getTargetPackage().equals(other.intent.getTargetPackage());
}
// --- parcelable helpers
/**
* {@inheritDoc}
*/
@Override
public int describeContents() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(label);
dest.writeParcelable(intent, 0);
}
/**
* Parcelable creator
*/
public static final Parcelable.Creator<SyncAction> CREATOR = new Parcelable.Creator<SyncAction>() {
/**
* {@inheritDoc}
*/
@Override
public SyncAction createFromParcel(Parcel source) {
return new SyncAction(source.readString(), (PendingIntent)source.readParcelable(
PendingIntent.class.getClassLoader()));
}
/**
* {@inheritDoc}
*/
@Override
public SyncAction[] newArray(int size) {
return new SyncAction[size];
}
};
}

@ -491,7 +491,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
getActivity().registerReceiver(refreshReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));
syncActionHelper.register();
if (Flags.checkAndClear(Flags.REFRESH)) {
refresh();
@ -552,7 +551,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
super.onPause();
AndroidUtilities.tryUnregisterReceiver(getActivity(), refreshReceiver);
syncActionHelper.unregister();
backgroundTimer.cancel();
}

@ -7,11 +7,8 @@ package com.todoroo.astrid.helper;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
@ -19,24 +16,19 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.SyncAction;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.sync.SyncResultCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import org.tasks.sync.IndeterminateProgressBarSyncResultCallback;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
/**
@ -52,16 +44,10 @@ import java.util.List;
*/
public class SyncActionHelper {
private static final Logger log = LoggerFactory.getLogger(SyncActionHelper.class);
public static final String PREF_LAST_AUTO_SYNC = "taskListLastAutoSync"; //$NON-NLS-1$
private final LinkedHashSet<SyncAction> syncActions = new LinkedHashSet<>();
public final SyncResultCallback syncResultCallback;
protected SyncActionReceiver syncActionReceiver = new SyncActionReceiver();
private final SyncV2Service syncService;
private final Activity activity;
private final Preferences preferences;
@ -93,42 +79,7 @@ public class SyncActionHelper {
}
}
// --- sync action receiver logic
/**
* Receiver which receives sync provider intents
*
*/
protected class SyncActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null
|| !AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS.equals(intent.getAction())) {
return;
}
try {
Bundle extras = intent.getExtras();
SyncAction syncAction = extras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE);
syncActions.add(syncAction);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
public void register() {
activity.registerReceiver(
syncActionReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS));
}
public void unregister() {
AndroidUtilities.tryUnregisterReceiver(activity, syncActionReceiver);
}
public void request() {
syncActions.clear();
Intent broadcastIntent = new Intent(
AstridApiConstants.BROADCAST_REQUEST_SYNC_ACTIONS);
activity.sendOrderedBroadcast(broadcastIntent,
@ -165,7 +116,7 @@ public class SyncActionHelper {
public void performSyncAction() {
List<GtasksSyncV2Provider> activeV2Providers = syncService.activeProviders();
int activeSyncs = syncActions.size() + activeV2Providers.size();
int activeSyncs = activeV2Providers.size();
if (activeSyncs == 0) {
String desiredCategory = activity.getString(R.string.SyP_label);

Loading…
Cancel
Save