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

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>