diff --git a/android/.idea/assetWizardSettings.xml b/android/.idea/assetWizardSettings.xml index 5aa074b..364e083 100644 --- a/android/.idea/assetWizardSettings.xml +++ b/android/.idea/assetWizardSettings.xml @@ -14,8 +14,8 @@ diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessage.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessage.java index 7b703f7..7dee2a8 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessage.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessage.java @@ -12,6 +12,7 @@ public class CMessage public final long Timestamp ; public final String Title; public final String Content; + public final PriorityEnum Priority; private static final SimpleDateFormat _format; static @@ -20,11 +21,12 @@ public class CMessage _format.setTimeZone(TimeZone.getDefault()); } - public CMessage(long t, String mt, String mc) + public CMessage(long t, String mt, String mc, PriorityEnum p) { Timestamp = t; Title = mt; Content = mc; + Priority = p; } @SuppressLint("SimpleDateFormat") diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessageList.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessageList.java index c5d51a1..a15fe5c 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessageList.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/CMessageList.java @@ -34,17 +34,18 @@ public class CMessageList int count = sharedPref.getInt("message_count", 0); for (int i=0; i < count; i++) { - long time = sharedPref.getLong("message["+i+"].timestamp", 0); - String title = sharedPref.getString("message["+i+"].title", ""); - String content = sharedPref.getString("message["+i+"].content", ""); + long time = sharedPref.getLong("message["+i+"].timestamp", 0); + String title = sharedPref.getString("message["+i+"].title", ""); + String content = sharedPref.getString("message["+i+"].content", ""); + PriorityEnum prio = PriorityEnum.parseAPI(sharedPref.getInt("message["+i+"].priority", 1)); - Messages.add(new CMessage(time, title, content)); + Messages.add(new CMessage(time, title, content, prio)); } } - public CMessage add(final long time, final String title, final String content) + public CMessage add(final long time, final String title, final String content, final PriorityEnum pe) { - CMessage msg = new CMessage(time, title, content); + CMessage msg = new CMessage(time, title, content, pe); boolean run = SCNApp.runOnUiThread(() -> { @@ -58,6 +59,7 @@ public class CMessageList e.putLong("message["+count+"].timestamp", time); e.putString("message["+count+"].title", title); e.putString("message["+count+"].content", content); + e.putInt("message["+count+"].priority", pe.ID); e.apply(); @@ -72,7 +74,7 @@ public class CMessageList if (!run) { - Messages.add(new CMessage(time, title, content)); + Messages.add(new CMessage(time, title, content, pe)); fullSave(); } @@ -107,6 +109,7 @@ public class CMessageList e.putLong("message["+i+"].timestamp", Messages.get(i).Timestamp); e.putString("message["+i+"].title", Messages.get(i).Title); e.putString("message["+i+"].content", Messages.get(i).Content); + e.putInt("message["+i+"].priority", Messages.get(i).Priority.ID); } e.apply(); diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/PriorityEnum.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/PriorityEnum.java new file mode 100644 index 0000000..acc53f5 --- /dev/null +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/PriorityEnum.java @@ -0,0 +1,30 @@ +package com.blackforestbytes.simplecloudnotifier.model; + +public enum PriorityEnum +{ + LOW(0), + NORMAL(1), + HIGH(2); + + public final int ID; + + PriorityEnum(int id) { ID = id; } + + public static PriorityEnum parseAPI(String v) throws Exception + { + for (PriorityEnum p : values()) + { + if (String.valueOf(p.ID).equals(v.trim())) return p; + } + throw new Exception("Invalid value for : '"+v+"'"); + } + + public static PriorityEnum parseAPI(int v) + { + for (PriorityEnum p : values()) + { + if (p.ID == v) return p; + } + return PriorityEnum.NORMAL; + } +} diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java index b8299f3..1691f4e 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java @@ -1,10 +1,8 @@ package com.blackforestbytes.simplecloudnotifier.model; -import android.os.Build; import android.util.Log; import android.view.View; -import com.blackforestbytes.simplecloudnotifier.BuildConfig; import com.blackforestbytes.simplecloudnotifier.SCNApp; import org.json.JSONObject; diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/FBMService.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/FBMService.java index 6bf4dfe..083938d 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/FBMService.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/FBMService.java @@ -12,6 +12,7 @@ import com.blackforestbytes.simplecloudnotifier.R; import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.model.CMessage; import com.blackforestbytes.simplecloudnotifier.model.CMessageList; +import com.blackforestbytes.simplecloudnotifier.model.PriorityEnum; import com.blackforestbytes.simplecloudnotifier.model.SCNSettings; import com.blackforestbytes.simplecloudnotifier.view.MainActivity; import com.google.firebase.messaging.FirebaseMessagingService; @@ -36,11 +37,12 @@ public class FBMService extends FirebaseMessagingService if (remoteMessage.getNotification() != null) Log.i("FB::MessageReceived", "Notify_Title: " + remoteMessage.getNotification().getTitle()); if (remoteMessage.getNotification() != null) Log.i("FB::MessageReceived", "Notify_Body: " + remoteMessage.getNotification().getBody()); - long time = Long.parseLong(remoteMessage.getData().get("timestamp")); - String title = remoteMessage.getData().get("title"); - String content = remoteMessage.getData().get("body"); + long time = Long.parseLong(remoteMessage.getData().get("timestamp")); + String title = remoteMessage.getData().get("title"); + String content = remoteMessage.getData().get("body"); + PriorityEnum prio = PriorityEnum.parseAPI(remoteMessage.getData().get("priority")); - CMessage msg = CMessageList.inst().add(time, title, content); + CMessage msg = CMessageList.inst().add(time, title, content, prio); if (SCNApp.isBackground()) diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/NotificationService.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/NotificationService.java index 2c03d02..eba12df 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/NotificationService.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/service/NotificationService.java @@ -12,7 +12,6 @@ import android.support.v4.app.NotificationCompat; import com.blackforestbytes.simplecloudnotifier.R; import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.model.CMessage; -import com.blackforestbytes.simplecloudnotifier.model.CMessageList; import com.blackforestbytes.simplecloudnotifier.view.MainActivity; public class NotificationService diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java index 2613b31..e7dae33 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java @@ -5,6 +5,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -64,6 +65,7 @@ public class MessageAdapter extends RecyclerView.Adapter private TextView tvTimestamp; private TextView tvTitle; private TextView tvMessage; + private ImageView ivPriority; private CMessage data; @@ -71,8 +73,9 @@ public class MessageAdapter extends RecyclerView.Adapter { super(itemView); tvTimestamp = itemView.findViewById(R.id.tvTimestamp); - tvTitle = itemView.findViewById(R.id.tvTitle); - tvMessage = itemView.findViewById(R.id.tvMessage); + tvTitle = itemView.findViewById(R.id.tvTitle); + tvMessage = itemView.findViewById(R.id.tvMessage); + ivPriority = itemView.findViewById(R.id.ivPriority); itemView.setOnClickListener(this); } @@ -81,6 +84,22 @@ public class MessageAdapter extends RecyclerView.Adapter tvTimestamp.setText(msg.formatTimestamp()); tvTitle.setText(msg.Title); tvMessage.setText(msg.Content); + + switch (msg.Priority) + { + case LOW: + ivPriority.setVisibility(View.VISIBLE); + ivPriority.setImageResource(R.drawable.priority_low); + break; + case NORMAL: + ivPriority.setVisibility(View.GONE); + break; + case HIGH: + ivPriority.setVisibility(View.VISIBLE); + ivPriority.setImageResource(R.drawable.priority_high); + break; + } + data = msg; } diff --git a/android/app/src/main/res/drawable/priority_high.xml b/android/app/src/main/res/drawable/priority_high.xml new file mode 100644 index 0000000..c41aa3a --- /dev/null +++ b/android/app/src/main/res/drawable/priority_high.xml @@ -0,0 +1,9 @@ + + + diff --git a/android/app/src/main/res/drawable/priority_low.xml b/android/app/src/main/res/drawable/priority_low.xml new file mode 100644 index 0000000..24e0941 --- /dev/null +++ b/android/app/src/main/res/drawable/priority_low.xml @@ -0,0 +1,9 @@ + + + diff --git a/android/app/src/main/res/layout/message_card.xml b/android/app/src/main/res/layout/message_card.xml index 5017836..849afd1 100644 --- a/android/app/src/main/res/layout/message_card.xml +++ b/android/app/src/main/res/layout/message_card.xml @@ -15,7 +15,7 @@ @@ -28,6 +28,7 @@ app:layout_constraintRight_toRightOf="parent" android:textSize="12sp" android:textStyle="italic" + android:text="2018-09-11 20:22:32" /> + android:text="asdasd asdasd asdasd a" /> + + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 1318ba0..4b59520 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -14,4 +14,5 @@ No notifications not connected reload + Priority icon diff --git a/android/build.gradle b/android/build.gradle index 1691445..733a50a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/web/css/style.css b/web/css/style.css index 29752b2..2325942 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -27,7 +27,7 @@ body min-width: 300px; max-width: 900px; position: relative; - min-height: 445px; + min-height: 485px; } #mainpnl input, diff --git a/web/index.php b/web/index.php index 60a0377..858ddde 100644 --- a/web/index.php +++ b/web/index.php @@ -4,7 +4,7 @@ Simple Cloud Notifications - + @@ -28,6 +28,17 @@
type="text" maxlength="64">
+
+
+
+ +
+
+
type="text" maxlength="80">
diff --git a/web/index_api.php b/web/index_api.php index 0213a7d..a2717af 100644 --- a/web/index_api.php +++ b/web/index_api.php @@ -20,10 +20,11 @@
curl                                          \
     --data "user_id={userid}"                 \
     --data "user_key={userkey}"               \
+    --data "priority={0|1|2}"                 \
     --data "title={message_title}"            \
     --data "content={message_content}"        \
     https://scn.blackforestbytes.com/send.php
-

The content parameter is optional, you can also send message with only a title

+

The content and priority parameters are optional, you can also send message with only a title and the default priority

curl                                          \
     --data "user_id={userid}"                 \
     --data "user_key={userkey}"               \
diff --git a/web/info.php b/web/info.php
index a1b5980..ac3cb10 100644
--- a/web/info.php
+++ b/web/info.php
@@ -19,7 +19,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, quota_max, quota_d
 $stmt->execute(['uid' => $user_id]);
 
 $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
-if (count($datas)<=0) die(json_encode(['success' => false, 'errid'=>201, 'message' => 'No User found']));
+if (count($datas)<=0) die(json_encode(['success' => false, 'errid'=>201, 'message' => 'User not found']));
 $data = $datas[0];
 
 if ($data === null) die(json_encode(['success' => false, 'errid'=>202, 'message' => 'User not found']));
diff --git a/web/js/logic.js b/web/js/logic.js
index c23fcab..1b6e560 100644
--- a/web/js/logic.js
+++ b/web/js/logic.js
@@ -12,17 +12,20 @@ function send()
 	let key = document.getElementById("ukey");
 	let msg = document.getElementById("msg");
 	let txt = document.getElementById("txt");
+	let pio = document.getElementById("prio");
 
 	uid.classList.remove('input-invalid');
 	key.classList.remove('input-invalid');
 	msg.classList.remove('input-invalid');
 	txt.classList.remove('input-invalid');
+	pio.classList.remove('input-invalid');
 
 	let data = new FormData();
 	data.append('user_id', uid.value);
 	data.append('user_key', key.value);
 	data.append('title', msg.value);
 	data.append('content', txt.value);
+	data.append('priority', pio.value);
 
 	let xhr = new XMLHttpRequest();
 	xhr.open('POST', '/send.php', true);
@@ -40,6 +43,7 @@ function send()
 				if (resp.errhighlight === 102) key.classList.add('input-invalid');
 				if (resp.errhighlight === 103) msg.classList.add('input-invalid');
 				if (resp.errhighlight === 104) txt.classList.add('input-invalid');
+				if (resp.errhighlight === 105) pio.classList.add('input-invalid');
 
 				Toastify({
 					text: resp.message,
diff --git a/web/send.php b/web/send.php
index 6666030..1b54ce9 100644
--- a/web/send.php
+++ b/web/send.php
@@ -17,11 +17,13 @@ if (!isset($INPUT['title']))    die(json_encode(['success' => false, 'errhighlig
 $user_id  = $INPUT['user_id'];
 $user_key = $INPUT['user_key'];
 $message  = $INPUT['title'];
-$content  = $INPUT['content'];
-if ($content === null || $content === false) $content = '';
+$content  = isset($INPUT['content'])  ? $INPUT['content']  : '';
+$priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1';
 
 //------------------------------------------------------------------
 
+if ($priority !== '0' && $priority !== '1' && $priority !== '2') die(json_encode(['success' => false, 'errhighlight' => 105, 'message' => 'Invalid priority']));
+
 if (strlen(trim($message)) == 0) die(json_encode(['success' => false, 'errhighlight' => 103, 'message' => 'No title specified']));
 if (strlen($message) > 120)      die(json_encode(['success' => false, 'errhighlight' => 103, 'message' => 'Title too long (120 characters)']));
 if (strlen($content) > 10000)    die(json_encode(['success' => false, 'errhighlight' => 104, 'message' => 'Content too long (10000 characters)']));
@@ -34,7 +36,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, fcm_token, messages_sent, quota
 $stmt->execute(['uid' => $user_id]);
 
 $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
-if (count($datas)<=0) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'No User found']));
+if (count($datas)<=0) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'User not found']));
 $data = $datas[0];
 
 if ($data === null) die(json_encode(['success' => false, 'errhighlight' => 101, 'message' => 'User not found']));
@@ -64,6 +66,7 @@ $payload = json_encode(
 	[
 		'title' => $message,
 		'body' => $content,
+		'priority' => $priority,
 		'timestamp' => time(),
 	]
 ]);
diff --git a/web/update.php b/web/update.php
index 3ea19c6..2b95aad 100644
--- a/web/update.php
+++ b/web/update.php
@@ -20,7 +20,7 @@ $stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, quota_max, quota_d
 $stmt->execute(['uid' => $user_id]);
 
 $datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
-if (count($datas)<=0) die(json_encode(['success' => false, 'message' => 'No User found']));
+if (count($datas)<=0) die(json_encode(['success' => false, 'message' => 'User not found']));
 $data = $datas[0];
 
 if ($data === null) die(json_encode(['success' => false, 'message' => 'User not found']));