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.Application
import android.app.NotificationManager import android.app.NotificationManager
import android.app.Service
import android.content.Context import android.content.Context
import android.net.wifi.WifiManager import android.net.wifi.WifiManager
import dagger.Module import dagger.Module
@ -11,6 +12,7 @@ import org.kiwix.kiwixlib.JNIKiwixServer
import org.kiwix.kiwixmobile.di.ServiceScope import org.kiwix.kiwixmobile.di.ServiceScope
import org.kiwix.kiwixmobile.webserver.WebServerHelper import org.kiwix.kiwixmobile.webserver.WebServerHelper
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotNotificationManager import org.kiwix.kiwixmobile.wifi_hotspot.HotspotNotificationManager
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotStateListener
import org.kiwix.kiwixmobile.wifi_hotspot.WifiHotspotManager import org.kiwix.kiwixmobile.wifi_hotspot.WifiHotspotManager
@Module @Module
@ -25,8 +27,16 @@ class ServiceModule {
@Provides @Provides
@ServiceScope @ServiceScope
fun providesWifiHotspotManager(wifiManager: WifiManager): WifiHotspotManager = fun providesWifiHotspotManager(
WifiHotspotManager(wifiManager) wifiManager: WifiManager,
hotspotStateListener: HotspotStateListener
): WifiHotspotManager =
WifiHotspotManager(wifiManager, hotspotStateListener)
@Provides
@ServiceScope
fun providesHotspotStateListener(service: Service): HotspotStateListener =
service as HotspotStateListener
@Provides @Provides
@ServiceScope @ServiceScope

View File

@ -57,8 +57,6 @@ public class HotspotService extends Service implements HotspotStateListener {
.inject(this); .inject(this);
super.onCreate(); super.onCreate();
hotspotManager.registerListener(this);
stopReceiver = new BroadcastReceiver() { stopReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {

View File

@ -24,8 +24,10 @@ public class WifiHotspotManager {
WifiManager wifiManager; WifiManager wifiManager;
@Inject @Inject
public WifiHotspotManager(@NonNull WifiManager wifiManager) { public WifiHotspotManager(@NonNull WifiManager wifiManager,
HotspotStateListener hotspotStateListener) {
this.wifiManager = wifiManager; this.wifiManager = wifiManager;
this.hotspotStateListener = hotspotStateListener;
} }
//Workaround to turn on hotspot for Oreo versions //Workaround to turn on hotspot for Oreo versions
@ -83,8 +85,4 @@ public class WifiHotspotManager {
+ " \n SSID is : " + " \n SSID is : "
+ wifiConfiguration.SSID); + wifiConfiguration.SSID);
} }
public void registerListener(@NonNull HotspotStateListener hotspotStateListener) {
this.hotspotStateListener = hotspotStateListener;
}
} }