Archived
Fixed multiple notification sound bug (yet to be tested), new booleans for AsyncTask
This commit is contained in:
@@ -21,9 +21,19 @@ import java.lang.NullPointerException
|
|||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.URLConnection
|
import java.net.URLConnection
|
||||||
|
|
||||||
class DataFetcher(isjobservice: Boolean, context: Context, application: Application, view: View) : AsyncTask<Void, Void, Void>() {
|
class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, context: Context, application: Application, view: View) : AsyncTask<Void, Void, Void>() {
|
||||||
|
|
||||||
var jobservice = isjobservice
|
var jobservice = isjobservice
|
||||||
|
var plan = isplan
|
||||||
|
var menu = ismenu
|
||||||
|
|
||||||
|
/* booleans to improve performance when fetching data
|
||||||
|
"plan" is required to fetch the substitution data
|
||||||
|
"menu" is required to fetch the food menu
|
||||||
|
"jobservice" is required to send a notification
|
||||||
|
"jobservice" = true has no effect unless "plan" is also true
|
||||||
|
*/
|
||||||
|
|
||||||
var mContext = context
|
var mContext = context
|
||||||
var mApplication = application
|
var mApplication = application
|
||||||
var mView = view
|
var mView = view
|
||||||
@@ -81,89 +91,82 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
|||||||
edit.putString("informational", informational).apply()
|
edit.putString("informational", informational).apply()
|
||||||
|
|
||||||
if (successfulAttempt) {
|
if (successfulAttempt) {
|
||||||
var foodInt = 0
|
if (menu) {
|
||||||
while (foodInt in 0 until foodElements.size) {
|
var foodInt = 0
|
||||||
try { // what a mess this is!
|
while (foodInt in 0 until foodElements.size) {
|
||||||
if (foodElements[foodInt].text().contains("Montag") ||
|
try { // what a mess this is!
|
||||||
foodElements[foodInt].text().contains("Dienstag") ||
|
if (foodElements[foodInt].text().contains("Montag") ||
|
||||||
foodElements[foodInt].text().contains("Mittwoch") ||
|
foodElements[foodInt].text().contains("Dienstag") ||
|
||||||
foodElements[foodInt].text().contains("Donnerstag") ||
|
foodElements[foodInt].text().contains("Mittwoch") ||
|
||||||
foodElements[foodInt].text().contains("Freitag")) {
|
foodElements[foodInt].text().contains("Donnerstag") ||
|
||||||
|
foodElements[foodInt].text().contains("Freitag")) {
|
||||||
|
|
||||||
if (foodElements[foodInt + 3].text().contains("Montag") ||
|
if (foodElements[foodInt + 3].text().contains("Montag") ||
|
||||||
foodElements[foodInt + 3].text().contains("Dienstag") ||
|
foodElements[foodInt + 3].text().contains("Dienstag") ||
|
||||||
foodElements[foodInt + 3].text().contains("Mittwoch") ||
|
foodElements[foodInt + 3].text().contains("Mittwoch") ||
|
||||||
foodElements[foodInt + 3].text().contains("Donnerstag") ||
|
foodElements[foodInt + 3].text().contains("Donnerstag") ||
|
||||||
foodElements[foodInt + 3].text().contains("Freitag") ||
|
foodElements[foodInt + 3].text().contains("Freitag") ||
|
||||||
foodElements[foodInt + 3].text().contains("von")) {
|
foodElements[foodInt + 3].text().contains("von")) {
|
||||||
|
foodList.add(foodElements[foodInt].text() + "\n"
|
||||||
|
+ foodElements[foodInt + 1].text() + "\n"
|
||||||
|
+ foodElements[foodInt + 2].text())
|
||||||
|
foodInt += 2
|
||||||
|
} else if (foodElements[foodInt + 2].text().contains("Montag") ||
|
||||||
|
foodElements[foodInt + 2].text().contains("Dienstag") ||
|
||||||
|
foodElements[foodInt + 2].text().contains("Mittwoch") ||
|
||||||
|
foodElements[foodInt + 2].text().contains("Donnerstag") ||
|
||||||
|
foodElements[foodInt + 2].text().contains("Freitag") ||
|
||||||
|
foodElements[foodInt + 2].text().contains("von")) {
|
||||||
|
foodList.add(foodElements[foodInt].text() + "\n"
|
||||||
|
+ foodElements[foodInt + 1].text())
|
||||||
|
foodInt += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
foodList.add(foodElements[foodInt].text())
|
||||||
|
}
|
||||||
|
} catch (e: IndexOutOfBoundsException) {
|
||||||
|
try {
|
||||||
foodList.add(foodElements[foodInt].text() + "\n"
|
foodList.add(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
+ foodElements[foodInt + 1].text() + "\n"
|
||||||
+ foodElements[foodInt + 2].text())
|
+ foodElements[foodInt + 2].text())
|
||||||
foodInt += 2
|
break
|
||||||
} else if (foodElements[foodInt + 2].text().contains("Montag") ||
|
} catch (e1: IndexOutOfBoundsException) {
|
||||||
foodElements[foodInt + 2].text().contains("Dienstag") ||
|
|
||||||
foodElements[foodInt + 2].text().contains("Mittwoch") ||
|
|
||||||
foodElements[foodInt + 2].text().contains("Donnerstag") ||
|
|
||||||
foodElements[foodInt + 2].text().contains("Freitag") ||
|
|
||||||
foodElements[foodInt + 2].text().contains("von")) {
|
|
||||||
foodList.add(foodElements[foodInt].text() + "\n"
|
foodList.add(foodElements[foodInt].text() + "\n"
|
||||||
+ foodElements[foodInt + 1].text())
|
+ foodElements[foodInt + 1].text())
|
||||||
foodInt += 1
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
foodList.add(foodElements[foodInt].text())
|
|
||||||
}
|
|
||||||
} catch (e: IndexOutOfBoundsException) {
|
|
||||||
try {
|
|
||||||
foodList.add(foodElements[foodInt].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 1].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 2].text())
|
|
||||||
break
|
|
||||||
} catch (e1: IndexOutOfBoundsException) {
|
|
||||||
foodList.add(foodElements[foodInt].text() + "\n"
|
|
||||||
+ foodElements[foodInt + 1].text())
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
foodInt++
|
||||||
}
|
}
|
||||||
foodInt++
|
|
||||||
|
easyPrefs.putListString("foodListPrefs", foodList)
|
||||||
}
|
}
|
||||||
|
|
||||||
easyPrefs.putListString("foodListPrefs", foodList)
|
if (plan) {
|
||||||
|
substViewModel.deleteAllSubst()
|
||||||
|
|
||||||
substViewModel.deleteAllSubst()
|
for (i in 0 until rows.size) {
|
||||||
|
val row = rows[i]
|
||||||
|
val cols = row.select("th") as Elements
|
||||||
|
|
||||||
for (i in 0 until rows.size) {
|
groupS[i] = cols[0].text()
|
||||||
val row = rows[i]
|
dateS[i] = cols[1].text()
|
||||||
val cols = row.select("th") as Elements
|
timeS[i] = cols[2].text()
|
||||||
|
courseS[i] = cols[3].text()
|
||||||
|
roomS[i] = cols[4].text()
|
||||||
|
additionalS[i] = cols[5].text()
|
||||||
|
|
||||||
groupS[i] = cols[0].text()
|
val md = MiscData()
|
||||||
dateS[i] = cols[1].text()
|
val drawable = md.getIcon(courseS[i].toString())
|
||||||
timeS[i] = cols[2].text()
|
val subst = Subst(drawable, groupS[i].toString(), dateS[i].toString(), timeS[i].toString(), courseS[i].toString(),
|
||||||
courseS[i] = cols[3].text()
|
roomS[i].toString(), additionalS[i].toString(), priority)
|
||||||
roomS[i] = cols[4].text()
|
priority--
|
||||||
additionalS[i] = cols[5].text()
|
substViewModel.insert(subst)
|
||||||
|
|
||||||
val md = MiscData()
|
if (jobservice) {
|
||||||
val drawable = md.getIcon(courseS[i].toString())
|
if (prefs.getString("courses", "").isEmpty() && prefs.getString("classes", "").isNotEmpty()) {
|
||||||
val subst = Subst(drawable, groupS[i].toString(), dateS[i].toString(), timeS[i].toString(), courseS[i].toString(),
|
if (groupS[i].toString().isNotEmpty() && !groupS[i].equals("")) {
|
||||||
roomS[i].toString(), additionalS[i].toString(), priority)
|
|
||||||
priority--
|
|
||||||
substViewModel.insert(subst)
|
|
||||||
|
|
||||||
if (jobservice) {
|
|
||||||
if (prefs.getString("courses", "").isEmpty() && prefs.getString("classes", "").isNotEmpty()) {
|
|
||||||
if (groupS[i].toString().isNotEmpty() && !groupS[i].equals("")) {
|
|
||||||
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
|
|
||||||
if (notifText.isNotEmpty()) {
|
|
||||||
notifText += ", "
|
|
||||||
}
|
|
||||||
notifText += courseS[i] + ": " + additionalS[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (prefs.getString("classes", "").isNotEmpty() && prefs.getString("courses", "").isNotEmpty()) {
|
|
||||||
if (!groupS[i].equals("") && !courseS[i].equals("")) {
|
|
||||||
if (prefs.getString("courses", "").contains(courseS[i].toString())) {
|
|
||||||
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
|
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
|
||||||
if (notifText.isNotEmpty()) {
|
if (notifText.isNotEmpty()) {
|
||||||
notifText += ", "
|
notifText += ", "
|
||||||
@@ -171,9 +174,21 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
|||||||
notifText += courseS[i] + ": " + additionalS[i]
|
notifText += courseS[i] + ": " + additionalS[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (prefs.getString("classes", "").isNotEmpty() && prefs.getString("courses", "").isNotEmpty()) {
|
||||||
|
if (!groupS[i].equals("") && !courseS[i].equals("")) {
|
||||||
|
if (prefs.getString("courses", "").contains(courseS[i].toString())) {
|
||||||
|
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
|
||||||
|
if (notifText.isNotEmpty()) {
|
||||||
|
notifText += ", "
|
||||||
|
}
|
||||||
|
notifText += courseS[i] + ": " + additionalS[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (jobservice) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
channel = NotificationChannel(channelId, channelName, importance)
|
channel = NotificationChannel(channelId, channelName, importance)
|
||||||
channel.enableLights(true)
|
channel.enableLights(true)
|
||||||
@@ -212,7 +227,6 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
|||||||
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||||
manager.notify(1, notification) // TODO notification plays multiple times
|
manager.notify(1, notification) // TODO notification plays multiple times
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class FragmentPlan extends Fragment {
|
|||||||
if (prefs.getInt("firstTimeOpening", 0) == 2) {
|
if (prefs.getInt("firstTimeOpening", 0) == 2) {
|
||||||
if (!prefs.getBoolean("notif", false)) {
|
if (!prefs.getBoolean("notif", false)) {
|
||||||
pullToRefresh.setRefreshing(true);
|
pullToRefresh.setRefreshing(true);
|
||||||
new DataFetcher(false, getContext(), getActivity().getApplication(), getView().getRootView()).execute();
|
new DataFetcher(true, false, false, getContext(), getActivity().getApplication(), getView().getRootView()).execute();
|
||||||
edit.putInt("firstTimeOpening", 3);
|
edit.putInt("firstTimeOpening", 3);
|
||||||
edit.apply();
|
edit.apply();
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ public class FragmentPlan extends Fragment {
|
|||||||
|
|
||||||
if (prefs.getBoolean("autoRefresh", false)) {
|
if (prefs.getBoolean("autoRefresh", false)) {
|
||||||
pullToRefresh.setRefreshing(true);
|
pullToRefresh.setRefreshing(true);
|
||||||
new DataFetcher(false, getContext(), getActivity().getApplication(), getView().getRootView()).execute();
|
new DataFetcher(true, false, false, getContext(), getActivity().getApplication(), getView().getRootView()).execute();
|
||||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||||
}
|
}
|
||||||
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
||||||
@@ -127,7 +127,7 @@ public class FragmentPlan extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
pullToRefresh.setRefreshing(true);
|
pullToRefresh.setRefreshing(true);
|
||||||
new DataFetcher(true, getContext(), getActivity().getApplication(), getView().getRootView()).execute(); // TODO test for notification
|
new DataFetcher(true, false, true, getContext(), getActivity().getApplication(), getView().getRootView()).execute(); // TODO test for notification
|
||||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user