improved comments in the WiFi-Direct Helper

This commit is contained in:
Faraphel 2024-04-30 20:28:25 +02:00
parent 7ed38b2624
commit 653d10260f

View file

@ -115,79 +115,78 @@ class WifiP2pHelper(
// Wrappers // Wrappers
/** /**
* Wrapper around WifiP2pManager::connect
*
* Connect to another device, allowing for a communication using Sockets * Connect to another device, allowing for a communication using Sockets
* @see WifiP2pManager.connect
*/ */
fun connect(config: WifiP2pConfig, listener: WifiP2pManager.ActionListener? = null) { fun connect(config: WifiP2pConfig, listener: WifiP2pManager.ActionListener? = null) {
this.manager.connect(this.channel, config, listener) this.manager.connect(this.channel, config, listener)
} }
/** /**
* Wrapper around WifiP2pManager::requestPeers
*
* Request the list of peers after a discovery. * Request the list of peers after a discovery.
* @see WifiP2pManager.requestPeers
*/ */
fun requestPeers(listener: WifiP2pManager.PeerListListener? = null) { fun requestPeers(listener: WifiP2pManager.PeerListListener? = null) {
this.manager.requestPeers(this.channel, listener) this.manager.requestPeers(this.channel, listener)
} }
/** /**
* Wrapper around WifiP2pManager::discoverPeers
*
* Start discovering peers. * Start discovering peers.
* Once founds, the WIFI_P2P_PEERS_CHANGED_ACTION event will be triggered. * Once founds, the WIFI_P2P_PEERS_CHANGED_ACTION event will be triggered.
* @see WifiP2pManager.discoverPeers
*/ */
fun discoverPeers(listener: WifiP2pManager.ActionListener? = null) { fun discoverPeers(listener: WifiP2pManager.ActionListener? = null) {
this.manager.discoverPeers(this.channel, listener) this.manager.discoverPeers(this.channel, listener)
} }
/** /**
* Wrapper around WifiP2pManager::requestConnectionInfo
*
* Obtain information about a connection with another device. * Obtain information about a connection with another device.
* @see WifiP2pManager.requestConnectionInfo
*/ */
fun requestConnectionInfo(listener: WifiP2pManager.ConnectionInfoListener? = null) { fun requestConnectionInfo(listener: WifiP2pManager.ConnectionInfoListener? = null) {
this.manager.requestConnectionInfo(this.channel, listener) this.manager.requestConnectionInfo(this.channel, listener)
} }
/** /**
* Wrapper around WifiP2pManager::requestGroupInfo
*
* Obtain information about the current group. * Obtain information about the current group.
* @see WifiP2pManager.requestGroupInfo
*/ */
fun requestGroupInfo(listener: WifiP2pManager.GroupInfoListener? = null) { fun requestGroupInfo(listener: WifiP2pManager.GroupInfoListener? = null) {
this.manager.requestGroupInfo(this.channel, listener) this.manager.requestGroupInfo(this.channel, listener)
} }
/** /**
* Wrapper around WifiP2pManager::createGroup
*
* Create a new WiFi-Direct group. * Create a new WiFi-Direct group.
* @see WifiP2pManager.createGroup
*/ */
fun createGroup(listener: WifiP2pManager.ActionListener? = null) { fun createGroup(listener: WifiP2pManager.ActionListener? = null) {
this.manager.createGroup(this.channel, listener) this.manager.createGroup(this.channel, listener)
} }
/** /**
* Wrapper around WifiP2pManager::removeGroup
*
* Disconnect from the current WiFi-Direct group. * Disconnect from the current WiFi-Direct group.
* @see WifiP2pManager.removeGroup
*/ */
fun removeGroup(listener: WifiP2pManager.ActionListener? = null) { fun removeGroup(listener: WifiP2pManager.ActionListener? = null) {
this.manager.removeGroup(this.channel, listener) this.manager.removeGroup(this.channel, listener)
} }
// Shortcuts
/** /**
* Create a new WiFi-Direct group. * Create a new WiFi-Direct group. If already connected to a group, quit it first.
* If already connected to a group, quit it first. *
* Note: most of the failure on removal are caused by not having a group already created, which is checked.
* *
* @param listener: the createGroup listener * @param listener: the createGroup listener
* @param onFailure: error handler for the removeGroup event * @param onRemoveFailure: error handler for the removeGroup event
*
* @see WifiP2pManager.createGroup
* @see WifiP2pManager.removeGroup
*/ */
fun recreateGroup( fun recreateGroup(
listener: WifiP2pManager.ActionListener? = null, listener: WifiP2pManager.ActionListener? = null,
onFailure: ((Int) -> Unit)? = null onRemoveFailure: ((Int) -> Unit)? = null
) { ) {
// get the current group information // get the current group information
this.requestGroupInfo { group -> this.requestGroupInfo { group ->
@ -201,7 +200,7 @@ class WifiP2pHelper(
override fun onFailure(reason: Int) { override fun onFailure(reason: Int) {
// call the handler // call the handler
onFailure?.invoke(reason) onRemoveFailure?.invoke(reason)
} }
}) })