package com.draga;

import com.badlogic.gdx.pay.PurchaseManagerConfig;
import com.badlogic.gdx.pay.PurchaseSystem;
import com.draga.spaceTravels3.Constants;
import com.draga.spaceTravels3.event.PurchasedEvent;

import java.util.ArrayList;

public abstract class Services
{
    private ArrayList<String> purchasedSkus = new ArrayList<>();

    public Services()
    {
    }

    public void setupPurchaseManager()
    {
        if (PurchaseSystem.hasManager())
        {
            PurchaseManagerConfig purchaseManagerConfig = getPurchaseManagerConfig();
            PurchaseSystem.install(new PurchaseObserver(), purchaseManagerConfig, false);
        }
    }

    public void purchaseSku(String sku)
    {
        if (PurchaseSystem.hasManager())
        {
            PurchaseSystem.purchase(sku);
        }
    }

    protected abstract PurchaseManagerConfig getPurchaseManagerConfig();

    public abstract void share();

    public abstract void googleSignIn();

    public abstract boolean googleIsSignedIn();

    public abstract void googleSignOut();

    public abstract void googleShowLeaderboards();

    public abstract void googleUpdateLeaderboard(String leaderboardID, int score);

    public abstract void googleShowLeaderboard(String leaderboardID);

    public abstract void googleUnlockAchievement(String string);

    public abstract void googleShowAchievements();

    public abstract void rateApp();

    public void restorePurchase()
    {
        PurchaseSystem.purchaseRestore();
    }

    public boolean hasPurchasedSku(String sku)
    {
        for (String purchasedSku : this.purchasedSkus)
        {
            if (purchasedSku.equals(sku))
            {
                return true;
            }
        }

        return false;
    }

    public void setPurchasedSku(String sku)
    {
        this.purchasedSkus.add(sku);
        Constants.General.EVENT_BUS.post(new PurchasedEvent(sku));
    }
}

@@ -404,32 +404,73 @@
 Manager()%0A    %7B%0A
+        PurchaseSystem.onAppRestarted();%0A
         if (Purc
@@ -486,32 +486,32 @@
 m.hasManager())%0A
-
         %7B%0A      
@@ -689,32 +689,106 @@
        %7D%0A    %7D%0A%0A
+    protected abstract PurchaseManagerConfig getPurchaseManagerConfig();%0A%0A
     public void 
@@ -924,89 +924,15 @@
   %7D%0A
+
     %7D%0A%0A
-    protected abstract PurchaseManagerConfig getPurchaseManagerConfig();%0A%0A
     

call gdx pay on app restarted as described on readme