added priority to messages

This commit is contained in:
2018-10-20 14:57:05 +02:00
parent 3bb7386d72
commit 8b44df8636
20 changed files with 135 additions and 32 deletions

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