Incorporate activityComponent and ActivityModule 1.1

This commit is contained in:
Justin Biggs 2020-01-12 12:53:43 -06:00
parent ad7dac1d7d
commit c6d69cfe42
23 changed files with 89 additions and 521 deletions

View File

@ -81,9 +81,12 @@ public class IntroActivity extends BaseActivity implements IntroContract.View {
};
private View[] views;
@Override protected void injection() {
ActivityExtensionsKt.getKiwixActivityComponent(this).inject(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
ActivityExtensionsKt.getKiwixActivityComponent(this).inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
LayoutInflater layoutInflater = getLayoutInflater();
@ -138,7 +141,4 @@ public class IntroActivity extends BaseActivity implements IntroContract.View {
timer.cancel();
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
}
}

View File

@ -101,6 +101,10 @@ class KiwixMainActivity : CoreMainActivity() {
}
}
override fun injection() {
this.kiwixActivityComponent.inject(this)
}
override fun hasValidFileAndUrl(url: String?, zimFileReader: ZimFileReader?) =
super.hasValidFileAndUrl(url, zimFileReader) && url != HOME_URL

View File

@ -1,6 +1,6 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* Copyright (c) 2020 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
@ -15,14 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver;
import dagger.Provides;
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

View File

@ -14,9 +14,7 @@ object Versions {
const val androidx_test_espresso: String = "3.1.1" // available: "3.2.0"
const val com_squareup_retrofit2: String = "2.5.0" // available: "2.6.2"
const val com_google_dagger: String = "2.21" // available: "2.25.2"
const val com_yahoo_squidb: String = "2.0.0" // available: "3.2.3"
const val com_jakewharton: String = "10.2.0"
@ -59,9 +57,9 @@ object Versions {
const val kotlin_stdlib_jdk7: String = "1.3.61"
const val com_google_dagger: String = "2.25.2" // available: "2.24"
const val leakcanary_android: String = "2.0"
const val com_yahoo_squidb: String = "2.0.0" // available: "3.2.3"
const val com_google_dagger: String = "2.25.2" // available: "2.24"
const val constraintlayout: String = "1.1.3"

View File

@ -58,10 +58,9 @@ dependencies {
}
// Leak canary
debugImplementation(Libs.leakcanary_android)
implementation(Libs.leakcanary_android)
implementation(Libs.android_arch_lifecycle_extensions)
implementation(Libs.objectbox_kotlin)
implementation(Libs.objectbox_rxjava)
}

View File

@ -24,38 +24,31 @@ import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import butterknife.ButterKnife
import butterknife.Unbinder
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
import org.kiwix.kiwixmobile.core.di.components.ActivityComponent
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import javax.inject.Inject
abstract class BaseActivity : AppCompatActivity() {
private lateinit var activityComponent: ActivityComponent
@Inject
lateinit var sharedPreferenceUtil: SharedPreferenceUtil
private var unbinder: Unbinder? = null
abstract fun injection(coreComponent: CoreComponent)
protected abstract fun injection()
override fun onCreate(savedInstanceState: Bundle?) {
CoreApp.getCoreComponent().inject(this)
activityComponent.activityComponentBuilder().activity(this).build()
injection()
super.onCreate(savedInstanceState)
LanguageUtils.handleLocaleChange(this, sharedPreferenceUtil)
}
override fun getTheme(): Resources.Theme {
val theme = super.getTheme()
if (sharedPreferenceUtil.nightMode()) {
setTheme(R.style.AppTheme_Night)
} else {
theme.applyStyle(R.style.StatusBarTheme, true)
}
return theme
}
override fun setContentView(@LayoutRes layoutResID: Int) {
super.setContentView(layoutResID)
unbinder = ButterKnife.bind(this)

View File

@ -113,10 +113,13 @@ public class BookmarksActivity extends BaseActivity implements BookmarksContract
}
};
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
presenter.attachView(this);
setContentView(R.layout.activity_bookmarks);
@ -253,7 +256,4 @@ public class BookmarksActivity extends BaseActivity implements BookmarksContract
}
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
}
}

View File

@ -18,7 +18,6 @@
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
@ -26,7 +25,6 @@ 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.base.BaseActivity
import org.kiwix.kiwixmobile.core.bookmark.BookmarksActivity
import org.kiwix.kiwixmobile.core.bookmark.BookmarksModule
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
@ -34,8 +32,10 @@ import org.kiwix.kiwixmobile.core.dao.NewBookDao
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
import org.kiwix.kiwixmobile.core.data.DataModule
import org.kiwix.kiwixmobile.core.data.DataSource
import org.kiwix.kiwixmobile.core.data.local.dao.BookDao
import org.kiwix.kiwixmobile.core.data.local.dao.BookmarksDao
import org.kiwix.kiwixmobile.core.data.local.dao.RecentSearchDao
import org.kiwix.kiwixmobile.core.data.remote.KiwixService
import org.kiwix.kiwixmobile.core.di.modules.ActivityModule
import org.kiwix.kiwixmobile.core.di.modules.ApplicationModule
import org.kiwix.kiwixmobile.core.di.modules.JNIModule
import org.kiwix.kiwixmobile.core.di.modules.NetworkModule
@ -47,15 +47,13 @@ import org.kiwix.kiwixmobile.core.history.HistoryModule
import org.kiwix.kiwixmobile.core.main.AddNoteDialog
import org.kiwix.kiwixmobile.core.main.KiwixWebView
import org.kiwix.kiwixmobile.core.reader.ZimContentProvider
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.search.AutoCompleteAdapter
import org.kiwix.kiwixmobile.core.search.SearchActivity
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity
import org.kiwix.kiwixmobile.core.utils.BookUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.webserver.ZimHostActivity
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule
import javax.inject.Singleton
@Singleton
@ -63,8 +61,6 @@ import javax.inject.Singleton
modules = [
BookmarksModule::class,
HistoryModule::class,
ZimHostModule::class,
ActivityModule::class,
ApplicationModule::class,
NetworkModule::class,
JNIModule::class,
@ -82,7 +78,6 @@ interface CoreComponent {
fun zimReaderContainer(): ZimReaderContainer
fun sharedPrefUtil(): SharedPreferenceUtil
fun zimFileReaderFactory(): ZimFileReader.Factory
fun storageObserver(): StorageObserver
fun kiwixService(): KiwixService
fun application(): Application
@ -94,7 +89,9 @@ interface CoreComponent {
fun connectivityManager(): ConnectivityManager
fun context(): Context
fun downloader(): Downloader
fun notificationManager(): NotificationManager
fun bookDao(): BookDao
fun bookmarksDao(): BookmarksDao
fun recentSearchDao(): RecentSearchDao
fun inject(application: CoreApp)
fun inject(zimContentProvider: ZimContentProvider)
@ -103,12 +100,13 @@ interface CoreComponent {
fun inject(autoCompleteAdapter: AutoCompleteAdapter)
fun inject(storageSelectDialog: StorageSelectDialog)
fun inject(addNoteDialog: AddNoteDialog)
fun inject(errorActivity: ErrorActivity)
fun inject(zimHostActivity: ZimHostActivity)
fun inject(searchActivity: SearchActivity)
fun inject(errorActivity: ErrorActivity)
// fun inject(zimHostActivity: ZimHostActivity)
fun inject(searchActivity: SearchActivity)
fun inject(helpActivity: HelpActivity)
fun inject(historyActivity: HistoryActivity)
fun inject(bookmarksActivity: BookmarksActivity)
fun inject(baseActivity: BaseActivity)
// fun inject(mainActivity: CoreMainActivity)
fun inject(settingsActivity: CoreSettingsActivity)
}

View File

@ -19,7 +19,7 @@ package org.kiwix.kiwixmobile.core.di.modules
import android.app.Activity
import android.view.Menu
import dagger.Binds
// import dagger.Binds
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.data.DataSource
@ -33,13 +33,17 @@ import org.kiwix.kiwixmobile.core.main.MainPresenter
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower
import org.kiwix.kiwixmobile.core.utils.DialogShower
import javax.inject.Named
@Module(includes = [DialogModule::class])
@Module
class ActivityModule {
@Provides
@ActivityScope
internal fun providesDialogShower(activity: Activity): DialogShower = AlertDialogShower(activity)
@Module
companion object {
@JvmStatic
@Provides
@ActivityScope
@ -66,7 +70,4 @@ class ActivityModule {
)
}
}
@Provides
@Named("activity")
fun provideActivity(): Activity = Activity()
}

View File

@ -32,13 +32,11 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import javax.inject.Inject;
import org.jetbrains.annotations.NotNull;
import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.R2;
import org.kiwix.kiwixmobile.core.base.BaseActivity;
import org.kiwix.kiwixmobile.core.dao.NewBookDao;
import org.kiwix.kiwixmobile.core.di.components.CoreComponent;
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity;
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk;
@ -47,8 +45,6 @@ import static org.kiwix.kiwixmobile.core.utils.LanguageUtils.getCurrentLocale;
public class ErrorActivity extends BaseActivity {
//ErrorActivityComponent errorActivityComponent;
@Inject
NewBookDao bookDao;
@Inject
@ -82,8 +78,8 @@ public class ErrorActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
injection();
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
setContentView(R.layout.activity_kiwix_error);
Intent callingIntent = getIntent();
@ -186,7 +182,7 @@ public class ErrorActivity extends BaseActivity {
restartApp();
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
}

View File

@ -50,7 +50,6 @@ public class HelpActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
setContentView(R.layout.activity_help);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
@ -86,8 +85,7 @@ public class HelpActivity extends BaseActivity {
titleDescriptionMap.put(getString(title), description.toString());
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
}

View File

@ -129,7 +129,6 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
presenter.attachView(this);
setContentView(R.layout.activity_history);
setSupportActionBar(toolbar);
@ -289,7 +288,7 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie
}
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
}

View File

@ -296,7 +296,6 @@ public abstract class CoreMainActivity extends BaseActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
presenter.attachView(this);
new WebView(this).destroy(); // Workaround for buggy webViews see #710
handleLocaleCheck();
@ -1666,7 +1665,4 @@ public abstract class CoreMainActivity extends BaseActivity
return view != null;
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
}
}

View File

@ -73,11 +73,13 @@ public class SearchActivity extends BaseActivity
private SearchView searchView;
private String searchText;
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
setContentView(R.layout.search);
if (savedInstanceState != null) {
@ -356,7 +358,4 @@ public class SearchActivity extends BaseActivity
}
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
}
}

View File

@ -38,8 +38,6 @@ public abstract class CoreSettingsActivity extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
setContentView(R.layout.settings);
allHistoryCleared = false;
@ -75,7 +73,7 @@ public abstract class CoreSettingsActivity extends BaseActivity {
toolbar.setNavigationOnClickListener(v -> onBackPressed());
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
@Override protected void injection() {
CoreApp.getCoreComponent().inject(this);
}
}

View File

@ -21,21 +21,14 @@ import android.content.Intent
import android.os.Bundle
import android.os.Process
import org.kiwix.kiwixmobile.core.BuildConfig
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
import org.kiwix.kiwixmobile.core.error.ErrorActivity
import kotlin.system.exitProcess
abstract class CoreSplashActivity : BaseActivity() {
override fun injection(coreComponent: CoreComponent) {
coreComponent.inject(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
injection(CoreApp.getCoreComponent())
if (!BuildConfig.DEBUG) {
val appContext = applicationContext
Thread.setDefaultUncaughtExceptionHandler { paramThread: Thread?,

View File

@ -22,18 +22,7 @@ import android.app.Activity
import androidx.appcompat.app.AlertDialog
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.StartHotspotManually
import javax.inject.Inject
import javax.inject.Named
class AlertDialogShower @Inject constructor(
@Named("activity") private val activity: Activity,
private val sharedPreferenceUtil: SharedPreferenceUtil
) : DialogShower {
override fun show(
dialog: KiwixDialog,
vararg clickListeners: () -> Unit
) {
AlertDialog.Builder(activity, dialogStyle())
class AlertDialogShower @Inject constructor(private val activity: Activity) : DialogShower {
override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) {
AlertDialog.Builder(activity)
@ -56,6 +45,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) : Di
?.invoke()
}
}
setCancelable(dialog.cancelable)
}
.show()
}

View File

@ -26,7 +26,8 @@ sealed class KiwixDialog(
val title: Int?,
val message: Int,
val positiveMessage: Int,
val negativeMessage: Int?
val negativeMessage: Int?,
val cancelable: Boolean = true
) {
data class DeleteZim(override val args: List<Any>) : KiwixDialog(
@ -64,6 +65,14 @@ sealed class KiwixDialog(
null
)
object ReadPermissionRequired : KiwixDialog(
R.string.storage_permission_denied,
R.string.grant_read_storage_permission,
R.string.go_to_permissions,
null,
cancelable = false
)
data class ShowHotspotDetails(override val args: List<Any>) : KiwixDialog(
R.string.hotspot_turned_on,
R.string.hotspot_details_message,

View File

@ -1,316 +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.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import kotlin.Unit;
import org.jetbrains.annotations.NotNull;
import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.R2;
import org.kiwix.kiwixmobile.core.base.BaseActivity;
import org.kiwix.kiwixmobile.core.di.components.CoreComponent;
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 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;
public class ZimHostActivity extends BaseActivity implements
ZimHostCallbacks, ZimHostContract.View {
@BindView(R2.id.startServerButton)
Button startServerButton;
@BindView(R2.id.server_textView)
TextView serverTextView;
@BindView(R2.id.recycler_view_zim_host)
RecyclerView recyclerViewZimHost;
@Inject
ZimHostContract.Presenter presenter;
@Inject
AlertDialogShower alertDialogShower;
private static final String TAG = "ZimHostActivity";
private static final String IP_STATE_KEY = "ip_state_key";
public static final String SELECTED_ZIM_PATHS_KEY = "selected_zim_paths";
private BooksOnDiskAdapter booksAdapter;
private BookOnDiskDelegate.BookDelegate bookDelegate;
private HotspotService hotspotService;
private String ip;
private ServiceConnection serviceConnection;
private ProgressDialog progressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injection(CoreApp.getCoreComponent());
setContentView(R.layout.activity_zim_host);
setUpToolbar();
bookDelegate =
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
null,
null,
bookOnDiskItem -> {
select(bookOnDiskItem);
return Unit.INSTANCE;
});
bookDelegate.setSelectionMode(SelectionMode.MULTI);
booksAdapter = new BooksOnDiskAdapter(bookDelegate,
BookOnDiskDelegate.LanguageDelegate.INSTANCE
);
if (savedInstanceState != null) {
ip = savedInstanceState.getString(IP_STATE_KEY);
layoutServerStarted();
}
recyclerViewZimHost.setAdapter(booksAdapter);
presenter.attachView(this);
presenter.loadBooks();
serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
hotspotService = ((HotspotService.HotspotBinder) service).getService();
hotspotService.registerCallBack(ZimHostActivity.this);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
}
};
startServerButton.setOnClickListener(v -> {
//Get the path of ZIMs user has selected
if (!ServerUtils.isServerStarted) {
if (getSelectedBooksPath().size() > 0) {
startHotspotHelper();
} else {
Toast.makeText(this, R.string.no_books_selected_toast_message,
Toast.LENGTH_SHORT).show();
}
} else {
startHotspotHelper();
}
});
}
private void startHotspotHelper() {
if (ServerUtils.isServerStarted) {
startService(createHotspotIntent(ACTION_STOP_SERVER));
} else {
startHotspotManuallyDialog();
}
}
private ArrayList<String> getSelectedBooksPath() {
ArrayList<String> selectedBooksPath = new ArrayList<>();
for (BooksOnDiskListItem item : booksAdapter.getItems()) {
if (item.isSelected()) {
BooksOnDiskListItem.BookOnDisk bookOnDisk = (BooksOnDiskListItem.BookOnDisk) item;
File file = bookOnDisk.getFile();
selectedBooksPath.add(file.getAbsolutePath());
Log.v(TAG, "ZIM PATH : " + file.getAbsolutePath());
}
}
return selectedBooksPath;
}
private void select(@NonNull BooksOnDiskListItem.BookOnDisk bookOnDisk) {
ArrayList<BooksOnDiskListItem> booksList = new ArrayList<>();
for (BooksOnDiskListItem item : booksAdapter.getItems()) {
if (item.equals(bookOnDisk)) {
item.setSelected(!item.isSelected());
}
booksList.add(item);
}
booksAdapter.setItems(booksList);
}
@Override protected void onStart() {
super.onStart();
bindService();
}
@Override protected void onStop() {
super.onStop();
unbindService();
}
private void bindService() {
bindService(new Intent(this, HotspotService.class), serviceConnection,
Context.BIND_AUTO_CREATE);
}
private void unbindService() {
if (hotspotService != null) {
unbindService(serviceConnection);
hotspotService.registerCallBack(null);
}
}
@Override protected void onResume() {
super.onResume();
presenter.loadBooks();
if (ServerUtils.isServerStarted) {
ip = ServerUtils.getSocketAddress();
layoutServerStarted();
}
}
private void layoutServerStarted() {
serverTextView.setText(getString(R.string.server_started_message, ip));
startServerButton.setText(getString(R.string.stop_server_label));
startServerButton.setBackgroundColor(getResources().getColor(R.color.stopServer));
bookDelegate.setSelectionMode(SelectionMode.NORMAL);
for (BooksOnDiskListItem item : booksAdapter.getItems()) {
item.setSelected(false);
}
booksAdapter.notifyDataSetChanged();
}
private void layoutServerStopped() {
serverTextView.setText(getString(R.string.server_textview_default_message));
startServerButton.setText(getString(R.string.start_server_label));
startServerButton.setBackgroundColor(getResources().getColor(R.color.greenTick));
bookDelegate.setSelectionMode(SelectionMode.MULTI);
booksAdapter.notifyDataSetChanged();
}
@Override protected void onDestroy() {
super.onDestroy();
presenter.detachView();
}
private void setUpToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getString(R.string.menu_host_books));
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
}
//Advice user to turn on hotspot manually for API<26
private void startHotspotManuallyDialog() {
alertDialogShower.show(new KiwixDialog.StartHotspotManually(),
() -> {
launchTetheringSettingsScreen();
return Unit.INSTANCE;
},
null,
() -> {
progressDialog =
ProgressDialog.show(this,
getString(R.string.progress_dialog_starting_server), "",
true);
startService(createHotspotIntent(ACTION_CHECK_IP_ADDRESS));
return Unit.INSTANCE;
}
);
}
private Intent createHotspotIntent(String action) {
return new Intent(this, HotspotService.class).setAction(action);
}
@Override public void onServerStarted(@NonNull String ipAddress) {
this.ip = ipAddress;
layoutServerStarted();
}
@Override public void onServerStopped() {
layoutServerStopped();
}
@Override public void onServerFailedToStart() {
Toast.makeText(this, R.string.server_failed_toast_message, Toast.LENGTH_LONG).show();
}
private void launchTetheringSettingsScreen() {
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn =
new ComponentName("com.android.settings", "com.android.settings.TetherSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
@Override protected void onSaveInstanceState(@Nullable Bundle outState) {
super.onSaveInstanceState(outState);
if (ServerUtils.isServerStarted) {
outState.putString(IP_STATE_KEY, ip);
}
}
@Override public void addBooks(@Nullable List<BooksOnDiskListItem> books) {
booksAdapter.setItems(books);
}
@Override public void onIpAddressValid() {
progressDialog.dismiss();
startService(createHotspotIntent(ACTION_START_SERVER).putStringArrayListExtra(
SELECTED_ZIM_PATHS_KEY, getSelectedBooksPath()));
}
@Override public void onIpAddressInvalid() {
progressDialog.dismiss();
Toast.makeText(this, R.string.server_failed_message,
Toast.LENGTH_SHORT)
.show();
}
@Override public void injection(@NotNull CoreComponent coreComponent) {
coreComponent.inject(this);
}
}

View File

@ -1,37 +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.app.Activity;
import dagger.Module;
import dagger.Provides;
@Module
public class ZimHostModule {
@Provides
ZimHostContract.Presenter provideZimHostPresenter(ZimHostPresenter zimHostPresenter) {
return zimHostPresenter;
}
@Provides Activity providesActivity(ZimHostActivity zimHostActivity) {
return zimHostActivity;
}
}

View File

@ -1,60 +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.zim_manager.fileselect_view.adapter.BooksOnDiskListItem;
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);
}
});
}
}

View File

@ -66,7 +66,7 @@
<string name="pref_credits_title">Credits</string>
<string name="tts_lang_not_supported">The language of this page is not supported, or appropriate language data was not installed. The article may not be properly read.</string>
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string>
<string name="custom_app_missing_content">Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store.</string>
<string name="custom_app_missing_content">Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store.</string>
<string name="go_to_play_store">Go to Play Store</string>
<string name="menu_bookmarks_list">Bookmarks</string>
<string name="no_section_info">No Content Headers Found</string>
@ -289,6 +289,9 @@
<string name="tag_vid">Vid</string>
<string name="tag_text_only">Text Only</string>
<string name="tag_short_text">Short Text</string>
<string name="storage_permission_denied">Storage Permission Denied</string>
<string name="grant_read_storage_permission">This app requires the ability to read storage to function. Please grant the permission in your settings</string>
<string name="go_to_permissions">Go to Settings</string>
<string-array name="pref_night_modes_entries">
<item>On</item>
<item>Off</item>

View File

@ -1,6 +1,18 @@
android.enableD8=true
android.enableD8.desugaring=true
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Jan 11 17:55:48 CST 2020
android.enableJetifier=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
android.enableD8.desugaring=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx4096m
android.enableD8=true