mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-05 07:38:20 -05:00
Add a list of books to exclude
Still need to fix some references to Books.installed(), please use injection for this.
This commit is contained in:
parent
b1ecf8a404
commit
ef314efa2f
@ -2,11 +2,18 @@ package org.bspeice.minimalbible;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
import org.crosswire.jsword.book.Books;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.functions.Func1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for the default modules used by MinimalBible
|
* Entry point for the default modules used by MinimalBible
|
||||||
@ -25,15 +32,52 @@ public class MinimalBibleModules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This field allows us to set application-wide whether we are in a test or not
|
* Provide a list of book names that are known bad. This can be because they trigger NPE,
|
||||||
* Allows components on down the line to know whether they should set some things up or not.
|
* or are just missing lots of content, etc.
|
||||||
* Additionally, not a Singleton so we can enable/disable testing mode as needed. However,
|
* @return the list of books (by name) to ignore
|
||||||
* for production, it's always false.
|
|
||||||
* @return Whether we are in a test - false
|
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Named("Testing")
|
@Singleton
|
||||||
boolean isTest() {
|
List<String> invalidBooks() {
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
Books provideInstalledBooks() {
|
||||||
|
return Books.installed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import org.bspeice.minimalbible.MinimalBibleModules;
|
|||||||
import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
||||||
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.jsword.book.Book;
|
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
import org.crosswire.jsword.book.Books;
|
import org.crosswire.jsword.book.Books;
|
||||||
import org.crosswire.jsword.book.install.InstallManager;
|
import org.crosswire.jsword.book.install.InstallManager;
|
||||||
@ -96,18 +95,6 @@ public class DownloadActivityModules {
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Move this to a true async
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
Books provideInstalledBooks() {
|
|
||||||
return Books.installed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
List<Book> provideInstalledBooks(Books b) {
|
|
||||||
return b.getBooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Collection<Installer> provideInstallers() {
|
Collection<Installer> provideInstallers() {
|
||||||
@ -116,9 +103,10 @@ public class DownloadActivityModules {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RefreshManager provideRefreshManager(Collection<Installer> installers, DownloadPrefs prefs,
|
RefreshManager provideRefreshManager(Collection<Installer> installers, List<String> exclude,
|
||||||
|
DownloadPrefs prefs,
|
||||||
@Named("DownloadActivityContext") Context context) {
|
@Named("DownloadActivityContext") Context context) {
|
||||||
return new RefreshManager(installers, prefs,
|
return new RefreshManager(installers, exclude, prefs,
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
|
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,32 +6,37 @@ import android.util.AttributeSet;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.Injector;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.book.Books;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the active "main book"
|
* Set the active "main book"
|
||||||
* Can not be implemented in Kotlin due to array needs
|
* Can not be implemented in Kotlin due to array needs
|
||||||
*/
|
*/
|
||||||
public class AvailableBookPreference extends ListPreference {
|
public class AvailableBookPreference extends ListPreference {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
List<Book> books;
|
||||||
|
|
||||||
public AvailableBookPreference(Context ctx, AttributeSet attrs) {
|
public AvailableBookPreference(Context ctx, AttributeSet attrs) {
|
||||||
super(ctx, attrs);
|
super(ctx, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected View onCreateView(ViewGroup parent) {
|
protected View onCreateView(ViewGroup parent) {
|
||||||
// TODO: Refactor out the static reference
|
((Injector) getContext()).inject(this);
|
||||||
List<Book> books = Books.installed().getBooks();
|
|
||||||
CharSequence[] entries = new CharSequence[books.size()];
|
CharSequence[] entries = new CharSequence[books.size()];
|
||||||
CharSequence[] entryValues = new CharSequence[books.size()];
|
CharSequence[] entryValues = new CharSequence[books.size()];
|
||||||
|
|
||||||
for (int i = 0; i < books.size(); i++) {
|
for (int i = 0; i < books.size(); i++) {
|
||||||
Book b = books.get(i);
|
Book b = books.get(i);
|
||||||
entries[i] = b.getName();
|
entries[i] = b.getName();
|
||||||
entryValues[i] = b.getInitials();
|
entryValues[i] = b.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
setEntries(entries);
|
setEntries(entries);
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package org.bspeice.minimalbible.activity.settings;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
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.activity.BaseActivity;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.InjectView;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.ObjectGraph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by bspeice on 12/29/14.
|
||||||
|
*/
|
||||||
|
public class MinimalBibleSettings extends PreferenceActivity
|
||||||
|
implements Injector {
|
||||||
|
|
||||||
|
ObjectGraph settingsGraph;
|
||||||
|
@InjectView(R.id.toolbar)
|
||||||
|
Toolbar toolbar;
|
||||||
|
@InjectView(R.id.container)
|
||||||
|
LinearLayout root;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
setContentView(R.layout.activity_settings);
|
||||||
|
BaseActivity.setupStatusBar(this);
|
||||||
|
|
||||||
|
ButterKnife.inject(this);
|
||||||
|
|
||||||
|
toolbar.setTitle(R.string.action_settings);
|
||||||
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,8 @@ public class BibleViewer extends BaseActivity implements Injector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a scoped object graph for anything used by the BibleViewer
|
* Build a scoped object graph for anything used by the BibleViewer
|
||||||
|
* and inject ourselves
|
||||||
|
* TODO: Refactor so buildObjGraph doesn't have side effects
|
||||||
*/
|
*/
|
||||||
private void buildObjGraph() {
|
private void buildObjGraph() {
|
||||||
if (bvObjectGraph == null) {
|
if (bvObjectGraph == null) {
|
||||||
|
@ -2,9 +2,11 @@ package org.bspeice.minimalbible.activity.viewer;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||||
import org.bspeice.minimalbible.service.manager.BookManager;
|
import org.bspeice.minimalbible.service.manager.BookManager;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@ -24,7 +26,8 @@ import rx.subjects.PublishSubject;
|
|||||||
@Module(
|
@Module(
|
||||||
injects = {
|
injects = {
|
||||||
BibleViewer.class,
|
BibleViewer.class,
|
||||||
}
|
},
|
||||||
|
addsTo = MinimalBibleModules.class
|
||||||
)
|
)
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class BibleViewerModules {
|
public class BibleViewerModules {
|
||||||
@ -90,8 +93,8 @@ public class BibleViewerModules {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
BookManager bookManager() {
|
BookManager bookManager(List<String> exclude) {
|
||||||
return new BookManager();
|
return new BookManager(exclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -16,6 +16,7 @@ import java.util.Date
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class RefreshManager(val installers: Collection<Installer>,
|
class RefreshManager(val installers: Collection<Installer>,
|
||||||
|
val exclude: List<String>,
|
||||||
val prefs: DownloadPrefs,
|
val prefs: DownloadPrefs,
|
||||||
val connManager: ConnectivityManager?) {
|
val connManager: ConnectivityManager?) {
|
||||||
val refreshComplete = AtomicBoolean()
|
val refreshComplete = AtomicBoolean()
|
||||||
@ -26,7 +27,9 @@ class RefreshManager(val installers: Collection<Installer>,
|
|||||||
it.reloadBookList() // TODO: Handle InstallException
|
it.reloadBookList() // TODO: Handle InstallException
|
||||||
prefs.downloadRefreshedOn(Date().getTime())
|
prefs.downloadRefreshedOn(Date().getTime())
|
||||||
}
|
}
|
||||||
mapOf(Pair(it, it.getBooks()))
|
val validBooks = it.getBooks()
|
||||||
|
.filterNot { exclude contains it.getInitials() }
|
||||||
|
mapOf(Pair(it, validBooks))
|
||||||
}
|
}
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.cache();
|
.cache();
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package org.bspeice.minimalbible.activity.settings
|
|
||||||
|
|
||||||
import android.preference.PreferenceActivity
|
|
||||||
import android.os.Bundle
|
|
||||||
import org.bspeice.minimalbible.R
|
|
||||||
import android.support.v7.widget.Toolbar
|
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by bspeice on 12/1/14.
|
|
||||||
*/
|
|
||||||
class MinimalBibleSettings() : PreferenceActivity() {
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super<PreferenceActivity>.onCreate(savedInstanceState)
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences)
|
|
||||||
setContentView(R.layout.activity_settings)
|
|
||||||
BaseActivity.setupStatusBar(this)
|
|
||||||
|
|
||||||
val toolbar = findViewById(R.id.toolbar) as Toolbar
|
|
||||||
toolbar.setTitle(R.string.action_settings)
|
|
||||||
|
|
||||||
val root = findViewById(R.id.container) as LinearLayout
|
|
||||||
BaseActivity.setupInsets(this, root)
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,11 +14,9 @@ import javax.inject.Singleton
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Singleton
|
Singleton
|
||||||
open class BookManager() {
|
open class BookManager(val ignore: List<String>) {
|
||||||
// Some extra books like to think they're installed, but trigger NPE all over the place...
|
|
||||||
val ignore = array("ERen_no", "ot1nt2");
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Remove static reference to Books.installed()
|
||||||
open val installedBooks = Observable.from(Books.installed()!!.getBooks())
|
open val installedBooks = Observable.from(Books.installed()!!.getBooks())
|
||||||
?.filter { !ignore.contains(it!!.getInitials()) }
|
?.filter { !ignore.contains(it!!.getInitials()) }
|
||||||
?.cache() ?: throw NoBooksInstalledException()
|
?.cache() ?: throw NoBooksInstalledException()
|
||||||
|
Loading…
Reference in New Issue
Block a user