Pass handler to BtInterface constructor instead of using global val.
This commit is contained in:
parent
9303952db0
commit
b66960849a
2 changed files with 7 additions and 5 deletions
|
@ -4,6 +4,7 @@ import java.util.UUID
|
|||
|
||||
import android.bluetooth.{BluetoothAdapter, BluetoothDevice, BluetoothSocket}
|
||||
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import com.google.common.collect.HashBiMap
|
||||
|
@ -26,7 +27,8 @@ object BluetoothInterface {
|
|||
/**
|
||||
* Handles all Bluetooth connectivity.
|
||||
*/
|
||||
class BluetoothInterface(service: ChatService, crypto: Crypto) extends InterfaceHandler {
|
||||
class BluetoothInterface(service: ChatService, crypto: Crypto, mainHandler: Handler)
|
||||
extends InterfaceHandler {
|
||||
|
||||
private val Tag = "BluetoothInterface"
|
||||
|
||||
|
@ -92,7 +94,7 @@ class BluetoothInterface(service: ChatService, crypto: Crypto) extends Interface
|
|||
|
||||
val scanInterval = PreferenceManager.getDefaultSharedPreferences(service)
|
||||
.getString("scan_interval_seconds", "15").toInt * 1000
|
||||
service.MainHandler.postDelayed(new Runnable {
|
||||
mainHandler.postDelayed(new Runnable {
|
||||
override def run(): Unit = discover()
|
||||
}, scanInterval)
|
||||
}
|
||||
|
|
|
@ -53,13 +53,13 @@ class ChatService extends Service {
|
|||
|
||||
lazy val database = new Database(this)
|
||||
|
||||
val MainHandler = new Handler()
|
||||
private val mainHandler = new Handler()
|
||||
|
||||
private lazy val binder = new ChatServiceBinder(this)
|
||||
|
||||
private lazy val crypto = new Crypto(this)
|
||||
|
||||
private lazy val btInterface = new BluetoothInterface(this, crypto)
|
||||
private lazy val btInterface = new BluetoothInterface(this, crypto, mainHandler)
|
||||
|
||||
private lazy val router = new Router(connections, sendVia)
|
||||
|
||||
|
@ -193,7 +193,7 @@ class ChatService extends Service {
|
|||
val nm = getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
|
||||
nm.notify(notificationIdGenerator.next(), notification)
|
||||
case _ =>
|
||||
MainHandler.post(new Runnable {
|
||||
mainHandler.post(new Runnable {
|
||||
override def run(): Unit =
|
||||
messageListeners.foreach(_.onMessageReceived(msg))
|
||||
})
|
||||
|
|
Reference in a new issue