diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt index 2a78c7dce..b0704ef55 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.widget.DeletingChaptersDialog +import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_recent_chapters.* import nucleus.factory.RequiresPresenter import timber.log.Timber @@ -101,13 +102,14 @@ class RecentChaptersFragment: setToolbarTitle(R.string.label_recent_updates) // Disable toolbar elevation, it looks better with sticky headers. -// ViewCompat.setElevation(activity.appbar, 0f) + activity.appbar.disableElevation() } -// override fun onDestroyView() { -// ViewCompat.setElevation(activity.appbar, 4.dpToPx.toFloat()) -// super.onDestroyView() -// } + override fun onDestroyView() { + // Restore toolbar elevation. + activity.appbar.enableElevation() + super.onDestroyView() + } /** * Returns selected chapters diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt index 434e287b7..8fb4a5b31 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt @@ -82,8 +82,8 @@ class RecentChaptersPresenter : BasePresenter() { // Find an active download for this chapter. val download = downloadManager.queue.find { it.chapter.id == item.chapter.id } - // If there's an active download, assign it, otherwise ask the manager if the chapter is - // downloaded and assign it to the status. + // If there's an active download, assign it, otherwise ask the manager if + // the chapter is downloaded and assign it to the status. if (download != null) { item.download = download } @@ -126,30 +126,36 @@ class RecentChaptersPresenter : BasePresenter() { * @param items the list of chapter from the database. */ private fun setDownloadedChapters(items: List) { - // Cached list of downloaded manga directories. - val mangaDirectories = mutableMapOf>() + // Cached list of downloaded manga directories. Directory name is also cached because + // it's slow when using SAF. + val mangaDirsForSource = mutableMapOf>() // Cached list of downloaded chapter directories for a manga. - val chapterDirectories = mutableMapOf>() + val chapterDirsForManga = mutableMapOf>() for (item in items) { val manga = item.manga val chapter = item.chapter val source = sourceManager.get(manga.source) ?: continue - val mangaDirs = mangaDirectories.getOrPut(source.id) { - downloadManager.findSourceDir(source)?.listFiles() ?: emptyArray() + // Get the directories for the source of the manga. + val dirsForSource = mangaDirsForSource.getOrPut(source.id) { + val sourceDir = downloadManager.findSourceDir(source) + sourceDir?.listFiles()?.associateBy { it.name }.orEmpty() } + // Get the manga directory in the source or continue. val mangaDirName = downloadManager.getMangaDirName(manga) - val mangaDir = mangaDirs.find { it.name == mangaDirName } ?: continue + val mangaDir = dirsForSource[mangaDirName] ?: continue - val chapterDirs = chapterDirectories.getOrPut(manga.id!!) { - mangaDir.listFiles() ?: emptyArray() + // Get the directories for the manga. + val chapterDirs = chapterDirsForManga.getOrPut(manga.id!!) { + mangaDir.listFiles()?.associateBy { it.name }.orEmpty() } + // Assign the download if the directory exists. val chapterDirName = downloadManager.getChapterDirName(chapter) - if (chapterDirs.any { it.name == chapterDirName }) { + if (chapterDirName in chapterDirs) { item.status = Download.DOWNLOADED } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt new file mode 100644 index 000000000..20c33a4fc --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt @@ -0,0 +1,48 @@ +package eu.kanade.tachiyomi.widget + +import android.animation.ObjectAnimator +import android.animation.StateListAnimator +import android.content.Context +import android.os.Build +import android.support.design.R +import android.support.design.widget.AppBarLayout +import android.util.AttributeSet + +class ElevationAppBarLayout @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null +) : AppBarLayout(context, attrs) { + + private var origStateAnimator: StateListAnimator? = null + + init { + if (Build.VERSION.SDK_INT >= 21) { + origStateAnimator = stateListAnimator + } + } + + fun enableElevation() { + if (Build.VERSION.SDK_INT >= 21) { + stateListAnimator = origStateAnimator + } + } + + fun disableElevation() { + if (Build.VERSION.SDK_INT >= 21) { + stateListAnimator = StateListAnimator().apply { + val objAnimator = ObjectAnimator.ofFloat(this, "elevation", 0f) + + // Enabled and collapsible, but not collapsed means not elevated + addState(intArrayOf(android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed), + objAnimator) + + // Default enabled state + addState(intArrayOf(android.R.attr.enabled), objAnimator) + + // Disabled state + addState(IntArray(0), objAnimator) + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 10b7b3f8e..9e24d4df2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,7 +12,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - @@ -30,7 +30,7 @@ app:tabMode="scrollable" app:tabMinWidth="75dp"/> - +