Skip to content

Commit

Permalink
app: v1.2.0
Browse files Browse the repository at this point in the history
- remove color format option -> send all
- added simple python server example
- fix crash when server edit
  • Loading branch information
Yanndroid committed Jul 1, 2024
1 parent 78cc7ac commit f009282
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 72 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ println("Locales: " + locales.join(', '))

android {
namespace 'de.dlyt.yanndroid.notifer'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "de.dlyt.yanndroid.notifer"
minSdk 26
targetSdk 33
versionCode 4
versionName "1.1.0"
targetSdk 34
versionCode 5
versionName "1.2.0"

resConfigs locales

Expand Down Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation 'io.github.oneuiproject.sesl:preference:1.1.0'
implementation("io.github.oneuiproject.sesl:picker-color:1.1.0")

implementation 'com.google.code.gson:gson:2.10'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.google.android.play:app-update:2.1.0'

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": 4,
"versionName": "1.1.0",
"versionCode": 5,
"versionName": "1.2.0",
"outputFile": "app-release.apk"
}
],
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/java/de/dlyt/yanndroid/notifer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,26 @@ private void sendTestNotification() {
List<Preferences.ServerInfo> mServers = new Preferences(mContext).getServers(null);

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,
NotificationManager.INTERRUPTION_FILTER_ALL);
Color.YELLOW,
getString(R.string.app_name),
mContext.getPackageName(),
0,
System.currentTimeMillis(),
false,
null,
false,
"Test Notification",
"This is a test notification",
null,
null,
null,
false,
0,
0,
NotificationManager.INTERRUPTION_FILTER_ALL
);

for (Preferences.ServerInfo mServer : mServers) {
body.put("color", ColorUtil.convertColor(Color.BLUE, mServer.colorFormat));
HttpRequest.post(mServer.url, body);
}
} catch (JSONException | NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ public ServerEditDialog(Context context, Preferences.ServerInfo serverInfo, Serv
View content = LayoutInflater.from(mContext).inflate(R.layout.dialog_edit_server, null);
AppCompatEditText serverName = content.findViewById(R.id.server_name);
AppCompatEditText serverUrl = content.findViewById(R.id.server_url);
AppCompatSpinner serverColorFormat = content.findViewById(R.id.server_color_format);

ArrayAdapter<ColorUtil.ColorFormat> adapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, ColorUtil.ColorFormat.values());
adapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item);
serverColorFormat.setAdapter(adapter);

if (serverInfo != null) {
serverName.setText(serverInfo.name);
serverUrl.setText(serverInfo.url);
serverColorFormat.setSelection(serverInfo.colorFormat.ordinal());
}

mDialog = new AlertDialog.Builder(context)
Expand All @@ -49,8 +43,7 @@ public ServerEditDialog(Context context, Preferences.ServerInfo serverInfo, Serv
if (serverInfo != null) listener.onReplaced(serverInfo);
listener.onAdd(new Preferences.ServerInfo(
serverName.getText().toString(),
serverUrl.getText().toString(),
ColorUtil.ColorFormat.values()[serverColorFormat.getSelectedItemPosition()]));
serverUrl.getText().toString()));
})
.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.HashMap;
import java.util.List;

import de.dlyt.yanndroid.notifer.utils.ColorUtil;
import de.dlyt.yanndroid.notifer.utils.HttpRequest;
import de.dlyt.yanndroid.notifer.utils.Preferences;

Expand Down Expand Up @@ -53,22 +52,18 @@ private void transmitNotification(StatusBarNotification sbn, boolean removed) {
String packageName = sbn.getPackageName();
if (mPreferences.isServiceEnabled() && mEnabledPackages.containsKey(packageName)) {
try {
JSONObject body = makeBody(sbn, removed);
JSONObject body = makeBody(sbn, mEnabledPackages.get(packageName), removed);

for (Preferences.ServerInfo mServer : mServers) {
body.put("color", ColorUtil.convertColor(
mEnabledPackages.get(packageName),
mServer.colorFormat));
HttpRequest.post(mServer.url, body);
}

} catch (JSONException | NullPointerException e) {
e.printStackTrace();
}
}
}

private JSONObject makeBody(StatusBarNotification sbn, boolean removed) throws JSONException, NullPointerException {
private JSONObject makeBody(StatusBarNotification sbn, int color, boolean removed) throws JSONException {
Bundle bundle = sbn.getNotification().extras;
String packageName = sbn.getPackageName();
CharSequence label;
Expand All @@ -81,6 +76,7 @@ private JSONObject makeBody(StatusBarNotification sbn, boolean removed) throws J
}

return HttpRequest.makeBody(
color,
label,
packageName,
sbn.getId(),
Expand Down
28 changes: 11 additions & 17 deletions app/src/main/java/de/dlyt/yanndroid/notifer/utils/ColorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@

public class ColorUtil {

public enum ColorFormat {
HEX, RGB, HSV, INT
public static String toRGB(int color) {
Color rgb = Color.valueOf(color);
return Arrays.toString(new int[]{(int) (rgb.red() * 255), (int) (rgb.green() * 255), (int) (rgb.blue() * 255)});
}

public static String convertColor(int color, ColorFormat format) {
switch (format) {
case HEX:
return String.format("#%06X", (0xFFFFFF & color));
case RGB:
Color rgb = Color.valueOf(color);
return Arrays.toString(new int[]{(int) (rgb.red() * 255), (int) (rgb.green() * 255), (int) (rgb.blue() * 255)});
case HSV:
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
return Arrays.toString(hsv);
case INT:
return String.valueOf(color);
}
return "";
public static String toHSV(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
return Arrays.toString(hsv);
}

public static String toHex(int color) {
return String.format("#%06X", (0xFFFFFF & color));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ 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, int dnd) throws JSONException {
public static JSONObject makeBody(int color, 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();

JSONObject colors = new JSONObject();
colors.put("hex", ColorUtil.toHex(color));
colors.put("rgb", ColorUtil.toRGB(color));
colors.put("hsv", ColorUtil.toHSV(color));
colors.put("int", color);

body.put("color", colors);
body.put("label", label);
body.put("package", packageName);
body.put("id", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ public interface PreferencesListener<T> {
public static class ServerInfo implements Comparable<ServerInfo> {
public String name;
public String url;
public ColorUtil.ColorFormat colorFormat;

public ServerInfo(String name, String url, ColorUtil.ColorFormat colorFormat) {
public ServerInfo(String name, String url) {
this.name = name;
this.url = url;
this.colorFormat = colorFormat;
}

@Override
Expand Down
23 changes: 1 addition & 22 deletions app/src/main/res/layout/dialog_edit_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,10 @@
android:id="@+id/server_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="15dp"
android:layout_marginTop="15dp"
android:hint="@string/server_url_hint"
android:lines="1" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/server_color_format"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/server_color_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>


</LinearLayout>

</ScrollView>
12 changes: 12 additions & 0 deletions server-example/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import http.server


class RequestHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
print(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8"))
self.send_response(200)
self.end_headers()


if __name__ == "__main__":
http.server.HTTPServer(("", 8000), RequestHandler).serve_forever()

0 comments on commit f009282

Please sign in to comment.