From d38b4e83fc1cfced23bb22463c73b5735ebe60f8 Mon Sep 17 00:00:00 2001 From: Justin Biggs Date: Mon, 2 Dec 2019 21:27:47 -0600 Subject: [PATCH] 1581 part two, committing core app dependency injection files, not running git hooks so that I can check in with @macgills and see if I'm on partly the right track. --- core/build.gradle | 5 +++ .../core/bookmark/BookmarksActivity.java | 8 ++++- .../core/di/components/CoreComponent.kt | 5 +++ .../di/components/ErrorActivityComponent.kt | 35 ++++++++++++++++++ .../di/components/HelpActivityComponent.kt | 35 ++++++++++++++++++ .../di/components/HistoryActivityComponent.kt | 36 +++++++++++++++++++ .../di/modules/ActivityBindingModule.java | 5 +-- .../kiwixmobile/core/error/ErrorActivity.java | 9 +++++ .../kiwixmobile/core/help/HelpActivity.java | 8 +++++ .../core/history/HistoryActivity.java | 9 ++++- .../core/webserver/ZimHostActivity.java | 12 +++++-- .../main/res/layout/kiwix_search_widget.xml | 3 +- 12 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ErrorActivityComponent.kt create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HelpActivityComponent.kt create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HistoryActivityComponent.kt diff --git a/core/build.gradle b/core/build.gradle index f69424b00..68be8eda2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -17,6 +17,7 @@ apply plugin: 'com.android.library' apply plugin: KiwixConfigurationPlugin apply plugin: 'io.objectbox' apply plugin: 'com.jakewharton.butterknife' +apply plugin: 'kotlin-kapt' android { buildTypes { @@ -36,6 +37,9 @@ dependencies { // use jdk8 java.time backport, as long app < Build.VERSION_CODES.O implementation(Libs.threetenabp) + implementation 'com.google.dagger:dagger:2.25.2' + kapt 'com.google.dagger:dagger-compiler:2.25.2' + // Get kiwixlib online if it is not populated locally if (!shouldUseLocalVersion()) { api(Libs.kiwixlib) @@ -66,4 +70,5 @@ dependencies { implementation(Libs.android_arch_lifecycle_extensions) implementation(Libs.objectbox_kotlin) implementation(Libs.objectbox_rxjava) + } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/bookmark/BookmarksActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/bookmark/BookmarksActivity.java index f3b4d29d9..61addec76 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/bookmark/BookmarksActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/bookmark/BookmarksActivity.java @@ -36,10 +36,12 @@ import java.io.File; import java.util.ArrayList; import java.util.List; import javax.inject.Inject; +import org.kiwix.kiwixmobile.core.CoreApp; import org.kiwix.kiwixmobile.core.Intents; 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.BookmarksActivityComponent; import org.kiwix.kiwixmobile.core.extensions.ImageViewExtensionsKt; import org.kiwix.kiwixmobile.core.main.CoreMainActivity; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; @@ -50,6 +52,8 @@ import static org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_CHOSE_X_URL; public class BookmarksActivity extends BaseActivity implements BookmarksContract.View, BookmarksAdapter.OnItemClickListener { + BookmarksActivityComponent bookmarksActivityComponent; + private final List bookmarksList = new ArrayList<>(); private final List allBookmarks = new ArrayList<>(); private final List deleteList = new ArrayList<>(); @@ -58,7 +62,7 @@ public class BookmarksActivity extends BaseActivity implements BookmarksContract Toolbar toolbar; @BindView(R2.id.recycler_view) RecyclerView recyclerView; - @Inject + //@Inject BookmarksContract.Presenter presenter; @Inject ZimReaderContainer zimReaderContainer; @@ -111,6 +115,8 @@ public class BookmarksActivity extends BaseActivity implements BookmarksContract @Override protected void onCreate(Bundle savedInstanceState) { + bookmarksActivityComponent = CoreApp.getCoreComponent().bookmarksActivityComponent().build(); + bookmarksActivityComponent.inject(this); super.onCreate(savedInstanceState); presenter.attachView(this); setContentView(R.layout.activity_bookmarks); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt index ed6815de2..29b5532c1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt @@ -79,6 +79,11 @@ interface CoreComponent { fun connectivityManager(): ConnectivityManager fun context(): Context fun downloader(): Downloader + fun bookmarksActivityComponent(): BookmarksActivityComponent.Builder + fun errorActivityComponent(): ErrorActivityComponent.Builder + fun historyActivityComponent(): HistoryActivityComponent.Builder + fun helpActivityComponent(): HelpActivityComponent.Builder + fun zimHostActivityComponent(): ZimHostActivityComponent.Builder fun inject(application: CoreApp) fun inject(zimContentProvider: ZimContentProvider) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ErrorActivityComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ErrorActivityComponent.kt new file mode 100644 index 000000000..21be2799d --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/ErrorActivityComponent.kt @@ -0,0 +1,35 @@ +/* + * 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.core.di.components + +import dagger.Subcomponent +import org.kiwix.kiwixmobile.core.di.ActivityScope +import org.kiwix.kiwixmobile.core.error.ErrorActivity + +@ActivityScope +@Subcomponent +interface ErrorActivityComponent { + + @Subcomponent.Builder + interface Builder { + fun build(): ErrorActivityComponent + } + + fun inject(errorActivity: ErrorActivity) +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HelpActivityComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HelpActivityComponent.kt new file mode 100644 index 000000000..de6858e63 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HelpActivityComponent.kt @@ -0,0 +1,35 @@ +/* + * 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.core.di.components + +import dagger.Subcomponent +import org.kiwix.kiwixmobile.core.di.ActivityScope +import org.kiwix.kiwixmobile.core.help.HelpActivity + +@ActivityScope +@Subcomponent +interface HelpActivityComponent { + + @Subcomponent.Builder + interface Builder { + fun build(): HelpActivityComponent + } + + fun inject(helpActivity: HelpActivity) +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HistoryActivityComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HistoryActivityComponent.kt new file mode 100644 index 000000000..3d90de1c3 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/HistoryActivityComponent.kt @@ -0,0 +1,36 @@ +/* + * 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.core.di.components + +import dagger.Subcomponent +import org.kiwix.kiwixmobile.core.di.ActivityScope +import org.kiwix.kiwixmobile.core.history.HistoryActivity +import org.kiwix.kiwixmobile.core.history.HistoryModule + +@ActivityScope +@Subcomponent(modules = [HistoryModule::class]) +interface HistoryActivityComponent { + + @Subcomponent.Builder + interface Builder { + fun build(): HistoryActivityComponent + } + + fun inject(historyActivity: HistoryActivity) +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityBindingModule.java b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityBindingModule.java index 21a7cbad0..2a86e4b4c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityBindingModule.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ActivityBindingModule.java @@ -20,15 +20,16 @@ package org.kiwix.kiwixmobile.core.di.modules; import dagger.Module; import dagger.android.ContributesAndroidInjector; +import javax.inject.Inject; import org.kiwix.kiwixmobile.core.bookmark.BookmarksActivity; import org.kiwix.kiwixmobile.core.bookmark.BookmarksModule; import org.kiwix.kiwixmobile.core.di.ActivityScope; +import org.kiwix.kiwixmobile.core.di.components.SearchActivityComponent; import org.kiwix.kiwixmobile.core.error.ErrorActivity; import org.kiwix.kiwixmobile.core.help.HelpActivity; import org.kiwix.kiwixmobile.core.history.HistoryActivity; import org.kiwix.kiwixmobile.core.history.HistoryModule; import org.kiwix.kiwixmobile.core.search.SearchActivity; -import org.kiwix.kiwixmobile.core.splash.CoreSplashActivity; import org.kiwix.kiwixmobile.core.webserver.ZimHostActivity; import org.kiwix.kiwixmobile.core.webserver.ZimHostModule; @@ -42,7 +43,7 @@ import org.kiwix.kiwixmobile.core.webserver.ZimHostModule; public abstract class ActivityBindingModule { @ActivityScope - @ContributesAndroidInjector + @ContributesAndroidInjector(modules = ActivityModule.class) public abstract SearchActivity provideSearchActivity(); @ActivityScope diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.java index b14a640cd..cd8164ef8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.java @@ -33,9 +33,12 @@ 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.di.components.ErrorActivityComponent; import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity; import org.kiwix.kiwixmobile.core.dao.NewBookDao; import org.kiwix.kiwixmobile.core.splash.CoreSplashActivity; @@ -46,6 +49,8 @@ import static org.kiwix.kiwixmobile.core.utils.LanguageUtils.getCurrentLocale; public class ErrorActivity extends BaseActivity { + ErrorActivityComponent errorActivityComponent; + @Inject NewBookDao bookDao; @Inject @@ -79,6 +84,10 @@ public class ErrorActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { + + errorActivityComponent = CoreApp.getCoreComponent().errorActivityComponent().build(); + errorActivityComponent.inject(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_kiwix_error); Intent callingIntent = getIntent(); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpActivity.java index 1b6faaf6d..e2d85d6d2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpActivity.java @@ -27,15 +27,20 @@ import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import butterknife.OnClick; import java.util.HashMap; +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.HelpActivityComponent; import org.kiwix.kiwixmobile.core.utils.LanguageUtils; import static org.kiwix.kiwixmobile.core.utils.Constants.CONTACT_EMAIL_ADDRESS; public class HelpActivity extends BaseActivity { + HelpActivityComponent helpActivityComponent; + private final HashMap titleDescriptionMap = new HashMap<>(); @BindView(R2.id.activity_help_toolbar) @@ -45,6 +50,9 @@ public class HelpActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { + helpActivityComponent = CoreApp.getCoreComponent().helpActivityComponent().build(); + helpActivityComponent.inject(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_help); setSupportActionBar(toolbar); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java index d8fb1a3e3..adb91f863 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java @@ -39,10 +39,13 @@ import java.io.File; import java.util.ArrayList; import java.util.List; import javax.inject.Inject; +import org.jetbrains.annotations.NotNull; +import org.kiwix.kiwixmobile.core.CoreApp; import org.kiwix.kiwixmobile.core.Intents; 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.HistoryActivityComponent; import org.kiwix.kiwixmobile.core.extensions.ImageViewExtensionsKt; import org.kiwix.kiwixmobile.core.main.CoreMainActivity; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; @@ -123,9 +126,13 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie } } }; - + HistoryActivityComponent historyActivityComponent; @Override protected void onCreate(Bundle savedInstanceState) { + + historyActivityComponent = CoreApp.getCoreComponent().historyActivityComponent().build(); + historyActivityComponent.inject(this); + super.onCreate(savedInstanceState); presenter.attachView(this); setContentView(R.layout.activity_history); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java index 324ddc25b..055cee9c2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/webserver/ZimHostActivity.java @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.webserver; +import android.app.Activity; import android.app.ProgressDialog; import android.content.ComponentName; import android.content.Context; @@ -39,9 +40,12 @@ 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.ZimHostActivityComponent; import org.kiwix.kiwixmobile.core.utils.AlertDialogShower; import org.kiwix.kiwixmobile.core.utils.KiwixDialog; import org.kiwix.kiwixmobile.core.utils.ServerUtils; @@ -58,6 +62,8 @@ import static org.kiwix.kiwixmobile.core.wifi_hotspot.HotspotService.ACTION_STOP public class ZimHostActivity extends BaseActivity implements ZimHostCallbacks, ZimHostContract.View { + ZimHostActivityComponent zimHostActivityComponent; + @BindView(R2.id.startServerButton) Button startServerButton; @BindView(R2.id.server_textView) @@ -68,7 +74,7 @@ public class ZimHostActivity extends BaseActivity implements @Inject ZimHostContract.Presenter presenter; - @Inject + //@Inject AlertDialogShower alertDialogShower; private static final String TAG = "ZimHostActivity"; @@ -84,6 +90,8 @@ public class ZimHostActivity extends BaseActivity implements @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + zimHostActivityComponent = CoreApp.getCoreComponent().zimHostActivityComponent().build(); + zimHostActivityComponent.inject(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_zim_host); @@ -129,7 +137,7 @@ public class ZimHostActivity extends BaseActivity implements if (getSelectedBooksPath().size() > 0) { startHotspotHelper(); } else { - Toast.makeText(ZimHostActivity.this, R.string.no_books_selected_toast_message, + Toast.makeText(this, R.string.no_books_selected_toast_message, Toast.LENGTH_SHORT).show(); } } else { diff --git a/core/src/main/res/layout/kiwix_search_widget.xml b/core/src/main/res/layout/kiwix_search_widget.xml index ee3376bc8..076cb94a5 100644 --- a/core/src/main/res/layout/kiwix_search_widget.xml +++ b/core/src/main/res/layout/kiwix_search_widget.xml @@ -1,6 +1,7 @@ + tools:text="@string/search_widget_text" />