Changed to GB.toast, fixed equals and added constructors to TaskerEventType.

This commit is contained in:
nightoftune 2019-03-03 17:41:39 +01:00
parent 4b9e9f0ee8
commit 7e736a449c
3 changed files with 25 additions and 27 deletions

View File

@ -194,10 +194,12 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) { public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
//TODO: Implement //TODO: Implement
System.out.println("A");
} }
@Override @Override
public void onNotification(NotificationSpec notificationSpec) { public void onNotification(NotificationSpec notificationSpec) {
System.out.println("YO");
//TODO: Implement //TODO: Implement
} }

View File

@ -10,42 +10,41 @@ import nodomain.freeyourgadget.gadgetbridge.R;
/** /**
* Default set of tasker events. * Default set of tasker events.
* <p> * <p>
* Extend here if you want to add more events. Use {@link TaskerEventType#create(String)} * Extend here if you want to add more events. Use {@link TaskerEventType#(String, int)} if you want to use the event together with
* and configure {@link TaskerEventType#withLocalization(int)} for {@link nodomain.freeyourgadget.gadgetbridge.tasker.settings.activities.TaskerEventsActivity} * {@link nodomain.freeyourgadget.gadgetbridge.tasker.settings.activities.TaskerEventsActivity}.
* <p> * <p>
* Don't forget to add the new event to {@link #getTypes()} method. * Don't forget to add the new event to {@link #getTypes()} method.
*/ */
public class TaskerEventType implements Serializable { public class TaskerEventType implements Serializable {
public static TaskerEventType BUTTON = TaskerEventType.create("button").withLocalization(R.string.tasker_event_button); public static TaskerEventType BUTTON = new TaskerEventType("button", R.string.tasker_event_button);
public static TaskerEventType CONNECTION = TaskerEventType.create("connection").withLocalization(R.string.tasker_event_connection); public static TaskerEventType CONNECTION = new TaskerEventType("connection", R.string.tasker_event_connection);
public static TaskerEventType DATA = TaskerEventType.create("data").withLocalization(R.string.tasker_event_data); public static TaskerEventType DATA = new TaskerEventType("data", R.string.tasker_event_data);
public static TaskerEventType NO_OP = TaskerEventType.create("no-op"); public static TaskerEventType NO_OP = new TaskerEventType("no-op");
private String type; private String type;
private int index; private int index;
private int localization; private int localization;
private TaskerEventType() { public TaskerEventType(String type) {
this.type = type;
this.index = 1;
} }
public TaskerEventType withLocalization(int localization) { public TaskerEventType(String type, int localization) {
this(type);
this.localization = localization; this.localization = localization;
return this;
}
public static TaskerEventType create(String type) {
TaskerEventType taskerEventType = new TaskerEventType();
taskerEventType.index = 1;
taskerEventType.type = type;
return taskerEventType;
} }
/**
* Scopes the event with an index. I.e. for two buttons.
*
* @param index Event index
* @return Scoped {@link TaskerEventType}
*/
public TaskerEventType withIndex(int index) { public TaskerEventType withIndex(int index) {
TaskerEventType taskerEventType = new TaskerEventType(); TaskerEventType taskerEventType = new TaskerEventType(type, localization);
taskerEventType.type = this.type; taskerEventType.index = this.index;
taskerEventType.index = index;
taskerEventType.localization = this.localization;
return taskerEventType; return taskerEventType;
} }
@ -68,7 +67,7 @@ public class TaskerEventType implements Serializable {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || !getClass().isAssignableFrom(o.getClass())) return false;
TaskerEventType that = (TaskerEventType) o; TaskerEventType that = (TaskerEventType) o;
return index == that.index && return index == that.index &&
Objects.equals(type, that.type); Objects.equals(type, that.type);

View File

@ -1,5 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.tasker.service; package nodomain.freeyourgadget.gadgetbridge.tasker.service;
import android.content.res.Resources;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.widget.Toast; import android.widget.Toast;
@ -7,6 +8,7 @@ import android.widget.Toast;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerIntent; import nodomain.freeyourgadget.gadgetbridge.tasker.plugin.TaskerIntent;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
/** /**
* Tasker convenience methods for direct access to tasker without {@link TaskerService}. * Tasker convenience methods for direct access to tasker without {@link TaskerService}.
@ -37,12 +39,7 @@ public class TaskerUtil {
* Creates a {@link android.widget.Toast} for the user to show that Tasker is enabled but no task is defined. * Creates a {@link android.widget.Toast} for the user to show that Tasker is enabled but no task is defined.
*/ */
public static void noTaskDefinedInformation() { public static void noTaskDefinedInformation() {
new Handler(Looper.getMainLooper()).post(new Runnable() { GB.toast(Resources.getSystem().getString(R.string.tasker_no_task_defined), Toast.LENGTH_LONG, GB.INFO);
@Override
public void run() {
Toast.makeText(GBApplication.getContext(), R.string.tasker_no_task_defined, Toast.LENGTH_LONG).show();
}
});
} }
} }