adding some crashfixes
This commit is contained in:
parent
e23e83ba4b
commit
7fb94453c5
|
@ -64,7 +64,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:e79ef36c10'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.shawnlin:number-picker:2.4.6'
|
||||
|
|
|
@ -41,7 +41,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.execSQL("CREATE TABLE $ALARMS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TIME_IN_MINUTES INTEGER, $COL_DAYS INTEGER, " +
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS $ALARMS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TIME_IN_MINUTES INTEGER, $COL_DAYS INTEGER, " +
|
||||
"$COL_IS_ENABLED INTEGER, $COL_VIBRATE INTEGER, $COL_SOUND_TITLE TEXT, $COL_SOUND_URI TEXT, $COL_LABEL TEXT)")
|
||||
insertInitialAlarms(db)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import com.simplemobiletools.clock.helpers.STOPWATCH_RUNNING_NOTIF_ID
|
|||
import com.simplemobiletools.clock.helpers.Stopwatch
|
||||
import com.simplemobiletools.clock.helpers.Stopwatch.State
|
||||
import com.simplemobiletools.clock.helpers.Stopwatch.UpdateListener
|
||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
@ -70,10 +72,13 @@ class StopwatchService : Service() {
|
|||
val channelId = "simple_alarm_stopwatch"
|
||||
val label = getString(R.string.stopwatch)
|
||||
val importance = NotificationManager.IMPORTANCE_DEFAULT
|
||||
if (isOreoPlus()) {
|
||||
NotificationChannel(channelId, label, importance).apply {
|
||||
setSound(null, null)
|
||||
notificationManager.createNotificationChannel(this)
|
||||
}
|
||||
}
|
||||
|
||||
return NotificationCompat.Builder(this, channelId)
|
||||
.setContentTitle(title)
|
||||
.setContentText(contentText)
|
||||
|
@ -88,12 +93,8 @@ class StopwatchService : Service() {
|
|||
|
||||
private fun updateNotification(totalTime: Long) {
|
||||
val formattedDuration = totalTime.getFormattedDuration()
|
||||
notificationBuilder.setContentTitle(formattedDuration)
|
||||
.setContentText(getString(R.string.stopwatch))
|
||||
notificationManager.notify(
|
||||
STOPWATCH_RUNNING_NOTIF_ID,
|
||||
notificationBuilder.build()
|
||||
)
|
||||
notificationBuilder.setContentTitle(formattedDuration).setContentText(getString(R.string.stopwatch))
|
||||
notificationManager.notify(STOPWATCH_RUNNING_NOTIF_ID, notificationBuilder.build())
|
||||
}
|
||||
|
||||
private val updateListener = object : UpdateListener {
|
||||
|
@ -104,7 +105,7 @@ class StopwatchService : Service() {
|
|||
}
|
||||
|
||||
override fun onStateChanged(state: State) {
|
||||
if (state == State.STOPPED) {
|
||||
if (state == State.STOPPED && isNougatPlus()) {
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import android.app.NotificationManager
|
|||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.simplemobiletools.clock.R
|
||||
|
@ -51,7 +53,10 @@ class TimerService : Service() {
|
|||
firstTimer.label.isNotEmpty() -> getString(R.string.timer_single_notification_label_msg, firstTimer.label)
|
||||
else -> resources.getQuantityString(R.plurals.timer_notification_msg, runningTimers.size, runningTimers.size)
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
|
||||
}
|
||||
} else {
|
||||
stopService()
|
||||
}
|
||||
|
@ -116,7 +121,9 @@ class TimerService : Service() {
|
|||
}
|
||||
|
||||
fun startTimerService(context: Context) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
object TimerStopService
|
||||
|
|
Loading…
Reference in New Issue