Skip to content

Commit

Permalink
Move to v0.5.3 && Update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
renyuneyun committed Jan 22, 2018
2 parents d963e80 + 609f49c commit 64bf501
Show file tree
Hide file tree
Showing 44 changed files with 1,238 additions and 623 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
======

* v0.5.3: Add `Scenario` to allow reuse of event data && Add more configurations to events && Fix import not working correctly && Code refactor
* Add `Scenario` as an abstraction of EventData and allow EventStructure to link to it
* Add *reverse* to directly reverse the Scenario
* Add *repeatable*, *persistent* as more granulated configuration to events
* Fix importing not working correctly due to filesystem handling
* Code factor
* Extract more abstract classes and generics

* v0.5.2: Add "cool down" (seconds) && Allow to match BSSID for WiFi Event && Check permissions before enabling plugins && fixes & improvements
* Add "cool down" time (in seconds) for the re-activation of the same event
* `WifiEventPlugin` can now handle BSSIDs
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'ryey.easer'
minSdkVersion 15
targetSdkVersion 23
versionCode 51
versionName "0.5.2"
versionCode 52
versionName "0.5.3"

vectorDrawables.useSupportLibrary = true

Expand Down
12 changes: 5 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,15 @@

<activity
android:name=".plugins.event.nfc_tag.WaitForNfcActivity"
android:theme="@style/AppTheme.ActivityDialog"
android:enabled="false">
android:enabled="false"
android:theme="@style/AppTheme.ActivityDialog">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".plugins.event.nfc_tag.NfcListenerActivity">
<activity android:name=".plugins.event.nfc_tag.NfcListenerActivity">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />

Expand All @@ -114,9 +112,9 @@
<service
android:name=".plugins.event.nfc_tag.NfcListenerService"
android:enabled="true"
android:exported="false">
android:exported="false"></service>

</service>
<activity android:name=".core.ui.edit.EditScenarioActivity"></activity>
</application>

</manifest>
5 changes: 3 additions & 2 deletions app/src/main/java/ryey/easer/commons/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class C {
public static final String STATE = "state";

public static final String VERSION = "version";
public static final int VERSION_USE_SCENARIO = 4;
public static final int VERSION_WIFI_ADD_BSSID = 3;
public static final int VERSION_ADD_JSON = 2;
public static final int VERSION_FULL_MULTI = 1;
public static final int VERSION_DEFAULT = 0;
public static final int VERSION_CURRENT = VERSION_WIFI_ADD_BSSID;
public static final int VERSION_FALLBACK = 0;
public static final int VERSION_CURRENT = VERSION_USE_SCENARIO;

public enum Format {
XML,
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/ryey/easer/core/Lotus.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ final class Lotus {
private final long cooldownInMillisecond;
private Calendar lastSatisfied;

private final boolean repeatable;
private final boolean persistent;
private boolean satisfied = false;

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down Expand Up @@ -99,8 +103,14 @@ public void onReceive(Context context, Intent intent) {
intent1.setAction(ACTION_SLOT_UNSATISFIED);
notifyLotusUnsatisfiedIntent = PendingIntent.getBroadcast(context, 0, intent1, 0);

mSlot = dataToSlot(eventTree.getEvent());
mSlot.register(notifyLotusIntent, notifyLotusUnsatisfiedIntent);
mSlot = dataToSlot(eventTree.getEventData());
if (eventTree.isRevert()) {
mSlot.register(notifyLotusUnsatisfiedIntent, notifyLotusIntent);
} else {
mSlot.register(notifyLotusIntent, notifyLotusUnsatisfiedIntent);
}
repeatable = eventTree.isRepeatable();
persistent = eventTree.isPersistent();

cooldownInMillisecond = SettingsHelper.coolDownInterval(context);
}
Expand Down Expand Up @@ -133,7 +143,10 @@ void cancel() {
}

private synchronized void onSlotSatisfied() {
if (!repeatable && satisfied)
return;
Logger.i("event <%s> satisfied", eventTree.getName());
satisfied = true;
if (cooldownInMillisecond > 0) {
Calendar now = Calendar.getInstance();
if (lastSatisfied != null) {
Expand All @@ -153,7 +166,10 @@ private synchronized void onSlotSatisfied() {
}

private synchronized void onSlotUnsatisfied() {
if (persistent && satisfied)
return;
Logger.i("Event %s unsatisfied", eventTree.getName());
satisfied = false;
for (Lotus sub : subs) {
sub.cancel();
}
Expand All @@ -165,7 +181,7 @@ private synchronized void onSlotUnsatisfied() {
* 並在其處(所在的遞歸棧)載入對應Profile
*/
private void traverseAndTrigger(EventTree node, boolean is_sub) {
EventData eventData = node.getEvent();
EventData eventData = node.getEventData();
AbstractSlot slot = mSlot;
if (is_sub) {
slot = dataToSlot(eventData);
Expand Down
46 changes: 42 additions & 4 deletions app/src/main/java/ryey/easer/core/data/EventStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.support.annotation.Nullable;

import ryey.easer.commons.plugindef.eventplugin.EventData;
import ryey.easer.core.data.storage.ScenarioDataStorage;

/*
* An Event consists of the following data:
Expand All @@ -36,8 +37,11 @@
*/
final public class EventStructure implements Named, Verifiable {
protected String name;
protected EventData eventData;
private ScenarioStructure scenario;
protected boolean active = true;
private boolean reverse = false;
private boolean repeatable = true;
private boolean persistent = false;
@Nullable protected String profileName;
@Nullable protected String parentName;

Expand All @@ -54,12 +58,22 @@ public void setName(String name) {
this.name = name;
}

public ScenarioStructure getScenario() {
return scenario;
}

public void setScenario(ScenarioStructure scenario) {
this.scenario = scenario;
}

@Deprecated
public EventData getEventData() {
return eventData;
return scenario.getEventData();
}

@Deprecated
public void setEventData(EventData eventData) {
this.eventData = eventData;
this.scenario = ScenarioDataStorage.generateAndRecordTmpScenario(name, eventData);
}

public boolean isActive() {
Expand Down Expand Up @@ -89,8 +103,32 @@ public void setParentName(String parentName) {
public boolean isValid() {
if ((name == null) || (name.isEmpty()))
return false;
if ((eventData == null) || (!eventData.isValid()))
if (scenario == null)
return false;
return true;
}

public boolean isRepeatable() {
return repeatable;
}

public void setRepeatable(boolean repeatable) {
this.repeatable = repeatable;
}

public boolean isPersistent() {
return persistent;
}

public void setPersistent(boolean persistent) {
this.persistent = persistent;
}

public boolean isReverse() {
return reverse;
}

public void setReverse(boolean reverse) {
this.reverse = reverse;
}
}
13 changes: 11 additions & 2 deletions app/src/main/java/ryey/easer/core/data/EventTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ public EventTree(EventStructure eventStructure) {
public String getName() {
return data.name;
}
public EventData getEvent() {
return data.eventData;
public EventData getEventData() {
return data.getScenario().getEventData();
}
public boolean isRevert() {
return data.isReverse();
}
public boolean isRepeatable() {
return data.isRepeatable();
}
public boolean isPersistent() {
return data.isPersistent();
}
public void addSub(EventTree sub) {
subs.add(sub);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ryey/easer/core/data/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void export_data(Context context, File dest) throws IOException {
File parent_dir = context.getFilesDir();

addDirToZip(zip, parent_dir, "event");
addDirToZip(zip, parent_dir, "scenario");
addDirToZip(zip, parent_dir, "profile");

zip.close();
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/ryey/easer/core/data/ScenarioStructure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ryey.easer.core.data;

import ryey.easer.Utils;
import ryey.easer.commons.plugindef.eventplugin.EventData;
import ryey.easer.core.data.storage.ScenarioDataStorage;

public class ScenarioStructure implements Named, Verifiable {

private String name;
private EventData eventData;

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}

public EventData getEventData() {
return eventData;
}

public void setEventData(EventData eventData) {
this.eventData = eventData;
}

public boolean isTmpScenario() {
return ScenarioDataStorage.hasTmp(name);
}

@Override
public boolean isValid() {
if ((name == null) || (name.isEmpty()))
return false;
if ((eventData == null) || (!eventData.isValid()))
return false;
return true;
}

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof ScenarioStructure))
return false;
if (!Utils.nullableEqual(name, ((ScenarioStructure) obj).name))
return false;
if (!Utils.nullableEqual(eventData, ((ScenarioStructure) obj).eventData))
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ryey.easer.core.data.Verifiable;
import ryey.easer.core.data.storage.backend.DataStorageBackendCommonInterface;

abstract class AbstractDataStorage<T extends Named & Verifiable, T_backend extends DataStorageBackendCommonInterface<T>> {
public abstract class AbstractDataStorage<T extends Named & Verifiable, T_backend extends DataStorageBackendCommonInterface<T>> {
T_backend[] storage_backend_list;

public List<String> list() {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/ryey/easer/core/data/storage/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
public class C extends ryey.easer.commons.C {
public static final String TYPE = "type";
public static final String EVENT = "event";
public static final String SCENARIO = "scenario";
public static final String ACTIVE = "active";
public static final String TRIG = "trigger";
public static final String AFTER = "after";
public static final String REVERSE = "reverse";
public static final String REPEATABLE = "repeatable";
public static final String PERSISTENT = "persistent";

public class TriggerType {
public static final String T_RAW = "raw_event";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ryey.easer.core.data.EventStructure;
import ryey.easer.core.data.EventTree;
import ryey.easer.core.data.ScenarioStructure;
import ryey.easer.core.data.storage.backend.EventDataStorageBackendInterface;
import ryey.easer.core.data.storage.backend.json.event.JsonEventDataStorageBackend;
import ryey.easer.core.data.storage.backend.xml.event.XmlEventDataStorageBackend;
Expand All @@ -15,21 +16,22 @@ public class EventDataStorage extends AbstractDataStorage<EventStructure, EventD

private static EventDataStorage instance = null;

Context context;
private final Context context;

public static EventDataStorage getInstance(Context context) {
if (instance == null) {
instance = new EventDataStorage();
instance = new EventDataStorage(context);
instance.storage_backend_list = new EventDataStorageBackendInterface[] {
JsonEventDataStorageBackend.getInstance(context),
XmlEventDataStorageBackend.getInstance(context),
};
instance.context = context;
}
return instance;
}

private EventDataStorage() {}
private EventDataStorage(Context context) {
this.context = context;
}

@Override
boolean isSafeToDelete(String name) {
Expand All @@ -41,7 +43,15 @@ boolean isSafeToDelete(String name) {
* {@inheritDoc}
*/
public boolean edit(String oldName, EventStructure event) throws IOException {
boolean success = super.edit(oldName, event);
boolean success;
{
ScenarioStructure oldScenario = get(oldName).getScenario();
if (oldScenario.isTmpScenario()) {
// If moving from a tmp scenario to a solid scenario, just remove the tmp scenario
ScenarioDataStorage.removeTmp(oldScenario.getName());
} // else do nothing since there is nothing to do with an old existing scenario
}
success = super.edit(oldName, event);
if (success) {
if (!oldName.equals(event.getName())) {
handleEventRename(oldName, event.getName());
Expand Down
Loading

0 comments on commit 64bf501

Please sign in to comment.