Injected proper classes in WebServerHelper

This commit is contained in:
s-ayush2903 2020-12-14 16:12:53 +05:30
parent 7faf13ee3a
commit 1669a87d3c
No known key found for this signature in database
GPG Key ID: B4341DD08B2371CB
3 changed files with 7 additions and 7 deletions

View File

@ -39,9 +39,9 @@ class ServiceModule {
@Provides @Provides
@ServiceScope @ServiceScope
fun providesWebServerHelper( fun providesWebServerHelper(
kiwixServer: KiwixServer, kiwixServerFactory: KiwixServer.Factory,
ipAddressCallbacks: IpAddressCallbacks ipAddressCallbacks: IpAddressCallbacks
): WebServerHelper = WebServerHelper(kiwixServer, ipAddressCallbacks) ): WebServerHelper = WebServerHelper(kiwixServerFactory, ipAddressCallbacks)
@Provides @Provides
@ServiceScope @ServiceScope

View File

@ -28,7 +28,7 @@ private const val TAG = "KiwixServer"
class KiwixServer @Inject constructor(private val jniKiwixServer: JNIKiwixServer) { class KiwixServer @Inject constructor(private val jniKiwixServer: JNIKiwixServer) {
class Factory { class Factory @Inject constructor() {
fun createKiwixServer(selectedBooksPath: ArrayList<String>): KiwixServer { fun createKiwixServer(selectedBooksPath: ArrayList<String>): KiwixServer {
val kiwixLibrary = Library() val kiwixLibrary = Library()
selectedBooksPath.forEach { path -> selectedBooksPath.forEach { path ->

View File

@ -40,13 +40,14 @@ import static org.kiwix.kiwixmobile.core.utils.ServerUtils.INVALID_IP;
public class WebServerHelper { public class WebServerHelper {
private static final String TAG = "WebServerHelper"; private static final String TAG = "WebServerHelper";
private KiwixServer kiwixServer; private KiwixServer kiwixServer;
private KiwixServer.Factory kiwixServerFactory;
private IpAddressCallbacks ipAddressCallbacks; private IpAddressCallbacks ipAddressCallbacks;
private boolean isServerStarted; private boolean isServerStarted;
private JNIKiwixServer server; private JNIKiwixServer server;
@Inject public WebServerHelper(@NonNull KiwixServer kiwixServer, @Inject public WebServerHelper(@NonNull KiwixServer.Factory kiwixServerFactory,
@NonNull IpAddressCallbacks ipAddressCallbacks) { @NonNull IpAddressCallbacks ipAddressCallbacks) {
this.kiwixServer = kiwixServer; this.kiwixServerFactory = kiwixServerFactory;
this.ipAddressCallbacks = ipAddressCallbacks; this.ipAddressCallbacks = ipAddressCallbacks;
} }
@ -71,8 +72,7 @@ public class WebServerHelper {
if (!isServerStarted) { if (!isServerStarted) {
int DEFAULT_PORT = 8080; int DEFAULT_PORT = 8080;
ServerUtils.port = DEFAULT_PORT; ServerUtils.port = DEFAULT_PORT;
KiwixServer.Factory factory = new KiwixServer.Factory(); kiwixServer = kiwixServerFactory.createKiwixServer(selectedBooksPath);
kiwixServer = factory.createKiwixServer(selectedBooksPath);
updateServerState(kiwixServer.startServer(ServerUtils.port)); updateServerState(kiwixServer.startServer(ServerUtils.port));
Log.d(TAG, "Server status" + isServerStarted); Log.d(TAG, "Server status" + isServerStarted);
} }