mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 18:11:50 +01:00
Disable elevation in recent chapters. Improve downloads discovery
This commit is contained in:
parent
c6b89a826c
commit
cdf5bbadea
@ -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
|
||||
|
@ -82,8 +82,8 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||
// 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<RecentChaptersFragment>() {
|
||||
* @param items the list of chapter from the database.
|
||||
*/
|
||||
private fun setDownloadedChapters(items: List<RecentChapterItem>) {
|
||||
// Cached list of downloaded manga directories.
|
||||
val mangaDirectories = mutableMapOf<Long, Array<UniFile>>()
|
||||
// Cached list of downloaded manga directories. Directory name is also cached because
|
||||
// it's slow when using SAF.
|
||||
val mangaDirsForSource = mutableMapOf<Long, Map<String?, UniFile>>()
|
||||
|
||||
// Cached list of downloaded chapter directories for a manga.
|
||||
val chapterDirectories = mutableMapOf<Long, Array<UniFile>>()
|
||||
val chapterDirsForManga = mutableMapOf<Long, Map<String?, UniFile>>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
@ -30,7 +30,7 @@
|
||||
app:tabMode="scrollable"
|
||||
app:tabMinWidth="75dp"/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
|
||||
|
||||
|
||||
<FrameLayout
|
||||
|
Loading…
Reference in New Issue
Block a user