Skip to content

Commit

Permalink
fix notification title partial match
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusteng committed Jan 9, 2024
1 parent 440a306 commit 1e47c76
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tw.tib.financisto"
android:versionName="2024-01-08 b" android:versionCode="128"
android:versionName="2024-01-09" android:versionCode="129"
android:installLocation="internalOnly">

<supports-screens
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/assets/whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

<a href="docs/notification_template.htm">Notification Template docs</a>

<p><b>2024-01-09</b></p>
<dl>
<dt>[-] Fix partial match notification title</dt>
<dd>
You can use % to indicate wildcard match.<br />
Example: If your notification title is like 'Money Out $123', you can match it with
'Money Out %'; if the title is like '$567 received', you can match it with '% received'.
</dd>
</dl>

<p><b>2024-01-08 b</b></p>
<dl>
<dt>[*] Partial match notification title</dt>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/tw/tib/financisto/db/DatabaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,12 @@ public List<SmsTemplate> getSmsTemplatesForCategory(long categoryId) {

public List<SmsTemplate> getSmsTemplatesByNumber(String smsNumber) {
try (Cursor c = db().rawQuery(
String.format("select %s from %s where %s LIKE ? order by %s, length(%s) desc",
String.format("select %s from %s where ? LIKE %s order by %s, length(%s) desc",
DatabaseUtils.generateSelectClause(DatabaseHelper.SmsTemplateColumns.NORMAL_PROJECTION, null),
DatabaseHelper.SMS_TEMPLATES_TABLE,
DatabaseHelper.SmsTemplateColumns.title,
DatabaseHelper.SmsTemplateColumns.sort_order,
DatabaseHelper.SmsTemplateColumns.template), new String[]{"%" + smsNumber + "%"})) {
DatabaseHelper.SmsTemplateColumns.template), new String[]{smsNumber})) {
List<SmsTemplate> res = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
SmsTemplate a = SmsTemplate.fromCursor(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import android.text.SpannableString;
import android.util.Log;

import java.util.List;
import java.util.Set;

import tw.tib.financisto.db.DatabaseAdapter;
import tw.tib.financisto.model.SmsTemplate;

public class NotificationListener extends NotificationListenerService {
private static final String TAG = "NotificationListener";
Expand Down Expand Up @@ -83,9 +85,9 @@ private void processNotification(StatusBarNotification sbn, boolean processTempl

if (processTemplate && (existing == null || !body.equals(existing.body))) {
final DatabaseAdapter db = new DatabaseAdapter(context);
Set<String> smsNumbers = db.findAllSmsTemplateNumbers();
List<SmsTemplate> templates = db.getSmsTemplatesByNumber(title);

if (smsNumbers.contains(title)) {
if (!templates.isEmpty()) {
Intent serviceIntent = new Intent(ACTION_NEW_TRANSACTION_SMS, null, context, FinancistoService.class);
serviceIntent.putExtra(SMS_TRANSACTION_NUMBER, title);
serviceIntent.putExtra(SMS_TRANSACTION_BODY, body);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
<!-- SMS stuff >> -->
<string name="sms_sender">發送通知的程式 / 簡訊發送門號</string>
<string name="sms_tpl_filter_hint">輸入數字或文字過濾</string>
<string name="sms_number_hint">發送通知的程式名稱或發送簡訊的門號</string>
<string name="sms_number_hint">發送通知的程式名稱或發送簡訊的門號, 可用 % 代表任意字串</string>
<string name="sms_tpl">通知 / 簡訊模板</string>
<string name="sms_tpl_title">模板 (?)</string>
<string name="sms_tpl_desc">佔位標籤: \n{{p}} - 金額\n{{a}} - 帳號/卡號片段\n{{t}} - 交易內容敘述 (盡可能短)\n{{u}} - 交易內容敘述 (盡可能長)\n{{*}} - 任意內容 (不處理)</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@
<!-- SMS stuff >> -->
<string name="sms_sender">Notification Sender / SMS Number</string>
<string name="sms_tpl_filter_hint">Filter by number or text</string>
<string name="sms_number_hint">Notification sender app name or SMS sender number</string>
<string name="sms_number_hint">Notification sender app name or SMS sender number, use % to indicate wildcard match</string>
<string name="sms_tpl">Notification / SMS Template</string>
<string name="sms_tpl_title">Template (?)</string>
<string name="sms_tpl_desc">Placeholders: \n{{p}} - price\n{{a}} - account last digits\n{{t}} - note text (non-greedy)\n{{u}} - note text (greedy)\n{{*}} - any symbols/words</string>
Expand Down

0 comments on commit 1e47c76

Please sign in to comment.