Inject HotspotStateListener

This commit is contained in:
Adeel 2019-08-29 20:42:10 +05:00
parent d1572c142d
commit d9b191bc78
3 changed files with 15 additions and 9 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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;
}
}