From 653d10260fdc71caeddb7c9c87e6349ff62eb075 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 30 Apr 2024 20:28:25 +0200 Subject: [PATCH] improved comments in the WiFi-Direct Helper --- .../connectivity/wifi_p2p/WifiP2pHelper.kt | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/faraphel/tasks_valider/connectivity/wifi_p2p/WifiP2pHelper.kt b/app/src/main/java/com/faraphel/tasks_valider/connectivity/wifi_p2p/WifiP2pHelper.kt index 6d2b309..574a030 100644 --- a/app/src/main/java/com/faraphel/tasks_valider/connectivity/wifi_p2p/WifiP2pHelper.kt +++ b/app/src/main/java/com/faraphel/tasks_valider/connectivity/wifi_p2p/WifiP2pHelper.kt @@ -115,79 +115,78 @@ class WifiP2pHelper( // Wrappers /** - * Wrapper around WifiP2pManager::connect - * * Connect to another device, allowing for a communication using Sockets + * @see WifiP2pManager.connect */ fun connect(config: WifiP2pConfig, listener: WifiP2pManager.ActionListener? = null) { this.manager.connect(this.channel, config, listener) } /** - * Wrapper around WifiP2pManager::requestPeers - * * Request the list of peers after a discovery. + * @see WifiP2pManager.requestPeers */ fun requestPeers(listener: WifiP2pManager.PeerListListener? = null) { this.manager.requestPeers(this.channel, listener) } /** - * Wrapper around WifiP2pManager::discoverPeers - * * Start discovering peers. * Once founds, the WIFI_P2P_PEERS_CHANGED_ACTION event will be triggered. + * @see WifiP2pManager.discoverPeers */ fun discoverPeers(listener: WifiP2pManager.ActionListener? = null) { this.manager.discoverPeers(this.channel, listener) } /** - * Wrapper around WifiP2pManager::requestConnectionInfo - * * Obtain information about a connection with another device. + * @see WifiP2pManager.requestConnectionInfo */ fun requestConnectionInfo(listener: WifiP2pManager.ConnectionInfoListener? = null) { this.manager.requestConnectionInfo(this.channel, listener) } /** - * Wrapper around WifiP2pManager::requestGroupInfo - * * Obtain information about the current group. + * @see WifiP2pManager.requestGroupInfo */ fun requestGroupInfo(listener: WifiP2pManager.GroupInfoListener? = null) { this.manager.requestGroupInfo(this.channel, listener) } /** - * Wrapper around WifiP2pManager::createGroup - * * Create a new WiFi-Direct group. + * @see WifiP2pManager.createGroup */ fun createGroup(listener: WifiP2pManager.ActionListener? = null) { this.manager.createGroup(this.channel, listener) } /** - * Wrapper around WifiP2pManager::removeGroup - * * Disconnect from the current WiFi-Direct group. + * @see WifiP2pManager.removeGroup */ fun removeGroup(listener: WifiP2pManager.ActionListener? = null) { this.manager.removeGroup(this.channel, listener) } + // Shortcuts + /** - * Create a new WiFi-Direct group. - * If already connected to a group, quit it first. + * Create a new WiFi-Direct group. 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 onFailure: error handler for the removeGroup event + * @param onRemoveFailure: error handler for the removeGroup event + * + * @see WifiP2pManager.createGroup + * @see WifiP2pManager.removeGroup */ fun recreateGroup( listener: WifiP2pManager.ActionListener? = null, - onFailure: ((Int) -> Unit)? = null + onRemoveFailure: ((Int) -> Unit)? = null ) { // get the current group information this.requestGroupInfo { group -> @@ -201,7 +200,7 @@ class WifiP2pHelper( override fun onFailure(reason: Int) { // call the handler - onFailure?.invoke(reason) + onRemoveFailure?.invoke(reason) } })