Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xb2016 committed Oct 28, 2024
1 parent 4255936 commit 3f0f1e8
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ open class EasyRecyclerView @JvmOverloads constructor(
override fun setAdapter(adapter: Adapter<*>?) {
super.setAdapter(adapter)
mAdapter = adapter
if (adapter != null && adapter.hasStableIds() &&
mChoiceMode != CHOICE_MODE_NONE && mCheckedIdStates == null
if (adapter != null &&
adapter.hasStableIds() &&
mChoiceMode != CHOICE_MODE_NONE &&
mCheckedIdStates == null
) {
mCheckedIdStates = LongSparseArray()
}
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/com/hippo/ehviewer/client/EhCacheKeyFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package com.hippo.ehviewer.client

object EhCacheKeyFactory {
fun getThumbKey(gid: Long): String = "preview:large:$gid:0"
private val NormalPreviewKeyRegex = Regex("(/\\d+-\\d+)\\.\\w+$")

fun getNormalPreviewKey(gid: Long, index: Int): String = "preview:normal:$gid:$index"
fun getThumbKey(gid: Long): String = "preview:large:$gid:0"

fun getLargePreviewKey(gid: Long, index: Int): String = "preview:large:$gid:$index"
fun getNormalPreviewKey(url: String) = NormalPreviewKeyRegex.find(url)?.groupValues[1] ?: url

fun getLargePreviewSetKey(gid: Long, index: Int): String = "large_preview_set:$gid:$index"
fun getLargePreviewKey(gid: Long, index: Int) = "preview:large:$gid:$index"

fun getImageKey(gid: Long, index: Int): String = "image:$gid:$index"
}
fun getImageKey(gid: Long, index: Int) = "image:$gid:$index"

val String.isNormalPreviewKey
get() = startsWith('/')
4 changes: 1 addition & 3 deletions app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ object EhCookieStore : CookieJar {
@Synchronized
fun clear() {
map.clear()
launchIO {
db.clear()
}
db.clear()
}

fun newCookie(
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,7 @@ object EhEngine {
hasRated = true
}
}
val needApi = filter &&
sEhFilter.needTags() &&
!hasTags ||
Settings.showGalleryPages &&
!hasPages ||
hasRated
val needApi = filter && sEhFilter.needTags() && !hasTags || Settings.showGalleryPages && !hasPages || hasRated
if (needApi) {
fillGalleryListByApi(list, url)
}
Expand All @@ -199,9 +194,7 @@ object EhEngine {
if (filter) {
// Thumbnail mode need filter uploader again
list.removeAll {
!sEhFilter.filterUploader(it) ||
!sEhFilter.filterTag(it) ||
!sEhFilter.filterTagNamespace(it)
!sEhFilter.filterUploader(it) || !sEhFilter.filterTag(it) || !sEhFilter.filterTagNamespace(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package com.hippo.ehviewer.client.data

import com.hippo.ehviewer.client.EhCacheKeyFactory
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.client.getLargePreviewKey
import com.hippo.widget.LoadImageView
import com.hippo.yorozuya.collect.IntList

Expand All @@ -40,7 +40,7 @@ class LargePreviewSet(
override fun getGalleryPreview(gid: Long, index: Int): GalleryPreview {
val galleryPreview = GalleryPreview()
galleryPreview.position = mPositionList[index]
galleryPreview.imageKey = EhCacheKeyFactory.getLargePreviewKey(gid, galleryPreview.position)
galleryPreview.imageKey = getLargePreviewKey(gid, galleryPreview.position)
galleryPreview.imageUrl = mImageUrlList[index]
galleryPreview.pageUrl = mPageUrlList[index]
return galleryPreview
Expand All @@ -49,7 +49,7 @@ class LargePreviewSet(
override fun load(view: LoadImageView, gid: Long, index: Int) {
view.resetClip()
view.load(
EhCacheKeyFactory.getLargePreviewKey(gid, mPositionList[index]),
getLargePreviewKey(gid, mPositionList[index]),
EhUtils.fixThumbUrl(mImageUrlList[index]),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.hippo.ehviewer.client.data

import com.hippo.ehviewer.client.getNormalPreviewKey
import com.hippo.widget.LoadImageView
import com.hippo.yorozuya.collect.IntList

Expand All @@ -28,15 +29,6 @@ class NormalPreviewSet(
private var mClipHeightList: IntList = IntList(),
private var mPageUrlList: ArrayList<String> = arrayListOf(),
) : PreviewSet() {
private fun getImageKey(imageUrl: String): String {
val index = imageUrl.indexOf('/')
return if (index >= 0) {
imageUrl.substring(index + 1)
} else {
imageUrl
}
}

fun addItem(
position: Int,
imageUrl: String,
Expand All @@ -47,7 +39,7 @@ class NormalPreviewSet(
pageUrl: String,
) {
mPositionList.add(position)
mImageKeyList.add(getImageKey(imageUrl))
mImageKeyList.add(getNormalPreviewKey(imageUrl))
mImageUrlList.add(imageUrl)
mOffsetXList.add(xOffset)
mOffsetYList.add(yOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ class AccountPreference(
builder.setNegativeButton(R.string.settings_eh_account_refresh_igneous, null)
}
builder.setPositiveButton(R.string.settings_eh_account_sign_out) { _: DialogInterface, _: Int ->
EhUtils.signOut()
mActivity.showTip(R.string.settings_eh_account_sign_out_tip, BaseScene.LENGTH_SHORT)
mActivity.lifecycleScope.launchIO {
EhUtils.signOut()
withUIContext {
mActivity.showTip(
R.string.settings_eh_account_sign_out_tip,
BaseScene.LENGTH_SHORT,
)
}
}
}
builder.setMessage(mMessage)
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package com.hippo.ehviewer.spider
import android.graphics.ImageDecoder
import com.hippo.ehviewer.EhApplication.Companion.nonCacheOkHttpClient
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhCacheKeyFactory
import com.hippo.ehviewer.client.EhRequestBuilder
import com.hippo.ehviewer.client.EhUtils.getSuitableTitle
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.getImageKey
import com.hippo.ehviewer.coil.edit
import com.hippo.ehviewer.coil.read
import com.hippo.ehviewer.download.DownloadManager
Expand Down Expand Up @@ -69,7 +69,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
}

private fun containInCache(index: Int): Boolean {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
return sCache.openSnapshot(key)?.use { true } == true
}

Expand All @@ -81,7 +81,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
private fun copyFromCacheToDownloadDir(index: Int, skip: Boolean): Boolean {
val dir = downloadDir ?: return false
// Find image file in cache
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
return runCatching {
sCache.read(key) {
// Get extension
Expand Down Expand Up @@ -115,7 +115,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
}

private fun removeFromCache(index: Int): Boolean {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
return sCache.remove(key)
}

Expand Down Expand Up @@ -217,7 +217,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {

// Read Mode, allow save to cache
if (mode == SpiderQueen.MODE_READ) {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
var received: Long = 0
runSuspendCatching {
sCache.edit(key) {
Expand All @@ -235,7 +235,7 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
}

fun saveToUniFile(index: Int, file: UniFile): Boolean {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)

// Read from diskCache first
sCache.read(key) {
Expand All @@ -261,15 +261,15 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
}

fun getExtension(index: Int): String? {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
return sCache.openSnapshot(key)?.use { it.metadata.toNioPath().readText() }
?: downloadDir?.let { findImageFile(it, index).first }
?.name.let { FileUtils.getExtensionFromFilename(it) }
}

fun getImageSource(index: Int): CloseableSource? {
if (mode == SpiderQueen.MODE_READ) {
val key = EhCacheKeyFactory.getImageKey(mGid, index)
val key = getImageKey(mGid, index)
sCache.openSnapshot(key)?.let {
val source = ImageDecoder.createSource(it.data.toFile())
return object : CloseableSource, AutoCloseable by it {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ class MainActivity :

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (mDrawerLayout != null && (
if (mDrawerLayout != null &&
(
mDrawerLayout!!.isDrawerOpen(GravityCompat.START) ||
mDrawerLayout!!.isDrawerOpen(GravityCompat.END)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class DownloadFragment : BasePreferenceFragment() {
val key = preference.key
if (Settings.KEY_DOWNLOAD_LOCATION == key) {
val file = Settings.downloadLocation
if (file != null && !UniFile.isFileUri(
Settings.downloadLocation!!.uri,
)
if (file != null &&
!UniFile.isFileUri(Settings.downloadLocation!!.uri)
) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.settings_download_download_location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class SetSecurityFragment :
Settings.putSecurity(security)
Settings.putEnableFingerprint(
mFingerprint!!.visibility == View.VISIBLE &&
mFingerprint!!.isChecked && security.isNotEmpty(),
mFingerprint!!.isChecked &&
security.isNotEmpty(),
)
}
requireActivity().onBackPressed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ class CookieSignInScene :

fun enter() {
if (mSignInJob?.isActive == true ||
null == mIpbMemberIdLayout || null == mIpbPassHashLayout ||
null == mIgneousLayout || null == mIpbMemberId ||
null == mIpbPassHash || null == mIgneous
null == mIpbMemberIdLayout ||
null == mIpbPassHashLayout ||
null == mIgneousLayout ||
null == mIpbMemberId ||
null == mIpbPassHash ||
null == mIgneous
) {
return
}
Expand All @@ -152,6 +155,7 @@ class CookieSignInScene :
hideSoftInput()
showProgress()
mSignInJob = viewLifecycleOwner.lifecycleScope.launchIO {
EhUtils.signOut()
runCatching {
storeCookie(ipbMemberId, ipbPassHash, igneous)
EhEngine.getProfile().run {
Expand All @@ -173,7 +177,6 @@ class CookieSignInScene :
}

private fun showResultErrorDialog(e: Throwable) {
EhCookieStore.clear()
AlertDialog.Builder(requireContext())
.setTitle(R.string.sign_in_failed)
.setMessage("${ExceptionUtils.getReadableString(e)}\n\n${getString(R.string.wrong_cookie_warning)}")
Expand All @@ -182,7 +185,6 @@ class CookieSignInScene :
}

private suspend fun storeCookie(id: String, hash: String, igneous: String) {
EhUtils.signOut()
EhCookieStore.addCookie(newCookie(EhCookieStore.KEY_IPB_MEMBER_ID, id, EhUrl.DOMAIN_E))
EhCookieStore.addCookie(newCookie(EhCookieStore.KEY_IPB_MEMBER_ID, id, EhUrl.DOMAIN_EX))
EhCookieStore.addCookie(newCookie(EhCookieStore.KEY_IPB_PASS_HASH, hash, EhUrl.DOMAIN_E))
Expand All @@ -209,7 +211,8 @@ class CookieSignInScene :
showTip(R.string.from_clipboard_error, LENGTH_SHORT)
return
}
if (kvs.size >= 2 && text.contains(EhCookieStore.KEY_IPB_MEMBER_ID) &&
if (kvs.size >= 2 &&
text.contains(EhCookieStore.KEY_IPB_MEMBER_ID) &&
text.contains(EhCookieStore.KEY_IPB_PASS_HASH)
) {
for (s in kvs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import com.hippo.easyrecyclerview.MarginItemDecoration
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhCacheKeyFactory
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.client.getThumbKey
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener
Expand Down Expand Up @@ -1086,7 +1086,7 @@ class DownloadsScene :
val info = mList!![holder.bindingAdapterPosition]
info.thumb?.let {
holder.thumb.load(
EhCacheKeyFactory.getThumbKey(info.gid),
getThumbKey(info.gid),
encodeMagicRequest(info),
hardware = false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import com.hippo.drawable.TriangleDrawable
import com.hippo.easyrecyclerview.MarginItemDecoration
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhCacheKeyFactory
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.getThumbKey
import com.hippo.ehviewer.widget.TileThumb
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager
import com.hippo.yorozuya.ViewUtils
Expand Down Expand Up @@ -189,7 +189,7 @@ internal abstract class GalleryAdapter(
gi.thumb = EhUtils.fixThumbUrl(gi.thumb!!)
when (mType) {
TYPE_LIST -> {
holder.thumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb!!, hardware = false)
holder.thumb.load(getThumbKey(gi.gid), gi.thumb!!, hardware = false)
holder.title.text = EhUtils.getSuitableTitle(gi)
holder.uploader!!.alpha = if (gi.disowned) .5f else 1f
if (TextUtils.isEmpty(gi.uploader)) {
Expand Down Expand Up @@ -229,7 +229,7 @@ internal abstract class GalleryAdapter(
}
TYPE_GRID -> {
(holder.thumb as TileThumb).setThumbSize(gi.thumbWidth, gi.thumbHeight)
holder.thumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb!!, hardware = false)
holder.thumb.load(getThumbKey(gi.gid), gi.thumb!!, hardware = false)
if (Settings.thumbShowTitle) {
holder.title.text = EhUtils.getSuitableTitle(gi)
holder.title.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ class GalleryCommentsScene :
return
}
mGalleryDetail = args.getParcelableCompat(KEY_GALLERY_DETAIL)
mShowAllComments =
mGalleryDetail != null &&
mGalleryDetail!!.comments != null &&
!mGalleryDetail!!.comments!!.hasMore
mShowAllComments = mGalleryDetail != null && mGalleryDetail!!.comments != null && !mGalleryDetail!!.comments!!.hasMore
}

private fun onInit() {
Expand All @@ -143,10 +140,7 @@ class GalleryCommentsScene :

private fun onRestore(savedInstanceState: Bundle) {
mGalleryDetail = savedInstanceState.getParcelableCompat(KEY_GALLERY_DETAIL)
mShowAllComments =
mGalleryDetail != null &&
mGalleryDetail!!.comments != null &&
!mGalleryDetail!!.comments!!.hasMore
mShowAllComments = mGalleryDetail != null && mGalleryDetail!!.comments != null && !mGalleryDetail!!.comments!!.hasMore
}

override fun onSaveInstanceState(outState: Bundle) {
Expand Down
Loading

0 comments on commit 3f0f1e8

Please sign in to comment.