Archived
"Last updated" time is now compared to a string embedded in the HTML instead of the "Last-Updated" header field to prevent duplicate notifications when the food menu refreshes
This commit is contained in:
@@ -33,7 +33,6 @@ class ColourAdapter(private var mColours: List<Colour>, onClickListener: OnClick
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: ColourViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ColourViewHolder, position: Int) {
|
||||||
val currentItem = mColours[position]
|
val currentItem = mColours[position]
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(holder.image.context)
|
|
||||||
|
|
||||||
holder.title.text = currentItem.title
|
holder.title.text = currentItem.title
|
||||||
holder.titleNoLang.text = currentItem.titleNoLang
|
holder.titleNoLang.text = currentItem.titleNoLang
|
||||||
@@ -54,6 +53,6 @@ class ColourAdapter(private var mColours: List<Colour>, onClickListener: OnClick
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface OnClickListener {
|
public interface OnClickListener {
|
||||||
fun onClick(position: Int, title: String, titleNolang: String)
|
fun onClick(position: Int, title: String, titleNoLang: String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,12 +49,9 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
private val edit = prefs.edit()
|
private val edit = prefs.edit()
|
||||||
private lateinit var pullToRefresh: SwipeRefreshLayout
|
private lateinit var pullToRefresh: SwipeRefreshLayout
|
||||||
private lateinit var progressBar: ProgressBar
|
private lateinit var progressBar: ProgressBar
|
||||||
private val oldDateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
|
|
||||||
private val newDateFormat = "yyyy-MM-dd, HH:mm:ss"
|
|
||||||
private var sdf = SimpleDateFormat(oldDateFormat)
|
|
||||||
private lateinit var d: Date
|
|
||||||
private val fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out)
|
private val fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out)
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
var currentTime = ""
|
||||||
|
|
||||||
override fun doInBackground(vararg params: Void?): Void? {
|
override fun doInBackground(vararg params: Void?): Void? {
|
||||||
try {
|
try {
|
||||||
@@ -142,9 +139,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
if (plan) {
|
if (plan) {
|
||||||
val substViewModel = SubstViewModel(mApplication)
|
val substViewModel = SubstViewModel(mApplication)
|
||||||
val doc = Jsoup.connect("https://djd4rkn355.github.io/subst_test").get()
|
val doc = Jsoup.connect("https://djd4rkn355.github.io/subst_test").get()
|
||||||
val connection = URL("https://djd4rkn355.github.io/subst").openConnection()
|
currentTime = doc.select("h1").text()
|
||||||
edit.putString("time", connection.getHeaderField("Last-Modified")).apply()
|
if (currentTime != prefs.getString("time", "")) {
|
||||||
d = sdf.parse(connection.getHeaderField("Last-Modified"))
|
|
||||||
val rows = doc.select("tr")
|
val rows = doc.select("tr")
|
||||||
val paragraphs = doc.select("p")
|
val paragraphs = doc.select("p")
|
||||||
|
|
||||||
@@ -192,20 +188,28 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
priority--
|
priority--
|
||||||
substViewModel.insertSubst(subst)
|
substViewModel.insertSubst(subst)
|
||||||
|
|
||||||
if (jobservice) {
|
if (jobservice && prefs.getBoolean("notif", true)) {
|
||||||
if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
|
if ((prefs.getString("courses", "")
|
||||||
|
?: "").isEmpty() && (prefs.getString("classes", "")
|
||||||
|
?: "").isNotEmpty()) {
|
||||||
if (groupS[i].isNotEmpty() && groupS[i] != "") {
|
if (groupS[i].isNotEmpty() && groupS[i] != "") {
|
||||||
if ((prefs.getString("classes", "") ?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "") ?: "").toString())) {
|
if ((prefs.getString("classes", "")
|
||||||
|
?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "")
|
||||||
|
?: "").toString())) {
|
||||||
if (notifText.isNotEmpty()) {
|
if (notifText.isNotEmpty()) {
|
||||||
notifText += ", "
|
notifText += ", "
|
||||||
}
|
}
|
||||||
notifText += courseS[i] + ": " + additionalS[i]
|
notifText += courseS[i] + ": " + additionalS[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((prefs.getString("classes", "") ?: "").isNotEmpty() && (prefs.getString("courses", "") ?: "").isNotEmpty()) {
|
} else if ((prefs.getString("classes", "")
|
||||||
|
?: "").isNotEmpty() && (prefs.getString("courses", "")
|
||||||
|
?: "").isNotEmpty()) {
|
||||||
if (groupS[i] != "" && courseS[i] != "") {
|
if (groupS[i] != "" && courseS[i] != "") {
|
||||||
if ((prefs.getString("courses", "") ?: "").contains(courseS[i])) {
|
if ((prefs.getString("courses", "") ?: "").contains(courseS[i])) {
|
||||||
if ((prefs.getString("classes", "") ?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "") ?: "").toString())) {
|
if ((prefs.getString("classes", "")
|
||||||
|
?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "")
|
||||||
|
?: "").toString())) {
|
||||||
if (notifText.isNotEmpty()) {
|
if (notifText.isNotEmpty()) {
|
||||||
notifText += ", "
|
notifText += ", "
|
||||||
}
|
}
|
||||||
@@ -215,8 +219,9 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
edit.putString("time", currentTime).apply()
|
||||||
}
|
}
|
||||||
if (jobservice) {
|
if (jobservice && prefs.getBoolean("notif", true)) {
|
||||||
val openApp = Intent(mContext, Main::class.java)
|
val openApp = Intent(mContext, Main::class.java)
|
||||||
openApp.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
openApp.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
@@ -250,6 +255,7 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (plan || menu) {
|
if (plan || menu) {
|
||||||
mView?.let { v: View ->
|
mView?.let { v: View ->
|
||||||
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
||||||
@@ -263,9 +269,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
|||||||
pullToRefresh.isRefreshing = false
|
pullToRefresh.isRefreshing = false
|
||||||
if (plan) {
|
if (plan) {
|
||||||
val snackBarView = v.findViewById<View>(R.id.coordination)
|
val snackBarView = v.findViewById<View>(R.id.coordination)
|
||||||
sdf.applyPattern(newDateFormat)
|
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
val lastUpdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(sdf.format(d)).toString()
|
val lastUpdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(currentTime)
|
||||||
Snackbar.make(snackBarView, lastUpdated, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(snackBarView, lastUpdated, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.app.job.JobService
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
|
import org.jsoup.Jsoup
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
class NotificationService : JobService() {
|
class NotificationService : JobService() {
|
||||||
@@ -29,21 +30,20 @@ class NotificationService : JobService() {
|
|||||||
val networkStatus = connectivityManager.activeNetworkInfo
|
val networkStatus = connectivityManager.activeNetworkInfo
|
||||||
|
|
||||||
Thread(Runnable {
|
Thread(Runnable {
|
||||||
|
if (!prefs.getBoolean("notif", false)) {
|
||||||
|
return@Runnable
|
||||||
|
} else {
|
||||||
if (jobCancelled || networkStatus == null) {
|
if (jobCancelled || networkStatus == null) {
|
||||||
return@Runnable
|
return@Runnable
|
||||||
}
|
}
|
||||||
if (prefs.getBoolean("notif", false)) {
|
if (prefs.getBoolean("notif", false)) {
|
||||||
edit.putInt("notificationTestNumberDev", prefs.getInt("notificationTestNumberDev", 0) + 1).apply()
|
edit.putInt("notificationTestNumberDev", prefs.getInt("notificationTestNumberDev", 0) + 1).apply()
|
||||||
try {
|
try {
|
||||||
val url = URL("https://djd4rkn355.github.io/subst.html")
|
|
||||||
val connection = url.openConnection()
|
|
||||||
if (connection.getHeaderField("Last-Modified") != prefs.getString("time", "")) {
|
|
||||||
DataFetcher(true, true, true, context, application, null).execute()
|
DataFetcher(true, true, true, context, application, null).execute()
|
||||||
edit.putString("time", connection.getHeaderField("Last-Modified")).apply()
|
|
||||||
}
|
|
||||||
} catch (ignored: Exception) {}
|
} catch (ignored: Exception) {}
|
||||||
}
|
}
|
||||||
jobFinished(params, false)
|
jobFinished(params, false)
|
||||||
|
}
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
|||||||
dialogView.findViewById<TextView>(R.id.dialogtext).text = getString(R.string.fortest)
|
dialogView.findViewById<TextView>(R.id.dialogtext).text = getString(R.string.fortest)
|
||||||
dialogButton.setOnClickListener {
|
dialogButton.setOnClickListener {
|
||||||
when (dialogEditText.text.toString()) {
|
when (dialogEditText.text.toString()) {
|
||||||
"@DIAGNOSTICS" -> {
|
"_DIAGNOSTICS" -> {
|
||||||
val alertDialogDev = AlertDialog.Builder(mContext, R.style.AlertDialog)
|
val alertDialogDev = AlertDialog.Builder(mContext, R.style.AlertDialog)
|
||||||
val devDialogView = LayoutInflater.from(mContext).inflate(R.layout.diagnostics_dialog, null)
|
val devDialogView = LayoutInflater.from(mContext).inflate(R.layout.diagnostics_dialog, null)
|
||||||
val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
|
val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
|
||||||
@@ -382,11 +382,11 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
|||||||
Toast.makeText(mContext, R.string.noyoutube, Toast.LENGTH_LONG).show()
|
Toast.makeText(mContext, R.string.noyoutube, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"@NOTIFICATION" -> {
|
"_NOTIFICATION" -> {
|
||||||
edit.putString("time", "").apply()
|
edit.putString("time", "").apply()
|
||||||
Toast.makeText(mContext, "Notification time cleared", Toast.LENGTH_LONG).show()
|
Toast.makeText(mContext, "Notification time 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()
|
||||||
Toast.makeText(mContext, "First time flag cleared", Toast.LENGTH_LONG).show()
|
Toast.makeText(mContext, "First time flag cleared", Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user