Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use, Once times days, minutes #30

Closed
webserveis opened this issue Sep 9, 2016 · 4 comments
Closed

How to use, Once times days, minutes #30

webserveis opened this issue Sep 9, 2016 · 4 comments

Comments

@webserveis
Copy link

Great library,
Since I can use for each X days run a process?

I have done with total times the ap runs, it works correctly

final static String APP_RATE_COUNT = "app_rate_count";
final static int APP_RATE_LAUNCHES = 3;

        Once.markDone(APP_RATE_COUNT);
        if (Once.beenDone(APP_RATE_COUNT, Amount.moreThan(APP_RATE_LAUNCHES))) {
            Once.clearDone(APP_RATE_COUNT);
            showDialogAppRate();
        }

But I try to do the equivalent but time units

@jonfinerty
Copy link
Owner

Hi webserveis,

Thanks, glad you're using it.

The time limits in Once work with a sliding window of time, not calendar days. If you want to show your rating dialog every three days it could be the following (where your 'X' is 3 in this case):

if (!Once.beenDone(TimeUnit.DAYS, 3, APP_RATE)) {
            showDialogAppRate();
            Once.markDone(APP_RATE);
}

This however will show your rating dialog immediately, then in 3 days and again in 3 more days...

So perhaps you could do something like this:

if (ratingPrecondition() && !Once.beenDone(TimeUnit.DAYS, 3, APP_RATE)) {
            showDialogAppRate();
            Once.markDone(APP_RATE);
}

Where ratingPrecondition() maybe checks if they've done some key actions in your app already

@ethanleeX
Copy link

ethanleeX commented Sep 12, 2016

I want to show the rate dialog every day not every 24 hours ,what should I do ?

@jonfinerty
Copy link
Owner

jonfinerty commented Sep 12, 2016

@LyCharlie hmm, well if there's a enough demand I may extend the library to allow this (I've avoided it as human times are fiddly)

In the mean time you could do the following:

Date lastDone = Once.lastDone(yourTagHere);
Date now = new Date();
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); 
if (!fmt.format(lastDone).equals(fmt.format(now))) {
    showDialog();
}

(Date comparison stolen from: http://stackoverflow.com/a/22442659/798464)

Hope that helps

@jonfinerty
Copy link
Owner

You folks happy?

If so I'll close the issue. Thanks for your input/questions 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants