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

Repeat every X times #1

Closed
zunjae opened this issue Jun 27, 2019 · 3 comments
Closed

Repeat every X times #1

zunjae opened this issue Jun 27, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@zunjae
Copy link

zunjae commented Jun 27, 2019

I almost wanted to implement the Once library (https://github.com/jonfinerty/Once) until I found your library. The Once has a feature I'd really like to see in Only and that is repeating a task every X times. There can be multiple variants for this feature.

Variant 1) perform action on the first time (when action has never been performed) and after X times
Variant 2) perform action after X times
Variant 3) perform action after X times and keep redoing this for Y times or an infinite amount of times

Examples:

  1. Ask user to rate app after opening the app 10 times, keep asking again after 10 times until the user has rated the app

  2. Notify user about new feature on the app launch and remind them every 10 app startups 2 times (meaning this action is done after 20 app startups)

  3. Keep reminding the user about something every X times for-ever

I hope you can consider this functionality and for starters just implement the basic one (variant 1 or 2)

@skydoves
Copy link
Owner

@zunjae
Thank you for your issue!
I will consider implementing those features next version. :)

@skydoves
Copy link
Owner

skydoves commented Jul 4, 2019

@zunjae
Hi, I thought about your multiple variants feature related to repeating a task every X times.
I implemented onLastDo, onBeforeDone features for pre and post-processing on version 1.0.2.

So I think here is the new solution to resolve Variant 1)

only("rating", times = 10) {
  onLastDo { // this will be executed after 10 times
    if (showPopupAndGetResult() == false) { // if user did not rate
      Only.clearOnly(name) // clears rating Only data. This makes repeat again from 0 times onDo task.
    }
  }
}

Variant 3) is quite similar.

only("repeat", times = 10) {
  onLastDo {
    Only.clearOnly(name)
    // doSomething
  }
}

And I implemented marking feature on version 1.0.3.
I think this is a solution that implementing remind them every 10 app startups 2 times using marking.

only("whatsNew", times = 20) {
  onDo {
    val marking = Only.getMarking(name)!!.toInt()
    Only.mark(name, marking + 1)
    if (marking % 10 == 0) {
      showPopup()
    }
  }
  version("1.0.0.0")
  mark(1)
}

But I think it is not too clear and simple for resolving Variant 2) yet.
It seems better implementing other feature which related to repeating a task every X times.
Anyway, thank you for your issue! :)

@zunjae
Copy link
Author

zunjae commented Jul 4, 2019

Looks good, thank you!

@skydoves skydoves added the enhancement New feature or request label Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants