Skip to content

Commit

Permalink
⚡ Release 2.14:
Browse files Browse the repository at this point in the history
- Changed api to add alarm: use AlarmManager.setAlarmClock
- Added app icon
  • Loading branch information
lhwdev committed Sep 27, 2021
1 parent 10339f2 commit 7d6e7f6
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.lhwdev.selfTestMacro"
minSdkVersion 19
targetSdkVersion 31
versionCode 1013
versionName "2.13"
versionCode 1014
versionName "2.14"

multiDexEnabled true

Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 41 additions & 14 deletions app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import android.annotation.SuppressLint
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import com.lhwdev.selfTestMacro.api.*
import net.gotev.cookiestore.InMemoryCookieStore
import java.net.CookieManager
Expand Down Expand Up @@ -96,18 +99,42 @@ fun Context.scheduleNextAlarm(
isRandom: Boolean,
nextDay: Boolean = false,
) {
(getSystemService(Context.ALARM_SERVICE) as AlarmManager).setExact(
AlarmManager.RTC_WAKEUP,
Calendar.getInstance().run {
val newMin = if(isRandom) (min + random.nextInt(-5, 6)).coerceIn(0, 59) else min
val new = clone() as Calendar
new[Calendar.HOUR_OF_DAY] = hour
new[Calendar.MINUTE] = newMin
new[Calendar.SECOND] = 0
new[Calendar.MILLISECOND] = 0
if(nextDay || new <= this) new.add(Calendar.DAY_OF_YEAR, 1)
new.timeInMillis
},
intent
)
val newTime = Calendar.getInstance().run {
val newMin = if(isRandom) (min + random.nextInt(-5, 6)).coerceIn(0, 59) else min
val new = clone() as Calendar
new[Calendar.HOUR_OF_DAY] = hour
new[Calendar.MINUTE] = newMin
new[Calendar.SECOND] = 0
new[Calendar.MILLISECOND] = 0
if(nextDay || new <= this) new.add(Calendar.DAY_OF_YEAR, 1)
new
}
Log.i("SelfTestMacro", "scheduling next alarm at $newTime")

val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
if(Build.VERSION.SDK_INT < 21) {
alarmManager.setExact(
AlarmManager.RTC_WAKEUP,
newTime.timeInMillis,
intent
)
} else {
alarmManager.setAlarmClock(
AlarmManager.AlarmClockInfo(
newTime.timeInMillis,
PendingIntent.getActivity(
this,
0,
Intent(this, MainActivity::class.java).also {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
},
PendingIntent.FLAG_ONE_SHOT or (if(Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_IMMUTABLE else 0)
)
),
intent
)
}

Log.i("SelfTestMacro", "scheduled next alarm")

}
6 changes: 3 additions & 3 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
6 changes: 3 additions & 3 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions app/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#2962FF</color>
</resources>

0 comments on commit 7d6e7f6

Please sign in to comment.