Archived
Now using Repository instead of ViewModel in DataFetcher as a fix for the database not persisting once updated from Firebase notification responder
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ android {
|
|||||||
applicationId "com.denizd.substitutionplan"
|
applicationId "com.denizd.substitutionplan"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 24
|
versionCode 25
|
||||||
versionName "2.2.1"
|
versionName "2.2.2"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
val docFood = Jsoup.connect(foodUrl).get()
|
val docFood = Jsoup.connect(foodUrl).get()
|
||||||
currentFoodTime = docFood.select("h1")[0].text()
|
currentFoodTime = docFood.select("h1")[0].text()
|
||||||
if (currentFoodTime != prefs.getString("timeFood", "")) {
|
if (currentFoodTime != prefs.getString("timeFood", "")) {
|
||||||
val foodViewModel = FoodViewModel(mApplication)
|
val foodRepository = FoodRepository(mApplication)
|
||||||
val foodElements = docFood.select("th")
|
val foodElements = docFood.select("th")
|
||||||
var foodInt = 0
|
var foodInt = 0
|
||||||
var priority = 0
|
var priority = 0
|
||||||
foodViewModel.deleteAll()
|
foodRepository.deleteAll()
|
||||||
while (foodInt in 0 until foodElements.size) {
|
while (foodInt in 0 until foodElements.size) {
|
||||||
try { // what a mess this is!
|
try { // what a mess this is!
|
||||||
with(foodElements[foodInt].text()) {
|
with(foodElements[foodInt].text()) {
|
||||||
@@ -68,29 +68,29 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
val two = foodElements[foodInt + 2].text()
|
val two = foodElements[foodInt + 2].text()
|
||||||
if (three.contains("Montag") || three.contains("Dienstag") || three.contains("Mittwoch") ||
|
if (three.contains("Montag") || three.contains("Dienstag") || three.contains("Mittwoch") ||
|
||||||
three.contains("Donnerstag") || three.contains("Freitag") || three.contains("von")) {
|
three.contains("Donnerstag") || three.contains("Freitag") || three.contains("von")) {
|
||||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
+ foodElements[foodInt + 1].text() + "\n"
|
||||||
+ foodElements[foodInt + 2].text(), priority))
|
+ foodElements[foodInt + 2].text(), priority))
|
||||||
foodInt += 2
|
foodInt += 2
|
||||||
} else if (two.contains("Montag") || two.contains("Dienstag") || two.contains("Mittwoch") ||
|
} else if (two.contains("Montag") || two.contains("Dienstag") || two.contains("Mittwoch") ||
|
||||||
two.contains("Donnerstag") || two.contains("Freitag") || two.contains("von")) {
|
two.contains("Donnerstag") || two.contains("Freitag") || two.contains("von")) {
|
||||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text(), priority))
|
+ foodElements[foodInt + 1].text(), priority))
|
||||||
foodInt += 1
|
foodInt += 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foodViewModel.insert(Food(foodElements[foodInt].text(), priority))
|
foodRepository.insert(Food(foodElements[foodInt].text(), priority))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: IndexOutOfBoundsException) {
|
} catch (e: IndexOutOfBoundsException) {
|
||||||
try {
|
try {
|
||||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
+ foodElements[foodInt + 1].text() + "\n"
|
||||||
+ foodElements[foodInt + 2].text(), priority))
|
+ foodElements[foodInt + 2].text(), priority))
|
||||||
break
|
break
|
||||||
} catch (e1: IndexOutOfBoundsException) {
|
} catch (e1: IndexOutOfBoundsException) {
|
||||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text(), priority))
|
+ foodElements[foodInt + 1].text(), priority))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
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("time", "")) {
|
if (currentTime != prefs.getString("time", "")) {
|
||||||
val substViewModel = SubstViewModel(mApplication)
|
val substRepo = SubstRepository(mApplication)
|
||||||
val rows = doc.select("tr")
|
val rows = doc.select("tr")
|
||||||
val paragraphs = doc.select("p")
|
val paragraphs = doc.select("p")
|
||||||
|
|
||||||
@@ -126,7 +126,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
}
|
}
|
||||||
edit.putString("informational", informational).apply()
|
edit.putString("informational", informational).apply()
|
||||||
|
|
||||||
substViewModel.deleteAllSubst()
|
// substViewModel.deleteAllSubst()
|
||||||
|
substRepo.deleteAllSubst()
|
||||||
|
|
||||||
for (i in 0 until rows.size) {
|
for (i in 0 until rows.size) {
|
||||||
val row = rows[i]
|
val row = rows[i]
|
||||||
@@ -143,7 +144,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
val subst = Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i],
|
val subst = Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i],
|
||||||
roomS[i], additionalS[i], priority)
|
roomS[i], additionalS[i], priority)
|
||||||
priority--
|
priority--
|
||||||
substViewModel.insertSubst(subst)
|
// substViewModel.insertSubst(subst)
|
||||||
|
substRepo.insert(subst)
|
||||||
|
|
||||||
if (jobservice && prefs.getBoolean("notif", true)) {
|
if (jobservice && prefs.getBoolean("notif", true)) {
|
||||||
if ((prefs.getString("courses", "")
|
if ((prefs.getString("courses", "")
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import com.google.firebase.messaging.RemoteMessage
|
|||||||
class FBNotificationService : FirebaseMessagingService() {
|
class FBNotificationService : FirebaseMessagingService() {
|
||||||
|
|
||||||
override fun onMessageReceived(p0: RemoteMessage?) {
|
override fun onMessageReceived(p0: RemoteMessage?) {
|
||||||
DataFetcher(true, true, true, this, application, null).execute()
|
DataFetcher(true, true, true, applicationContext, application, null).execute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user