From c6216afa60328ba8b08e48c756e45a3ff758a4f8 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 1 Dec 2014 20:48:32 -0500 Subject: [PATCH] Multiple Bible support and internet usage settings Fixes #2 completely. --- .../activity/downloader/DownloadPrefs.java | 1 - .../settings/AvailableBookPreference.java | 42 +++++++++++++++++++ .../activity/viewer/BibleViewerModules.java | 2 +- .../viewer/BibleViewerPreferences.java | 3 +- app/src/main/res/xml/preferences.xml | 11 +++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/settings/AvailableBookPreference.java diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadPrefs.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadPrefs.java index 8570b9b..4922562 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadPrefs.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadPrefs.java @@ -19,5 +19,4 @@ public interface DownloadPrefs { long downloadRefreshedOn(); void downloadRefreshedOn(long downloadRefreshedOn); - } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/settings/AvailableBookPreference.java b/app/src/main/java/org/bspeice/minimalbible/activity/settings/AvailableBookPreference.java new file mode 100644 index 0000000..81b82ee --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/activity/settings/AvailableBookPreference.java @@ -0,0 +1,42 @@ +package org.bspeice.minimalbible.activity.settings; + +import android.content.Context; +import android.preference.ListPreference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +import org.crosswire.jsword.book.Book; +import org.crosswire.jsword.book.Books; + +import java.util.List; + +/** + * Set the active "main book" + * Can not be implemented in Kotlin due to array needs + */ +public class AvailableBookPreference extends ListPreference { + + public AvailableBookPreference(Context ctx, AttributeSet attrs) { + super(ctx, attrs); + } + + @Override + protected View onCreateView(ViewGroup parent) { + // TODO: Refactor out the static reference + List books = Books.installed().getBooks(); + 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(); + } + + setEntries(entries); + setEntryValues(entryValues); + + return super.onCreateView(parent); + } +} diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java index 816ab12..e550051 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java @@ -50,7 +50,7 @@ public class BibleViewerModules { .first(new Func1() { @Override public Boolean call(Book book) { - return book.getName().equals(prefs.defaultBookName()); + return book.getInitials().equals(prefs.defaultBookInitials()); } }) .subscribe(new Action1() { diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerPreferences.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerPreferences.java index 8efbb09..76848ec 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerPreferences.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerPreferences.java @@ -9,11 +9,10 @@ import de.devland.esperandro.annotations.SharedPreferences; @SharedPreferences public interface BibleViewerPreferences { - String defaultBookName(); + String defaultBookInitials(); void defaultBookName(String defaultBookName); @Default(ofInt = 14) int baseTextSize(); - void baseTextSize(int baseTextSize); } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 0214586..a204c31 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -14,4 +14,15 @@ but I will likely want to re-implement this in the future --> cmwmobile:stepSize="1" cmwmobile:units="pt." /> + + + + \ No newline at end of file