mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-06-30 21:36:10 -04:00
Some more cleanup and additions
Android is seriously not test-friendly
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package org.bspeice.minimalbible.activity.downloader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
@ -106,7 +107,9 @@ public class DownloadActivityModules {
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
RefreshManager provideRefreshManager(Collection<Installer> installers) {
|
||||
return new RefreshManager(installers);
|
||||
RefreshManager provideRefreshManager(Collection<Installer> installers, DownloadPrefs prefs,
|
||||
@Named("DownloadActivityContext") Context context) {
|
||||
return new RefreshManager(installers, prefs,
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,17 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
import rx.Observable
|
||||
import org.crosswire.jsword.book.Book
|
||||
import rx.schedulers.Schedulers
|
||||
import java.util.Calendar
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs
|
||||
import android.net.ConnectivityManager
|
||||
|
||||
/**
|
||||
* Created by bspeice on 10/22/14.
|
||||
*/
|
||||
|
||||
class RefreshManager(val installers: Collection<Installer>) {
|
||||
class RefreshManager(val installers: Collection<Installer>,
|
||||
val prefs: DownloadPrefs,
|
||||
val connManager: ConnectivityManager?) {
|
||||
val refreshComplete = AtomicBoolean()
|
||||
val availableModules: Observable<Map<Installer, List<Book>>> =
|
||||
Observable.from(installers)
|
||||
@ -36,11 +41,27 @@ class RefreshManager(val installers: Collection<Installer>) {
|
||||
availableModules.subscribe({}, {}, { refreshComplete set true })
|
||||
}
|
||||
|
||||
fun doReload(): Boolean = true
|
||||
val fifteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1296000
|
||||
|
||||
fun doReload(enabledDownload: Boolean, lastUpdated: Long, onWifi: Boolean): Boolean =
|
||||
if (!enabledDownload || !onWifi)
|
||||
false
|
||||
else if (lastUpdated < fifteenDaysAgo)
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
fun doReload(): Boolean = doReload(prefs.hasEnabledDownload(),
|
||||
prefs.downloadRefreshedOn(),
|
||||
// TODO: Functional is awesome, but this might be a bit ridiculous
|
||||
(if (connManager?.getActiveNetworkInfo() != null)
|
||||
connManager!!.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
|
||||
else
|
||||
false)
|
||||
)
|
||||
|
||||
fun installerFromBook(b: Book): Observable<Installer> = Observable.just(
|
||||
availableModules.filter {
|
||||
it.flatMap { it.value } contains b
|
||||
}
|
||||
.toBlocking().first().entrySet().first().getKey())
|
||||
}.toBlocking().first().entrySet().first().getKey())
|
||||
}
|
Reference in New Issue
Block a user