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.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 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 mApplication = application
|
||||
var mView = view
|
||||
@@ -81,6 +91,7 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
||||
edit.putString("informational", informational).apply()
|
||||
|
||||
if (successfulAttempt) {
|
||||
if (menu) {
|
||||
var foodInt = 0
|
||||
while (foodInt in 0 until foodElements.size) {
|
||||
try { // what a mess this is!
|
||||
@@ -130,7 +141,9 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
||||
}
|
||||
|
||||
easyPrefs.putListString("foodListPrefs", foodList)
|
||||
}
|
||||
|
||||
if (plan) {
|
||||
substViewModel.deleteAllSubst()
|
||||
|
||||
for (i in 0 until rows.size) {
|
||||
@@ -173,7 +186,9 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (jobservice) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
channel = NotificationChannel(channelId, channelName, importance)
|
||||
channel.enableLights(true)
|
||||
@@ -212,7 +227,6 @@ class DataFetcher(isjobservice: Boolean, context: Context, application: Applicat
|
||||
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
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.getBoolean("notif", false)) {
|
||||
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.apply();
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class FragmentPlan extends Fragment {
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
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)));
|
||||
}
|
||||
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
||||
@@ -127,7 +127,7 @@ public class FragmentPlan extends Fragment {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
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)));
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user