Skip to content

Commit

Permalink
fix update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Mar 23, 2023
1 parent 58ea155 commit d7e55c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions mobile/src/main/java/com/jwoglom/controlx2/CommService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ class CommService : WearableListenerService(), GoogleApiClient.ConnectionCallbac
}
}

private val checkForUpdatesDelayMs: Long = 1000 * 30 // 30 seconds
private var checkForUpdatesTask: Runnable = Runnable {
AppVersionCheck(applicationContext)
}
Expand All @@ -645,7 +646,7 @@ class CommService : WearableListenerService(), GoogleApiClient.ConnectionCallbac
logToFile = true,
shouldLog = ShouldLogToFile(this),
writeCharacteristicFailedCallback = handleWriteCharacteristicFailedCallback)
Timber.d("service onCreate")
Timber.i("service onCreate")

// Listen to BLE state changes
val intentFilter = IntentFilter()
Expand Down Expand Up @@ -675,7 +676,7 @@ class CommService : WearableListenerService(), GoogleApiClient.ConnectionCallbac
pumpCommHandler = PumpCommHandler(looper)

pumpCommHandler?.postDelayed(periodicUpdateTask, periodicUpdateIntervalMs)
pumpCommHandler?.postDelayed(checkForUpdatesTask, periodicUpdateIntervalMs)
pumpCommHandler?.postDelayed(checkForUpdatesTask, checkForUpdatesDelayMs)

Thread {
while (!mApiClient.isConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.app.NotificationCompat
import com.android.volley.Request
import com.android.volley.toolbox.JsonObjectRequest
import com.google.common.base.Strings
import com.jwoglom.controlx2.R
import org.json.JSONObject
import timber.log.Timber
import java.util.*
Expand All @@ -35,6 +36,7 @@ fun AppVersionCheck(context: Context) {
val version = AppVersionInfo(context)
val data = buildAppVersionCheckData(version)

Timber.i("AppVersionCheck init: $data")
val req = JsonObjectRequest(
Request.Method.GET,
"${AppVersionCheckUrl}${version.version}",
Expand Down Expand Up @@ -91,10 +93,14 @@ fun notifyForUpdate(context: Context, description: String, newVersion: String) {
val pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)

NotificationCompat.Builder(context, notificationChannelId)
val notif = NotificationCompat.Builder(context, notificationChannelId)
.setSmallIcon(R.drawable.pump)
.setContentTitle("ControlX2 Update Available: $newVersion")
.setTicker("ControlX2 Update Available: $newVersion")
.setContentText(description)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()

notificationManager.notify(100, notif)
}

0 comments on commit d7e55c9

Please sign in to comment.