mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Upgrade to Dagger 2
Still some pressing issues, but the hard work is done.
This commit is contained in:
parent
ae499803fb
commit
717582fccc
40
app/app.iml
40
app/app.iml
@ -12,9 +12,13 @@
|
|||||||
<option name="SELECTED_TEST_ARTIFACT" value="_unit_test_" />
|
<option name="SELECTED_TEST_ARTIFACT" value="_unit_test_" />
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
|
||||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugUnitTest" />
|
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugUnitTest" />
|
||||||
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugUnitTestSources" />
|
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugUnitTestSources" />
|
||||||
|
<afterSyncTasks>
|
||||||
|
<task>generateDebugSources</task>
|
||||||
|
<task>mockableAndroidJar</task>
|
||||||
|
<task>prepareDebugUnitTestDependencies</task>
|
||||||
|
</afterSyncTasks>
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
@ -23,7 +27,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
@ -32,6 +36,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/kapt/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/kapt/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
||||||
@ -90,53 +95,38 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
|
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="spek-0.1.165" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="spek-0.1.165" level="project" />
|
||||||
<orderEntry type="library" exported="" name="guava-15.0" level="project" />
|
<orderEntry type="library" exported="" name="javax.annotation-api-1.2" level="project" />
|
||||||
<orderEntry type="library" exported="" name="xz-1.4" level="project" />
|
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="mockito-core-2.0.14-beta" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="dagger-1.2.2" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="lucene-analyzers-3.0.3" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="dagger-compiler-1.2.2" level="project" />
|
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="objenesis-2.1" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="objenesis-2.1" level="project" />
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="cglib-nodep-3.1" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="cglib-nodep-3.1" level="project" />
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
|
||||||
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
|
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="esperandro-2.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="commons-compress-1.7" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="recyclerview-v7-22.0.0" level="project" />
|
<orderEntry type="library" exported="" name="recyclerview-v7-22.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="acra-4.6.2" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="rxjava-core-0.20.7" level="project" />
|
<orderEntry type="library" exported="" name="rxjava-core-0.20.7" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="acra-4.6.2" level="project" />
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="mockable-android-22" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="mockable-android-22" level="project" />
|
||||||
<orderEntry type="library" exported="" name="logger-1.10" level="project" />
|
<orderEntry type="library" exported="" name="logger-1.10" level="project" />
|
||||||
<orderEntry type="library" exported="" name="annotations-4.1.1.4" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.213" level="project" />
|
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.213" level="project" />
|
||||||
<orderEntry type="library" exported="" name="lucene-snowball-3.0.3" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
|
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="lucene-core-3.0.3" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="systembartint-1.0.4" level="project" />
|
<orderEntry type="library" exported="" name="systembartint-1.0.4" level="project" />
|
||||||
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
|
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
||||||
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="dagger-2.1-SNAPSHOT" level="project" />
|
||||||
<orderEntry type="library" exported="" name="esperandro-api-2.2.0" level="project" />
|
<orderEntry type="library" exported="" name="esperandro-api-2.2.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="cardview-v7-22.0.0" level="project" />
|
<orderEntry type="library" exported="" name="cardview-v7-22.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="rxjava-android-0.20.7" level="project" />
|
<orderEntry type="library" exported="" name="rxjava-android-0.20.7" level="project" />
|
||||||
<orderEntry type="library" exported="" name="slf4j-api-1.7.6" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="httpcore-4.3.2" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="lucene-smartcn-3.0.3" level="project" />
|
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="byte-buddy-0.6.8" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="commons-lang3-3.4" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="javawriter-2.5.1" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
|
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="byte-buddy-0.6.11" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="commons-lang3-3.4" level="project" />
|
||||||
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.213" level="project" />
|
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.213" level="project" />
|
||||||
<orderEntry type="library" exported="" name="commons-net-3.3" level="project" />
|
|
||||||
<orderEntry type="library" exported="" scope="TEST" name="awaitility-1.6.3" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="awaitility-1.6.3" level="project" />
|
||||||
<orderEntry type="library" exported="" name="jdom2-2.0.5" level="project" />
|
<orderEntry type="library" exported="" scope="TEST" name="mockito-core-2.0.23-beta" level="project" />
|
||||||
|
<orderEntry type="module" module-name="jsword-minimalbible" exported="" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,10 +1,11 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
||||||
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
|
||||||
classpath 'com.github.triplet.gradle:play-publisher:1.0.2'
|
classpath 'com.github.triplet.gradle:play-publisher:1.0.2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16,6 +17,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'com.neenbedankt.android-apt'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'play'
|
apply plugin: 'play'
|
||||||
|
|
||||||
@ -75,14 +77,16 @@ play {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':jsword-minimalbible')
|
compile project(path: ':jsword-minimalbible', configuration: 'buildJSword')
|
||||||
|
|
||||||
compile 'com.squareup.dagger:dagger:+'
|
compile 'com.google.dagger:dagger:+'
|
||||||
provided 'com.squareup.dagger:dagger-compiler:+'
|
apt 'com.google.dagger:dagger-compiler:+'
|
||||||
|
provided 'javax.annotation:javax.annotation-api:1.2'
|
||||||
|
|
||||||
compile 'de.devland.esperandro:esperandro-api:+'
|
compile 'de.devland.esperandro:esperandro-api:+'
|
||||||
provided 'de.devland.esperandro:esperandro:+'
|
apt 'de.devland.esperandro:esperandro:+'
|
||||||
compile 'com.jakewharton:butterknife:+'
|
|
||||||
|
compile 'com.jakewharton:butterknife:6.1.0'
|
||||||
compile 'com.readystatesoftware.systembartint:systembartint:+'
|
compile 'com.readystatesoftware.systembartint:systembartint:+'
|
||||||
compile 'com.netflix.rxjava:rxjava-android:+'
|
compile 'com.netflix.rxjava:rxjava-android:+'
|
||||||
compile 'com.android.support:appcompat-v7:+'
|
compile 'com.android.support:appcompat-v7:+'
|
||||||
|
@ -13,7 +13,7 @@ import com.orhanobut.logger.Logger;
|
|||||||
mode = ReportingInteractionMode.SILENT
|
mode = ReportingInteractionMode.SILENT
|
||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
public class MinimalBibleDebug extends MinimalBible implements Injector {
|
public class MinimalBibleDebug extends MinimalBible {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
@ -10,14 +10,11 @@ import org.crosswire.jsword.book.sword.SwordBookPath;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import dagger.ObjectGraph;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the application!
|
* Set up the application!
|
||||||
*/
|
*/
|
||||||
public class MinimalBible extends Application implements Injector {
|
public class MinimalBible extends Application {
|
||||||
private static Context mContext;
|
private static Context mContext;
|
||||||
private ObjectGraph mObjectGraph;
|
|
||||||
|
|
||||||
public static MinimalBible get(Context ctx) {
|
public static MinimalBible get(Context ctx) {
|
||||||
return (MinimalBible) ctx.getApplicationContext();
|
return (MinimalBible) ctx.getApplicationContext();
|
||||||
@ -33,22 +30,9 @@ public class MinimalBible extends Application implements Injector {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
mContext = this;
|
mContext = this;
|
||||||
Logger.init().setLogLevel(LogLevel.NONE);
|
Logger.init().setLogLevel(LogLevel.NONE);
|
||||||
buildObjGraph();
|
|
||||||
setJswordHome();
|
setJswordHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildObjGraph() {
|
|
||||||
mObjectGraph = ObjectGraph.create(Modules.list(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void inject(Object o) {
|
|
||||||
mObjectGraph.inject(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectGraph plus(Object... modules) {
|
|
||||||
return mObjectGraph.plus(modules);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify jSword that it needs to store files in the Android internal directory
|
* Notify jSword that it needs to store files in the Android internal directory
|
||||||
* NOTE: Android will uninstall these files if you uninstall MinimalBible.
|
* NOTE: Android will uninstall these files if you uninstall MinimalBible.
|
||||||
|
@ -16,9 +16,6 @@ import java.util.List;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import de.devland.esperandro.Esperandro;
|
import de.devland.esperandro.Esperandro;
|
||||||
@ -29,8 +26,7 @@ import rx.functions.Func1;
|
|||||||
/**
|
/**
|
||||||
* Entry point for the default modules used by MinimalBible
|
* Entry point for the default modules used by MinimalBible
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@Module
|
||||||
@Module(library = true)
|
|
||||||
public class MinimalBibleModules {
|
public class MinimalBibleModules {
|
||||||
MinimalBible app;
|
MinimalBible app;
|
||||||
|
|
||||||
@ -39,7 +35,6 @@ public class MinimalBibleModules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
Application provideApplication() {
|
Application provideApplication() {
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@ -51,7 +46,6 @@ public class MinimalBibleModules {
|
|||||||
* @return the list of books (by name) to ignore
|
* @return the list of books (by name) to ignore
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
List<String> invalidBooks() {
|
List<String> invalidBooks() {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
list.add("ABU"); // Missing content
|
list.add("ABU"); // Missing content
|
||||||
@ -61,30 +55,15 @@ public class MinimalBibleModules {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Move this to a true async
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provide a raw reference to the books installed. Please don't use this, chances are
|
|
||||||
* you should go through List<Book> since it excludes the invalid books.
|
|
||||||
*
|
|
||||||
* @return The raw reference to JSword Books class
|
|
||||||
*/
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
Books provideInstalledBooks() {
|
|
||||||
return Books.installed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to get the list of books installed, as filtered by what should be excluded
|
* Use this to get the list of books installed, as filtered by what should be excluded
|
||||||
*
|
*
|
||||||
* @param b The raw Books instance to get the installed list from
|
|
||||||
* @param invalidBooks The books to exclude from usage
|
* @param invalidBooks The books to exclude from usage
|
||||||
* @return The books available for using
|
* @return The books available for using
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
List<Book> provideInstalledBooks(Books b, final List<String> invalidBooks) {
|
List<Book> provideInstalledBooks(final List<String> invalidBooks) {
|
||||||
List<Book> rawBooks = b.getBooks();
|
List<Book> rawBooks = Books.installed().getBooks();
|
||||||
return Observable.from(rawBooks)
|
return Observable.from(rawBooks)
|
||||||
.filter(new Func1<Book, Boolean>() {
|
.filter(new Func1<Book, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
@ -96,14 +75,18 @@ public class MinimalBibleModules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
BibleViewerPreferences providePrefs() {
|
BibleViewerPreferences providePrefs() {
|
||||||
return Esperandro.getPreferences(BibleViewerPreferences.class, app);
|
return Esperandro.getPreferences(BibleViewerPreferences.class, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Assume a book exists, throw an error if nothing available
|
||||||
|
*
|
||||||
|
* @param bookManager
|
||||||
|
* @param prefs
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
@Named("MainBook")
|
|
||||||
Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs) {
|
Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs) {
|
||||||
final AtomicReference<Book> mBook = new AtomicReference<>(null);
|
final AtomicReference<Book> mBook = new AtomicReference<>(null);
|
||||||
bookManager.getInstalledBooks()
|
bookManager.getInstalledBooks()
|
||||||
@ -151,13 +134,11 @@ public class MinimalBibleModules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
BookManager bookManager(List<String> exclude) {
|
BookManager bookManager(List<String> exclude) {
|
||||||
return new BookManager(exclude);
|
return new BookManager(exclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
IndexManager indexManager() {
|
IndexManager indexManager() {
|
||||||
return IndexManagerFactory.getIndexManager();
|
return IndexManagerFactory.getIndexManager();
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
|
||||||
import dagger.ObjectGraph;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holding location for activity object graphs.
|
* Holding location for activity object graphs.
|
||||||
* This technique could be extended to other things, but honestly,
|
* This technique could be extended to other things, but honestly,
|
||||||
@ -14,10 +12,10 @@ import dagger.ObjectGraph;
|
|||||||
* an ObjectGraph anyway.
|
* an ObjectGraph anyway.
|
||||||
* This works because getSupportFragmentManager() is scoped to each activity.
|
* This works because getSupportFragmentManager() is scoped to each activity.
|
||||||
*/
|
*/
|
||||||
public class OGHolder extends Fragment {
|
public class OGHolder<T> extends Fragment {
|
||||||
private final static String TAG = "OGHolder";
|
private final static String TAG = "OGHolder";
|
||||||
|
|
||||||
private ObjectGraph mObjectGraph;
|
private T mComponent;
|
||||||
|
|
||||||
public static OGHolder get(FragmentActivity activity) {
|
public static OGHolder get(FragmentActivity activity) {
|
||||||
FragmentManager manager = activity.getSupportFragmentManager();
|
FragmentManager manager = activity.getSupportFragmentManager();
|
||||||
@ -35,11 +33,11 @@ public class OGHolder extends Fragment {
|
|||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void persistGraph(ObjectGraph graph) {
|
public T getmComponent() {
|
||||||
mObjectGraph = graph;
|
return mComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectGraph fetchGraph() {
|
public void setmComponent(T mComponent) {
|
||||||
return mObjectGraph;
|
this.mComponent = mComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,11 @@ public class BookItemHolder {
|
|||||||
public void bindHolder() {
|
public void bindHolder() {
|
||||||
acronym.setText(b.getInitials());
|
acronym.setText(b.getInitials());
|
||||||
itemName.setText(b.getName());
|
itemName.setText(b.getName());
|
||||||
|
// TODO: I shouldn't have to check for this condition.
|
||||||
|
if (bookManager == null) {
|
||||||
|
displayInstalled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
DLProgressEvent dlProgressEvent = bookManager.getDownloadProgress(b);
|
DLProgressEvent dlProgressEvent = bookManager.getDownloadProgress(b);
|
||||||
if (dlProgressEvent != null) {
|
if (dlProgressEvent != null) {
|
||||||
displayProgress(dlProgressEvent);
|
displayProgress(dlProgressEvent);
|
||||||
|
@ -13,9 +13,11 @@ import android.widget.ListView;
|
|||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseFragment;
|
import org.bspeice.minimalbible.activity.BaseFragment;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.injection.ActivityContextModule;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.injection.BookListFragmentComponent;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.injection.DaggerBookListFragmentComponent;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||||
import org.crosswire.common.util.Language;
|
import org.crosswire.common.util.Language;
|
||||||
@ -69,8 +71,12 @@ public class BookListFragment extends BaseFragment {
|
|||||||
* Returns a new instance of this fragment for the given section number.
|
* Returns a new instance of this fragment for the given section number.
|
||||||
* TODO: Switch to AutoFactory/@Provides rather than inline creation.
|
* TODO: Switch to AutoFactory/@Provides rather than inline creation.
|
||||||
*/
|
*/
|
||||||
public static BookListFragment newInstance(BookCategory c) {
|
public static BookListFragment newInstance(BookCategory c, DownloadActivity activity) {
|
||||||
BookListFragment fragment = new BookListFragment();
|
BookListFragment fragment = new BookListFragment();
|
||||||
|
DaggerBookListFragmentComponent.builder()
|
||||||
|
.activityContextModule(new ActivityContextModule(activity))
|
||||||
|
.build()
|
||||||
|
.injectBookListFragment(fragment);
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_BOOK_CATEGORY, c.toString());
|
args.putString(ARG_BOOK_CATEGORY, c.toString());
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
@ -80,7 +86,10 @@ public class BookListFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
((Injector)getActivity()).inject(this);
|
BookListFragmentComponent component = DaggerBookListFragmentComponent.builder()
|
||||||
|
.activityContextModule(new ActivityContextModule((DownloadActivity) getActivity()))
|
||||||
|
.build();
|
||||||
|
component.injectBookListFragment(this);
|
||||||
|
|
||||||
bookCategory = BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY));
|
bookCategory = BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY));
|
||||||
availableLanguages = localeManager.sortedLanguagesForCategory(bookCategory);
|
availableLanguages = localeManager.sortedLanguagesForCategory(bookCategory);
|
||||||
|
@ -15,10 +15,10 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
import org.bspeice.minimalbible.Injector;
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
|
||||||
import org.bspeice.minimalbible.OGHolder;
|
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.injection.DaggerDownloadActivityComponent;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.injection.DownloadActivityComponent;
|
||||||
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -26,18 +26,15 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import dagger.ObjectGraph;
|
|
||||||
|
|
||||||
public class DownloadActivity extends BaseActivity implements
|
public class DownloadActivity extends BaseActivity implements
|
||||||
Injector,
|
Injector,
|
||||||
AdapterView.OnItemClickListener {
|
AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("ValidCategories")
|
|
||||||
List<BookCategory> validCategories;
|
List<BookCategory> validCategories;
|
||||||
|
|
||||||
@InjectView(R.id.navigation_drawer)
|
@InjectView(R.id.navigation_drawer)
|
||||||
@ -52,30 +49,10 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
@InjectView(R.id.drawer_layout)
|
@InjectView(R.id.drawer_layout)
|
||||||
DrawerLayout drawerLayout;
|
DrawerLayout drawerLayout;
|
||||||
|
|
||||||
private ObjectGraph daObjectGraph;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a scoped object graph for anything used by the DownloadActivity
|
|
||||||
*/
|
|
||||||
private void buildObjGraph() {
|
|
||||||
if (daObjectGraph == null) {
|
|
||||||
OGHolder holder = OGHolder.get(this);
|
|
||||||
ObjectGraph holderGraph = holder.fetchGraph();
|
|
||||||
if (holderGraph == null) {
|
|
||||||
daObjectGraph = MinimalBible.get(this)
|
|
||||||
.plus(new DownloadActivityModules(this));
|
|
||||||
holder.persistGraph(daObjectGraph);
|
|
||||||
} else {
|
|
||||||
daObjectGraph = holderGraph;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
daObjectGraph.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(Object o) {
|
public void inject(Object o) {
|
||||||
buildObjGraph();
|
// TODO: Cache the component
|
||||||
daObjectGraph.inject(o);
|
DownloadActivityComponent component = DaggerDownloadActivityComponent.create();
|
||||||
|
component.injectDownloadActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,7 +115,7 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
fragmentManager
|
fragmentManager
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.content,
|
.replace(R.id.content,
|
||||||
BookListFragment.newInstance(validCategories.get(position)))
|
BookListFragment.newInstance(validCategories.get(position), this))
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
drawerLayout.closeDrawers();
|
drawerLayout.closeDrawers();
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
package org.bspeice.minimalbible.activity.downloader;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
|
||||||
import org.bspeice.minimalbible.activity.search.MBIndexManager;
|
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
|
||||||
import org.crosswire.jsword.book.Books;
|
|
||||||
import org.crosswire.jsword.book.install.InstallManager;
|
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
import de.devland.esperandro.Esperandro;
|
|
||||||
import rx.subjects.PublishSubject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module mappings for the classes under the Download Activity
|
|
||||||
*/
|
|
||||||
@Module(
|
|
||||||
injects = {
|
|
||||||
BookListFragment.class,
|
|
||||||
BookItemHolder.class,
|
|
||||||
BookManager.class,
|
|
||||||
RefreshManager.class,
|
|
||||||
DownloadActivity.class
|
|
||||||
},
|
|
||||||
addsTo = MinimalBibleModules.class,
|
|
||||||
library = true
|
|
||||||
)
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class DownloadActivityModules {
|
|
||||||
DownloadActivity activity;
|
|
||||||
|
|
||||||
DownloadActivityModules(DownloadActivity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
DownloadPrefs provideDownloadPrefs() {
|
|
||||||
return Esperandro.getPreferences(DownloadPrefs.class, activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
DownloadActivity provideDownloadActivity() {
|
|
||||||
return activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
Injector provideActivityInjector() {
|
|
||||||
return activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provide the context for the DownloadActivity. We name it so that we don't have to
|
|
||||||
* \@Provides a specific class, but can keep track of what exactly we mean by "Context"
|
|
||||||
*
|
|
||||||
* @return The DownloadActivity Context
|
|
||||||
*/
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("DownloadActivityContext")
|
|
||||||
Context provideActivityContext() {
|
|
||||||
return activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
PublishSubject<DLProgressEvent> dlProgressEventPublisher() {
|
|
||||||
return PublishSubject.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
BookManager provideBookDownloadManager(Books installedBooks, RefreshManager rm,
|
|
||||||
PublishSubject<DLProgressEvent> progressEvents,
|
|
||||||
MBIndexManager mbIndexManager) {
|
|
||||||
return new BookManager(installedBooks, rm, progressEvents, mbIndexManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("ValidCategories")
|
|
||||||
List<BookCategory> provideValidCategories() {
|
|
||||||
return new ArrayList<BookCategory>() {{
|
|
||||||
add(BookCategory.BIBLE);
|
|
||||||
add(BookCategory.COMMENTARY);
|
|
||||||
add(BookCategory.DICTIONARY);
|
|
||||||
add(BookCategory.MAPS);
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
Collection<Installer> provideInstallers() {
|
|
||||||
return new InstallManager().getInstallers().values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
RefreshManager provideRefreshManager(Collection<Installer> installers, List<String> exclude,
|
|
||||||
DownloadPrefs prefs,
|
|
||||||
@Named("DownloadActivityContext") Context context) {
|
|
||||||
return new RefreshManager(installers, exclude, prefs,
|
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
LocaleManager provideLocaleManager(RefreshManager refreshManager) {
|
|
||||||
return new LocaleManager(refreshManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.downloader.injection;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class ActivityContextModule {
|
||||||
|
|
||||||
|
DownloadActivity activity;
|
||||||
|
|
||||||
|
public ActivityContextModule(DownloadActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
DownloadActivity downloadActivity() {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.downloader.injection;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.BookListFragment;
|
||||||
|
import org.bspeice.minimalbible.common.injection.InvalidBookModule;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Component(modules = {ActivityContextModule.class, DownloadManagerModule.class,
|
||||||
|
InvalidBookModule.class})
|
||||||
|
public interface BookListFragmentComponent {
|
||||||
|
|
||||||
|
BookListFragment injectBookListFragment(BookListFragment fragment);
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.downloader.injection;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Component(modules = ValidCategoryModule.class)
|
||||||
|
public interface DownloadActivityComponent {
|
||||||
|
|
||||||
|
public DownloadActivity injectDownloadActivity(DownloadActivity activity);
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.downloader.injection;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
||||||
|
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||||
|
import org.bspeice.minimalbible.activity.search.MBIndexManager;
|
||||||
|
import org.crosswire.jsword.book.Books;
|
||||||
|
import org.crosswire.jsword.book.install.InstallManager;
|
||||||
|
import org.crosswire.jsword.book.install.Installer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import de.devland.esperandro.Esperandro;
|
||||||
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class DownloadManagerModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
DownloadPrefs provideDownloadPrefs(DownloadActivity activity) {
|
||||||
|
return Esperandro.getPreferences(DownloadPrefs.class, activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
PublishSubject<DLProgressEvent> dlProgressEventPublisher() {
|
||||||
|
return PublishSubject.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
BookManager provideBookDownloadManager(Books installedBooks, RefreshManager rm,
|
||||||
|
PublishSubject<DLProgressEvent> progressEvents,
|
||||||
|
MBIndexManager mbIndexManager) {
|
||||||
|
return new BookManager(installedBooks, rm, progressEvents, mbIndexManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
Collection<Installer> provideInstallers() {
|
||||||
|
return new InstallManager().getInstallers().values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
RefreshManager provideRefreshManager(Collection<Installer> installers, List<String> exclude,
|
||||||
|
DownloadPrefs prefs,
|
||||||
|
DownloadActivity activity) {
|
||||||
|
return new RefreshManager(installers, exclude, prefs,
|
||||||
|
(ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
LocaleManager provideLocaleManager(RefreshManager refreshManager) {
|
||||||
|
return new LocaleManager(refreshManager);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.downloader.injection;
|
||||||
|
|
||||||
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class ValidCategoryModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
List<BookCategory> provideValidCategories() {
|
||||||
|
return new ArrayList<BookCategory>() {{
|
||||||
|
add(BookCategory.BIBLE);
|
||||||
|
add(BookCategory.COMMENTARY);
|
||||||
|
add(BookCategory.DICTIONARY);
|
||||||
|
add(BookCategory.MAPS);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -5,11 +5,9 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
|
||||||
import org.bspeice.minimalbible.OGHolder;
|
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
|
import org.bspeice.minimalbible.common.injection.MainBookModule;
|
||||||
import org.crosswire.jsword.passage.Verse;
|
import org.crosswire.jsword.passage.Verse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,11 +16,9 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import dagger.ObjectGraph;
|
|
||||||
|
|
||||||
|
|
||||||
public class BasicSearch extends BaseActivity
|
public class BasicSearch extends BaseActivity {
|
||||||
implements Injector {
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SearchProvider searchProvider;
|
SearchProvider searchProvider;
|
||||||
@ -33,25 +29,13 @@ public class BasicSearch extends BaseActivity
|
|||||||
@InjectView(R.id.toolbar)
|
@InjectView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
|
||||||
private ObjectGraph searchObjGraph;
|
|
||||||
|
|
||||||
private void buildObjGraph() {
|
public void inject() {
|
||||||
if (searchObjGraph == null) {
|
// TODO: Cache the component
|
||||||
OGHolder holder = OGHolder.get(this);
|
BasicSearchComponent component = DaggerBasicSearchComponent.builder()
|
||||||
searchObjGraph = holder.fetchGraph();
|
.mainBookModule(new MainBookModule(this))
|
||||||
if (searchObjGraph == null) {
|
.build();
|
||||||
searchObjGraph = MinimalBible.get(this)
|
component.injectBasicSearch(this);
|
||||||
.plus(new SearchModules());
|
|
||||||
holder.persistGraph(searchObjGraph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
searchObjGraph.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(Object o) {
|
|
||||||
buildObjGraph();
|
|
||||||
searchObjGraph.inject(o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +43,7 @@ public class BasicSearch extends BaseActivity
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_search_results);
|
setContentView(R.layout.activity_search_results);
|
||||||
|
|
||||||
inject(this);
|
inject();
|
||||||
ButterKnife.inject(this);
|
ButterKnife.inject(this);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.search;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.common.injection.InvalidBookModule;
|
||||||
|
import org.bspeice.minimalbible.common.injection.MainBookModule;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Component(modules = {SearchModules.class, MainBookModule.class, InvalidBookModule.class})
|
||||||
|
public interface BasicSearchComponent {
|
||||||
|
|
||||||
|
BasicSearch injectBasicSearch(BasicSearch basicSearch);
|
||||||
|
}
|
@ -1,25 +1,19 @@
|
|||||||
package org.bspeice.minimalbible.activity.search;
|
package org.bspeice.minimalbible.activity.search;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.index.IndexManager;
|
import org.crosswire.jsword.index.IndexManager;
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
@Module(
|
@Module
|
||||||
injects = BasicSearch.class,
|
|
||||||
addsTo = MinimalBibleModules.class
|
|
||||||
)
|
|
||||||
public class SearchModules {
|
public class SearchModules {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
SearchProvider searchProvider(@Named("MainBook") Book book,
|
SearchProvider searchProvider(@Nullable Book book,
|
||||||
IndexManager indexManager) {
|
IndexManager indexManager) {
|
||||||
return new SearchProvider(indexManager, book);
|
return new SearchProvider(indexManager, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,24 +5,14 @@ import android.preference.PreferenceActivity;
|
|||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import dagger.Module;
|
|
||||||
import dagger.ObjectGraph;
|
|
||||||
|
|
||||||
/**
|
public class MinimalBibleSettings extends PreferenceActivity {
|
||||||
* Created by bspeice on 12/29/14.
|
|
||||||
*/
|
|
||||||
public class MinimalBibleSettings extends PreferenceActivity
|
|
||||||
implements Injector {
|
|
||||||
|
|
||||||
ObjectGraph settingsGraph;
|
|
||||||
@InjectView(R.id.toolbar)
|
@InjectView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
@InjectView(R.id.container)
|
@InjectView(R.id.container)
|
||||||
@ -41,24 +31,4 @@ public class MinimalBibleSettings extends PreferenceActivity
|
|||||||
toolbar.setTitle(R.string.action_settings);
|
toolbar.setTitle(R.string.action_settings);
|
||||||
BaseActivity.setupInsets(this, root);
|
BaseActivity.setupInsets(this, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectGraph buildObjGraph() {
|
|
||||||
MinimalBible app = (MinimalBible) getApplicationContext();
|
|
||||||
|
|
||||||
return app.plus(new SettingsModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(Object o) {
|
|
||||||
if (settingsGraph == null) {
|
|
||||||
settingsGraph = buildObjGraph();
|
|
||||||
}
|
|
||||||
settingsGraph.inject(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module(injects = AvailableBookPreference.class,
|
|
||||||
addsTo = MinimalBibleModules.class)
|
|
||||||
class SettingsModule {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
@ -13,32 +14,31 @@ import android.support.v7.widget.Toolbar;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
|
||||||
import org.bspeice.minimalbible.OGHolder;
|
|
||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||||
import org.bspeice.minimalbible.activity.search.BasicSearch;
|
import org.bspeice.minimalbible.activity.search.BasicSearch;
|
||||||
import org.bspeice.minimalbible.activity.search.MBIndexManager;
|
import org.bspeice.minimalbible.activity.search.MBIndexManager;
|
||||||
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.injection.BibleViewerModules;
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.injection.DaggerViewerComponent;
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.injection.ViewerComponent;
|
||||||
|
import org.bspeice.minimalbible.common.injection.MainBookModule;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.index.IndexStatus;
|
import org.crosswire.jsword.index.IndexStatus;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import dagger.ObjectGraph;
|
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.functions.Action1;
|
import rx.functions.Action1;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
public class BibleViewer extends BaseActivity implements Injector {
|
public class BibleViewer extends BaseActivity {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("MainBook")
|
@Nullable
|
||||||
Book mainBook;
|
Book mainBook;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -62,30 +62,14 @@ public class BibleViewer extends BaseActivity implements Injector {
|
|||||||
@InjectView(R.id.drawer_layout)
|
@InjectView(R.id.drawer_layout)
|
||||||
DrawerLayout drawerLayout;
|
DrawerLayout drawerLayout;
|
||||||
|
|
||||||
private ObjectGraph bvObjectGraph;
|
public void inject() {
|
||||||
|
// TODO: Cache the component
|
||||||
/**
|
// TODO: Refactor the component design
|
||||||
* Build a scoped object graph for anything used by the BibleViewer
|
ViewerComponent component = DaggerViewerComponent.builder()
|
||||||
* and inject ourselves
|
.mainBookModule(new MainBookModule(this))
|
||||||
* TODO: Refactor so buildObjGraph doesn't have side effects
|
.bibleViewerModules(new BibleViewerModules(this))
|
||||||
*/
|
.build();
|
||||||
private void buildObjGraph() {
|
component.injectBibleViewer(this);
|
||||||
if (bvObjectGraph == null) {
|
|
||||||
OGHolder holder = OGHolder.get(this);
|
|
||||||
bvObjectGraph = holder.fetchGraph();
|
|
||||||
if (bvObjectGraph == null) {
|
|
||||||
bvObjectGraph = MinimalBible.get(this)
|
|
||||||
.plus(new BibleViewerModules(this));
|
|
||||||
holder.persistGraph(bvObjectGraph);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bvObjectGraph.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(Object o) {
|
|
||||||
buildObjGraph();
|
|
||||||
bvObjectGraph.inject(o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +80,7 @@ public class BibleViewer extends BaseActivity implements Injector {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
this.inject(this);
|
this.inject();
|
||||||
|
|
||||||
// Check that we have a book installed
|
// Check that we have a book installed
|
||||||
if (mainBook == null) {
|
if (mainBook == null) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package org.bspeice.minimalbible.activity.viewer;
|
package org.bspeice.minimalbible.activity.viewer.injection;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
import org.bspeice.minimalbible.activity.viewer.BibleViewer;
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.BookScrollEvent;
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
@ -11,13 +10,7 @@ import rx.subjects.PublishSubject;
|
|||||||
/**
|
/**
|
||||||
* Modules used for the BibleViewer activity
|
* Modules used for the BibleViewer activity
|
||||||
*/
|
*/
|
||||||
@Module(
|
@Module
|
||||||
injects = {
|
|
||||||
BibleViewer.class,
|
|
||||||
},
|
|
||||||
addsTo = MinimalBibleModules.class
|
|
||||||
)
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class BibleViewerModules {
|
public class BibleViewerModules {
|
||||||
BibleViewer activity;
|
BibleViewer activity;
|
||||||
|
|
||||||
@ -27,7 +20,6 @@ public class BibleViewerModules {
|
|||||||
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
|
||||||
PublishSubject<BookScrollEvent> scrollEventPublisher() {
|
PublishSubject<BookScrollEvent> scrollEventPublisher() {
|
||||||
return PublishSubject.create();
|
return PublishSubject.create();
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.viewer.injection;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.BibleViewer;
|
||||||
|
import org.bspeice.minimalbible.common.injection.InvalidBookModule;
|
||||||
|
import org.bspeice.minimalbible.common.injection.MainBookModule;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Component(modules = {MainBookModule.class, BibleViewerModules.class,
|
||||||
|
InvalidBookModule.class})
|
||||||
|
public interface ViewerComponent {
|
||||||
|
|
||||||
|
public BibleViewer injectBibleViewer(BibleViewer viewer);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package org.bspeice.minimalbible.common.injection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class InvalidBookModule {
|
||||||
|
/**
|
||||||
|
* Provide a list of book names that are known bad. This can be because they trigger NPE,
|
||||||
|
* or are just missing lots of content, etc.
|
||||||
|
*
|
||||||
|
* @return the list of books (by name) to ignore
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
List<String> invalidBooks() {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list.add("ABU"); // Missing content
|
||||||
|
list.add("ERen_no"); // Thinks its installed, when it isn't. Triggers NPE
|
||||||
|
list.add("ot1nt2"); // Thinks its installed, when it isn't. Triggers NPE
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
package org.bspeice.minimalbible.common.injection;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.search.MBIndexManager;
|
||||||
|
import org.bspeice.minimalbible.activity.viewer.BibleViewerPreferences;
|
||||||
|
import org.bspeice.minimalbible.service.manager.BookManager;
|
||||||
|
import org.crosswire.jsword.book.Book;
|
||||||
|
import org.crosswire.jsword.book.Books;
|
||||||
|
import org.crosswire.jsword.index.IndexManager;
|
||||||
|
import org.crosswire.jsword.index.IndexManagerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import de.devland.esperandro.Esperandro;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.functions.Action1;
|
||||||
|
import rx.functions.Func1;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class MainBookModule {
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public MainBookModule(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to get the list of books installed, as filtered by what should be excluded
|
||||||
|
*
|
||||||
|
* @param b The raw Books instance to get the installed list from
|
||||||
|
* @param invalidBooks The books to exclude from usage
|
||||||
|
* @return The books available for using
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
List<Book> provideInstalledBooks(Books b, final List<String> invalidBooks) {
|
||||||
|
List<Book> rawBooks = b.getBooks();
|
||||||
|
return Observable.from(rawBooks)
|
||||||
|
.filter(new Func1<Book, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean call(Book book) {
|
||||||
|
return !invalidBooks.contains(book.getInitials());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toList().toBlocking().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Preferences to a separate module?
|
||||||
|
@Provides
|
||||||
|
BibleViewerPreferences providePrefs() {
|
||||||
|
return Esperandro.getPreferences(BibleViewerPreferences.class, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Nullable
|
||||||
|
Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs) {
|
||||||
|
final AtomicReference<Book> mBook = new AtomicReference<>(null);
|
||||||
|
bookManager.getInstalledBooks()
|
||||||
|
.first(new Func1<Book, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean call(Book book) {
|
||||||
|
return book.getInitials().equals(prefs.defaultBookInitials());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.subscribe(new Action1<Book>() {
|
||||||
|
@Override
|
||||||
|
public void call(Book book) {
|
||||||
|
mBook.set(book);
|
||||||
|
}
|
||||||
|
}, new Action1<Throwable>() {
|
||||||
|
@Override
|
||||||
|
public void call(Throwable throwable) {
|
||||||
|
Log.d("BibleViewerModules", throwable.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mBook.get() == null) {
|
||||||
|
try {
|
||||||
|
Book fallback;
|
||||||
|
fallback = bookManager.getInstalledBooks()
|
||||||
|
.onErrorReturn(new Func1<Throwable, Book>() {
|
||||||
|
@Override
|
||||||
|
public Book call(Throwable throwable) {
|
||||||
|
// If there's no book installed, we can't select the main one...
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toBlocking().first();
|
||||||
|
|
||||||
|
prefs.defaultBookInitials(fallback.getName());
|
||||||
|
mBook.set(fallback);
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
// If no books are installed, there's really nothing we can do...
|
||||||
|
Log.d("BibleViewerModules", "No books are installed, so can't select a main book.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mBook.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
BookManager bookManager(List<String> exclude) {
|
||||||
|
return new BookManager(exclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
IndexManager indexManager() {
|
||||||
|
return IndexManagerFactory.getIndexManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
MBIndexManager mbIndexManager(IndexManager indexManager) {
|
||||||
|
return new MBIndexManager(indexManager);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package org.bspeice.minimalbible.activity.downloader.manager
|
package org.bspeice.minimalbible.activity.downloader.manager
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import org.crosswire.common.util.Language
|
import org.crosswire.common.util.Language
|
||||||
import org.crosswire.jsword.book.BookCategory
|
import org.crosswire.jsword.book.BookCategory
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -33,6 +34,7 @@ class LocaleManager(val rM: RefreshManager) {
|
|||||||
|
|
||||||
fun sortedLanguagesForCategory(cat: BookCategory): List<Language> =
|
fun sortedLanguagesForCategory(cat: BookCategory): List<Language> =
|
||||||
languagesForCategory(cat)
|
languagesForCategory(cat)
|
||||||
|
.doOnNext { Log.d("LocaleManager", "Just trying to do something... ${it}") }
|
||||||
// Finally, sort all languages, prioritizing the current
|
// Finally, sort all languages, prioritizing the current
|
||||||
.toSortedList { left, right -> compareLanguages(left, right, currentLanguage) }
|
.toSortedList { left, right -> compareLanguages(left, right, currentLanguage) }
|
||||||
// And flatten this into the actual List needed
|
// And flatten this into the actual List needed
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.bspeice.minimalbible.activity.downloader.manager
|
package org.bspeice.minimalbible.activity.downloader.manager
|
||||||
|
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
|
import android.util.Log
|
||||||
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs
|
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs
|
||||||
import org.crosswire.jsword.book.Book
|
import org.crosswire.jsword.book.Book
|
||||||
import org.crosswire.jsword.book.install.Installer
|
import org.crosswire.jsword.book.install.Installer
|
||||||
@ -16,21 +17,24 @@ class RefreshManager(val installers: Collection<Installer>,
|
|||||||
val currentTime = Calendar.getInstance().getTime().getTime()
|
val currentTime = Calendar.getInstance().getTime().getTime()
|
||||||
val fifteenDaysAgo = currentTime - 1296000
|
val fifteenDaysAgo = currentTime - 1296000
|
||||||
|
|
||||||
val availableModules: Observable<Map<Installer, List<Book>>> =
|
val availableModules: Observable<Map<Installer, List<Book>>> = Observable.from(installers)
|
||||||
Observable.from(installers)
|
.map {
|
||||||
.map {
|
/*
|
||||||
if (performReload())
|
if (performReload())
|
||||||
it.reloadBookList()
|
it.reloadBookList()
|
||||||
|
*/
|
||||||
|
Log.d("RefreshManager", "Just trying to do something...")
|
||||||
|
|
||||||
// TODO: mapOf(it to booksFromInstaller)
|
// TODO: mapOf(it to booksFromInstaller)
|
||||||
mapOf(Pair(it,
|
mapOf(Pair(it,
|
||||||
booksFromInstaller(it, exclude)))
|
booksFromInstaller(it, exclude)))
|
||||||
}
|
}
|
||||||
// Don't update timestamps until done. Additionally, make this operation
|
// Don't update timestamps until done. Additionally, make this operation
|
||||||
// part of the pipeline, so it remains a cold observable
|
// part of the pipeline, so it remains a cold observable
|
||||||
.doOnCompleted { prefs.downloadRefreshedOn(currentTime) }
|
.doOnCompleted { prefs.downloadRefreshedOn(currentTime) }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.cache()
|
.doOnError({ Log.e("RefreshManager", "Testing", it) })
|
||||||
|
.cache()
|
||||||
|
|
||||||
val flatModules: Observable<Book> =
|
val flatModules: Observable<Book> =
|
||||||
availableModules
|
availableModules
|
||||||
@ -53,8 +57,10 @@ class RefreshManager(val installers: Collection<Installer>,
|
|||||||
prefs.downloadRefreshedOn(),
|
prefs.downloadRefreshedOn(),
|
||||||
connManager?.getActiveNetworkInfo()?.getType())
|
connManager?.getActiveNetworkInfo()?.getType())
|
||||||
|
|
||||||
fun booksFromInstaller(inst: Installer, exclude: List<String>) =
|
fun booksFromInstaller(inst: Installer, exclude: List<String>): List<Book> {
|
||||||
inst.getBooks().filterNot { exclude contains it.getInitials() }
|
Log.d("Getting books from: ", "${inst.getInstallerDefinition()}")
|
||||||
|
return inst.getBooks().filterNot { exclude contains it.getInitials() }
|
||||||
|
}
|
||||||
|
|
||||||
fun installerFromBook(b: Book): Observable<Installer> = Observable.just(
|
fun installerFromBook(b: Book): Observable<Installer> = Observable.just(
|
||||||
availableModules.filter {
|
availableModules.filter {
|
||||||
|
@ -1,165 +0,0 @@
|
|||||||
package org.bspeice.minimalbible.test.activity.downloader.manager;
|
|
||||||
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
|
|
||||||
import org.bspeice.minimalbible.Injector;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs;
|
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
|
||||||
import org.crosswire.jsword.book.Book;
|
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.ObjectGraph;
|
|
||||||
import dagger.Provides;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
public class RefreshManagerTest implements Injector {
|
|
||||||
|
|
||||||
final String mockBookName = "MockBook";
|
|
||||||
/**
|
|
||||||
* The object graph that should be given to classes under test. Each test is responsible
|
|
||||||
* for setting their own ObjectGraph.
|
|
||||||
*/
|
|
||||||
ObjectGraph mObjectGraph;
|
|
||||||
@Inject
|
|
||||||
RefreshManager rM;
|
|
||||||
Installer mockInstaller;
|
|
||||||
Book mockBook;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
// Environment setup
|
|
||||||
mockBook = mock(Book.class);
|
|
||||||
when(mockBook.getName()).thenReturn(mockBookName);
|
|
||||||
|
|
||||||
mockInstaller = mock(Installer.class);
|
|
||||||
List<Book> bookList = new ArrayList<Book>();
|
|
||||||
bookList.add(mockBook);
|
|
||||||
when(mockInstaller.getBooks()).thenReturn(bookList);
|
|
||||||
|
|
||||||
Collection<Installer> mockInstallers = new ArrayList<Installer>();
|
|
||||||
mockInstallers.add(mockInstaller);
|
|
||||||
|
|
||||||
RMTModules modules = new RMTModules(mockInstallers);
|
|
||||||
mObjectGraph = ObjectGraph.create(modules);
|
|
||||||
|
|
||||||
// Now the actual test
|
|
||||||
mObjectGraph.inject(this); // Get the RefreshManager
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(Object o) {
|
|
||||||
mObjectGraph.inject(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetAvailableModulesFlattened() throws Exception {
|
|
||||||
rM.getFlatModules()
|
|
||||||
.toBlocking()
|
|
||||||
.forEach(new Action1<Book>() {
|
|
||||||
@Override
|
|
||||||
public void call(Book book) {
|
|
||||||
assertEquals(mockBookName, book.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
verify(mockInstaller).getBooks();
|
|
||||||
verify(mockBook).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInstallerFromBook() throws Exception {
|
|
||||||
Installer i = rM.installerFromBook(mockBook).toBlocking().first();
|
|
||||||
|
|
||||||
assertSame(mockInstaller, i);
|
|
||||||
verify(mockInstaller).getBooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the conditions are right for downloading
|
|
||||||
* I'd like to point out that I can test all of this without requiring mocking of
|
|
||||||
* either the preferences or network state. Value Boundaries for the win.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testDoUpdate() {
|
|
||||||
long fourteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1209600;
|
|
||||||
long sixteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1382400;
|
|
||||||
|
|
||||||
assertFalse(rM.doReload(true, fourteenDaysAgo, ConnectivityManager.TYPE_DUMMY));
|
|
||||||
assertFalse(rM.doReload(true, fourteenDaysAgo, ConnectivityManager.TYPE_WIFI));
|
|
||||||
assertFalse(rM.doReload(true, sixteenDaysAgo, ConnectivityManager.TYPE_DUMMY));
|
|
||||||
assertTrue(rM.doReload(true, sixteenDaysAgo, ConnectivityManager.TYPE_WIFI));
|
|
||||||
|
|
||||||
assertFalse(rM.doReload(false, fourteenDaysAgo, ConnectivityManager.TYPE_WIFI));
|
|
||||||
assertFalse(rM.doReload(false, fourteenDaysAgo, ConnectivityManager.TYPE_DUMMY));
|
|
||||||
assertFalse(rM.doReload(false, sixteenDaysAgo, ConnectivityManager.TYPE_WIFI));
|
|
||||||
assertFalse(rM.doReload(false, sixteenDaysAgo, ConnectivityManager.TYPE_DUMMY));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module(injects = {RefreshManagerTest.class, RefreshManager.class})
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
class RMTModules {
|
|
||||||
Collection<Installer> installers;
|
|
||||||
ConnectivityManager manager;
|
|
||||||
DownloadPrefs prefs;
|
|
||||||
|
|
||||||
RMTModules(Collection<Installer> installers) {
|
|
||||||
this.installers = installers;
|
|
||||||
|
|
||||||
// Set reasonable defaults for the manager and preferences, can over-ride if need-be
|
|
||||||
manager = mock(ConnectivityManager.class);
|
|
||||||
NetworkInfo mockNetworkInfo = Mockito.mock(NetworkInfo.class);
|
|
||||||
|
|
||||||
when(manager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo);
|
|
||||||
when(mockNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI);
|
|
||||||
|
|
||||||
prefs = mock(DownloadPrefs.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
Collection<Installer> provideInstallers() {
|
|
||||||
return this.installers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setConnectivityManager(ConnectivityManager manager) {
|
|
||||||
this.manager = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPrefs(DownloadPrefs prefs) {
|
|
||||||
this.prefs = prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
List<String> excludeList() {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
RefreshManager refreshManager(Collection<Installer> installers, List<String> excludes) {
|
|
||||||
return new RefreshManager(installers, excludes,
|
|
||||||
prefs, manager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user