mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -04:00
#1600 Move ZimHostActivity to app module
This commit is contained in:
parent
ec4525560f
commit
d18d25d6fb
@ -2,6 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.kiwix.kiwixmobile">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<application android:name=".KiwixApp">
|
||||
<activity
|
||||
android:name=".main.KiwixMainActivity"
|
||||
@ -140,5 +142,8 @@
|
||||
<data android:host="*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".webserver.ZimHostActivity" />
|
||||
|
||||
<service android:name=".webserver.wifi_hotspot.HotspotService" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.di
|
||||
package org.kiwix.kiwixmobile.core.di
|
||||
|
||||
import javax.inject.Scope
|
||||
|
@ -15,17 +15,19 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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 {
|
@ -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
|
||||
}
|
@ -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
|
@ -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
|
@ -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 {
|
@ -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
|
||||
}
|
@ -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
|
@ -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<ZimHostActivity>()
|
||||
}
|
||||
|
||||
override fun urlIsInvalid() =
|
||||
super.urlIsInvalid() || currentWebView.url == homeUrl
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<String> getSelectedBooksPath() {
|
||||
@ -289,7 +295,7 @@ public class ZimHostActivity extends BaseActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void addBooks(@Nullable List<BooksOnDiskListItem> books) {
|
||||
@Override public void addBooks(@NotNull List<? extends BooksOnDiskListItem> books) {
|
||||
booksAdapter.setItems(books);
|
||||
}
|
||||
|
@ -15,20 +15,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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()
|
||||
}
|
@ -15,22 +15,17 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<ZimHostContract.Presenter> {
|
||||
void addBooks(List<BooksOnDiskListItem> books);
|
||||
interface View : BaseContract.View<Presenter> {
|
||||
fun addBooks(books: List<BooksOnDiskListItem>)
|
||||
}
|
||||
|
||||
interface Presenter
|
||||
extends BaseContract.Presenter<ZimHostContract.View> {
|
||||
void loadBooks();
|
||||
interface Presenter : BaseContract.Presenter<View> {
|
||||
fun loadBooks()
|
||||
}
|
||||
}
|
@ -15,26 +15,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<View>(),
|
||||
Presenter {
|
||||
|
||||
override fun loadBooks() {
|
||||
dataSource.languageCategorizedBooks
|
||||
.subscribe(object : SingleObserver<List<BooksOnDiskListItem>> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
compositeDisposable.add(d)
|
||||
}
|
||||
|
||||
override fun onSuccess(books: List<BooksOnDiskListItem>) {
|
||||
view!!.addBooks(books)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Unable to load books", e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ZimHostPresenter"
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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()
|
@ -15,12 +15,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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) {
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.wifi_hotspot;
|
||||
package org.kiwix.kiwixmobile.webserver.wifi_hotspot;
|
||||
|
||||
public interface IpAddressCallbacks {
|
||||
|
@ -8,8 +8,6 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<!-- Device with versions >= Pie need this permission -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
@ -47,7 +45,6 @@
|
||||
|
||||
<activity android:name=".search.SearchActivity" />
|
||||
<activity android:name=".bookmark.BookmarksActivity" />
|
||||
<activity android:name=".webserver.ZimHostActivity" />
|
||||
|
||||
<provider
|
||||
android:name=".reader.ZimContentProvider"
|
||||
@ -68,7 +65,6 @@
|
||||
android:resource="@xml/kiwix_widget_provider_info" />
|
||||
</receiver>
|
||||
|
||||
<service android:name=".wifi_hotspot.HotspotService" />
|
||||
|
||||
<activity
|
||||
android:name=".error.ErrorActivity"
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.di
|
||||
package org.kiwix.kiwixmobile.core.di
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import dagger.MapKey
|
@ -18,12 +18,14 @@
|
||||
package org.kiwix.kiwixmobile.core.di.components
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import dagger.BindsInstance
|
||||
import dagger.Component
|
||||
import eu.mhutti1.utils.storage.StorageSelectDialog
|
||||
import org.kiwix.kiwixmobile.core.CoreApp
|
||||
import org.kiwix.kiwixmobile.core.StorageObserver
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
|
||||
@ -43,7 +45,6 @@ import org.kiwix.kiwixmobile.core.search.AutoCompleteAdapter
|
||||
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
|
||||
import org.kiwix.kiwixmobile.core.utils.BookUtils
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.StorageObserver
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@ -64,7 +65,6 @@ interface CoreComponent {
|
||||
fun build(): CoreComponent
|
||||
}
|
||||
|
||||
fun serviceComponent(): ServiceComponent.Builder
|
||||
fun zimReaderContainer(): ZimReaderContainer
|
||||
fun sharedPrefUtil(): SharedPreferenceUtil
|
||||
fun zimFileReaderFactory(): ZimFileReader.Factory
|
||||
@ -79,6 +79,7 @@ interface CoreComponent {
|
||||
fun connectivityManager(): ConnectivityManager
|
||||
fun context(): Context
|
||||
fun downloader(): Downloader
|
||||
fun notificationManager(): NotificationManager
|
||||
|
||||
fun inject(application: CoreApp)
|
||||
fun inject(zimContentProvider: ZimContentProvider)
|
||||
|
@ -31,8 +31,6 @@ import org.kiwix.kiwixmobile.core.intro.IntroActivity;
|
||||
import org.kiwix.kiwixmobile.core.intro.IntroModule;
|
||||
import org.kiwix.kiwixmobile.core.search.SearchActivity;
|
||||
import org.kiwix.kiwixmobile.core.splash.SplashActivity;
|
||||
import org.kiwix.kiwixmobile.core.webserver.ZimHostActivity;
|
||||
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule;
|
||||
|
||||
/**
|
||||
* Dagger.Android annotation processor will create the sub-components. We also specify the modules
|
||||
@ -70,8 +68,4 @@ public abstract class ActivityBindingModule {
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
public abstract HelpActivity provideHelpActivity();
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector(modules = ZimHostModule.class)
|
||||
public abstract ZimHostActivity provideZimHostActivity();
|
||||
}
|
||||
|
@ -112,7 +112,6 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.NetworkUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.StyleUtils;
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils;
|
||||
import org.kiwix.kiwixmobile.core.webserver.ZimHostActivity;
|
||||
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;
|
||||
@ -889,13 +888,14 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
|
||||
intentSupportKiwix.putExtra(EXTRA_EXTERNAL_LINK, true);
|
||||
openExternalUrl(intentSupportKiwix);
|
||||
} else if (itemId == R.id.menu_host_books) {
|
||||
Intent intent = new Intent(this, ZimHostActivity.class);
|
||||
startActivity(intent);
|
||||
onHostBooksClicked();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
protected abstract void onHostBooksClicked();
|
||||
|
||||
protected abstract void createNewTab();
|
||||
|
||||
/** Creates the full screen AddNoteDialog, which is a DialogFragment */
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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<ZimHostContract.View>
|
||||
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<List<BooksOnDiskListItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
compositeDisposable.add(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<BooksOnDiskListItem> books) {
|
||||
view.addBooks(books);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "Unable to load books", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user