diff --git a/app/build.gradle b/app/build.gradle index 5c42e9d..10c20b8 100644 --- a/app/build.gradle +++ b/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' diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 63e2fd9..e5b0de3 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 0b9851f..44af4c6 100644 --- a/app/release/output-metadata.json +++ b/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" } ] diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt index 7f162d3..0d412fd 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/HISUtility.kt @@ -34,12 +34,12 @@ internal object HISUtility { fun checkForUpdates(context: Context?, callback: (examRows: List?) -> Unit) { val savedRows = getSavedExamRows(context) ?: run { callback(null) - return + return@checkForUpdates } val newRows: MutableList = mutableListOf() fetchExamRows(context) { examRows -> - if (examRows != null) { + if (examRows != null && savedRows.isNotEmpty()) { for (examRow in examRows) { if (!savedRows.contains(examRow)) { newRows.add(examRow) diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt index 33a6a38..585dc79 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt +++ b/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(1, TimeUnit.HOURS) - .build() - WorkManager.getInstance(this).enqueue(uploadWorkRequest) + val updateWeblogWorkerRequest: WorkRequest = + PeriodicWorkRequestBuilder(1, TimeUnit.HOURS) + .build() + val updateGradesWorkerRequest: WorkRequest = + PeriodicWorkRequestBuilder(3, TimeUnit.HOURS) + .build() + + WorkManager.getInstance(this).enqueue(updateWeblogWorkerRequest) + WorkManager.getInstance(this).enqueue(updateGradesWorkerRequest) Utilities.fetchRepoReleaseInformation(this, ::repoReleaseCallback) } diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateGradesWorker.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateGradesWorker.kt new file mode 100644 index 0000000..aee9d15 --- /dev/null +++ b/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() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWeblogWorker.kt similarity index 68% rename from app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt rename to app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWeblogWorker.kt index a88d500..26358c0 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt +++ b/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() }