From 748d2bc8634e6827e57f0b7bda9e3ef4bacabbcd Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Tue, 22 Mar 2016 02:12:59 -0400 Subject: [PATCH 1/2] fix FlattrServiceCreator --- .../core/util/flattr/FlattrServiceCreator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java index e4818214e..e09b6642e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java @@ -1,11 +1,13 @@ package de.danoeh.antennapod.core.util.flattr; import android.util.Log; -import de.danoeh.antennapod.core.BuildConfig; + import org.shredzone.flattr4j.FlattrFactory; import org.shredzone.flattr4j.FlattrService; import org.shredzone.flattr4j.oauth.AccessToken; +import de.danoeh.antennapod.core.BuildConfig; + /** Ensures that only one instance of the FlattrService class exists at a time */ public class FlattrServiceCreator { @@ -14,7 +16,10 @@ public class FlattrServiceCreator { private static volatile FlattrService flattrService; public static FlattrService getService(AccessToken token) { - return FlattrFactory.getInstance().createFlattrService(token); + if (flattrService == null) { + flattrService = FlattrFactory.getInstance().createFlattrService(token); + } + return flattrService; } public static void deleteFlattrService() { From a7d00f952ca8d551210ec903d9348416c30fe755 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Tue, 22 Mar 2016 11:36:24 -0400 Subject: [PATCH 2/2] make FlattrService creation and deletion synchronized --- .../antennapod/core/util/flattr/FlattrServiceCreator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java index e09b6642e..97958eea7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java @@ -15,14 +15,14 @@ public class FlattrServiceCreator { private static volatile FlattrService flattrService; - public static FlattrService getService(AccessToken token) { + public synchronized static FlattrService getService(AccessToken token) { if (flattrService == null) { flattrService = FlattrFactory.getInstance().createFlattrService(token); } return flattrService; } - public static void deleteFlattrService() { + public synchronized static void deleteFlattrService() { if (BuildConfig.DEBUG) Log.d(TAG, "Deleting service instance"); flattrService = null; }