added priority to messages

This commit is contained in:
Mike Schwörer 2018-10-20 14:57:05 +02:00
parent 3bb7386d72
commit 8b44df8636
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
20 changed files with 135 additions and 32 deletions

View File

@ -14,8 +14,8 @@
<option name="values">
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_refresh" />
<entry key="sourceFile" value="C:\Users\Mike\Downloads\if_refresh_383083.svg" />
<entry key="outputName" value="priority_low" />
<entry key="sourceFile" value="C:\Users\Mike\Downloads\Low Priority-595b40b75ba036ed117d9842.svg" />
</map>
</option>
</PersistentState>

View File

@ -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")

View File

@ -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();

View File

@ -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 <PriorityEnum> : '"+v+"'");
}
public static PriorityEnum parseAPI(int v)
{
for (PriorityEnum p : values())
{
if (p.ID == v) return p;
}
return PriorityEnum.NORMAL;
}
}

View File

@ -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;

View File

@ -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())

View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M21.4,10.6l-8,-8c-0.8,-0.8 -2,-0.8 -2.8,0l-8,8c-0.8,0.8 -0.8,2 0,2.8l8,8c0.8,0.8 2,0.8 2.8,0l8,-8C22.2,12.6 22.2,11.4 21.4,10.6zM13,17h-2v-2h2V17zM13,13h-2V7h2V13z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M21.4,10.6l-8,-8c-0.8,-0.8 -2,-0.8 -2.8,0l-8,8c-0.8,0.8 -0.8,2 0,2.8l8,8c0.8,0.8 2,0.8 2.8,0l8,-8C22.2,12.6 22.2,11.4 21.4,10.6zM12,17l-3,-3h2V7h2v7h2L12,17z"/>
</vector>

View File

@ -15,7 +15,7 @@
<android.support.constraint.ConstraintLayout
android:background="@color/cardview_light_background"
android:background="#FFFFFFFF"
android:layout_margin="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -28,6 +28,7 @@
app:layout_constraintRight_toRightOf="parent"
android:textSize="12sp"
android:textStyle="italic"
android:text="2018-09-11 20:22:32" />
<TextView
@ -37,7 +38,6 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tvTimestamp"
android:layout_marginRight="4sp"
android:layout_marginEnd="4sp"
android:textSize="16sp"
android:textColor="@color/colorBlack"
@ -52,14 +52,26 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/tvTitle"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toLeftOf="@+id/ivPriority"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_margin="4sp"
android:ellipsize="none"
android:maxLines="32"
android:scrollHorizontally="false"
android:text="asdasd asdasd asd asd a" />
android:text="asdasd asdasd asdasd a" />
<ImageView
android:id="@+id/ivPriority"
android:visibility="gone"
android:layout_width="24dp"
android:layout_height="24dp"
app:layout_constraintTop_toBottomOf="@+id/tvTimestamp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_margin="4sp"
android:paddingTop="3dp"
android:contentDescription="@string/desc_priority_icon" />
</android.support.constraint.ConstraintLayout>

View File

@ -14,4 +14,5 @@
<string name="no_notifications">No notifications</string>
<string name="str_not_connected">not connected</string>
<string name="str_reload">reload</string>
<string name="desc_priority_icon">Priority icon</string>
</resources>

View File

@ -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

View File

@ -27,7 +27,7 @@ body
min-width: 300px;
max-width: 900px;
position: relative;
min-height: 445px;
min-height: 485px;
}
#mainpnl input,

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Simple Cloud Notifications</title>
<link rel="stylesheet" href="/css/toastify.min.css"/>
<link rel="stylesheet" href="/css/mini-default.min.css">
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/ -->
<!--<link rel="stylesheet" href="/css/mini-nord.min.css">-->
<!--<link rel="stylesheet" href="/css/mini-dark.min.css">-->
<link rel="stylesheet" href="/css/style.css">
@ -28,6 +28,17 @@
<div class="col-sm-12 col-md"><input placeholder="Key" id="ukey" class="doc" <?php echo (isset($_GET['preset_user_key']) ? (' value="'.$_GET['preset_user_key'].'" '):(''));?> type="text" maxlength="64"></div>
</div>
<div class="row responsive-label">
<div class="col-sm-12 col-md-3"><label for="prio" class="doc">Priority</label></div>
<div class="col-sm-12 col-md">
<select id="prio" class="doc" type="text" style="width:100%;">
<option value="0" <?php echo (( isset($_GET['preset_priority'])&&$_GET['preset_priority']==='0') ? 'selected':'');?>>Low</option>
<option value="1" <?php echo ((!isset($_GET['preset_priority'])||$_GET['preset_priority']==='1') ? 'selected':'');?>>Normal</option>
<option value="2" <?php echo (( isset($_GET['preset_priority'])&&$_GET['preset_priority']==='2') ? 'selected':'');?>>High</option>
</select>
</div>
</div>
<div class="row responsive-label">
<div class="col-sm-12 col-md-3"><label for="msg" class="doc">Message Title</label></div>
<div class="col-sm-12 col-md"><input placeholder="Message" id="msg" class="doc" <?php echo (isset($_GET['preset_title']) ? (' value="'.$_GET['preset_title'].'" '):(''));?> type="text" maxlength="80"></div>

View File

@ -20,10 +20,11 @@
<pre>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</pre>
<p>The <code>content</code> parameter is optional, you can also send message with only a title</p>
<p>The <code>content</code> and <code>priority</code> parameters are optional, you can also send message with only a title and the default priority</p>
<pre>curl \
--data "user_id={userid}" \
--data "user_key={userkey}" \

View File

@ -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']));

View File

@ -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,

View File

@ -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(),
]
]);

View File

@ -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']));