Skip to content

Commit

Permalink
Merge branch 'feature' into fix
Browse files Browse the repository at this point in the history
  • Loading branch information
renyuneyun committed Feb 17, 2018
2 parents 8312b77 + 11933b2 commit 7156a99
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 11 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/ryey/easer/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import android.widget.Toast;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -112,4 +115,20 @@ public static int checkedIndexFirst(CompoundButton[] buttons) {
}
throw new IllegalStateException("At least one button should be checked");
}

private static final String F_DATE = "%DATE%";
private static final String F_TIME = "%TIME%";

private static final SimpleDateFormat sdf_date = new SimpleDateFormat("yyyy-MM-DD", Locale.US);
private static final SimpleDateFormat sdf_time = new SimpleDateFormat("HH-mm-ss", Locale.US);

public static String format(String format_string) {
if (format_string == null)
return null;
Date now = Calendar.getInstance().getTime();
String res = format_string;
res = res.replaceAll(F_DATE, sdf_date.format(now));
res = res.replaceAll(F_TIME, sdf_time.format(now));
return res;
}
}
6 changes: 4 additions & 2 deletions app/src/main/java/ryey/easer/core/EHService.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public void onCreate() {
filter.addAction(ProfileLoaderIntentService.ACTION_PROFILE_LOADED);
registerReceiver(mReceiver, filter);
reloadTriggers();
for (Lotus lotus : mLotusArray) {
lotus.check();
if (SettingsHelper.passiveMode(this)) {
for (Lotus lotus : mLotusArray) {
lotus.check();
}
}
Logger.i("EHService created");
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/ryey/easer/core/Lotus.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ private void triggerAndPromote() {
Lotus subLotus = new Lotus(context, sub, executorService);
subs.add(subLotus);
subLotus.listen();
subLotus.check();
if (SettingsHelper.passiveMode(context)) {
subLotus.check();
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/ryey/easer/core/SettingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public static int coolDownInterval(Context context) {
return Integer.parseInt(interval_pref);
}

public static boolean passiveMode(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.key_pref_passive_mode), true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Calendar;

import ryey.easer.Utils;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.operationplugin.OperationLoader;

Expand Down Expand Up @@ -54,7 +55,7 @@ public boolean load(@ValidData @NonNull AlarmOperationData data) {
}
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, data.message);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, Utils.format(data.message));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.orhanobut.logger.Logger;

import java.util.ArrayList;

import ryey.easer.Utils;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.operationplugin.OperationLoader;
Expand All @@ -37,7 +40,7 @@ public BroadcastLoader(Context context) {

@Override
public boolean load(@ValidData @NonNull BroadcastOperationData data) {
IntentData iData = data.data;
IntentData iData = preprocess(data.data);
Intent intent = new Intent();
intent.setAction(iData.action);
if (iData.category != null)
Expand Down Expand Up @@ -70,9 +73,30 @@ public boolean load(@ValidData @NonNull BroadcastOperationData data) {
}
intent.putExtras(extras);
}
Logger.d(intent);
context.sendBroadcast(intent);
Logger.d("broadcast has been sent [%s]", iData);
return true;
}

private static IntentData preprocess(IntentData data) {
IntentData res = new IntentData();
res.action = Utils.format(data.action);
if (data.category != null) {
res.category = new ArrayList<>(data.category.size());
for (String c : data.category) {
res.category.add(Utils.format(c));
}
}
res.type = Utils.format(data.type);
res.data = Uri.parse(Utils.format(data.data.getPath()));
if (data.extras != null) {
res.extras = new ArrayList<>(data.extras.size());
for (IntentData.ExtraItem extra : data.extras) {
IntentData.ExtraItem p_extra = new IntentData.ExtraItem();
p_extra.key = Utils.format(extra.key);
p_extra.value = Utils.format(extra.value);
res.extras.add(p_extra);
}
}
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.IOException;

import ryey.easer.Utils;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.operationplugin.OperationLoader;
import ryey.easer.plugins.reusable.PluginHelper;
Expand All @@ -38,7 +39,7 @@ public CommandLoader(Context context) {
@Override
public boolean load(@ValidData @NonNull CommandOperationData data) {
boolean success = true;
String text = data.get();
String text = Utils.format(data.get());
String []commands = text.split("\n");
Process process;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.ThreadLocalRandom;

import ryey.easer.R;
import ryey.easer.Utils;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.operationplugin.OperationLoader;

Expand All @@ -50,8 +51,8 @@ public boolean load(@ValidData @NonNull SendNotificationOperationData data) {

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(data.title);
builder.setContentText(data.content);
builder.setContentTitle(Utils.format(data.title));
builder.setContentText(Utils.format(data.content));

notificationManager.notify(NOTIFICATION_ID, builder.build());
NOTIFICATION_ID++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.support.annotation.NonNull;
import android.telephony.SmsManager;

import ryey.easer.Utils;
import ryey.easer.commons.plugindef.ValidData;
import ryey.easer.commons.plugindef.operationplugin.OperationLoader;

Expand All @@ -33,8 +34,12 @@ public SmsLoader(Context context) {

@Override
public boolean load(@ValidData @NonNull SmsOperationData data) {
String destination = data.destination;
String content = Utils.format(data.content);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(data.destination, null, data.content, null, null);
if (smsManager == null)
return false;
smsManager.sendTextMessage(destination, null, content, null, null);
return true;
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@
<string name="text_reverse_desc">反轉情境</string>
<string name="text_persistent">固定滿足態</string>
<string name="text_volatile">不固定滿足態</string>
<string name="pref_passive_mode_title">被動模式</string>
<string name="pref_passive_mode_summary_off">當激活事件時,檢查當前狀態</string>
<string name="pref_passive_mode_summary_on">僅監聽事件;事件激活時不檢查</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="key_pref_version" translatable="false">preference_version</string>
<string name="key_pref_use_root" translatable="false">preference_use_root</string>
<string name="key_pref_cooldown" translatable="false">preference_cool_down_time</string>
<string name="key_pref_passive_mode" translatable="false">preference_passive_mode</string>
<string name="key_pref_plugins" translatable="false">preference_plugins</string>
<string name="key_pref_enabled_operation_plugins" translatable="false">preference_enabled_operation_plugins</string>
<string name="key_pref_enabled_event_plugins" translatable="false">preference_enabled_event_plugins</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Reminder: Easer is still in development. It may contain bugs and the UI definite
<string name="pref_cooldown_summary">Interval between two triggers of the same event</string>
<string name="cooldown_time_illformed">The number must not be lower than 0 and not too large to fit in a integer</string>

<string name="pref_passive_mode_title">Passive mode</string>
<string name="pref_passive_mode_summary_on">Listen to Event; no checking when activated</string>
<string name="pref_passive_mode_summary_off">Check the satisfaction state when (each) Event is activated</string>

<string name="pref_enabled_plugins_title">Enabled plugins</string>
<string name="pref_enabled_plugins_summary">Enable or disable certain plugins</string>

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
android:singleLine="true"
android:summary="@string/pref_cooldown_summary"
android:title="@string/pref_cooldown_title" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_pref_passive_mode"
android:summaryOn="@string/pref_passive_mode_summary_on"
android:summaryOff="@string/pref_passive_mode_summary_off"
android:title="@string/pref_passive_mode_title" />
<Preference
android:key="@string/key_pref_plugins"
android:summary="@string/pref_enabled_plugins_summary"
Expand Down

0 comments on commit 7156a99

Please sign in to comment.