Fixed a bug that caused the background refresh to not work when a data notification has been received

This commit is contained in:
Deniz Düzgören
2019-09-01 21:02:17 +02:00
parent 82b5fa1b97
commit c1c025f616
2 changed files with 13 additions and 10 deletions
@@ -26,7 +26,8 @@ import kotlin.collections.ArrayList
/** /**
* This class gets data from the djd4rkn355.github.io domain asynchronously and persists it in the * This class gets data from the djd4rkn355.github.io domain asynchronously and persists it in the
* database. By using booleans as parameters, network usage and speed can be improved as only * database. By using booleans as parameters, network usage and speed can be improved as only
* requested data will be downloaded and processed. * requested data will be downloaded and processed. Furthermore, the class provides a boolean
* to determine whether to send a notification to the user, if applicable.
* *
* @param isPlan substitution plan will be downloaded and persisted in the database if true * @param isPlan substitution plan will be downloaded and persisted in the database if true
* @param isMenu food menu will be downloaded and persisted in the database if true * @param isMenu food menu will be downloaded and persisted in the database if true
@@ -58,9 +59,11 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
foodUrl = "https://djd4rkn355.github.io/food_test.html" foodUrl = "https://djd4rkn355.github.io/food_test.html"
} }
when { if (menu) {
menu -> requestFoodMenuData() requestFoodMenuData()
plan -> requestSubstPlanAndNotification() }
if (plan) {
requestSubstPlan()
} }
if (plan || menu) { if (plan || menu) {
@@ -122,7 +125,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
} }
} }
private fun requestSubstPlanAndNotification() { private fun requestSubstPlan() {
val doc = Jsoup.connect(substUrl).get() val doc = Jsoup.connect(substUrl).get()
currentTime = doc.select("h1")[0].text() currentTime = doc.select("h1")[0].text()
if (currentTime != prefs.getString("timeNew", "")) { if (currentTime != prefs.getString("timeNew", "")) {
@@ -162,15 +165,15 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
} }
if (jobService && prefs.getBoolean("notif", true)) { if (jobService && prefs.getBoolean("notif", true)) {
substArray.filter { substArray.filter { substitution ->
MiscData.checkPersonalSubstitutions( MiscData.checkPersonalSubstitutions(
it, substitution,
coursePreference, coursePreference,
classPreference, classPreference,
false false
) )
}.forEach { substItem -> }.forEach { substItem ->
notifText += "${if (notifText.isNotEmpty()) ",\n" else ""}$substItem.course: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}" notifText += "${if (notifText.isNotEmpty()) ",\n" else ""}${substItem.course}: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}"
} }
} }
@@ -27,9 +27,9 @@ internal class PersonalPlanFragment : PlanFragment() {
persPlanEmpty = true persPlanEmpty = true
recyclerView.visibility = View.VISIBLE recyclerView.visibility = View.VISIBLE
substitutions.filter { substitutions.filter { substitution ->
MiscData.checkPersonalSubstitutions( MiscData.checkPersonalSubstitutions(
it, substitution,
coursePreference, coursePreference,
classPreference, classPreference,
true true