Commit 559d938a by Sebastián Katzer

Dont reset chronometer when updating progressbar [fixes #1459]

parent c4fa11b7
...@@ -28,7 +28,6 @@ import de.appplant.cordova.plugin.notification.receiver.AbstractClearReceiver; ...@@ -28,7 +28,6 @@ import de.appplant.cordova.plugin.notification.receiver.AbstractClearReceiver;
import static de.appplant.cordova.plugin.notification.Request.EXTRA_LAST; import static de.appplant.cordova.plugin.notification.Request.EXTRA_LAST;
/** /**
* The clear intent receiver is triggered when the user clears a * The clear intent receiver is triggered when the user clears a
* notification manually. It un-persists the cleared notification from the * notification manually. It un-persists the cleared notification from the
......
...@@ -56,6 +56,7 @@ import static de.appplant.cordova.plugin.notification.Notification.Type.TRIGGERE ...@@ -56,6 +56,7 @@ import static de.appplant.cordova.plugin.notification.Notification.Type.TRIGGERE
* care of firing the event. When the event is processed, a notification is put * care of firing the event. When the event is processed, a notification is put
* in the Android notification center and status bar. * in the Android notification center and status bar.
*/ */
@SuppressWarnings({"Convert2Diamond", "Convert2Lambda"})
public class LocalNotification extends CordovaPlugin { public class LocalNotification extends CordovaPlugin {
// Reference to the web view for static access // Reference to the web view for static access
......
...@@ -31,6 +31,7 @@ import android.support.v4.app.NotificationCompat; ...@@ -31,6 +31,7 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.MessagingStyle.Message; import android.support.v4.app.NotificationCompat.MessagingStyle.Message;
import android.support.v4.media.app.NotificationCompat.MediaStyle; import android.support.v4.media.app.NotificationCompat.MediaStyle;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import android.util.SparseArray;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
...@@ -45,8 +46,12 @@ import static de.appplant.cordova.plugin.notification.Notification.EXTRA_UPDATE; ...@@ -45,8 +46,12 @@ import static de.appplant.cordova.plugin.notification.Notification.EXTRA_UPDATE;
* Builder class for local notifications. Build fully configured local * Builder class for local notifications. Build fully configured local
* notification specified by JSON object passed from JS side. * notification specified by JSON object passed from JS side.
*/ */
@SuppressWarnings("Convert2Diamond")
public final class Builder { public final class Builder {
// Cache for the builder instances
private static SparseArray<NotificationCompat.Builder> cache = null;
// Application context passed by constructor // Application context passed by constructor
private final Context context; private final Context context;
...@@ -123,7 +128,7 @@ public final class Builder { ...@@ -123,7 +128,7 @@ public final class Builder {
extras.putInt(Notification.EXTRA_ID, options.getId()); extras.putInt(Notification.EXTRA_ID, options.getId());
extras.putString(Options.EXTRA_SOUND, sound.toString()); extras.putString(Options.EXTRA_SOUND, sound.toString());
builder = new NotificationCompat.Builder(context, Manager.CHANNEL_ID) builder = findOrCreateBuilder()
.setDefaults(options.getDefaults()) .setDefaults(options.getDefaults())
.setExtras(extras) .setExtras(extras)
.setOnlyAlertOnce(false) .setOnlyAlertOnce(false)
...@@ -148,6 +153,7 @@ public final class Builder { ...@@ -148,6 +153,7 @@ public final class Builder {
} }
if (options.isWithProgressBar()) { if (options.isWithProgressBar()) {
cacheBuilder(builder);
builder.setProgress( builder.setProgress(
options.getProgressMaxValue(), options.getProgressMaxValue(),
options.getProgressValue(), options.getProgressValue(),
...@@ -406,4 +412,35 @@ public final class Builder { ...@@ -406,4 +412,35 @@ public final class Builder {
return extras != null && extras.getBoolean(EXTRA_UPDATE, false); return extras != null && extras.getBoolean(EXTRA_UPDATE, false);
} }
/**
* Returns a cached builder instance or creates a new one.
*/
private NotificationCompat.Builder findOrCreateBuilder() {
NotificationCompat.Builder builder = null;
int key = options.getId();
if (cache != null) {
builder = cache.get(key);
}
if (builder == null) {
builder = new NotificationCompat.Builder(context, Manager.CHANNEL_ID);
}
return builder;
}
/**
* Caches the builder instance so it can be used later.
*
* @param builder The instance to cache.
*/
private void cacheBuilder (NotificationCompat.Builder builder) {
if (cache == null) {
cache = new SparseArray<NotificationCompat.Builder>();
}
cache.put(options.getId(), builder);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment