Simplified ConnectionHandler interface.

This commit is contained in:
Felix Ableitner 2016-05-10 17:18:43 +09:00
parent 7d1f929c2c
commit 8bafd62e35
2 changed files with 11 additions and 13 deletions

View file

@ -8,6 +8,7 @@ import android.content.{Context, Intent, IntentFilter}
import android.net.ConnectivityManager
import android.os.Handler
import com.nutomic.ensichat.bluetooth.BluetoothInterface
import com.nutomic.ensichat.core.interfaces.TransmissionInterface
import com.nutomic.ensichat.core.util.Database
import com.nutomic.ensichat.core.{ConnectionHandler, Crypto}
import com.nutomic.ensichat.util.{NetworkChangedReceiver, SettingsWrapper}
@ -56,11 +57,11 @@ class ChatService extends Service {
override def onCreate(): Unit = {
super.onCreate()
notificationHandler.updatePersistentNotification(getConnectionHandler.connections().size)
if (Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
connectionHandler.addTransmissionInterface(new BluetoothInterface(this, new Handler(),
connectionHandler))
}
connectionHandler.start()
var additionalInterfaces = Set[TransmissionInterface]()
if (Option(BluetoothAdapter.getDefaultAdapter).isDefined)
additionalInterfaces += new BluetoothInterface(this, new Handler(), connectionHandler)
connectionHandler.start(additionalInterfaces)
registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}

View file

@ -37,8 +37,12 @@ final class ConnectionHandler(settings: SettingsInterface, database: Database,
/**
* Generates keys and starts Bluetooth interface.
*
* @param additionalInterfaces Instances of [[TransmissionInterface]] to transfer data over
* platform specific interfaces (eg Bluetooth).
*/
def start(): Unit = {
def start(additionalInterfaces: Set[TransmissionInterface] = Set()): Unit = {
additionalInterfaces.foreach(transmissionInterfaces += _)
FutureHelper {
crypto.generateLocalKeys()
Log.i(Tag, "Service started, address is " + crypto.localAddress)
@ -54,13 +58,6 @@ final class ConnectionHandler(settings: SettingsInterface, database: Database,
database.close()
}
/**
* NOTE: This *must* be called before [[start()]], or it will have no effect.
*/
def addTransmissionInterface(interface: TransmissionInterface) = {
transmissionInterfaces += interface
}
/**
* Sends a new message to the given target address.
*/