Fixed viewer flickering
Added moving with volume button Added nomedia Added help link to error snackbar
This commit is contained in:
@@ -41,6 +41,7 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import xyz.quaver.hitomi.GalleryBlock
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.pupil.BuildConfig
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.types.Tag
|
||||
@@ -86,6 +87,10 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
.skipMemoryCache(true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.error(R.drawable.image_broken_variant)
|
||||
.apply {
|
||||
if (BuildConfig.CENSOR)
|
||||
override(5, 8)
|
||||
}
|
||||
.into(galleryblock_thumbnail)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,22 +18,25 @@
|
||||
|
||||
package xyz.quaver.pupil.adapters
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.RequestManager
|
||||
import com.bumptech.glide.load.DataSource
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import xyz.quaver.pupil.BuildConfig
|
||||
import xyz.quaver.pupil.R
|
||||
|
||||
class ReaderAdapter(private val glide: RequestManager, private val images: List<String>) : RecyclerView.Adapter<ReaderAdapter.ViewHolder>() {
|
||||
|
||||
var isFullScreen = false
|
||||
private var prev : Drawable? = null
|
||||
|
||||
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view)
|
||||
|
||||
@@ -46,19 +49,41 @@ class ReaderAdapter(private val glide: RequestManager, private val images: List<
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
runBlocking {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val image = glide
|
||||
.load(images[position])
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
.error(R.drawable.image_broken_variant)
|
||||
.submit()
|
||||
.get()
|
||||
holder.view as ImageView
|
||||
|
||||
(holder.view as ImageView).setImageDrawable(image)
|
||||
}.join()
|
||||
}
|
||||
glide
|
||||
.load(images[position])
|
||||
.dontTransform()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
.error(R.drawable.image_broken_variant)
|
||||
.apply {
|
||||
if (BuildConfig.CENSOR)
|
||||
override(5, 8)
|
||||
if (isFullScreen)
|
||||
placeholder(prev)
|
||||
}
|
||||
.listener(object: RequestListener<Drawable> {
|
||||
override fun onLoadFailed(
|
||||
e: GlideException?,
|
||||
model: Any?,
|
||||
target: Target<Drawable>?,
|
||||
isFirstResource: Boolean
|
||||
) = false
|
||||
|
||||
override fun onResourceReady(
|
||||
resource: Drawable?,
|
||||
model: Any?,
|
||||
target: Target<Drawable>?,
|
||||
dataSource: DataSource?,
|
||||
isFirstResource: Boolean
|
||||
): Boolean {
|
||||
prev = resource?.constantState?.newDrawable()?.mutate()
|
||||
|
||||
return false
|
||||
}
|
||||
})
|
||||
.into(holder.view)
|
||||
}
|
||||
|
||||
override fun getItemCount() = images.size
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.RequestManager
|
||||
import xyz.quaver.pupil.BuildConfig
|
||||
|
||||
class ThumbnailAdapter(private val glide: RequestManager, private val thumbnails: List<String>) : RecyclerView.Adapter<ThumbnailAdapter.ViewHolder>() {
|
||||
|
||||
@@ -34,6 +35,10 @@ class ThumbnailAdapter(private val glide: RequestManager, private val thumbnails
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
glide
|
||||
.load(thumbnails[position])
|
||||
.apply {
|
||||
if (BuildConfig.CENSOR)
|
||||
override(5, 8)
|
||||
}
|
||||
.into(holder.view)
|
||||
}
|
||||
|
||||
|
||||
@@ -206,10 +206,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val maxPage = ceil(totalItems / perPage.toDouble()).roundToInt()
|
||||
|
||||
return when(keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (currentPage < maxPage) {
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (currentPage > 0) {
|
||||
runOnUiThread {
|
||||
currentPage++
|
||||
currentPage--
|
||||
|
||||
cancelFetch()
|
||||
clearGalleries()
|
||||
@@ -220,10 +220,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
true
|
||||
}
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (currentPage > 0) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (currentPage < maxPage) {
|
||||
runOnUiThread {
|
||||
currentPage--
|
||||
currentPage++
|
||||
|
||||
cancelFetch()
|
||||
clearGalleries()
|
||||
@@ -796,7 +796,7 @@ class MainActivity : AppCompatActivity() {
|
||||
s ?: return
|
||||
|
||||
if (s.any { it.isUpperCase() })
|
||||
s.replace(0, s.length, s.toString().toLowerCase())
|
||||
s.replace(0, s.length, s.toString().toLowerCase(Locale.getDefault()))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
@@ -45,10 +46,7 @@ import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.adapters.ReaderAdapter
|
||||
import xyz.quaver.pupil.util.GalleryDownloader
|
||||
import xyz.quaver.pupil.util.Histories
|
||||
import xyz.quaver.pupil.util.ItemClickSupport
|
||||
import xyz.quaver.pupil.util.hasPermission
|
||||
import xyz.quaver.pupil.util.*
|
||||
|
||||
class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
@@ -220,6 +218,23 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
//currentPage is 1-based
|
||||
return when(keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPositionWithOffset(currentPage-2, 0)
|
||||
|
||||
true
|
||||
}
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPositionWithOffset(currentPage, 0)
|
||||
|
||||
true
|
||||
}
|
||||
else -> super.onKeyDown(keyCode, event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initDownloader() {
|
||||
var d: GalleryDownloader? = GalleryDownloader.get(galleryID)
|
||||
|
||||
@@ -262,7 +277,12 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
onErrorHandler = {
|
||||
Snackbar.make(reader_layout, it.message ?: it.javaClass.name, Snackbar.LENGTH_INDEFINITE).show()
|
||||
Snackbar
|
||||
.make(reader_layout, it.message ?: it.javaClass.name, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.reader_help) { view ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.error_help))))
|
||||
}
|
||||
.show()
|
||||
downloader.download = false
|
||||
}
|
||||
onCompleteHandler = {
|
||||
@@ -340,7 +360,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
scrollMode(false)
|
||||
fullscreen(true)
|
||||
} else {
|
||||
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPosition(currentPage)
|
||||
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPosition(currentPage) //Moves to next page because currentPage is 1-based indexing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import xyz.quaver.pupil.util.Lock
|
||||
import xyz.quaver.pupil.util.LockManager
|
||||
import xyz.quaver.pupil.util.getDownloadDirectory
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
@@ -278,7 +279,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||
s ?: return
|
||||
|
||||
if (s.any { it.isUpperCase() })
|
||||
s.replace(0, s.length, s.toString().toLowerCase())
|
||||
s.replace(0, s.length, s.toString().toLowerCase(Locale.getDefault()))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -352,6 +353,38 @@ class SettingsActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
with(findPreference<Preference>("nomedia")) {
|
||||
this!!
|
||||
|
||||
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val directories = listOf(
|
||||
context.cacheDir,
|
||||
getDownloadDirectory(context)
|
||||
)
|
||||
|
||||
when (newValue as Boolean) {
|
||||
true -> {
|
||||
directories.forEach {
|
||||
it ?: return@forEach
|
||||
|
||||
if (it.exists())
|
||||
File(it, ".nomedia").createNewFile()
|
||||
}
|
||||
}
|
||||
false -> {
|
||||
directories.forEach {
|
||||
it ?: return@forEach
|
||||
|
||||
if (it.exists())
|
||||
File(it, ".nomedia").delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,8 @@ class GalleryDownloader(
|
||||
downloadJob = CoroutineScope(Dispatchers.Default).launch {
|
||||
val reader = reader!!.await()
|
||||
|
||||
notificationBuilder.setContentTitle(reader.title)
|
||||
|
||||
if (reader.readerItems.isEmpty()) {
|
||||
onErrorHandler?.invoke(IOException(getString(R.string.unable_to_connect)))
|
||||
return@launch
|
||||
@@ -312,16 +314,11 @@ class GalleryDownloader(
|
||||
notificationBuilder = NotificationCompat.Builder(this, "download").apply {
|
||||
setContentTitle(getString(R.string.reader_loading))
|
||||
setContentText(getString(R.string.reader_notification_text))
|
||||
setSmallIcon(R.drawable.ic_download)
|
||||
setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
setContentIntent(pendingIntent)
|
||||
setProgress(0, 0, true)
|
||||
priority = NotificationCompat.PRIORITY_LOW
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
while (reader == null) ;
|
||||
notificationBuilder.setContentTitle(reader.await().title)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user