-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #565 from AryanSarafDev/TimerRevamp
Timer revamp
- Loading branch information
Showing
22 changed files
with
2,816 additions
and
847 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
android/app/src/main/kotlin/com/example/ultimate_alarm_clock/CommonTimerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.ultimate_alarm_clock | ||
|
||
import android.os.CountDownTimer | ||
|
||
object CommonTimerManager { | ||
private var commonTimer: CommonTimer? = null | ||
|
||
fun getCommonTimer(listener: TimerListener): CommonTimer { | ||
if (commonTimer == null) { | ||
commonTimer = CommonTimer(listener) | ||
} | ||
return commonTimer!! | ||
} | ||
} | ||
class CommonTimer(private val listener: TimerListener) { | ||
private var timer: CountDownTimer? = null | ||
|
||
fun startTimer(durationMillis: Long) { | ||
timer?.cancel() // Cancel any existing timer | ||
timer = object : CountDownTimer(durationMillis, 1000) { | ||
override fun onTick(millisUntilFinished: Long) { | ||
listener.onTick(millisUntilFinished) | ||
} | ||
|
||
override fun onFinish() { | ||
listener.onFinish() | ||
} | ||
}.start() | ||
} | ||
|
||
fun stopTimer() { | ||
timer?.cancel() | ||
} | ||
} | ||
|
||
interface TimerListener { | ||
fun onTick(millisUntilFinished: Long) | ||
fun onFinish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/app/src/main/kotlin/com/example/ultimate_alarm_clock/TimerBroadcasts/CancelTimer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.ultimate_alarm_clock.TimerBroadcasts | ||
|
||
import android.app.NotificationManager | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.example.ultimate_alarm_clock.CommonTimerManager | ||
import com.example.ultimate_alarm_clock.TimerListener | ||
|
||
class CancelTimer : BroadcastReceiver() { | ||
override fun onReceive(context: Context, intent: Intent?) { | ||
var notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
val commonTimer = CommonTimerManager.getCommonTimer(object : TimerListener { | ||
override fun onTick(millisUntilFinished: Long) { | ||
} | ||
override fun onFinish() { | ||
notificationManager.cancel(1) | ||
} | ||
}) | ||
commonTimer.stopTimer() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
android/app/src/main/kotlin/com/example/ultimate_alarm_clock/TimerDatabaseHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.ultimate_alarm_clock | ||
import android.content.Context | ||
import android.database.sqlite.SQLiteDatabase | ||
import android.database.sqlite.SQLiteOpenHelper | ||
|
||
class TimerDatabaseHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) { | ||
|
||
companion object { | ||
private const val DATABASE_VERSION = 1 | ||
private const val DATABASE_NAME = "timer.db" | ||
} | ||
|
||
override fun onCreate(db: SQLiteDatabase) { | ||
db.rawQuery(""" create table timers ( | ||
id integer primary key autoincrement, | ||
startedOn text not null, | ||
timerValue integer not null, | ||
timeElapsed integer not null, | ||
ringtoneName text not null, | ||
timerName text not null, | ||
isPaused integer not null)""",null) | ||
} | ||
|
||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { | ||
} | ||
} |
Oops, something went wrong.