diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java index c9b919c..246e311 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java @@ -3,9 +3,7 @@ package org.bspeice.minimalbible.activity.downloader; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -33,6 +31,7 @@ import javax.inject.Inject; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnItemSelected; +import dagger.Lazy; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; @@ -52,7 +51,7 @@ public class BookListFragment extends BaseFragment { @Inject DownloadPrefs downloadPrefs; @Inject - RefreshManager refreshManager; + Lazy refreshManager; @Inject LocaleManager localeManager; @@ -143,14 +142,29 @@ public class BookListFragment extends BaseFragment { ); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); languagesSpinner.setAdapter(adapter); - Drawable d = languagesSpinner.getBackground(); - Log.d("Spinner", d.toString()); + + // Use Object to avoid the incredibly long type parameters + refreshManager.get().getAvailableModules() + .subscribe(new Action1() { + @Override + public void call(Object o) { + } + }, + new Action1() { + @Override + public void call(Throwable throwable) { + Toast.makeText(getActivity(), + getString(R.string.error_book_refresh), + Toast.LENGTH_SHORT) + .show(); + } + }); } @SuppressWarnings("unused") @OnItemSelected(R.id.spn_available_languages) public void onClick(final int position) { - booksByLanguage(refreshManager.getFlatModules(), + booksByLanguage(refreshManager.get().getFlatModules(), availableLanguages.get(position), bookCategory) // Repack all the books @@ -231,6 +245,7 @@ public class BookListFragment extends BaseFragment { downloadPrefs.hasEnabledDownload(true); // And warn them that it has been enabled in the future. + // TODO: Migrate to strings.xml showToast("Downloading now enabled. Disable in settings"); fragment.displayModules(); } @@ -238,6 +253,7 @@ public class BookListFragment extends BaseFragment { void buttonNegative() { // Clicked to not download - Permanently disable downloading downloadPrefs.hasEnabledDownload(false); + // TODO: Migrate to strings.xml showToast("Disabling downloading. Re-enable it in settings."); fragment.getActivity().finish(); } diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt index b382c23..9e1848c 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt @@ -1,7 +1,6 @@ package org.bspeice.minimalbible.activity.downloader.manager import org.crosswire.jsword.book.install.Installer -import java.util.concurrent.atomic.AtomicBoolean import rx.Observable import org.crosswire.jsword.book.Book import rx.schedulers.Schedulers @@ -19,12 +18,12 @@ class RefreshManager(val installers: Collection, val exclude: List, val prefs: DownloadPrefs, val connManager: ConnectivityManager?) { - val refreshComplete = AtomicBoolean() + val availableModules: Observable>> = Observable.from(installers) .map { if (doReload()) { - it.reloadBookList() // TODO: Handle InstallException + it.reloadBookList() prefs.downloadRefreshedOn(Date().getTime()) } val validBooks = it.getBooks() @@ -45,12 +44,6 @@ class RefreshManager(val installers: Collection, BookComparators.getInitialComparator().compare(book1, book2) }; - // Constructor - Split from the value creation because `subscribe` returns - // the subscriber object, not the underlying value - { - availableModules.subscribe({}, {}, { refreshComplete set true }) - } - val fifteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1296000 fun doReload(downloadEnabled: Boolean, lastUpdated: Long, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c1ef28..baa503e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,7 +6,9 @@ Close navigation drawer Settings Downloads - Could not remove book. Try restarting application? + Could not remove, please restart application Categories + Error refreshing. Try again later +