-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the logic of checking changes in service
Now service tracks changes not by comparing old and new update time, but by total sum of all scores.
- Loading branch information
1 parent
5963ba5
commit ff982c7
Showing
3 changed files
with
55 additions
and
36 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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/ua/samosfator/moduleok/notification/ScoresChangedTask.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,44 @@ | ||
package ua.samosfator.moduleok.notification; | ||
|
||
import java.util.List; | ||
import java.util.TimerTask; | ||
|
||
import java8.util.stream.StreamSupport; | ||
import ua.samosfator.moduleok.SessionIdExpiredException; | ||
import ua.samosfator.moduleok.StudentKeeper; | ||
import ua.samosfator.moduleok.parser.Subject; | ||
|
||
public class ScoresChangedTask extends TimerTask { | ||
@Override | ||
public void run() { | ||
if (areScoresChanged()) { | ||
ScoreCheckerNotification.sendNotification(); | ||
} | ||
} | ||
|
||
private boolean areScoresChanged() { | ||
List<Subject> oldSubjects = getSubjects(); | ||
try { | ||
StudentKeeper.refreshStudent(); | ||
} catch (SessionIdExpiredException ignored) { | ||
} | ||
List<Subject> newSubjects = getSubjects(); | ||
|
||
return getTotalSumAllScores(oldSubjects) != getTotalSumAllScores(newSubjects); | ||
} | ||
|
||
private int getTotalSumAllScores(List<Subject> subjects) { | ||
final int[] oldTotalScore = {0}; | ||
StreamSupport.parallelStream(subjects) | ||
.map(subject -> StreamSupport.parallelStream(subject.getModules())) | ||
.map(modulesStream -> modulesStream.map(module -> oldTotalScore[0] += module.getScore())); | ||
return oldTotalScore[0]; | ||
} | ||
|
||
private List<Subject> getSubjects() { | ||
return StudentKeeper.getCurrentStudent() | ||
.getSemesters() | ||
.get(StudentKeeper.getCurrentSemesterIndex()) | ||
.getSubjects(); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
app/src/main/java/ua/samosfator/moduleok/notification/UpdateTimeTask.java
This file was deleted.
Oops, something went wrong.