Downloader Bug fix

UI Optimized
Scroller autohide, track disable
This commit is contained in:
tom5079
2020-09-13 16:19:32 +09:00
parent df3a478ef3
commit 1521bc1223
13 changed files with 195 additions and 166 deletions

View File

@@ -71,11 +71,9 @@ val client: OkHttpClient
class Pupil : Application() {
init {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
}
override fun onCreate() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
preferences = PreferenceManager.getDefaultSharedPreferences(this)
val userID = Preferences["user_id", ""].let { userID ->

View File

@@ -20,6 +20,7 @@ package xyz.quaver.pupil.adapters
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.Log
import android.util.SparseBooleanArray
import android.view.LayoutInflater
import android.view.View
@@ -125,6 +126,8 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
}
fun bind(galleryID: Int) {
val time = System.currentTimeMillis()
val cache = Cache.getInstance(view.context, galleryID)
val galleryBlock = cache.metadata.galleryBlock ?: return
@@ -219,13 +222,15 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
}
galleryblock_tag_group.removeAllViews()
galleryBlock.relatedTags.forEach {
galleryblock_tag_group.addView(TagChip(context, Tag.parse(it)).apply {
setOnClickListener { view ->
for (callback in onChipClickedHandler)
callback.invoke((view as TagChip).tag)
}
})
CoroutineScope(Dispatchers.Default).launch {
galleryBlock.relatedTags.forEach {
TagChip(context, Tag.parse(it)).apply {
setOnClickListener { view ->
for (callback in onChipClickedHandler)
callback.invoke((view as TagChip).tag)
}
}.let { launch(Dispatchers.Main) { galleryblock_tag_group.addView(it) } }
}
}
galleryblock_id.text = galleryBlock.id.toString()
@@ -274,6 +279,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
galleryblock_tag_group.visibility = View.GONE
}
}
Log.i("PUPILD", "${System.currentTimeMillis() - time}")
}
}
class NextViewHolder(view: LinearLayout) : RecyclerView.ViewHolder(view)

View File

@@ -41,7 +41,6 @@ import xyz.quaver.hitomi.Reader
import xyz.quaver.hitomi.getReferer
import xyz.quaver.hitomi.imageUrlFromImage
import xyz.quaver.hiyobi.createImgList
import xyz.quaver.io.util.readBytes
import xyz.quaver.pupil.BuildConfig
import xyz.quaver.pupil.R
import xyz.quaver.pupil.services.DownloadService
@@ -143,7 +142,7 @@ class ReaderAdapter(private val activity: ReaderActivity,
CoroutineScope(Dispatchers.IO).launch {
glide
.load(image.readBytes())
.load(image.uri)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.apply {

View File

@@ -309,11 +309,25 @@ class DownloadService : Service() {
progress.put(galleryID, MutableList(reader.galleryInfo.files.size) { 0F })
cache.metadata.imageList?.forEachIndexed { index, image ->
progress[galleryID]?.set(index, if (image != null) Float.POSITIVE_INFINITY else 0F)
cache.metadata.imageList?.let {
if (progress[galleryID]?.size != it.size) {
cache.metadata.imageList?.filterNotNull()?.forEach { file ->
cache.findFile(file)?.delete()
}
cache.metadata.imageList = MutableList(reader.galleryInfo.files.size) { null }
return@let
}
it.forEachIndexed { index, image ->
progress[galleryID]?.set(index, if (image != null) Float.POSITIVE_INFINITY else 0F)
}
}
if (isCompleted(galleryID)) {
if (DownloadManager.getInstance(this@DownloadService)
.getDownloadFolder(galleryID) != null)
Cache.getInstance(this@DownloadService, galleryID).moveToDownload()
notificationManager.cancel(galleryID)
startId?.let { stopSelf(it) }
return@launch

View File

@@ -26,6 +26,7 @@ import android.text.InputType
import android.view.*
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDelegate
import androidx.cardview.widget.CardView
import androidx.core.view.GravityCompat
import com.arlib.floatingsearchview.FloatingSearchView
@@ -97,7 +98,9 @@ class MainActivity :
override fun onCreate(savedInstanceState: Bundle?) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (intent.action == Intent.ACTION_VIEW) {
intent.dataString?.let { url ->
@@ -111,8 +114,6 @@ class MainActivity :
}
}
setContentView(R.layout.activity_main)
if (Preferences["download_folder", ""].isEmpty())
DownloadLocationDialogFragment().show(supportFragmentManager, "Download Location Dialog")

View File

@@ -200,24 +200,42 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
fun moveToDownload() = CoroutineScope(Dispatchers.IO).launch {
val downloadFolder = downloadFolder ?: return@launch
if (downloadFolder.getChild(".metadata").exists())
return@launch
metadata.imageList?.forEach { imageName ->
imageName ?: return@forEach
val target = downloadFolder.getChild(imageName)
val source = cacheFolder.getChild(imageName)
if (!source.exists())
if (!source.exists() || target.exists())
return@forEach
kotlin.runCatching {
target.createNewFile()
source.readBytes()?.let { target.writeBytes(it) }
target.outputStream()?.use { target -> source.inputStream()?.use { source ->
source.copyTo(target)
} }
}
}
val cacheThumbnail = cacheFolder.getChild(".thumbnail")
val downloadThumbnail = downloadFolder.getChild(".thumbnail")
if (cacheThumbnail.exists() && !downloadThumbnail.exists()) {
kotlin.runCatching {
downloadThumbnail.createNewFile()
downloadThumbnail.outputStream()?.use { target -> cacheThumbnail.inputStream()?.use { source ->
source.copyTo(target)
} }
cacheThumbnail.delete()
}
}
val cacheMetadata = cacheFolder.getChild(".metadata")
val downloadMetadata = downloadFolder.getChild(".metadata")
if (cacheMetadata.exists()) {
if (cacheMetadata.exists() && !downloadMetadata.exists()) {
kotlin.runCatching {
downloadMetadata.createNewFile()
downloadMetadata.writeText(Json.encodeToString(metadata))