From d18d25d6fb32795757b734638a193476fe10c20b Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Thu, 21 Nov 2019 15:50:16 +0000 Subject: [PATCH] #1600 Move ZimHostActivity to app module --- app/src/main/AndroidManifest.xml | 5 ++ .../kiwix/kiwixmobile/ActivityExtensions.kt | 2 +- .../java/org/kiwix/kiwixmobile/KiwixApp.kt | 4 +- .../kiwixmobile/KiwixViewModelFactory.java | 2 +- .../kiwixmobile/{ => core}/di/KiwixScope.kt | 2 +- .../kiwix/kiwixmobile/core/di/ServiceScope.kt | 0 .../di/components/KiwixActivityComponent.kt | 14 ++++- .../di/components/KiwixComponent.kt | 10 +-- .../core/di/components/ServiceComponent.kt | 2 +- .../di/modules/KiwixActivityModule.kt | 3 +- .../{ => core}/di/modules/KiwixModule.kt | 4 +- .../core/di/modules/ServiceModule.kt | 29 +++------ .../{ => core}/di/modules/ViewModelModule.kt | 4 +- .../kiwixmobile/main/KiwixMainActivity.kt | 5 ++ .../webserver/WebServerHelper.java | 4 +- .../webserver/ZimHostActivity.java | 30 +++++---- .../kiwixmobile/webserver/ZimHostCallbacks.kt | 22 +++---- .../kiwixmobile/webserver/ZimHostContract.kt | 19 +++--- .../kiwixmobile/webserver/ZimHostModule.kt | 26 +++----- .../kiwixmobile/webserver/ZimHostPresenter.kt | 56 +++++++++++++++++ .../HotspotNotificationManager.java | 4 +- .../wifi_hotspot/HotspotService.java | 14 ++--- .../wifi_hotspot/HotspotStateReceiver.kt | 7 ++- .../wifi_hotspot/IpAddressCallbacks.java | 2 +- core/src/main/AndroidManifest.xml | 4 -- .../kiwixmobile/{ => core}/di/ViewModelKey.kt | 2 +- .../core/di/components/CoreComponent.kt | 5 +- .../di/modules/ActivityBindingModule.java | 6 -- .../core/main/CoreMainActivity.java | 6 +- .../core/webserver/ZimHostPresenter.java | 62 ------------------- .../custom/di/CustomViewModelModule.kt | 2 +- .../custom/main/CustomMainActivity.kt | 5 ++ 32 files changed, 171 insertions(+), 191 deletions(-) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/KiwixScope.kt (95%) rename {core => app}/src/main/java/org/kiwix/kiwixmobile/core/di/ServiceScope.kt (100%) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/components/KiwixActivityComponent.kt (85%) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/components/KiwixComponent.kt (78%) rename {core => app}/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt (94%) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/modules/KiwixActivityModule.kt (88%) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/modules/KiwixModule.kt (91%) rename {core => app}/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt (70%) rename app/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/modules/ViewModelModule.kt (94%) rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile}/webserver/WebServerHelper.java (97%) rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile}/webserver/ZimHostActivity.java (91%) rename core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostCallbacks.java => app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostCallbacks.kt (71%) rename core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostContract.java => app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostContract.kt (68%) rename core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostModule.java => app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostModule.kt (60%) create mode 100644 app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile/webserver}/wifi_hotspot/HotspotNotificationManager.java (96%) rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile/webserver}/wifi_hotspot/HotspotService.java (90%) rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile/webserver}/wifi_hotspot/HotspotStateReceiver.kt (88%) rename {core/src/main/java/org/kiwix/kiwixmobile/core => app/src/main/java/org/kiwix/kiwixmobile/webserver}/wifi_hotspot/IpAddressCallbacks.java (93%) rename core/src/main/java/org/kiwix/kiwixmobile/{ => core}/di/ViewModelKey.kt (96%) delete mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostPresenter.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d771ec35a..68f20ecfd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + + + + diff --git a/app/src/main/java/org/kiwix/kiwixmobile/ActivityExtensions.kt b/app/src/main/java/org/kiwix/kiwixmobile/ActivityExtensions.kt index b5a695372..82a957039 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/ActivityExtensions.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/ActivityExtensions.kt @@ -19,7 +19,7 @@ package org.kiwix.kiwixmobile import org.kiwix.kiwixmobile.core.base.BaseActivity -import org.kiwix.kiwixmobile.di.components.KiwixComponent +import org.kiwix.kiwixmobile.core.di.components.KiwixComponent private val BaseActivity.kiwixComponent: KiwixComponent get() = (applicationContext as KiwixApp).kiwixComponent diff --git a/app/src/main/java/org/kiwix/kiwixmobile/KiwixApp.kt b/app/src/main/java/org/kiwix/kiwixmobile/KiwixApp.kt index 53f775d83..e215d8175 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/KiwixApp.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/KiwixApp.kt @@ -19,8 +19,8 @@ package org.kiwix.kiwixmobile import org.kiwix.kiwixmobile.core.CoreApp -import org.kiwix.kiwixmobile.di.components.DaggerKiwixComponent -import org.kiwix.kiwixmobile.di.components.KiwixComponent +import org.kiwix.kiwixmobile.core.di.components.DaggerKiwixComponent +import org.kiwix.kiwixmobile.core.di.components.KiwixComponent class KiwixApp : CoreApp() { @Suppress("ConvertLambdaToReference") // we want the entire call to be lazy diff --git a/app/src/main/java/org/kiwix/kiwixmobile/KiwixViewModelFactory.java b/app/src/main/java/org/kiwix/kiwixmobile/KiwixViewModelFactory.java index 5a3bca9f1..2c62cd951 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/KiwixViewModelFactory.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/KiwixViewModelFactory.java @@ -23,7 +23,7 @@ import java.util.Map; import javax.inject.Inject; import javax.inject.Provider; import org.kiwix.kiwixmobile.core.ViewModelFactory; -import org.kiwix.kiwixmobile.di.KiwixScope; +import org.kiwix.kiwixmobile.core.di.KiwixScope; @KiwixScope public class KiwixViewModelFactory extends ViewModelFactory { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/KiwixScope.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/KiwixScope.kt similarity index 95% rename from app/src/main/java/org/kiwix/kiwixmobile/di/KiwixScope.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/KiwixScope.kt index 9e6ac4bdd..223ffb663 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/KiwixScope.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/KiwixScope.kt @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.di +package org.kiwix.kiwixmobile.core.di import javax.inject.Scope diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/ServiceScope.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/ServiceScope.kt similarity index 100% rename from core/src/main/java/org/kiwix/kiwixmobile/core/di/ServiceScope.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/ServiceScope.kt diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixActivityComponent.kt similarity index 85% rename from app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixActivityComponent.kt index ea574d3fb..20be7c239 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixActivityComponent.kt @@ -15,17 +15,19 @@ * along with this program. If not, see . * */ -package org.kiwix.kiwixmobile.di.components +package org.kiwix.kiwixmobile.core.di.components import android.app.Activity import dagger.BindsInstance import dagger.Subcomponent import org.kiwix.kiwixmobile.core.di.ActivityScope -import org.kiwix.kiwixmobile.di.modules.KiwixActivityModule +import org.kiwix.kiwixmobile.core.di.modules.KiwixActivityModule import org.kiwix.kiwixmobile.language.LanguageActivity import org.kiwix.kiwixmobile.local_file_transfer.LocalFileTransferActivity import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity +import org.kiwix.kiwixmobile.webserver.ZimHostActivity +import org.kiwix.kiwixmobile.webserver.ZimHostModule import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity import org.kiwix.kiwixmobile.zim_manager.download_view.DownloadFragment import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment @@ -33,7 +35,12 @@ import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment @ActivityScope -@Subcomponent(modules = [KiwixActivityModule::class]) +@Subcomponent( + modules = [ + KiwixActivityModule::class, + ZimHostModule::class + ] +) interface KiwixActivityComponent { fun inject(downloadFragment: DownloadFragment) fun inject(libraryFragment: LibraryFragment) @@ -44,6 +51,7 @@ interface KiwixActivityComponent { fun inject(languageActivity: LanguageActivity) fun inject(kiwixMainActivity: KiwixMainActivity) fun inject(kiwixSettingsActivity: KiwixSettingsActivity) + fun inject(zimHostActivity: ZimHostActivity) @Subcomponent.Builder interface Builder { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixComponent.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixComponent.kt similarity index 78% rename from app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixComponent.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixComponent.kt index 9b1e8450c..03c6966cb 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixComponent.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/KiwixComponent.kt @@ -16,13 +16,12 @@ * */ -package org.kiwix.kiwixmobile.di.components +package org.kiwix.kiwixmobile.core.di.components import dagger.Component -import org.kiwix.kiwixmobile.core.di.components.CoreComponent -import org.kiwix.kiwixmobile.di.modules.KiwixModule -import org.kiwix.kiwixmobile.di.KiwixScope -import org.kiwix.kiwixmobile.di.modules.ViewModelModule +import org.kiwix.kiwixmobile.core.di.KiwixScope +import org.kiwix.kiwixmobile.core.di.modules.KiwixModule +import org.kiwix.kiwixmobile.core.di.modules.ViewModelModule @KiwixScope @Component( @@ -31,4 +30,5 @@ import org.kiwix.kiwixmobile.di.modules.ViewModelModule ) interface KiwixComponent { fun activityComponentBuilder(): KiwixActivityComponent.Builder + fun serviceComponent(): ServiceComponent.Builder } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt similarity index 94% rename from core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt index 1adbaab0b..815427c4d 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/components/ServiceComponent.kt @@ -23,7 +23,7 @@ import dagger.BindsInstance import dagger.Subcomponent import org.kiwix.kiwixmobile.core.di.ServiceScope import org.kiwix.kiwixmobile.core.di.modules.ServiceModule -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService @Subcomponent(modules = [ServiceModule::class]) @ServiceScope diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixActivityModule.kt similarity index 88% rename from app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixActivityModule.kt index a881282d0..e14156f8c 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixActivityModule.kt @@ -16,10 +16,9 @@ * */ -package org.kiwix.kiwixmobile.di.modules +package org.kiwix.kiwixmobile.core.di.modules import dagger.Module -import org.kiwix.kiwixmobile.core.di.modules.ActivityModule @Module(includes = [ActivityModule::class]) class KiwixActivityModule diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixModule.kt similarity index 91% rename from app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixModule.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixModule.kt index a045e9f1a..89255bcc2 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/KiwixModule.kt @@ -16,13 +16,13 @@ * */ -package org.kiwix.kiwixmobile.di.modules +package org.kiwix.kiwixmobile.core.di.modules import android.content.Context import android.location.LocationManager import dagger.Module import dagger.Provides -import org.kiwix.kiwixmobile.di.KiwixScope +import org.kiwix.kiwixmobile.core.di.KiwixScope @Module object KiwixModule { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt similarity index 70% rename from core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt index 5fa094080..6c59a3938 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ServiceModule.kt @@ -26,11 +26,11 @@ import dagger.Provides import org.kiwix.kiwixlib.JNIKiwixLibrary import org.kiwix.kiwixlib.JNIKiwixServer import org.kiwix.kiwixmobile.core.di.ServiceScope -import org.kiwix.kiwixmobile.core.webserver.WebServerHelper -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotNotificationManager -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotStateReceiver -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotStateReceiver.Callback -import org.kiwix.kiwixmobile.core.wifi_hotspot.IpAddressCallbacks +import org.kiwix.kiwixmobile.webserver.WebServerHelper +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotNotificationManager +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotStateReceiver +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotStateReceiver.Callback +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks @Module class ServiceModule { @@ -41,12 +41,7 @@ class ServiceModule { jniKiwixLibrary: JNIKiwixLibrary, kiwixServer: JNIKiwixServer, ipAddressCallbacks: IpAddressCallbacks - ): WebServerHelper = - WebServerHelper( - jniKiwixLibrary, - kiwixServer, - ipAddressCallbacks - ) + ): WebServerHelper = WebServerHelper(jniKiwixLibrary, kiwixServer, ipAddressCallbacks) @Provides @ServiceScope @@ -67,19 +62,15 @@ class ServiceModule { fun providesHotspotNotificationManager( notificationManager: NotificationManager, context: Context - ): HotspotNotificationManager = - HotspotNotificationManager(notificationManager, context) + ): HotspotNotificationManager = HotspotNotificationManager(notificationManager, context) @Provides @ServiceScope - fun providesHotspotStateReceiver( - callback: Callback - ): HotspotStateReceiver = + fun providesHotspotStateReceiver(callback: Callback): HotspotStateReceiver = HotspotStateReceiver(callback) @Provides @ServiceScope - fun providesHotspotStateReceiverCallback( - service: Service - ): HotspotStateReceiver.Callback = service as Callback + fun providesHotspotStateReceiverCallback(service: Service): HotspotStateReceiver.Callback = + service as Callback } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ViewModelModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ViewModelModule.kt similarity index 94% rename from app/src/main/java/org/kiwix/kiwixmobile/di/modules/ViewModelModule.kt rename to app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ViewModelModule.kt index 710a2d6a2..7a37e1b01 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/ViewModelModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ViewModelModule.kt @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.di.modules +package org.kiwix.kiwixmobile.core.di.modules import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider @@ -25,7 +25,7 @@ import dagger.Module import dagger.multibindings.IntoMap import org.kiwix.kiwixmobile.KiwixViewModelFactory import org.kiwix.kiwixmobile.language.viewmodel.LanguageViewModel -import org.kiwix.kiwixmobile.di.ViewModelKey +import org.kiwix.kiwixmobile.core.di.ViewModelKey import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel @Module diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt index eb7b6d646..1497efe88 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt @@ -43,6 +43,7 @@ import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil.PREF_KIWIX_MOBILE import org.kiwix.kiwixmobile.core.utils.UpdateUtils.reformatProviderUrl import org.kiwix.kiwixmobile.core.utils.files.FileUtils import org.kiwix.kiwixmobile.kiwixActivityComponent +import org.kiwix.kiwixmobile.webserver.ZimHostActivity import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity import java.io.File @@ -116,6 +117,10 @@ class KiwixMainActivity : CoreMainActivity() { override fun hasValidFileAndUrl(url: String?, zimFileReader: ZimFileReader?) = super.hasValidFileAndUrl(url, zimFileReader) && url != homeUrl + override fun onHostBooksClicked() { + start() + } + override fun urlIsInvalid() = super.urlIsInvalid() || currentWebView.url == homeUrl diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/WebServerHelper.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.java similarity index 97% rename from core/src/main/java/org/kiwix/kiwixmobile/core/webserver/WebServerHelper.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.java index cbbb8d3e0..a992bb369 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/WebServerHelper.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/WebServerHelper.java @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.webserver; +package org.kiwix.kiwixmobile.webserver; import android.util.Log; import androidx.annotation.NonNull; @@ -29,7 +29,7 @@ import org.kiwix.kiwixlib.JNIKiwixException; import org.kiwix.kiwixlib.JNIKiwixLibrary; import org.kiwix.kiwixlib.JNIKiwixServer; import org.kiwix.kiwixmobile.core.utils.ServerUtils; -import org.kiwix.kiwixmobile.core.wifi_hotspot.IpAddressCallbacks; +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks; import static org.kiwix.kiwixmobile.core.utils.ServerUtils.INVALID_IP; diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java similarity index 91% rename from core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java index 324ddc25b..fe8c04077 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostActivity.java @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.webserver; +package org.kiwix.kiwixmobile.webserver; import android.app.ProgressDialog; import android.content.ComponentName; @@ -39,24 +39,26 @@ import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import kotlin.Unit; +import org.jetbrains.annotations.NotNull; +import org.kiwix.kiwixmobile.ActivityExtensionsKt; import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.R2; import org.kiwix.kiwixmobile.core.base.BaseActivity; import org.kiwix.kiwixmobile.core.utils.AlertDialogShower; import org.kiwix.kiwixmobile.core.utils.KiwixDialog; import org.kiwix.kiwixmobile.core.utils.ServerUtils; -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService; import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode; import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate; import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter; import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem; +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService; -import static org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService.ACTION_CHECK_IP_ADDRESS; -import static org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService.ACTION_START_SERVER; -import static org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService.ACTION_STOP_SERVER; +import static org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_CHECK_IP_ADDRESS; +import static org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_START_SERVER; +import static org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.ACTION_STOP_SERVER; public class ZimHostActivity extends BaseActivity implements - ZimHostCallbacks, ZimHostContract.View { + ZimHostCallbacks, ZimHostContract.View { @BindView(R2.id.startServerButton) Button startServerButton; @@ -82,6 +84,10 @@ public class ZimHostActivity extends BaseActivity implements private ServiceConnection serviceConnection; private ProgressDialog progressDialog; + @Override protected void injection() { + ActivityExtensionsKt.getKiwixActivityComponent(this).inject(this); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -139,11 +145,11 @@ public class ZimHostActivity extends BaseActivity implements } private void startHotspotHelper() { - if (ServerUtils.isServerStarted) { - startService(createHotspotIntent(ACTION_STOP_SERVER)); - } else { - startHotspotManuallyDialog(); - } + if (ServerUtils.isServerStarted) { + startService(createHotspotIntent(ACTION_STOP_SERVER)); + } else { + startHotspotManuallyDialog(); + } } private ArrayList getSelectedBooksPath() { @@ -289,7 +295,7 @@ public class ZimHostActivity extends BaseActivity implements } } - @Override public void addBooks(@Nullable List books) { + @Override public void addBooks(@NotNull List books) { booksAdapter.setItems(books); } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostCallbacks.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostCallbacks.kt similarity index 71% rename from core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostCallbacks.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostCallbacks.kt index ed93009ec..93111da07 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostCallbacks.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostCallbacks.kt @@ -15,20 +15,12 @@ * along with this program. If not, see . * */ +package org.kiwix.kiwixmobile.webserver -package org.kiwix.kiwixmobile.core.webserver; - -import androidx.annotation.NonNull; - -public interface ZimHostCallbacks { - - void onServerStarted(@NonNull String ip); - - void onServerStopped(); - - void onServerFailedToStart(); - - void onIpAddressValid(); - - void onIpAddressInvalid(); +interface ZimHostCallbacks { + fun onServerStarted(ip: String) + fun onServerStopped() + fun onServerFailedToStart() + fun onIpAddressValid() + fun onIpAddressInvalid() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostContract.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostContract.kt similarity index 68% rename from core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostContract.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostContract.kt index 93970563f..5c420b2bc 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostContract.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostContract.kt @@ -15,22 +15,17 @@ * along with this program. If not, see . * */ +package org.kiwix.kiwixmobile.webserver -package org.kiwix.kiwixmobile.core.webserver; - -import java.util.List; -import org.kiwix.kiwixmobile.core.base.BaseContract; -import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem; +import org.kiwix.kiwixmobile.core.base.BaseContract +import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem class ZimHostContract { - - interface View - extends BaseContract.View { - void addBooks(List books); + interface View : BaseContract.View { + fun addBooks(books: List) } - interface Presenter - extends BaseContract.Presenter { - void loadBooks(); + interface Presenter : BaseContract.Presenter { + fun loadBooks() } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostModule.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostModule.kt similarity index 60% rename from core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostModule.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostModule.kt index 55862bc09..34811083b 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostModule.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostModule.kt @@ -15,26 +15,14 @@ * along with this program. If not, see . * */ +package org.kiwix.kiwixmobile.webserver -package org.kiwix.kiwixmobile.core.webserver; - -import android.app.Activity; -import dagger.Module; -import dagger.Provides; -import org.kiwix.kiwixmobile.core.di.ActivityScope; +import dagger.Binds +import dagger.Module +import org.kiwix.kiwixmobile.core.di.ActivityScope @Module -public class ZimHostModule { - - @ActivityScope - @Provides - ZimHostContract.Presenter provideZimHostPresenter(ZimHostPresenter zimHostPresenter) { - return zimHostPresenter; - } - - @ActivityScope - @Provides Activity providesActivity(ZimHostActivity zimHostActivity) { - return zimHostActivity; - } +abstract class ZimHostModule { + @ActivityScope @Binds + abstract fun bindsZimHostPresenter(zimHostPresenter: ZimHostPresenter): ZimHostContract.Presenter } - diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt new file mode 100644 index 000000000..74b1924ae --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt @@ -0,0 +1,56 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.kiwix.kiwixmobile.webserver + +import android.util.Log +import io.reactivex.SingleObserver +import io.reactivex.disposables.Disposable +import org.kiwix.kiwixmobile.core.base.BasePresenter +import org.kiwix.kiwixmobile.core.data.DataSource +import org.kiwix.kiwixmobile.core.di.ActivityScope +import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem +import org.kiwix.kiwixmobile.webserver.ZimHostContract.Presenter +import org.kiwix.kiwixmobile.webserver.ZimHostContract.View +import javax.inject.Inject + +@ActivityScope +class ZimHostPresenter @Inject internal constructor(private val dataSource: DataSource) : + BasePresenter(), + Presenter { + + override fun loadBooks() { + dataSource.languageCategorizedBooks + .subscribe(object : SingleObserver> { + override fun onSubscribe(d: Disposable) { + compositeDisposable.add(d) + } + + override fun onSuccess(books: List) { + view!!.addBooks(books) + } + + override fun onError(e: Throwable) { + Log.e(TAG, "Unable to load books", e) + } + }) + } + + companion object { + private const val TAG = "ZimHostPresenter" + } +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotNotificationManager.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java similarity index 96% rename from core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotNotificationManager.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java index ce0499091..ac915f97d 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotNotificationManager.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.wifi_hotspot; +package org.kiwix.kiwixmobile.webserver.wifi_hotspot; import android.app.Notification; import android.app.NotificationChannel; @@ -30,7 +30,7 @@ import androidx.core.app.NotificationCompat; import javax.inject.Inject; import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.utils.Constants; -import org.kiwix.kiwixmobile.core.webserver.ZimHostActivity; +import org.kiwix.kiwixmobile.webserver.ZimHostActivity; public class HotspotNotificationManager { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotService.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.java similarity index 90% rename from core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotService.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.java index f000ec8e7..5af081a45 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotService.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.java @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.wifi_hotspot; +package org.kiwix.kiwixmobile.webserver.wifi_hotspot; import android.app.Service; import android.content.Intent; @@ -26,15 +26,15 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import javax.inject.Inject; -import org.kiwix.kiwixmobile.core.CoreApp; +import org.kiwix.kiwixmobile.KiwixApp; import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.extensions.ContextExtensionsKt; import org.kiwix.kiwixmobile.core.utils.ServerUtils; -import org.kiwix.kiwixmobile.core.webserver.WebServerHelper; -import org.kiwix.kiwixmobile.core.webserver.ZimHostCallbacks; +import org.kiwix.kiwixmobile.webserver.WebServerHelper; +import org.kiwix.kiwixmobile.webserver.ZimHostCallbacks; -import static org.kiwix.kiwixmobile.core.webserver.ZimHostActivity.SELECTED_ZIM_PATHS_KEY; -import static org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotNotificationManager.HOTSPOT_NOTIFICATION_ID; +import static org.kiwix.kiwixmobile.webserver.ZimHostActivity.SELECTED_ZIM_PATHS_KEY; +import static org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotNotificationManager.HOTSPOT_NOTIFICATION_ID; /** * HotspotService is used to add a foreground service for the wifi hotspot. @@ -59,7 +59,7 @@ public class HotspotService extends Service HotspotStateReceiver hotspotStateReceiver; @Override public void onCreate() { - CoreApp.getCoreComponent() + ((KiwixApp) this.getApplicationContext()).getKiwixComponent() .serviceComponent() .service(this) .build() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotStateReceiver.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotStateReceiver.kt similarity index 88% rename from core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotStateReceiver.kt rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotStateReceiver.kt index eebac9962..1b1e71e89 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/HotspotStateReceiver.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotStateReceiver.kt @@ -15,12 +15,12 @@ * along with this program. If not, see . * */ -package org.kiwix.kiwixmobile.core.wifi_hotspot +package org.kiwix.kiwixmobile.webserver.wifi_hotspot import android.content.Context import android.content.Intent -import org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotStateReceiver.HotspotState.DISABLED import org.kiwix.kiwixmobile.core.base.BaseBroadcastReceiver +import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotStateReceiver.HotspotState.DISABLED import javax.inject.Inject const val EXTRA_WIFI_AP_STATE = "wifi_state" @@ -32,7 +32,8 @@ const val WIFI_AP_STATE_ENABLING = 12 const val WIFI_AP_STATE_ENABLED = 13 const val WIFI_AP_STATE_FAILED = 14 -class HotspotStateReceiver @Inject constructor(val callback: Callback) : BaseBroadcastReceiver() { +class HotspotStateReceiver @Inject constructor(private val callback: Callback) : + BaseBroadcastReceiver() { override val action: String = ACTION_WIFI_AP_STATE override fun onIntentWithActionReceived(context: Context, intent: Intent) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/IpAddressCallbacks.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/IpAddressCallbacks.java similarity index 93% rename from core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/IpAddressCallbacks.java rename to app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/IpAddressCallbacks.java index 2ddb5c5f3..a626c77ce 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/wifi_hotspot/IpAddressCallbacks.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/IpAddressCallbacks.java @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.wifi_hotspot; +package org.kiwix.kiwixmobile.webserver.wifi_hotspot; public interface IpAddressCallbacks { diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 06e014896..291195804 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -8,8 +8,6 @@ - - @@ -47,7 +45,6 @@ - - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.core.webserver; - -import android.util.Log; -import io.reactivex.SingleObserver; -import io.reactivex.disposables.Disposable; -import java.util.List; -import javax.inject.Inject; -import org.kiwix.kiwixmobile.core.base.BasePresenter; -import org.kiwix.kiwixmobile.core.data.DataSource; -import org.kiwix.kiwixmobile.core.di.ActivityScope; -import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem; - -@ActivityScope -class ZimHostPresenter extends BasePresenter - implements ZimHostContract.Presenter { - - private static final String TAG = "ZimHostPresenter"; - private final DataSource dataSource; - - @Inject ZimHostPresenter(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public void loadBooks() { - dataSource.getLanguageCategorizedBooks() - .subscribe(new SingleObserver>() { - @Override - public void onSubscribe(Disposable d) { - compositeDisposable.add(d); - } - - @Override - public void onSuccess(List books) { - view.addBooks(books); - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to load books", e); - } - }); - } -} diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomViewModelModule.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomViewModelModule.kt index f26a6b67a..ddc32e54f 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomViewModelModule.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/di/CustomViewModelModule.kt @@ -25,7 +25,7 @@ import dagger.Module import dagger.multibindings.IntoMap import org.kiwix.kiwixmobile.custom.CustomViewModelFactory import org.kiwix.kiwixmobile.custom.download.CustomDownloadViewModel -import org.kiwix.kiwixmobile.di.ViewModelKey +import org.kiwix.kiwixmobile.core.di.ViewModelKey @Module abstract class CustomViewModelModule { diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt index 55b4a654d..4fcb85b6a 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt @@ -74,9 +74,14 @@ class CustomMainActivity : CoreMainActivity() { val onCreateOptionsMenu = super.onCreateOptionsMenu(menu) menu?.findItem(R.id.menu_help)?.isVisible = false menu?.findItem(R.id.menu_openfile)?.isVisible = false + menu?.findItem(R.id.menu_host_books)?.isVisible = false return onCreateOptionsMenu } + override fun onHostBooksClicked() { + TODO("not implemented") + } + override fun createWebClient( webViewCallback: WebViewCallback, zimReaderContainer: ZimReaderContainer