3 Commits

Author SHA1 Message Date
ac681065fa billing permission 2018-11-11 19:36:58 +01:00
90d8b46179 actually use settings 2018-10-22 16:29:37 +02:00
jenkins
280b5ca4aa [Jenkins] Increment version 2018-10-22 15:29:28 +02:00
8 changed files with 137 additions and 33 deletions

View File

@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.blackforestbytes.simplecloudnotifier">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="false"

View File

@@ -97,3 +97,33 @@ public class SCNApp extends Application implements LifecycleObserver
isBackground = false;
}
}
/*
==TODO==
- Pro mode
- no ads
- more quota
- restore pro mode
- send pro state to server
- prevent duplicate-send
- send custom msg-id in API
- prevent second ack on same msg-id
- more in-depth API doc on website (?)
- perhaps response codes in api (?)
- test notification channels
- publish (+ HN post ?)
- Use for mscom server errrors
- Use for bfb server errors
- Use for transmission state
- Message on connnection lost (seperate process - resend until succ)
- Message on connnection regained
- Message on seed-count changed
*/

View File

@@ -55,6 +55,9 @@ public class CMessageList
SharedPreferences.Editor e = sharedPref.edit();
Messages.add(msg);
while (Messages.size()>SCNSettings.inst().LocalCacheSize) Messages.remove(0);
e.putInt("message_count", count+1);
e.putLong("message["+count+"].timestamp", time);
e.putString("message["+count+"].title", title);

View File

@@ -25,6 +25,8 @@ public class FBMService extends FirebaseMessagingService
{
try
{
if (!SCNSettings.inst().Enabled) return;
Log.i("FB::MessageReceived", "From: " + remoteMessage.getFrom());
Log.i("FB::MessageReceived", "Payload: " + remoteMessage.getData());
if (remoteMessage.getNotification() != null) Log.i("FB::MessageReceived", "Notify_Title: " + remoteMessage.getNotification().getTitle());
@@ -40,11 +42,11 @@ public class FBMService extends FirebaseMessagingService
if (SCNApp.isBackground())
{
NotificationService.inst().show(msg);
NotificationService.inst().showBackground(msg);
}
else
{
SCNApp.showToast("Message recieved: " + title, Toast.LENGTH_LONG);
NotificationService.inst().showForeground(msg);
}
}
catch (Exception e)

View File

@@ -1,23 +1,33 @@
package com.blackforestbytes.simplecloudnotifier.service;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.widget.Toast;
import com.blackforestbytes.simplecloudnotifier.R;
import com.blackforestbytes.simplecloudnotifier.SCNApp;
import com.blackforestbytes.simplecloudnotifier.model.CMessage;
import com.blackforestbytes.simplecloudnotifier.model.NotificationSettings;
import com.blackforestbytes.simplecloudnotifier.model.PriorityEnum;
import com.blackforestbytes.simplecloudnotifier.model.SCNSettings;
import com.blackforestbytes.simplecloudnotifier.view.MainActivity;
import androidx.core.app.NotificationCompat;
public class NotificationService
{
private final static String CHANNEL_ID = "CHAN_BFB_SCN_MESSAGES";
private final static String CHANNEL_ID_LOW = "CHAN_BFB_SCN_MESSAGES_LOW";
private final static String CHANNEL_ID_NORM = "CHAN_BFB_SCN_MESSAGES_NORM";
private final static String CHANNEL_ID_HIGH = "CHAN_BFB_SCN_MESSAGES_HIGH";
private final static Object _lock = new Object();
private static NotificationService _inst = null;
@@ -32,39 +42,92 @@ public class NotificationService
private NotificationService()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
updateChannels();
}
public void updateChannels()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
Context ctxt = SCNApp.getContext();
NotificationManager notifman = ctxt.getSystemService(NotificationManager.class);
if (notifman == null) return;
NotificationChannel channelLow = notifman.getNotificationChannel(CHANNEL_ID_LOW);
if (channelLow == null) notifman.createNotificationChannel(channelLow = new NotificationChannel(CHANNEL_ID_LOW, "Push notifications (low priority)", NotificationManager.IMPORTANCE_LOW));
NotificationChannel channelNorm = notifman.getNotificationChannel(CHANNEL_ID_NORM);
if (channelNorm == null) notifman.createNotificationChannel(channelNorm = new NotificationChannel(CHANNEL_ID_NORM, "Push notifications (normal priority)", NotificationManager.IMPORTANCE_DEFAULT));
NotificationChannel channelHigh = notifman.getNotificationChannel(CHANNEL_ID_HIGH);
if (channelHigh == null) notifman.createNotificationChannel(channelHigh = new NotificationChannel(CHANNEL_ID_HIGH, "Push notifications (high priority)", NotificationManager.IMPORTANCE_HIGH));
channelLow.setDescription("Messages from the API with priority set to low");
channelLow.enableLights(SCNSettings.inst().PriorityLow.EnableLED);
channelLow.setLightColor(SCNSettings.inst().PriorityLow.LEDColor);
channelLow.enableVibration(SCNSettings.inst().PriorityLow.EnableVibration);
channelLow.setVibrationPattern(new long[]{200});
channelNorm.setDescription("Messages from the API with priority set to normal");
channelNorm.enableLights(SCNSettings.inst().PriorityNorm.EnableLED);
channelNorm.setLightColor(SCNSettings.inst().PriorityNorm.LEDColor);
channelNorm.enableVibration(SCNSettings.inst().PriorityNorm.EnableVibration);
channelNorm.setVibrationPattern(new long[]{200});
channelHigh.setDescription("Messages from the API with priority set to high");
channelHigh.enableLights(SCNSettings.inst().PriorityHigh.EnableLED);
channelHigh.setLightColor(SCNSettings.inst().PriorityHigh.LEDColor);
channelHigh.enableVibration(SCNSettings.inst().PriorityHigh.EnableVibration);
channelHigh.setVibrationPattern(new long[]{200});
channelLow.setBypassDnd(true);
channelLow.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
}
public void showForeground(CMessage msg)
{
SCNApp.showToast("Message recieved: " + msg.Title, Toast.LENGTH_LONG);
}
public void showBackground(CMessage msg)
{
Context ctxt = SCNApp.getContext();
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Push notifications", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Messages from the API");
channel.setLightColor(Color.rgb(255, 0, 0));
channel.setVibrationPattern(new long[]{200});
channel.enableLights(true);
channel.enableVibration(true);
NotificationManager notificationManager = ctxt.getSystemService(NotificationManager.class);
if (notificationManager != null) notificationManager.createNotificationChannel(channel);
}
}
public void show(CMessage msg)
String channel = CHANNEL_ID_NORM;
NotificationSettings ns = SCNSettings.inst().PriorityNorm;
switch (msg.Priority)
{
Context ctxt = SCNApp.getContext();
case LOW: ns = SCNSettings.inst().PriorityLow; channel = CHANNEL_ID_LOW; break;
case NORMAL: ns = SCNSettings.inst().PriorityNorm; channel = CHANNEL_ID_NORM; break;
case HIGH: ns = SCNSettings.inst().PriorityHigh; channel = CHANNEL_ID_HIGH; break;
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctxt, channel);
mBuilder.setSmallIcon(R.drawable.ic_bfb);
mBuilder.setContentTitle(msg.Title);
mBuilder.setContentText(msg.Content);
mBuilder.setShowWhen(true);
mBuilder.setWhen(msg.Timestamp);
mBuilder.setAutoCancel(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
{
if (msg.Priority == PriorityEnum.LOW) mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
if (msg.Priority == PriorityEnum.NORMAL) mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if (msg.Priority == PriorityEnum.HIGH) mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
if (ns.EnableVibration) mBuilder.setVibrate(new long[]{200});
if (ns.EnableLED) mBuilder.setLights(ns.LEDColor, 500, 500);
}
if (ns.EnableSound && !ns.SoundSource.isEmpty())
{
mBuilder.setSound(Uri.parse(ns.SoundSource), AudioManager.STREAM_ALARM);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctxt, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_bfb)
.setContentTitle(msg.Title)
.setContentText(msg.Content)
.setShowWhen(true)
.setWhen(msg.Timestamp)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true);
Intent intent = new Intent(ctxt, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(ctxt, 0, intent, 0);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager = (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null) mNotificationManager.notify(0, mBuilder.build());
Notification n = mBuilder.build();
if (ns.EnableSound && !ns.SoundSource.isEmpty() && ns.RepeatSound) n.flags |= Notification.FLAG_INSISTENT;
if (mNotificationManager != null) mNotificationManager.notify(0, n);
}
}

View File

@@ -1,5 +1,6 @@
package com.blackforestbytes.simplecloudnotifier.view;
import android.app.NotificationManager;
import android.content.Context;
import android.media.AudioManager;
import android.net.Uri;
@@ -17,6 +18,7 @@ import android.widget.TextView;
import com.blackforestbytes.simplecloudnotifier.R;
import com.blackforestbytes.simplecloudnotifier.model.SCNSettings;
import com.blackforestbytes.simplecloudnotifier.service.NotificationService;
import org.jetbrains.annotations.NotNull;
@@ -190,6 +192,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener
{
SCNSettings.inst().save();
updateUI();
NotificationService.inst().updateChannels();
}
private void onUpgradeAccount()

View File

@@ -63,6 +63,7 @@
<ImageView
android:id="@+id/ivPriority"
android:tint="#BBB"
android:visibility="gone"
android:layout_width="24dp"
android:layout_height="24dp"

View File

@@ -1,3 +1,3 @@
#Sat Oct 20 18:59:02 CEST 2018
VERSION_NAME=0.0.3
VERSION_CODE=3
#Mon Oct 22 15:29:01 CEST 2018
VERSION_NAME=0.0.4
VERSION_CODE=4