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
@ServiceScope
fun providesWebServerHelper(
kiwixServer: KiwixServer,
kiwixServerFactory: KiwixServer.Factory,
ipAddressCallbacks: IpAddressCallbacks
): WebServerHelper = WebServerHelper(kiwixServer, ipAddressCallbacks)
): WebServerHelper = WebServerHelper(kiwixServerFactory, ipAddressCallbacks)
@Provides
@ServiceScope

View File

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

View File

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