-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from eggheadgames/improve-library-usability
Improve library usability
- Loading branch information
Showing
7 changed files
with
215 additions
and
195 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.billing | ||
|
||
import android.app.Activity | ||
import android.os.Handler | ||
import android.os.Looper | ||
import androidx.annotation.CallSuper | ||
|
||
abstract class BillingService { | ||
|
||
private val purchaseServiceListeners: MutableList<PurchaseServiceListener> = mutableListOf() | ||
private val subscriptionServiceListeners: MutableList<SubscriptionServiceListener> = mutableListOf() | ||
|
||
fun addPurchaseListener(purchaseServiceListener: PurchaseServiceListener) { | ||
purchaseServiceListeners.add(purchaseServiceListener) | ||
} | ||
|
||
fun removePurchaseListener(purchaseServiceListener: PurchaseServiceListener) { | ||
purchaseServiceListeners.remove(purchaseServiceListener) | ||
} | ||
|
||
fun addSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { | ||
subscriptionServiceListeners.add(subscriptionServiceListener) | ||
} | ||
|
||
fun removeSubscriptionListener(subscriptionServiceListener: SubscriptionServiceListener) { | ||
subscriptionServiceListeners.remove(subscriptionServiceListener) | ||
} | ||
|
||
/** | ||
* @param sku - product specificator | ||
* @param isRestore - a flag indicating whether it's a fresh purchase or restored product | ||
*/ | ||
fun productOwned(sku: String?, isRestore: Boolean) { | ||
findUiHandler().post { | ||
productOwnedInternal(sku, isRestore) | ||
} | ||
} | ||
|
||
fun productOwnedInternal(sku: String?, isRestore: Boolean) { | ||
for (purchaseServiceListener in purchaseServiceListeners) { | ||
if (isRestore) { | ||
purchaseServiceListener.onProductRestored(sku) | ||
} else { | ||
purchaseServiceListener.onProductPurchased(sku) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param sku - subscription specificator | ||
* @param isRestore - a flag indicating whether it's a fresh purchase or restored subscription | ||
*/ | ||
fun subscriptionOwned(sku: String, isRestore: Boolean) { | ||
findUiHandler().post { | ||
subscriptionOwnedInternal(sku, isRestore) | ||
} | ||
} | ||
|
||
fun subscriptionOwnedInternal(sku: String, isRestore: Boolean) { | ||
for (subscriptionServiceListener in subscriptionServiceListeners) { | ||
if (isRestore) { | ||
subscriptionServiceListener.onSubscriptionRestored(sku) | ||
} else { | ||
subscriptionServiceListener.onSubscriptionPurchased(sku) | ||
} | ||
} | ||
} | ||
|
||
fun updatePrices(iapkeyPrices: Map<String, String>) { | ||
findUiHandler().post { | ||
updatePricesInternal(iapkeyPrices) | ||
} | ||
} | ||
|
||
fun updatePricesInternal(iapkeyPrices: Map<String, String>) { | ||
for (billingServiceListener in purchaseServiceListeners) { | ||
billingServiceListener.onPricesUpdated(iapkeyPrices) | ||
} | ||
for (billingServiceListener in subscriptionServiceListeners) { | ||
billingServiceListener.onPricesUpdated(iapkeyPrices) | ||
} | ||
} | ||
|
||
abstract fun init(key: String?) | ||
abstract fun buy(activity: Activity, sku: String) | ||
abstract fun subscribe(activity: Activity, sku: String) | ||
abstract fun unsubscribe(activity: Activity, sku: String) | ||
abstract fun enableDebugLogging(enable: Boolean) | ||
|
||
@CallSuper | ||
open fun close() { | ||
subscriptionServiceListeners.clear() | ||
purchaseServiceListeners.clear() | ||
} | ||
} | ||
|
||
fun findUiHandler(): Handler { | ||
return Handler(Looper.getMainLooper()) | ||
} |
This file contains 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
This file contains 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
87 changes: 0 additions & 87 deletions
87
library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.