Minor changes to download cache. Also keep the library view, as recreation is expensive

This commit is contained in:
inorichi 2017-11-28 23:58:31 +01:00
parent d1d1d60c30
commit 28a21d0b8f
4 changed files with 18 additions and 18 deletions

View File

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit
class DownloadCache(private val context: Context, class DownloadCache(private val context: Context,
private val provider: DownloadProvider, private val provider: DownloadProvider,
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
preferences: PreferencesHelper = Injekt.get()) { private val preferences: PreferencesHelper = Injekt.get()) {
/** /**
* The interval after which this cache should be invalidated. 1 hour shouldn't cause major * The interval after which this cache should be invalidated. 1 hour shouldn't cause major
@ -42,24 +42,23 @@ class DownloadCache(private val context: Context,
/** /**
* The root directory for downloads. * The root directory for downloads.
*/ */
private var rootDir = setRootDir(preferences.downloadsDirectory().getOrDefault()) private var rootDir = RootDirectory(getDirectoryFromPreference())
init { init {
setRootDir(preferences.downloadsDirectory().getOrDefault())
preferences.downloadsDirectory().asObservable() preferences.downloadsDirectory().asObservable()
.skip(1) .skip(1)
.subscribe { setRootDir(it) } .subscribe {
lastRenew = 0L // invalidate cache
rootDir = RootDirectory(getDirectoryFromPreference())
}
} }
/** /**
* Sets the root downloads directory and invalidates the cache. * Returns the downloads directory from the user's preferences.
*
* @param directory the downloads directory in [Uri] format.
*/ */
private fun setRootDir(directory: String): RootDirectory { private fun getDirectoryFromPreference(): UniFile {
rootDir = RootDirectory(UniFile.fromUri(context, Uri.parse(directory))) val dir = preferences.downloadsDirectory().getOrDefault()
lastRenew = 0L return UniFile.fromUri(context, Uri.parse(dir))
return rootDir
} }
/** /**

View File

@ -429,7 +429,7 @@ class LibraryController(
presenter.onOpenManga() presenter.onOpenManga()
router.pushController(RouterTransaction.with(MangaController(manga)) router.pushController(RouterTransaction.with(MangaController(manga))
.pushChangeHandler(FadeChangeHandler()) .pushChangeHandler(FadeChangeHandler(false))
.popChangeHandler(FadeChangeHandler())) .popChangeHandler(FadeChangeHandler()))
} }

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<eu.kanade.tachiyomi.widget.RevealAnimationView <eu.kanade.tachiyomi.widget.RevealAnimationView
android:id="@+id/reveal_view" android:id="@+id/reveal_view"

View File

@ -3,4 +3,5 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_pager" android:id="@+id/view_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:background="?android:attr/colorBackground" />