Bug fix
Remember thin mode preference TagChip favorites
This commit is contained in:
@@ -20,7 +20,6 @@ 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
|
||||
@@ -70,7 +69,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
|
||||
val timer = Timer()
|
||||
|
||||
var isThin = false
|
||||
var thin: Boolean = Preferences["thin"]
|
||||
|
||||
inner class GalleryViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
var timerTask: TimerTask? = null
|
||||
@@ -88,7 +87,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
with(view.galleryblock_progressbar) {
|
||||
val imageList = cache.metadata.imageList!!
|
||||
|
||||
progress = imageList.filterNotNull().size
|
||||
progress = imageList.count { it != null }
|
||||
max = imageList.size
|
||||
|
||||
with(view.galleryblock_progressbar_layout) {
|
||||
@@ -96,7 +95,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (progress == max) {
|
||||
if (!imageList.contains(null)) {
|
||||
val downloadManager = DownloadManager.getInstance(context)
|
||||
|
||||
if (completeFlag.get(galleryID, false)) {
|
||||
@@ -143,7 +142,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
val artists = galleryBlock.artists
|
||||
val series = galleryBlock.series
|
||||
|
||||
if (isThin)
|
||||
if (thin)
|
||||
galleryblock_thumbnail.layoutParams.width = context.resources.getDimensionPixelSize(
|
||||
R.dimen.galleryblock_thumbnail_thin
|
||||
)
|
||||
@@ -273,7 +272,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
|
||||
|
||||
|
||||
// Make some views invisible to make it thinner
|
||||
if (isThin) {
|
||||
if (thin) {
|
||||
galleryblock_language.visibility = View.GONE
|
||||
galleryblock_type.visibility = View.GONE
|
||||
galleryblock_tag_group.visibility = View.GONE
|
||||
|
||||
@@ -311,25 +311,15 @@ class DownloadService : Service() {
|
||||
|
||||
progress.put(galleryID, MutableList(reader.galleryInfo.files.size) { 0F })
|
||||
|
||||
FirebaseCrashlytics.getInstance().log(
|
||||
"""
|
||||
GALLERYID: $galleryID
|
||||
CACHE: ${cache.findFile(".metadata")}
|
||||
PATTERN: ${Preferences["download_folder_name", ""]}
|
||||
READER ID: ${reader.galleryInfo.id}
|
||||
READER SIZE: ${reader.galleryInfo.files.size}
|
||||
CACHE READER ID: ${cache.metadata.reader?.galleryInfo?.id}}
|
||||
CACHE READER SIZE: ${cache.metadata.reader?.galleryInfo?.files?.size}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
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
|
||||
FirebaseCrashlytics.getInstance().log(
|
||||
"""
|
||||
GALLERYID: $galleryID
|
||||
${it.size} - ${progress[galleryID]?.size}
|
||||
""".trimIndent()
|
||||
)
|
||||
error("ImageList Size does not match")
|
||||
}
|
||||
|
||||
it.forEachIndexed { index, image ->
|
||||
@@ -361,7 +351,17 @@ class DownloadService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
reader.requestBuilders.forEachIndexed { index, it ->
|
||||
reader.requestBuilders.also {
|
||||
if (it.size != progress[galleryID]?.size) {
|
||||
FirebaseCrashlytics.getInstance().log(
|
||||
"""
|
||||
GALLERYID: $galleryID
|
||||
${it.size} - ${progress[galleryID]?.size}
|
||||
""".trimIndent()
|
||||
)
|
||||
error("Requests Size does not match")
|
||||
}
|
||||
}.forEachIndexed { index, it ->
|
||||
if (progress[galleryID]?.get(index)?.isInfinite() != true) {
|
||||
val request = it.tag(Tag(galleryID, index, startId)).build()
|
||||
client.newCall(request).enqueue(callback)
|
||||
|
||||
@@ -39,6 +39,7 @@ import kotlinx.android.synthetic.main.activity_main_content.*
|
||||
import kotlinx.coroutines.*
|
||||
import xyz.quaver.floatingsearchview.FloatingSearchView
|
||||
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
|
||||
import xyz.quaver.floatingsearchview.util.view.MenuView
|
||||
import xyz.quaver.floatingsearchview.util.view.SearchInputView
|
||||
import xyz.quaver.hitomi.doSearch
|
||||
import xyz.quaver.hitomi.getGalleryIDsFromNozomi
|
||||
@@ -635,6 +636,14 @@ class MainActivity :
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
findViewById<MenuView>(R.id.menu_view).menuItems.firstOrNull {
|
||||
(it as MenuItem).itemId == R.id.main_menu_thin
|
||||
}?.let {
|
||||
(it as MenuItem).isChecked = Preferences["thin"]
|
||||
}
|
||||
}
|
||||
|
||||
onHistoryDeleteClickedListener = {
|
||||
searchHistory.remove(it)
|
||||
swapSuggestions(defaultSuggestions)
|
||||
@@ -709,9 +718,14 @@ class MainActivity :
|
||||
when(item?.itemId) {
|
||||
R.id.main_menu_settings -> startActivityForResult(Intent(this@MainActivity, SettingsActivity::class.java), R.id.request_settings.normalizeID())
|
||||
R.id.main_menu_thin -> {
|
||||
val thin = !item.isChecked
|
||||
|
||||
item.isChecked = thin
|
||||
main_recyclerview.apply {
|
||||
(adapter as GalleryBlockAdapter).apply {
|
||||
isThin = !isThin
|
||||
this.thin = thin
|
||||
|
||||
Preferences["thin"] = thin
|
||||
}
|
||||
|
||||
adapter = adapter // Force to redraw
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.chip.Chip
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.favoriteTags
|
||||
import xyz.quaver.pupil.types.Tag
|
||||
import xyz.quaver.pupil.util.wordCapitalize
|
||||
|
||||
@@ -56,6 +57,34 @@ class TagChip(context: Context, tag: Tag) : Chip(context) {
|
||||
ContextCompat.getDrawable(context, R.drawable.gender_female_white)
|
||||
}
|
||||
else -> null
|
||||
}.also {
|
||||
if (favoriteTags.contains(tag))
|
||||
setChipBackgroundColorResource(R.color.material_orange_500)
|
||||
}
|
||||
|
||||
isCloseIconVisible = true
|
||||
closeIcon = ContextCompat.getDrawable(context,
|
||||
if (favoriteTags.contains(tag))
|
||||
R.drawable.ic_star_filled
|
||||
else
|
||||
R.drawable.ic_star_empty
|
||||
)
|
||||
|
||||
setOnCloseIconClickListener {
|
||||
if (favoriteTags.contains(tag)) {
|
||||
favoriteTags.remove(tag)
|
||||
closeIcon = ContextCompat.getDrawable(context, R.drawable.ic_star_empty)
|
||||
|
||||
when(tag.area) {
|
||||
"male" -> setChipBackgroundColorResource(R.color.material_blue_700)
|
||||
"female" -> setChipBackgroundColorResource(R.color.material_pink_600)
|
||||
else -> chipBackgroundColor = null
|
||||
}
|
||||
} else {
|
||||
favoriteTags.add(tag)
|
||||
closeIcon = ContextCompat.getDrawable(context, R.drawable.ic_star_filled)
|
||||
setChipBackgroundColorResource(R.color.material_orange_500)
|
||||
}
|
||||
}
|
||||
|
||||
text = when (tag.area) {
|
||||
|
||||
@@ -212,7 +212,9 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
||||
return@forEach
|
||||
|
||||
kotlin.runCatching {
|
||||
target.createNewFile()
|
||||
if (!target.exists())
|
||||
target.createNewFile()
|
||||
|
||||
target.outputStream()?.use { target -> source.inputStream()?.use { source ->
|
||||
source.copyTo(target)
|
||||
} }
|
||||
@@ -224,7 +226,9 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
||||
|
||||
if (cacheThumbnail.exists() && !downloadThumbnail.exists()) {
|
||||
kotlin.runCatching {
|
||||
downloadThumbnail.createNewFile()
|
||||
if (!downloadThumbnail.exists())
|
||||
downloadThumbnail.createNewFile()
|
||||
|
||||
downloadThumbnail.outputStream()?.use { target -> cacheThumbnail.inputStream()?.use { source ->
|
||||
source.copyTo(target)
|
||||
} }
|
||||
@@ -237,7 +241,9 @@ class Cache private constructor(context: Context, val galleryID: Int) : ContextW
|
||||
|
||||
if (cacheMetadata.exists() && !downloadMetadata.exists()) {
|
||||
kotlin.runCatching {
|
||||
downloadMetadata.createNewFile()
|
||||
if (!downloadMetadata.exists())
|
||||
downloadMetadata.createNewFile()
|
||||
|
||||
downloadMetadata.writeText(Json.encodeToString(metadata))
|
||||
cacheMetadata.delete()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user