adding some crashfixes

This commit is contained in:
tibbi
2022-10-09 23:16:47 +02:00
parent e23e83ba4b
commit 7fb94453c5
4 changed files with 22 additions and 14 deletions

View File

@ -64,7 +64,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:e79ef36c10' implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.shawnlin:number-picker:2.4.6' implementation 'com.shawnlin:number-picker:2.4.6'

View File

@ -41,7 +41,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
override fun onCreate(db: SQLiteDatabase) { 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)") "$COL_IS_ENABLED INTEGER, $COL_VIBRATE INTEGER, $COL_SOUND_TITLE TEXT, $COL_SOUND_URI TEXT, $COL_LABEL TEXT)")
insertInitialAlarms(db) insertInitialAlarms(db)
} }

View File

@ -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
import com.simplemobiletools.clock.helpers.Stopwatch.State import com.simplemobiletools.clock.helpers.Stopwatch.State
import com.simplemobiletools.clock.helpers.Stopwatch.UpdateListener 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.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -70,10 +72,13 @@ class StopwatchService : Service() {
val channelId = "simple_alarm_stopwatch" val channelId = "simple_alarm_stopwatch"
val label = getString(R.string.stopwatch) val label = getString(R.string.stopwatch)
val importance = NotificationManager.IMPORTANCE_DEFAULT val importance = NotificationManager.IMPORTANCE_DEFAULT
NotificationChannel(channelId, label, importance).apply { if (isOreoPlus()) {
setSound(null, null) NotificationChannel(channelId, label, importance).apply {
notificationManager.createNotificationChannel(this) setSound(null, null)
notificationManager.createNotificationChannel(this)
}
} }
return NotificationCompat.Builder(this, channelId) return NotificationCompat.Builder(this, channelId)
.setContentTitle(title) .setContentTitle(title)
.setContentText(contentText) .setContentText(contentText)
@ -88,12 +93,8 @@ class StopwatchService : Service() {
private fun updateNotification(totalTime: Long) { private fun updateNotification(totalTime: Long) {
val formattedDuration = totalTime.getFormattedDuration() val formattedDuration = totalTime.getFormattedDuration()
notificationBuilder.setContentTitle(formattedDuration) notificationBuilder.setContentTitle(formattedDuration).setContentText(getString(R.string.stopwatch))
.setContentText(getString(R.string.stopwatch)) notificationManager.notify(STOPWATCH_RUNNING_NOTIF_ID, notificationBuilder.build())
notificationManager.notify(
STOPWATCH_RUNNING_NOTIF_ID,
notificationBuilder.build()
)
} }
private val updateListener = object : UpdateListener { private val updateListener = object : UpdateListener {
@ -104,7 +105,7 @@ class StopwatchService : Service() {
} }
override fun onStateChanged(state: State) { override fun onStateChanged(state: State) {
if (state == State.STOPPED) { if (state == State.STOPPED && isNougatPlus()) {
stopForeground(STOP_FOREGROUND_REMOVE) stopForeground(STOP_FOREGROUND_REMOVE)
} }
} }

View File

@ -6,7 +6,9 @@ import android.app.NotificationManager
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Handler
import android.os.IBinder import android.os.IBinder
import android.os.Looper
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.simplemobiletools.clock.R 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) 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) else -> resources.getQuantityString(R.plurals.timer_notification_msg, runningTimers.size, runningTimers.size)
} }
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
Handler(Looper.getMainLooper()).post {
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
}
} else { } else {
stopService() stopService()
} }
@ -116,7 +121,9 @@ class TimerService : Service() {
} }
fun startTimerService(context: Context) { fun startTimerService(context: Context) {
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java)) Handler(Looper.getMainLooper()).post {
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
}
} }
object TimerStopService object TimerStopService