A small and simple library for managing trial period in your android app.
Add this to your root build.gradle file under repositories:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Add this to your app level build.gradle as dependency:
implementation 'com.github.pzienowicz:Trialer:{latest.version}'
val trialer = Trialer(this)
trialer.trialEndedListener = object : TrialEndedListener {
override fun onTrialEnded(validatorClass: ValidatorInterface) {
Toast.makeText(
applicationContext,
"Trial ended by: " + validatorClass::class.java.simpleName,
Toast.LENGTH_LONG
).show()
}
}
trialer.addValidator(InstallDateValidator(10))
trialer.addValidator(StaticDateValidator(someFutureDate))
trialer.addValidator(RunTimesValidator(5))
trialer.addValidator(YourCustomValidator())
trialer.addAction(DisplayToastAction(context, "Toast by DisplayToastAction"))
trialer.valid()
Trialer trialer = new Trialer(this);
trialer.setTrialEndedListener(validatorClass ->
Toast.makeText(
getApplicationContext(),
"Trial ended by: " + validatorClass.getClass().getSimpleName(),
Toast.LENGTH_LONG
).show()
);
trialer.addValidator(new InstallDateValidator(10));
trialer.addValidator(new StaticDateValidator(someFutureDate.getTime()));
trialer.addValidator(new RunTimesValidator(5));
trialer.addValidator(new YourCustomValidator());
trialer.addAction(new DisplayToastAction(context, "Toast by DisplayToastAction"))
trialer.valid();
Simple validator - it fails if given date is in the past.
val someFutureDate = Calendar.getInstance()
someFutureDate.add(Calendar.DATE, 30)
...
trialer.addValidator(StaticDateValidator(someFutureDate.time))
...
It fails when X days have passed since installation.
val days = 10 //Int
...
trialer.addValidator(InstallDateValidator(days))
...
It fails when X times your activity has been launched.
val runTimes = 5 //Int
...
trialer.addValidator(RunTimesValidator(runTimes))
...
You are able to create your custom validators. Just implement ValidatorInterface interface. You can run Trialer with as many validators as you want.
Feel free to contribute and add your custom validators.
If you don't want to use TrialEndedListener, you can just use simple action, which will be run if trial ended. For now we have few actions specified below. If these actions don't meet your needs, please implement ActionInterface and create your own action.
Closes activity if trial ended.
trialer.addAction(FinishActivityAction(activity))
Displays toast message if trial ended.
trialer.addAction(DisplayToastAction(context, "Toast by DisplayToastAction"))