Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mobile-android/app/src/main/java/au/gov/health/covidsafe/streetpass/Work.kt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (59 sloc)
1.93 KB
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
| package au.gov.health.covidsafe.streetpass | |
| import android.bluetooth.BluetoothDevice | |
| import android.bluetooth.BluetoothGatt | |
| import android.content.Context | |
| import com.google.gson.Gson | |
| import au.gov.health.covidsafe.logging.CentralLog | |
| import kotlin.properties.Delegates | |
| class Work constructor( | |
| var device: BluetoothDevice, | |
| var connectable: ConnectablePeripheral, | |
| private val onWorkTimeoutListener: OnWorkTimeoutListener | |
| ) : Comparable<Work> { | |
| var timeStamp: Long by Delegates.notNull() | |
| var checklist = WorkCheckList() | |
| var gatt: BluetoothGatt? = null | |
| var finished = false | |
| var timeout : Long = 0 | |
| private val TAG = "Work" | |
| val timeoutRunnable: Runnable = Runnable { | |
| onWorkTimeoutListener.onWorkTimeout(this) | |
| } | |
| init { | |
| timeStamp = System.currentTimeMillis() | |
| } | |
| fun isCriticalsCompleted(): Boolean { | |
| return (checklist.connected.status && checklist.readCharacteristic.status && checklist.writeCharacteristic.status) || checklist.skipped.status | |
| } | |
| fun startWork( | |
| context: Context, | |
| gattCallback: StreetPassWorker.StreetPassGattCallback | |
| ) { | |
| gatt = device.connectGatt(context, false, gattCallback) | |
| if (gatt == null) { | |
| CentralLog.e(TAG, "Unable to connect to ${device.address}") | |
| } | |
| } | |
| override fun compareTo(other: Work): Int { | |
| return -(timeStamp - other.timeStamp).toInt() | |
| } | |
| inner class WorkCheckList { | |
| var started = Check() | |
| var connected = Check() | |
| var mtuChanged = Check() | |
| var readCharacteristic = Check() | |
| var writeCharacteristic = Check() | |
| var disconnected = Check() | |
| var skipped = Check() | |
| override fun toString(): String { | |
| return Gson().toJson(this) | |
| } | |
| } | |
| inner class Check { | |
| var status = false | |
| var timePerformed: Long = 0 | |
| } | |
| interface OnWorkTimeoutListener { | |
| fun onWorkTimeout(work: Work) | |
| } | |
| } |