Skip to content

Commit

Permalink
app: v1.1.0
Browse files Browse the repository at this point in the history
- added dnd
- fix enabled-packages and servers updating
  • Loading branch information
Yanndroid committed Nov 1, 2023
1 parent b4fd501 commit 78cc7ac
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
8 changes: 2 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId "de.dlyt.yanndroid.notifer"
minSdk 26
targetSdk 33
versionCode 3
versionName "1.0.2"
versionCode 4
versionName "1.1.0"

resConfigs locales

Expand All @@ -32,10 +32,6 @@ android {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
Binary file modified app/release/app-release.aab
Binary file not shown.
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 3,
"versionName": "1.0.2",
"versionCode": 4,
"versionName": "1.1.0",
"outputFile": "app-release.apk"
}
],
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/de/dlyt/yanndroid/notifer/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.dlyt.yanndroid.notifer;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
Expand Down Expand Up @@ -134,8 +135,10 @@ private void sendTestNotification() {
JSONObject body = HttpRequest.makeBody(
getString(R.string.app_name), mContext.getPackageName(), 0,
System.currentTimeMillis(), false, "", false,
"Test Notification", "This is a test notification", "", "",
"", false, 0, 0);
"Test Notification", "This is a test notification",
"", "", "",
false, 0, 0,
NotificationManager.INTERRUPTION_FILTER_ALL);

for (Preferences.ServerInfo mServer : mServers) {
body.put("color", ColorUtil.convertColor(Color.BLUE, mServer.colorFormat));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.dlyt.yanndroid.notifer.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
Expand All @@ -22,13 +24,17 @@ public class NotificationListener extends NotificationListenerService {
private HashMap<String, Integer> mEnabledPackages;
private List<Preferences.ServerInfo> mServers;

private NotificationManager mNotificationManager;

@Override
public void onCreate() {
super.onCreate();
mPreferences = new Preferences(this);

mEnabledPackages = mPreferences.getEnabledPackages(enabledPackages -> mEnabledPackages = enabledPackages);
mServers = mPreferences.getServers(servers -> mServers = servers);

mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}

@Override
Expand Down Expand Up @@ -89,7 +95,8 @@ private JSONObject makeBody(StatusBarNotification sbn, boolean removed) throws J
bundle.getString("android.bigText"),
bundle.getBoolean("android.progressIndeterminate"),
bundle.getInt("android.progressMax"),
bundle.getInt("android.progress")
bundle.getInt("android.progress"),
mNotificationManager.getCurrentInterruptionFilter()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void post(String url, JSONObject json) {
}).start();
}

public static JSONObject makeBody(CharSequence label, String packageName, int id, long time, boolean ongoing, String template, boolean removed, String title, String text, String subText, String titleBig, String textBig, boolean progressIndeterminate, int progressMax, int progress) throws JSONException {
public static JSONObject makeBody(CharSequence label, String packageName, int id, long time, boolean ongoing, String template, boolean removed, String title, String text, String subText, String titleBig, String textBig, boolean progressIndeterminate, int progressMax, int progress, int dnd) throws JSONException {
JSONObject body = new JSONObject();

body.put("label", label);
Expand All @@ -47,6 +47,7 @@ public static JSONObject makeBody(CharSequence label, String packageName, int id
body.put("progress_indeterminate", progressIndeterminate);
body.put("progress_max", progressMax);
body.put("progress", progress);
body.put("dnd", dnd);

return body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

public class Preferences {

private SharedPreferences.OnSharedPreferenceChangeListener mEnabledPackagesListener; //strong reference to avoid garbage collection
private SharedPreferences.OnSharedPreferenceChangeListener mServersListener; //strong reference to avoid garbage collection

public interface PreferencesListener<T> {
void onChange(T value);
}
Expand Down Expand Up @@ -57,10 +60,11 @@ public void setServiceEnabled(boolean enabled) {

public HashMap<String, Integer> getEnabledPackages(PreferencesListener<HashMap<String, Integer>> listener) {
if (listener != null) {
mSharedPreferences.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
mEnabledPackagesListener = (sharedPreferences, key) -> {
if (ENABLED_PACKAGES_KEY.equals(key))
listener.onChange(loadEnabledPackages());
});
};
mSharedPreferences.registerOnSharedPreferenceChangeListener(mEnabledPackagesListener);
}
return loadEnabledPackages();
}
Expand All @@ -76,10 +80,11 @@ public void setEnabledPackages(HashMap<String, Integer> enabledPackages) {

public List<ServerInfo> getServers(PreferencesListener<List<ServerInfo>> listener) {
if (listener != null) {
mSharedPreferences.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
mServersListener = (sharedPreferences, key) -> {
if (SERVERS_KEY.equals(key))
listener.onChange(loadServers());
});
};
mSharedPreferences.registerOnSharedPreferenceChangeListener(mServersListener);
}
return loadServers();
}
Expand Down

0 comments on commit 78cc7ac

Please sign in to comment.