From d9b191bc784b47183ada993d9a54afcb56bf3624 Mon Sep 17 00:00:00 2001 From: Adeel Date: Thu, 29 Aug 2019 20:42:10 +0500 Subject: [PATCH] Inject HotspotStateListener --- .../kiwix/kiwixmobile/di/modules/ServiceModule.kt | 14 ++++++++++++-- .../kiwixmobile/wifi_hotspot/HotspotService.java | 2 -- .../wifi_hotspot/WifiHotspotManager.java | 8 +++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt index 77f24aa75..51ee3a2c8 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ServiceModule.kt @@ -2,6 +2,7 @@ package org.kiwix.kiwixmobile.di.modules import android.app.Application import android.app.NotificationManager +import android.app.Service import android.content.Context import android.net.wifi.WifiManager import dagger.Module @@ -11,6 +12,7 @@ import org.kiwix.kiwixlib.JNIKiwixServer import org.kiwix.kiwixmobile.di.ServiceScope import org.kiwix.kiwixmobile.webserver.WebServerHelper import org.kiwix.kiwixmobile.wifi_hotspot.HotspotNotificationManager +import org.kiwix.kiwixmobile.wifi_hotspot.HotspotStateListener import org.kiwix.kiwixmobile.wifi_hotspot.WifiHotspotManager @Module @@ -25,8 +27,16 @@ class ServiceModule { @Provides @ServiceScope - fun providesWifiHotspotManager(wifiManager: WifiManager): WifiHotspotManager = - WifiHotspotManager(wifiManager) + fun providesWifiHotspotManager( + wifiManager: WifiManager, + hotspotStateListener: HotspotStateListener + ): WifiHotspotManager = + WifiHotspotManager(wifiManager, hotspotStateListener) + + @Provides + @ServiceScope + fun providesHotspotStateListener(service: Service): HotspotStateListener = + service as HotspotStateListener @Provides @ServiceScope diff --git a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/HotspotService.java b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/HotspotService.java index 0164367d3..545f4b709 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/HotspotService.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/HotspotService.java @@ -57,8 +57,6 @@ public class HotspotService extends Service implements HotspotStateListener { .inject(this); super.onCreate(); - hotspotManager.registerListener(this); - stopReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java index a64c9f661..8e6e0d237 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java @@ -24,8 +24,10 @@ public class WifiHotspotManager { WifiManager wifiManager; @Inject - public WifiHotspotManager(@NonNull WifiManager wifiManager) { + public WifiHotspotManager(@NonNull WifiManager wifiManager, + HotspotStateListener hotspotStateListener) { this.wifiManager = wifiManager; + this.hotspotStateListener = hotspotStateListener; } //Workaround to turn on hotspot for Oreo versions @@ -83,8 +85,4 @@ public class WifiHotspotManager { + " \n SSID is : " + wifiConfiguration.SSID); } - - public void registerListener(@NonNull HotspotStateListener hotspotStateListener) { - this.hotspotStateListener = hotspotStateListener; - } }