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 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 dagger.Module;
|
||||
import dagger.Provides;
|
||||
import rx.Observable;
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Allows components on down the line to know whether they should set some things up or not.
|
||||
* Additionally, not a Singleton so we can enable/disable testing mode as needed. However,
|
||||
* for production, it's always false.
|
||||
* @return Whether we are in a test - false
|
||||
* 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
|
||||
@Named("Testing")
|
||||
boolean isTest() {
|
||||
return false;
|
||||
@Singleton
|
||||
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;
|
||||
}
|
||||
|
||||
//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.LocaleManager;
|
||||
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.Books;
|
||||
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
|
||||
@Singleton
|
||||
Collection<Installer> provideInstallers() {
|
||||
@ -116,9 +103,10 @@ public class DownloadActivityModules {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
RefreshManager provideRefreshManager(Collection<Installer> installers, DownloadPrefs prefs,
|
||||
RefreshManager provideRefreshManager(Collection<Installer> installers, List<String> exclude,
|
||||
DownloadPrefs prefs,
|
||||
@Named("DownloadActivityContext") Context context) {
|
||||
return new RefreshManager(installers, prefs,
|
||||
return new RefreshManager(installers, exclude, prefs,
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
|
||||
}
|
||||
|
||||
|
@ -6,32 +6,37 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Set the active "main book"
|
||||
* Can not be implemented in Kotlin due to array needs
|
||||
*/
|
||||
public class AvailableBookPreference extends ListPreference {
|
||||
|
||||
@Inject
|
||||
List<Book> books;
|
||||
|
||||
public AvailableBookPreference(Context ctx, AttributeSet attrs) {
|
||||
super(ctx, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
// TODO: Refactor out the static reference
|
||||
List<Book> books = Books.installed().getBooks();
|
||||
((Injector) getContext()).inject(this);
|
||||
|
||||
CharSequence[] entries = new CharSequence[books.size()];
|
||||
CharSequence[] entryValues = new CharSequence[books.size()];
|
||||
|
||||
for (int i = 0; i < books.size(); i++) {
|
||||
Book b = books.get(i);
|
||||
entries[i] = b.getName();
|
||||
entryValues[i] = b.getInitials();
|
||||
entryValues[i] = b.getName();
|
||||
}
|
||||
|
||||
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
|
||||
* and inject ourselves
|
||||
* TODO: Refactor so buildObjGraph doesn't have side effects
|
||||
*/
|
||||
private void buildObjGraph() {
|
||||
if (bvObjectGraph == null) {
|
||||
|
@ -2,9 +2,11 @@ package org.bspeice.minimalbible.activity.viewer;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
import org.bspeice.minimalbible.service.manager.BookManager;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@ -24,7 +26,8 @@ import rx.subjects.PublishSubject;
|
||||
@Module(
|
||||
injects = {
|
||||
BibleViewer.class,
|
||||
}
|
||||
},
|
||||
addsTo = MinimalBibleModules.class
|
||||
)
|
||||
@SuppressWarnings("unused")
|
||||
public class BibleViewerModules {
|
||||
@ -90,8 +93,8 @@ public class BibleViewerModules {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
BookManager bookManager() {
|
||||
return new BookManager();
|
||||
BookManager bookManager(List<String> exclude) {
|
||||
return new BookManager(exclude);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -16,6 +16,7 @@ import java.util.Date
|
||||
*/
|
||||
|
||||
class RefreshManager(val installers: Collection<Installer>,
|
||||
val exclude: List<String>,
|
||||
val prefs: DownloadPrefs,
|
||||
val connManager: ConnectivityManager?) {
|
||||
val refreshComplete = AtomicBoolean()
|
||||
@ -26,7 +27,9 @@ class RefreshManager(val installers: Collection<Installer>,
|
||||
it.reloadBookList() // TODO: Handle InstallException
|
||||
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())
|
||||
.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
|
||||
open class BookManager() {
|
||||
// Some extra books like to think they're installed, but trigger NPE all over the place...
|
||||
val ignore = array("ERen_no", "ot1nt2");
|
||||
|
||||
open class BookManager(val ignore: List<String>) {
|
||||
|
||||
// TODO: Remove static reference to Books.installed()
|
||||
open val installedBooks = Observable.from(Books.installed()!!.getBooks())
|
||||
?.filter { !ignore.contains(it!!.getInitials()) }
|
||||
?.cache() ?: throw NoBooksInstalledException()
|
||||
|
Loading…
Reference in New Issue
Block a user