Browse Source

fixed grade notification bug. increase grade refresh interval

main v0.10.4
Nareshkumar Rao 4 years ago
parent
commit
fddd2f6537
  1. 8
      app/build.gradle
  2. BIN
      app/release/app-release.apk
  3. 4
      app/release/output-metadata.json
  4. 4
      app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt
  5. 13
      app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt
  6. 24
      app/src/main/java/com/nareshkumarrao/eiweblog/UpdateGradesWorker.kt
  7. 17
      app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWeblogWorker.kt

8
app/build.gradle

@ -11,8 +11,8 @@ android {
applicationId "com.nareshkumarrao.eiweblog"
minSdkVersion 16
targetSdkVersion 30
versionCode 7
versionName "0.10.3"
versionCode 8
versionName "0.10.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@ -39,8 +39,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'

BIN
app/release/app-release.apk

Binary file not shown.

4
app/release/output-metadata.json

@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 7,
"versionName": "0.10.3",
"versionCode": 8,
"versionName": "0.10.4",
"outputFile": "app-release.apk"
}
]

4
app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt

@ -34,12 +34,12 @@ internal object HISUtility {
fun checkForUpdates(context: Context?, callback: (examRows: List<ExamRow>?) -> Unit) {
val savedRows = getSavedExamRows(context) ?: run {
callback(null)
return
return@checkForUpdates
}
val newRows: MutableList<ExamRow> = mutableListOf()
fetchExamRows(context) { examRows ->
if (examRows != null) {
if (examRows != null && savedRows.isNotEmpty()) {
for (examRow in examRows) {
if (!savedRows.contains(examRow)) {
newRows.add(examRow)

13
app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt

@ -37,10 +37,15 @@ class MainActivity : AppCompatActivity() {
Utilities.createNotificationChannel(this)
HISUtility.createNotificationChannel(this)
val uploadWorkRequest: WorkRequest =
PeriodicWorkRequestBuilder<UpdateWorker>(1, TimeUnit.HOURS)
.build()
WorkManager.getInstance(this).enqueue(uploadWorkRequest)
val updateWeblogWorkerRequest: WorkRequest =
PeriodicWorkRequestBuilder<UpdateWeblogWorker>(1, TimeUnit.HOURS)
.build()
val updateGradesWorkerRequest: WorkRequest =
PeriodicWorkRequestBuilder<UpdateGradesWorker>(3, TimeUnit.HOURS)
.build()
WorkManager.getInstance(this).enqueue(updateWeblogWorkerRequest)
WorkManager.getInstance(this).enqueue(updateGradesWorkerRequest)
Utilities.fetchRepoReleaseInformation(this, ::repoReleaseCallback)
}

24
app/src/main/java/com/nareshkumarrao/eiweblog/UpdateGradesWorker.kt

@ -0,0 +1,24 @@
package com.nareshkumarrao.eiweblog
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
class UpdateGradesWorker(private val context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
override fun doWork(): Result {
val sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
val gradesNotificationsEnabled = sharedPref?.getBoolean(context.getString(R.string.enable_grades_notifications_key), true)
if (gradesNotificationsEnabled!!) {
HISUtility.checkForUpdates(context) { gradeUpdates ->
if (gradeUpdates != null) {
for (grade in gradeUpdates) {
HISUtility.sendNotification(context, grade, gradeUpdates.indexOf(grade))
}
}
}
}
return Result.success()
}
}

17
app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt → app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWeblogWorker.kt

@ -6,22 +6,21 @@ import androidx.work.WorkerParameters
import java.math.BigInteger
import java.security.MessageDigest
class UpdateWorker(private val context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
class UpdateWeblogWorker(private val context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
override fun doWork(): Result {
val sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
val weblogNotificationsEnabled = sharedPref?.getBoolean(context.getString(R.string.enable_weblog_notifications_key), true)
val gradesNotificationsEnabled = sharedPref?.getBoolean(context.getString(R.string.enable_grades_notifications_key), true)
if(weblogNotificationsEnabled!!){
if (weblogNotificationsEnabled!!) {
Utilities.weblogList(context) { articles ->
articles ?: return@weblogList
val lastArticle = Utilities.getLatestRelevantArticle(articles)!!
val hashString = lastArticle.title + lastArticle.content + lastArticle.date
val oldHash = md5(hashString)
Utilities.fetchWeblogXML(applicationContext){newArticles ->
Utilities.fetchWeblogXML(applicationContext) { newArticles ->
newArticles ?: return@fetchWeblogXML
val lastNewArticle = Utilities.getLatestRelevantArticle(newArticles)!!
val newHashString = lastNewArticle.title + lastNewArticle.content + lastNewArticle.date
@ -34,16 +33,6 @@ class UpdateWorker(private val context: Context, workerParams: WorkerParameters)
}
}
if(gradesNotificationsEnabled!!){
HISUtility.checkForUpdates(context) { gradeUpdates ->
if (gradeUpdates != null) {
for (grade in gradeUpdates) {
HISUtility.sendNotification(context, grade, gradeUpdates.indexOf(grade))
}
}
}
}
return Result.success()
}
Loading…
Cancel
Save