Archived
Simplified the code for splitting up the data for the food menu
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 25
|
versionCode 26
|
||||||
versionName "2.2.2"
|
versionName "2.2.3"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -56,47 +56,25 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
if (currentFoodTime != prefs.getString("timeFood", "")) {
|
if (currentFoodTime != prefs.getString("timeFood", "")) {
|
||||||
val foodRepository = FoodRepository(mApplication)
|
val foodRepository = FoodRepository(mApplication)
|
||||||
val foodElements = docFood.select("th")
|
val foodElements = docFood.select("th")
|
||||||
var foodInt = 0
|
|
||||||
var priority = 0
|
|
||||||
foodRepository.deleteAll()
|
foodRepository.deleteAll()
|
||||||
while (foodInt in 0 until foodElements.size) {
|
|
||||||
try { // what a mess this is!
|
|
||||||
with(foodElements[foodInt].text()) {
|
|
||||||
if (contains("Montag") || contains("Dienstag") || contains("Mittwoch") ||
|
|
||||||
contains("Donnerstag") || contains("Freitag")) {
|
|
||||||
val three = foodElements[foodInt + 3].text()
|
|
||||||
val two = foodElements[foodInt + 2].text()
|
|
||||||
if (three.contains("Montag") || three.contains("Dienstag") || three.contains("Mittwoch") ||
|
|
||||||
three.contains("Donnerstag") || three.contains("Freitag") || three.contains("von")) {
|
|
||||||
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 2].text(), priority))
|
|
||||||
foodInt += 2
|
|
||||||
} else if (two.contains("Montag") || two.contains("Dienstag") || two.contains("Mittwoch") ||
|
|
||||||
two.contains("Donnerstag") || two.contains("Freitag") || two.contains("von")) {
|
|
||||||
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 1].text(), priority))
|
|
||||||
foodInt += 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foodRepository.insert(Food(foodElements[foodInt].text(), priority))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: IndexOutOfBoundsException) {
|
val indices = ArrayList<Int>()
|
||||||
try {
|
val daysAndVon = arrayOf("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "von")
|
||||||
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
for (i in 0 until foodElements.size) {
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
if (checkStringForArray(foodElements[i].text(), daysAndVon)) indices.add(i)
|
||||||
+ foodElements[foodInt + 2].text(), priority))
|
}
|
||||||
break
|
indices.add(foodElements.size)
|
||||||
} catch (e1: IndexOutOfBoundsException) {
|
|
||||||
foodRepository.insert(Food(foodElements[foodInt].text() + "\n"
|
for ((priority, l) in (0 until indices.size - 1).withIndex()) {
|
||||||
+ foodElements[foodInt + 1].text(), priority))
|
var s = ""
|
||||||
break
|
for (i2 in indices[l] until indices[l + 1]) {
|
||||||
|
if (s.isEmpty()) {
|
||||||
|
s = foodElements[i2].text()
|
||||||
|
} else {
|
||||||
|
s += "\n${foodElements[i2].text()}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foodInt++
|
foodRepository.insert(Food(s, priority))
|
||||||
priority++
|
|
||||||
}
|
}
|
||||||
edit.putString("timeFood", currentFoodTime).apply()
|
edit.putString("timeFood", currentFoodTime).apply()
|
||||||
}
|
}
|
||||||
@@ -243,4 +221,13 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
} catch (ignored: Exception) {}
|
} catch (ignored: Exception) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkStringForArray(s: String, checking: Array<String>): Boolean {
|
||||||
|
for (i in checking.indices) {
|
||||||
|
if (s.contains(checking[i])) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -389,8 +389,8 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"_NOTIFICATION" -> {
|
"_NOTIFICATION" -> {
|
||||||
edit.putString("time", "").apply()
|
edit.putString("time", "").putString("timeFood", "").apply()
|
||||||
Toast.makeText(mContext, "Notification time cleared", Toast.LENGTH_LONG).show()
|
Toast.makeText(mContext, "Notification times cleared", Toast.LENGTH_LONG).show()
|
||||||
} // TODO add option to clear database
|
} // TODO add option to clear database
|
||||||
"_FIRSTTIME" -> {
|
"_FIRSTTIME" -> {
|
||||||
edit.putBoolean("firstTime", true).apply()
|
edit.putBoolean("firstTime", true).apply()
|
||||||
|
|||||||
Reference in New Issue
Block a user