Version 1.3.0 (little design overhaul) with additional fixes

This commit is contained in:
Deniz Düzgören
2019-05-09 07:48:17 +02:00
parent 4c3d011c6f
commit 907a746b55
35 changed files with 392 additions and 1167 deletions
@@ -10,11 +10,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.media.RingtoneManager;
import android.os.AsyncTask;
import android.os.Build;
import android.preference.PreferenceManager;
import android.widget.RemoteViews;
import android.widget.TextView;
import com.madapps.prefrences.EasyPrefrences;
@@ -30,8 +30,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class ScheduledJobService extends JobService {
@@ -50,41 +48,34 @@ public class ScheduledJobService extends JobService {
final SharedPreferences.Editor edit = prefs.edit();
substViewModel = new SubstViewModel(getApplication());
// substViewModel = ViewModelProviders.of().get(SubstViewModel.class);
// substViewModel.getAllSubst().observe(this, new Observer<List<Subst>>() {
// @Override
// public void onChanged(List<Subst> substs) {
new Thread(new Runnable() {
@Override
public void run() {
if (jobCancelled) {
return;
}
if (prefs.getBoolean("notif", false)) {
edit.putInt("notificationTestNumberDev", prefs.getInt("notificationTestNumberDev", 0) + 1);
new Thread(new Runnable() {
@Override
public void run() {
if (jobCancelled) {
return;
}
if (prefs.getBoolean("notif", false)) {
edit.putInt("notificationTestNumberDev", prefs.getInt("notificationTestNumberDev", 0) + 1);
edit.apply();
URL url;
URLConnection connection = null;
try {
url = new URL("https://djd4rkn355.github.io/subst");
connection = url.openConnection();
} catch (MalformedURLException e) {}
catch (IOException e) {}
try {
if ((!connection.getHeaderField("Last-Modified").equals(prefs.getString("time", "")))) {
new fetcher(context).execute();
edit.putString("time", connection.getHeaderField("Last-Modified"));
edit.apply();
URL url;
URLConnection connection = null;
try {
url = new URL("https://djd4rkn355.github.io/subst");
connection = url.openConnection();
} catch (MalformedURLException e) {}
catch (IOException e) {}
try {
if ((!connection.getHeaderField("Last-Modified").equals(prefs.getString("time", "")))) {
// if (true) {
new fetcher(context).execute();
edit.putString("time", connection.getHeaderField("Last-Modified"));
edit.apply();
}
} catch (NullPointerException e1) {
}
}
jobFinished(params, false);
} catch (NullPointerException e1) {
}
}).start();
// }
// });
}
jobFinished(params, false);
}
}).start();
}
@Override
@@ -95,18 +86,16 @@ public class ScheduledJobService extends JobService {
private class fetcher extends AsyncTask<Void, Void, Void> {
private int count = 0, columns = 0, pCount = 0, priority = 200;
private int count = 0, pCount = 0, priority = 200;
Context mContext;
String notifText = "", foodInfo = "", informational = "";
String notifText = "", informational = "";
String[] groupS, dateS, timeS, courseS, roomS, additionalS;
boolean attempt = false, emptyIcon;
URL url;
URLConnection connection;
String modified;
Elements rows, paragraphs;
Elements[] paragraphsFood = new Elements[2];
Elements foodElements;
Element[] dateFood = new Element[2], blockFood = new Element[2];
Document doc, docFood;
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "general";
@@ -228,7 +217,7 @@ public class ScheduledJobService extends JobService {
roomS[i] = cols.get(4).text();
additionalS[i] = cols.get(5).text();
int drawable = icons(courseS[i]);
int drawable = DataGetter.getIcon(courseS[i]);
Subst subst = new Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i], roomS[i], additionalS[i], priority);
priority--;
substViewModel.insert(subst);
@@ -267,97 +256,34 @@ public class ScheduledJobService extends JobService {
notificationLayout.setTextViewText(R.id.notification_title, getString(R.string.subst));
notificationLayout.setTextViewText(R.id.notification_textview, notifText);
if (!notifText.isEmpty()) {
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notification = new NotificationCompat.Builder(mContext) // TODO switch out the deprecated notification delivery method
// .setContentTitle(getString(R.string.subst))
// .setStyle(new NotificationCompat.BigTextStyle()
// .bigText(notifText))
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setSmallIcon(R.drawable.ic_avh)
.setChannelId(channelId)
.setContentIntent(openAppPending)
.setAutoCancel(true)
.build();
} else {
notification = new NotificationCompat.Builder(mContext)
// .setContentTitle(getString(R.string.subst))
// .setStyle(new NotificationCompat.BigTextStyle()
// .bigText(notifText))
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setSmallIcon(R.drawable.ic_avh)
.setContentIntent(openAppPending)
.setAutoCancel(true)
.build();
}
manager.notify(1, notification);
if (!notifText.isEmpty()) {
Notification notification;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notification = new NotificationCompat.Builder(mContext) // TODO switch out the deprecated notification delivery method
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setSmallIcon(R.drawable.ic_avh)
.setChannelId(channelId)
.setContentIntent(openAppPending)
.setAutoCancel(true)
.build();
} else {
notification = new NotificationCompat.Builder(mContext)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setSmallIcon(R.drawable.ic_avh)
.setContentIntent(openAppPending)
.setAutoCancel(true)
.build();
}
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
manager.notify(1, notification);
}
}
return null;
}
private int icons(String course) {
emptyIcon = false;
if (course.toLowerCase().contains("deu") || course.toLowerCase().contains("dep") || course.toLowerCase().contains("daz")) {
return R.drawable.ic_german;
} else if (course.toLowerCase().contains("mat") || course.toLowerCase().contains("map")) {
return R.drawable.ic_maths;
} else if (course.toLowerCase().contains("eng") || course.toLowerCase().contains("enp") || course.toLowerCase().contains("ena")) {
return R.drawable.ic_english;
} else if (course.toLowerCase().contains("spo") || course.toLowerCase().contains("spp") || course.toLowerCase().contains("spth")) {
return R.drawable.ic_pe;
} else if (course.toLowerCase().contains("pol") || course.toLowerCase().contains("pop")) {
return R.drawable.ic_politics;
} else if (course.toLowerCase().contains("dar") || course.toLowerCase().contains("dap")) {
return R.drawable.ic_drama;
} else if (course.toLowerCase().contains("phy") || course.toLowerCase().contains("php")) {
return R.drawable.ic_physics;
} else if (course.toLowerCase().contains("bio") || course.toLowerCase().contains("bip") || course.toLowerCase().contains("nw")) {
return R.drawable.ic_biology;
} else if (course.toLowerCase().contains("che") || course.toLowerCase().contains("chp")) {
return R.drawable.ic_chemistry;
} else if (course.toLowerCase().contains("phi") || course.toLowerCase().contains("psp")) {
return R.drawable.ic_philosophy;
} else if (course.toLowerCase().contains("laa") || course.toLowerCase().contains("laf") || course.toLowerCase().contains("lat")) {
return R.drawable.ic_latin;
} else if (course.toLowerCase().contains("spa") || course.toLowerCase().contains("spf")) {
return R.drawable.ic_spanish;
} else if (course.toLowerCase().contains("fra") || course.toLowerCase().contains("frf") || course.toLowerCase().contains("frz")) {
return R.drawable.ic_french;
} else if (course.toLowerCase().contains("inf")) {
return R.drawable.ic_compsci;
} else if (course.toLowerCase().contains("ges")) {
return R.drawable.ic_history;
} else if (course.toLowerCase().contains("rel")) {
return R.drawable.ic_religion;
} else if (course.toLowerCase().contains("geg") || course.toLowerCase().contains("wuk")) {
return R.drawable.ic_geography;
} else if (course.toLowerCase().contains("kun")) {
return R.drawable.ic_arts;
} else if (course.toLowerCase().contains("mus")) {
return R.drawable.ic_music;
} else if (course.toLowerCase().contains("tue")) {
return R.drawable.ic_turkish;
} else if (course.toLowerCase().contains("chi")) {
return R.drawable.ic_chinese;
} else if (course.toLowerCase().contains("gll")) {
return R.drawable.ic_gll;
} else if (course.toLowerCase().contains("wat")) {
return R.drawable.ic_wat;
} else if (course.toLowerCase().contains("för")) {
return R.drawable.ic_help;
} else if (course.toLowerCase().contains("wp") || course.toLowerCase().contains("met")) {
return R.drawable.ic_pencil;
} else {
emptyIcon = true;
return R.drawable.ic_empty;
}
}
@Override
protected void onPostExecute(Void result) {}
}