Skip to content

Commit

Permalink
Update gradle plugin and kotlin version, and only run refresh worker …
Browse files Browse the repository at this point in the history
…if within scheduled time
  • Loading branch information
premnirmal committed Jan 2, 2025
1 parent a951948 commit 07f5b0a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ class AlarmScheduler @Inject constructor(
private val workManager: WorkManager
) {

fun isWithinSchedulingPreferences(): Boolean {
val dayOfWeek = clock.todayLocal()
.dayOfWeek
val startTimez = appPreferences.startTime()
val endTimez = appPreferences.endTime()
// whether the start time is after the end time e.g. start time is 11pm and end time is 5am
val inverse =
startTimez.hour > endTimez.hour || (startTimez.hour == endTimez.hour && startTimez.minute > endTimez.minute)
val now: ZonedDateTime = clock.todayZoned()
val startTime = clock.todayZoned()
.withHour(startTimez.hour)
.withMinute(startTimez.minute)
var endTime = clock.todayZoned()
.withHour(endTimez.hour)
.withMinute(endTimez.minute)
if (inverse && now.isAfter(startTime)) {
endTime = endTime.plusDays(1)
}
val selectedDaysOfWeek = appPreferences.updateDays()

return (now.isBefore(endTime) && (now.isAfter(startTime)
|| now.isEqual(startTime)) && selectedDaysOfWeek.contains(dayOfWeek))
}

/**
* Takes care of weekends and after hours
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class RefreshWorker(context: Context, params: WorkerParameters) : CoroutineWorke
}

@Inject internal lateinit var stocksProvider: StocksProvider
@Inject internal lateinit var alarmScheduler: AlarmScheduler

override suspend fun doWork(): Result {
return if (applicationContext.isNetworkOnline()) {
Injector.appComponent().inject(this)
if (!alarmScheduler.isWithinSchedulingPreferences()) {
return Result.success()
}
val result = stocksProvider.fetch()
if (result.hasError) {
Result.retry()
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# this file is purely for f-droid because it cannot infer the version name/code from the git tag
versionName=3.9.834
versionCode=300900834
versionName=3.9.835
versionCode=300900835
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.9.10'
ext.kotlin_version = '1.9.21'
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.1'
classpath 'com.android.tools.build:gradle:8.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.48.1"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 07f5b0a

Please sign in to comment.