Last active
December 1, 2016 17:15
-
-
Save paulocoutinhox/66c5a221d553a89d1e801cb37f6446a9 to your computer and use it in GitHub Desktop.
CustomerSystemService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Criar: canListenProduct | |
Criar: canDownloadProduct | |
Esses métodos conterão todas as regras de negócio e deverão no final de cada regra chamar o callback necessário. | |
No método canListen, por exemplo, você pode criar um callback para quando o usuário deve ouvir o preview, ouvir normal ou no ouvir porque ele no tem a library necessária. | |
--> canListenPreview | |
--> canListenNormal | |
--> doesNotHaveTheNecessaryLibrary | |
*/ | |
public static void canAccessProduct(final MyProduct myProduct, final CanAccessProductListener listener) { | |
if (myProduct == null) { | |
if (listener != null) { | |
listener.onProductInvalid(); | |
} | |
} else { | |
Product product = ProductService.createFromMyProduct(myProduct); | |
canAccessProduct(product, listener); | |
} | |
} | |
public static void canAccessProduct(final Product product, final CanAccessProductListener listener) { | |
if (product == null) { | |
if (listener != null) { | |
listener.onProductInvalid(); | |
} | |
} else { | |
if (UserData.isLoggedWithSubscriptionActive()) { | |
if (listener != null) { | |
listener.onSuccess(product); | |
} | |
} else if (product.isFreeContent() && UserData.isLoggedIn()) { | |
if (listener != null) { | |
listener.onSuccess(product); | |
} | |
} else if (!UserData.isLoggedIn()) { | |
if (listener != null) { | |
listener.onCustomerNotLogged(); | |
} | |
} else if (!UserData.isLoggedAndHasSubscription()) { | |
if (listener != null) { | |
listener.onCustomerNotSubscriber(); | |
} | |
} else if (UserData.isLoggedWithSubscriptionExpired()) { | |
if (listener != null) { | |
listener.onCustomerSubscriptionExpired(); | |
} | |
} | |
} | |
} | |
public interface CanAccessProductListener { | |
void onSuccess(final Product product); | |
void onProductInvalid(); | |
void onCustomerNotLogged(); | |
void onCustomerNotSubscriber(); | |
void onCustomerSubscriptionExpired(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment