mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-07-13 03:35:20 -04:00
Only show languages for selected book category
Previously displayed all languages, period. Also includes some testing updates to make sure everything is still covered.
This commit is contained in:
@ -15,6 +15,7 @@ import android.widget.Toast;
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseFragment;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||
import org.crosswire.common.util.Language;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
@ -36,18 +37,21 @@ import rx.functions.Func1;
|
||||
import rx.functions.Func2;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
* A fragment to list out the books available for downloading.
|
||||
* Each fragment will be responsible for a single category,
|
||||
* another fragment will be created if a second category is needed.
|
||||
*/
|
||||
|
||||
public class BookListFragment extends BaseFragment {
|
||||
protected static final String ARG_BOOK_CATEGORY = "book_category";
|
||||
protected BookCategory bookCategory;
|
||||
|
||||
@Inject
|
||||
DownloadPrefs downloadPrefs;
|
||||
@Inject
|
||||
RefreshManager refreshManager;
|
||||
@Inject
|
||||
List<Language> availableLanguages;
|
||||
LocaleManager localeManager;
|
||||
|
||||
@InjectView(R.id.lst_download_available)
|
||||
ListView downloadsAvailable;
|
||||
@ -56,6 +60,9 @@ public class BookListFragment extends BaseFragment {
|
||||
|
||||
LayoutInflater inflater;
|
||||
|
||||
// A cache of the languages currently available for this category
|
||||
List<Language> availableLanguages;
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section number.
|
||||
* TODO: Switch to AutoFactory/@Provides rather than inline creation.
|
||||
@ -72,6 +79,9 @@ public class BookListFragment extends BaseFragment {
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
((Injector)getActivity()).inject(this);
|
||||
|
||||
bookCategory = BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY));
|
||||
availableLanguages = localeManager.sortedLanguagesForCategory(bookCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,7 +132,8 @@ public class BookListFragment extends BaseFragment {
|
||||
void displayLanguageSpinner() {
|
||||
ArrayAdapter<Object> adapter = new ArrayAdapter<>(this.getActivity(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
availableLanguages.toArray());
|
||||
availableLanguages.toArray()
|
||||
);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
languagesSpinner.setAdapter(adapter);
|
||||
|
||||
@ -138,7 +149,7 @@ public class BookListFragment extends BaseFragment {
|
||||
public void onClick(final int position) {
|
||||
booksByLanguage(refreshManager.getFlatModules(),
|
||||
availableLanguages.get(position),
|
||||
BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY)))
|
||||
bookCategory)
|
||||
// Repack all the books
|
||||
.toSortedList(new Func2<Book, Book, Integer>() {
|
||||
@Override
|
||||
@ -157,6 +168,7 @@ public class BookListFragment extends BaseFragment {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Refactor out, this information should come from LocaleManager
|
||||
protected Observable<Book> booksByLanguage(Observable<Book> books, final Language language,
|
||||
final BookCategory category) {
|
||||
return books
|
||||
|
@ -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.common.util.Language;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
import org.crosswire.jsword.book.Books;
|
||||
@ -49,17 +48,20 @@ public class DownloadActivityModules {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
DownloadPrefs provideDownloadPrefs() {
|
||||
return Esperandro.getPreferences(DownloadPrefs.class, activity);
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
DownloadActivity provideDownloadActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
Injector provideActivityInjector() {
|
||||
return activity;
|
||||
}
|
||||
@ -67,19 +69,24 @@ public class DownloadActivityModules {
|
||||
/**
|
||||
* 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")
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("DownloadActivityContext")
|
||||
Context provideActivityContext() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
BookManager provideBookDownloadManager(Books installedBooks, RefreshManager rm) {
|
||||
return new BookManager(installedBooks, rm);
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("ValidCategories")
|
||||
List<BookCategory> provideValidCategories() {
|
||||
return new ArrayList<BookCategory>() {{
|
||||
@ -91,7 +98,8 @@ public class DownloadActivityModules {
|
||||
}
|
||||
|
||||
//TODO: Move this to a true async
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
Books provideInstalledBooks() {
|
||||
return Books.installed();
|
||||
}
|
||||
@ -101,12 +109,14 @@ public class DownloadActivityModules {
|
||||
return b.getBooks();
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
Collection<Installer> provideInstallers() {
|
||||
return new InstallManager().getInstallers().values();
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
RefreshManager provideRefreshManager(Collection<Installer> installers, DownloadPrefs prefs,
|
||||
@Named("DownloadActivityContext") Context context) {
|
||||
return new RefreshManager(installers, prefs,
|
||||
@ -117,9 +127,4 @@ public class DownloadActivityModules {
|
||||
LocaleManager provideLocaleManager(RefreshManager refreshManager) {
|
||||
return new LocaleManager(refreshManager);
|
||||
}
|
||||
|
||||
@Provides
|
||||
List<Language> availableLanguages(LocaleManager localeManager) {
|
||||
return localeManager.getSortedLanguagesList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user