mirror of https://github.com/tasks/tasks
finished up Sync action
parent
16bd76b18f
commit
5934d21d4a
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 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. {@link EXTRAS_TASK_ID} will be passed
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
// --- parcelable helpers
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
public SyncAction createFromParcel(Parcel source) {
|
||||
return new SyncAction(source.readString(), (PendingIntent)source.readParcelable(
|
||||
PendingIntent.class.getClassLoader()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public SyncAction[] newArray(int size) {
|
||||
return new SyncAction[size];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.producteev;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
import com.todoroo.astrid.api.SyncAction;
|
||||
|
||||
/**
|
||||
* Exposes sync action
|
||||
*
|
||||
*/
|
||||
public class ProducteevSyncActionExposer extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// if we aren't logged in, don't expose sync action
|
||||
if(!ProducteevUtilities.INSTANCE.isLoggedIn())
|
||||
return;
|
||||
|
||||
Intent syncIntent = new Intent(ProducteevBackgroundService.SYNC_ACTION, null,
|
||||
context, ProducteevBackgroundService.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
SyncAction syncAction = new SyncAction(context.getString(R.string.producteev_PPr_header),
|
||||
pendingIntent);
|
||||
|
||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction);
|
||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.rmilk;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
import com.todoroo.astrid.api.SyncAction;
|
||||
|
||||
/**
|
||||
* Exposes sync action
|
||||
*
|
||||
*/
|
||||
public class MilkSyncActionExposer extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// if we aren't logged in, don't expose sync action
|
||||
if(!MilkUtilities.isLoggedIn())
|
||||
return;
|
||||
|
||||
Intent syncIntent = new Intent(MilkBackgroundService.SYNC_ACTION, null,
|
||||
context, MilkBackgroundService.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
SyncAction syncAction = new SyncAction(context.getString(R.string.rmilk_MPr_header),
|
||||
pendingIntent);
|
||||
|
||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, MilkUtilities.IDENTIFIER);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction);
|
||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue