-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
336 additions
and
153 deletions.
There are no files selected for viewing
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
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
10 changes: 10 additions & 0 deletions
10
.../main/java/com/github/frimtec/android/pikettassist/ui/billing/BillingManagerContract.java
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,10 @@ | ||
package com.github.frimtec.android.pikettassist.ui.billing; | ||
|
||
public interface BillingManagerContract { | ||
|
||
boolean isBillingClientReady(); | ||
|
||
void queryPurchases(); | ||
|
||
void destroy(); | ||
} |
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
31 changes: 31 additions & 0 deletions
31
.../main/java/com/github/frimtec/android/pikettassist/ui/billing/DonationReminderHelper.java
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,31 @@ | ||
package com.github.frimtec.android.pikettassist.ui.billing; | ||
|
||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
import android.util.Log; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Random; | ||
|
||
public class DonationReminderHelper { | ||
|
||
private static final String TAG = "DonationReminderHelper"; | ||
|
||
private static final Random RANDOM = new Random(System.currentTimeMillis()); | ||
|
||
public static boolean randomizedOn(Context context, float probability) { | ||
long installationAgeInDays = Integer.MAX_VALUE; | ||
if (context != null) { | ||
try { | ||
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); | ||
installationAgeInDays = Duration.between(Instant.ofEpochMilli(packageInfo.firstInstallTime), Instant.now()).toDays(); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
Log.e(TAG, "Can not get package info", e); | ||
} | ||
} | ||
return RANDOM.nextFloat() <= Math.min((installationAgeInDays - 30f) * 0.01f, probability); | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
app/src/oss/java/com/github/frimtec/android/pikettassist/donation/BillingAdapter.java
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,54 @@ | ||
package com.github.frimtec.android.pikettassist.donation; | ||
|
||
import static com.github.frimtec.android.pikettassist.ui.billing.BillingProvider.BillingState.NOT_PURCHASED; | ||
import static com.github.frimtec.android.pikettassist.ui.billing.DonationReminderHelper.randomizedOn; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.fragment.app.FragmentActivity; | ||
|
||
import com.github.frimtec.android.pikettassist.donation.billing.PaypalBillingManager; | ||
import com.github.frimtec.android.pikettassist.ui.billing.BillingManagerContract; | ||
import com.github.frimtec.android.pikettassist.ui.billing.BillingProvider; | ||
|
||
|
||
public class BillingAdapter implements BillingProvider { | ||
|
||
public static final String BILLING_DIALOG_TAG = "billing_dialog"; | ||
|
||
private final BillingManagerContract billingManager; | ||
|
||
private final BillingState bronzeSponsor = NOT_PURCHASED; | ||
private final BillingState silverSponsor = NOT_PURCHASED; | ||
private final BillingState goldSponsor = NOT_PURCHASED; | ||
|
||
public BillingAdapter(@SuppressWarnings("unused") FragmentActivity activity) { | ||
this.billingManager = new PaypalBillingManager(); | ||
} | ||
|
||
@Override | ||
public BillingManagerContract getBillingManager() { | ||
return billingManager; | ||
} | ||
|
||
public BillingState getBronzeSponsor() { | ||
return bronzeSponsor; | ||
} | ||
|
||
@Override | ||
public boolean isDonationReminderAppropriate(Context context) { | ||
return randomizedOn(context, 0.05f); | ||
} | ||
|
||
public BillingState getSilverSponsor() { | ||
return silverSponsor; | ||
} | ||
|
||
public BillingState getGoldSponsor() { | ||
return goldSponsor; | ||
} | ||
|
||
public void destroy() { | ||
this.billingManager.destroy(); | ||
} | ||
} |
Oops, something went wrong.