Archived
Removed redundant String ArrayLists in DataFetcher, made notifications simpler to glance at, changed accent colour of notifications
This commit is contained in:
+3
-10
@@ -27,7 +27,6 @@ dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0-rc1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
||||
implementation 'org.jsoup:jsoup:1.11.3'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha09'
|
||||
@@ -35,24 +34,18 @@ dependencies {
|
||||
|
||||
implementation 'com.google.firebase:firebase-core:17.1.0'
|
||||
implementation 'com.google.firebase:firebase-messaging:20.0.0'
|
||||
|
||||
// implementation 'androidx.core:core-ktx:1.0.2'
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
|
||||
|
||||
implementation 'com.jaredrummler:android-device-names:1.1.8'
|
||||
implementation 'org.jsoup:jsoup:1.11.3'
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
def lifecycle_version = "2.0.0"
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
||||
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
|
||||
|
||||
def room_version = "2.1.0-alpha04"
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
|
||||
|
||||
// implementation "androidx.work:work-runtime-ktx:2.0.1"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
@@ -87,13 +87,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
val rows = doc.select("tr")
|
||||
val paragraphs = doc.select("p")
|
||||
|
||||
val groupS = ArrayList<String>()
|
||||
val dateS = ArrayList<String>()
|
||||
val timeS = ArrayList<String>()
|
||||
val courseS = ArrayList<String>()
|
||||
val roomS = ArrayList<String>()
|
||||
val additionalS = ArrayList<String>()
|
||||
|
||||
for (i in 0 until paragraphs.size) {
|
||||
if (i == 0) {
|
||||
informational = paragraphs[i].text()
|
||||
@@ -103,51 +96,33 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
edit.putString("informational", informational).apply()
|
||||
|
||||
// substViewModel.deleteAllSubst()
|
||||
substRepo.deleteAllSubst()
|
||||
|
||||
for (i in 0 until rows.size) {
|
||||
val row = rows[i]
|
||||
val cols = row.select("th")
|
||||
|
||||
groupS.add(cols[0].text())
|
||||
dateS.add(cols[1].text())
|
||||
timeS.add(cols[2].text())
|
||||
courseS.add(cols[3].text())
|
||||
roomS.add(cols[4].text())
|
||||
additionalS.add(cols[5].text())
|
||||
val subst = Subst(groupS[i], dateS[i], timeS[i], courseS[i],
|
||||
roomS[i], additionalS[i], priority)
|
||||
val group = cols[0].text()
|
||||
val course = cols[3].text()
|
||||
val additional = cols[5].text()
|
||||
substRepo.insert(Subst(group = group, date = cols[1].text(), time = cols[2].text(), course = course,
|
||||
room = cols[4].text(), additional = additional, priority = priority))
|
||||
priority--
|
||||
// substViewModel.insertSubst(subst)
|
||||
substRepo.insert(subst)
|
||||
|
||||
if (jobservice && prefs.getBoolean("notif", true)) {
|
||||
if ((prefs.getString("courses", "")
|
||||
?: "").isEmpty() && (prefs.getString("classes", "")
|
||||
?: "").isNotEmpty()) {
|
||||
if (groupS[i].isNotEmpty() && groupS[i] != "") {
|
||||
if ((prefs.getString("classes", "")
|
||||
?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "")
|
||||
?: "").toString())) {
|
||||
if (notifText.isNotEmpty()) {
|
||||
notifText += ", "
|
||||
}
|
||||
notifText += courseS[i] + ": " + additionalS[i]
|
||||
if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
|
||||
if (group.isNotEmpty() && group != "") {
|
||||
if ((prefs.getString("classes", "") ?: "").contains(group) || group.contains((prefs.getString("classes", "") ?: "").toString())) {
|
||||
|
||||
notifText += "${if (notifText.isNotEmpty()) ",\n" else ""}$course: ${if (additional.isNotEmpty()) additional else "---"}"
|
||||
}
|
||||
}
|
||||
} else if ((prefs.getString("classes", "")
|
||||
?: "").isNotEmpty() && (prefs.getString("courses", "")
|
||||
?: "").isNotEmpty()) {
|
||||
if (groupS[i] != "" && courseS[i] != "") {
|
||||
if ((prefs.getString("courses", "") ?: "").contains(courseS[i])) {
|
||||
if ((prefs.getString("classes", "")
|
||||
?: "").contains(groupS[i]) || groupS[i].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 (group != "" && course != "") {
|
||||
if ((prefs.getString("courses", "") ?: "").contains(course)) {
|
||||
if ((prefs.getString("classes", "") ?: "").contains(group) || group.contains((prefs.getString("classes", "") ?: "").toString())) {
|
||||
|
||||
notifText += "${if (notifText.isNotEmpty()) ",\n" else ""}$course: ${if (additional.isNotEmpty()) additional else "---"}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,7 +130,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
}
|
||||
|
||||
if (jobservice && prefs.getBoolean("notif", true)) {
|
||||
if (notifText.isNotEmpty()) {
|
||||
|
||||
val openApp = Intent(mContext, Main::class.java)
|
||||
openApp.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
@@ -165,29 +141,29 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
notificationLayout.setTextViewText(R.id.notification_title, mContext.getString(R.string.substitutionPlan))
|
||||
notificationLayout.setTextViewText(R.id.notification_textview, notifText)
|
||||
|
||||
if (notifText.isNotEmpty()) {
|
||||
val manager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channelId = "general"
|
||||
val channelName = mContext.getString(R.string.general)
|
||||
val manager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channelId = "general"
|
||||
val channelName = mContext.getString(R.string.general)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)
|
||||
channel.enableLights(true)
|
||||
channel.lightColor = Color.BLUE
|
||||
manager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(mContext, channelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
|
||||
.build()
|
||||
manager.notify(1, notification)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)
|
||||
channel.enableLights(true)
|
||||
channel.lightColor = Color.BLUE
|
||||
manager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(mContext, channelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
|
||||
.setColor(ContextCompat.getColor(mContext, R.color.colorAccent))
|
||||
.build()
|
||||
manager.notify(1, notification)
|
||||
}
|
||||
|
||||
edit.putString("timeNew", currentTime).apply()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,27 +26,31 @@ class FBPingService : JobService() {
|
||||
|
||||
FirebaseApp.initializeApp(context)
|
||||
|
||||
if (prefs.getBoolean("notif", true)) {
|
||||
FirebaseMessaging.getInstance().subscribeToTopic("substitutions-android")
|
||||
} else {
|
||||
FirebaseMessaging.getInstance().unsubscribeFromTopic("substitutions-android")
|
||||
FirebaseMessaging.getInstance().apply {
|
||||
|
||||
if (prefs.getBoolean("notif", true)) {
|
||||
subscribeToTopic("substitutions-android")
|
||||
} else {
|
||||
unsubscribeFromTopic("substitutions-android")
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
subscribeToTopic("substitutions-debug")
|
||||
} else {
|
||||
unsubscribeFromTopic("substitutions-debug")
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
subscribeToTopic("substitutions-ios")
|
||||
} else {
|
||||
unsubscribeFromTopic("substitutions-ios")
|
||||
}
|
||||
|
||||
subscribeToTopic("substitutions-broadcast")
|
||||
|
||||
prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply()
|
||||
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
FirebaseMessaging.getInstance().subscribeToTopic("substitutions-debug")
|
||||
} else {
|
||||
FirebaseMessaging.getInstance().unsubscribeFromTopic("substitutions-debug")
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
FirebaseMessaging.getInstance().subscribeToTopic("substitutions-ios")
|
||||
} else {
|
||||
FirebaseMessaging.getInstance().unsubscribeFromTopic("substitutions-ios")
|
||||
}
|
||||
|
||||
FirebaseMessaging.getInstance().subscribeToTopic("substitutions-broadcast")
|
||||
prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply()
|
||||
|
||||
jobFinished(params, false)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user