-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefreshService.java
47 lines (35 loc) · 1.25 KB
/
RefreshService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package naomi.me.spotopen;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import naomi.me.spotopen.Model.UWClass;
/**
* Created by naomikoo on 2016-09-09.
*/
public class RefreshService extends IntentService {
public RefreshService() {
super(RefreshService.class.getName());
setIntentRedelivery(true);
}
@Override
protected void onHandleIntent(Intent intent) {
// update db and send notification
ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(1);
// This schedule a runnable task every 30 seconds
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
public void run() {
checkForSpots();
}
}, 0, 30, TimeUnit.SECONDS);
}
private void checkForSpots() {
List<UWClass> list = ClassApplication.db.getAllClasses();
for (UWClass uwClass : list) {
ClassDownloaderHelper.downloadAndUpdateDB(uwClass.getTerm(), uwClass.getSubject(), uwClass.getNumber(), uwClass.getSection(), this);
}
}
}