Remove search cover feature due to upstream change

This commit is contained in:
FooIbar committed 2024-11-09 22:54:07 +08:00
1 parent 17581ca204
commit f4c7320bb5
13 files changed
+119 -123

No files matched your search

@@ -15,18 +15,32 @@
*/
package com.hippo.ehviewer.client
import android.app.DownloadManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.os.Environment
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.core.net.toUri
import arrow.core.memoize
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.data.GalleryDetail
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.parser.Archive
import com.hippo.ehviewer.spider.SpiderDen
import com.hippo.ehviewer.util.AppConfig
import com.hippo.ehviewer.util.FileUtils
import com.hippo.ehviewer.util.addTextToClipboard
import com.materialkolor.hct.Hct
import com.materialkolor.ktx.from
import com.materialkolor.ktx.toColor
import eu.kanade.tachiyomi.util.lang.withUIContext
import kotlin.math.abs
import splitties.systemservices.downloadManager
object EhUtils {
const val NONE = -1 // Use it for homepage
@@ -84,16 +98,12 @@ object EhUtils {
)
private val CATEGORY_STRINGS = CATEGORY_VALUES.entries.map { (k, v) -> v to k }
private val ImageHashRegex = Regex("[0-9a-f]{40}")
val isExHentai: Boolean
get() = Settings.gallerySite.value == EhUrl.SITE_EX
val isMpvAvailable
get() = EhCookieStore.getHathPerks()?.contains('q') == true
fun getImageHash(thumbUrl: String) = ImageHashRegex.find(thumbUrl)?.groupValues[0]
fun getCategory(type: String?): Int {
for (entry in CATEGORY_STRINGS) {
for (str in entry.first) {
@@ -182,4 +192,35 @@ object EhUtils {
// TODO But not sure every '|' means that
return title.substringBeforeLast('|').trim().ifEmpty { null }
}
context(Context)
suspend fun downloadArchive(galleryDetail: GalleryDetail, archive: Archive) {
val gid = galleryDetail.gid
EhEngine.downloadArchive(gid, galleryDetail.token, archive.res, archive.isHAtH)?.let {
val uri = it.toUri()
val intent = Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, "application/zip")
}
val name = "$gid-${getSuitableTitle(galleryDetail)}.zip"
try {
startActivity(intent)
withUIContext { addTextToClipboard(name, true) }
} catch (_: ActivityNotFoundException) {
val r = DownloadManager.Request(uri)
r.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name),
)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
downloadManager.enqueue(r)
}
if (Settings.archiveMetadata) {
SpiderDen(galleryDetail).apply {
initDownloadDir()
writeComicInfo()
}
}
}
}
}
@@ -26,7 +26,7 @@ import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ImageSearch
import androidx.compose.material.icons.filled.FolderZip
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
@@ -84,6 +84,8 @@ import com.hippo.ehviewer.client.data.ListUrlBuilder
import com.hippo.ehviewer.client.data.TagNamespace
import com.hippo.ehviewer.client.data.asGalleryDetail
import com.hippo.ehviewer.client.data.findBaseInfo
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.client.exception.NoHAtHClientException
import com.hippo.ehviewer.coil.justDownload
import com.hippo.ehviewer.collectAsState
import com.hippo.ehviewer.dao.DownloadInfo
@@ -100,6 +102,7 @@ import com.hippo.ehviewer.ui.confirmRemoveDownload
import com.hippo.ehviewer.ui.destinations.GalleryCommentsScreenDestination
import com.hippo.ehviewer.ui.getFavoriteIcon
import com.hippo.ehviewer.ui.jumpToReaderByPage
import com.hippo.ehviewer.ui.main.ArchiveList
import com.hippo.ehviewer.ui.main.EhPreviewItem
import com.hippo.ehviewer.ui.main.GalleryCommentCard
import com.hippo.ehviewer.ui.main.GalleryDetailErrorTip
@@ -128,6 +131,7 @@ import com.hippo.ehviewer.ui.tools.rememberInVM
import com.hippo.ehviewer.util.FavouriteStatusRouter
import com.hippo.ehviewer.util.addTextToClipboard
import com.hippo.ehviewer.util.bgWork
import com.hippo.ehviewer.util.displayString
import com.hippo.ehviewer.util.flattenForEach
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -524,18 +528,55 @@ fun BelowHeader(galleryDetail: GalleryDetail) {
}
},
)
val invalidUrl = stringResource(R.string.error_invalid_url)
EhIconButton(
icon = Icons.Default.ImageSearch,
text = stringResource(id = R.string.search_cover),
onClick = {
val hash = EhUtils.getImageHash(galleryDetail.thumbKey!!)
if (hash != null) {
navigate(ListUrlBuilder(mode = ListUrlBuilder.MODE_IMAGE_SEARCH, hash = hash).asDst())
} else {
launch { showSnackbar(invalidUrl) }
val signInFirst = stringResource(R.string.sign_in_first)
val noArchive = stringResource(R.string.no_archives)
val downloadStarted = stringResource(R.string.download_archive_started)
val downloadFailed = stringResource(R.string.download_archive_failure)
val failureNoHath = stringResource(R.string.download_archive_failure_no_hath)
val archiveResult = remember(galleryDetail) {
async(Dispatchers.IO + Job(), CoroutineStart.LAZY) {
with(galleryDetail) {
EhEngine.getArchiveList(archiveUrl!!, gid, token)
}
},
}
}
fun showArchiveDialog() {
launchIO {
if (galleryDetail.apiUid < 0) {
showSnackbar(signInFirst)
} else {
runSuspendCatching {
val (archiveList, funds) = bgWork { archiveResult.await() }
if (archiveList.isEmpty()) {
showSnackbar(noArchive)
} else {
val selected = showNoButton {
ArchiveList(
funds = funds,
items = archiveList,
onItemClick = { resume(it) },
)
}
EhUtils.downloadArchive(galleryDetail, selected)
showSnackbar(downloadStarted)
}
}.onFailure {
when (it) {
is NoHAtHClientException -> showSnackbar(failureNoHath)
is EhException -> showSnackbar(it.displayString())
else -> {
logcat(it)
showSnackbar(downloadFailed)
}
}
}
}
}
}
EhIconButton(
icon = Icons.Default.FolderZip,
text = stringResource(id = R.string.archive),
onClick = ::showArchiveDialog,
)
val torrentText = stringResource(R.string.torrent_count, galleryDetail.torrentCount)
val noTorrents = stringResource(R.string.no_torrents)
@@ -1,11 +1,6 @@
package com.hippo.ehviewer.ui.screen
import android.app.DownloadManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Environment
import android.os.Parcelable
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
import androidx.collection.SieveCache
@@ -14,7 +9,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.FolderZip
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.CircularProgressIndicator
@@ -52,26 +46,20 @@ import com.hippo.ehviewer.client.data.BaseGalleryInfo
import com.hippo.ehviewer.client.data.GalleryDetail
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.data.findBaseInfo
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.client.exception.NoHAtHClientException
import com.hippo.ehviewer.client.getImageKey
import com.hippo.ehviewer.coil.justDownload
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.download.DownloadManager as EhDownloadManager
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.ktbuilder.imageRequest
import com.hippo.ehviewer.spider.SpiderDen
import com.hippo.ehviewer.ui.MainActivity
import com.hippo.ehviewer.ui.composing
import com.hippo.ehviewer.ui.main.ArchiveList
import com.hippo.ehviewer.ui.main.GalleryDetailErrorTip
import com.hippo.ehviewer.ui.navToReader
import com.hippo.ehviewer.ui.openBrowser
import com.hippo.ehviewer.ui.tools.launchInVM
import com.hippo.ehviewer.ui.tools.rememberInVM
import com.hippo.ehviewer.util.AppConfig
import com.hippo.ehviewer.util.AppHelper
import com.hippo.ehviewer.util.FileUtils
import com.hippo.ehviewer.util.addTextToClipboard
import com.hippo.ehviewer.util.awaitActivityResult
import com.hippo.ehviewer.util.bgWork
import com.hippo.ehviewer.util.displayString
@@ -82,16 +70,9 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.lang.withUIContext
import eu.kanade.tachiyomi.util.system.logcat
import kotlin.coroutines.resume
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.parcelize.Parcelize
import moe.tarsin.coroutines.runSuspendCatching
import splitties.systemservices.downloadManager
val detailCache = SieveCache<Long, GalleryDetail>(25)
@@ -154,78 +135,7 @@ fun AnimatedVisibilityScope.GalleryDetailScreen(args: GalleryDetailScreenArgs, n
}
}
val archiveResult = remember(galleryInfo) {
async(Dispatchers.IO + Job(), CoroutineStart.LAZY) {
val detail = galleryInfo as GalleryDetail
EhEngine.getArchiveList(detail.archiveUrl!!, gid, token)
}
}
val failureNoHath = stringResource(R.string.download_archive_failure_no_hath)
val noArchive = stringResource(R.string.no_archives)
val downloadStarted = stringResource(R.string.download_archive_started)
val downloadFailed = stringResource(R.string.download_archive_failure)
val signInFirst = stringResource(R.string.sign_in_first)
fun showArchiveDialog() {
val galleryDetail = galleryInfo as? GalleryDetail ?: return
launchIO {
if (galleryDetail.apiUid < 0) {
showSnackbar(signInFirst)
} else {
runSuspendCatching {
val (archiveList, funds) = bgWork { archiveResult.await() }
if (archiveList.isEmpty()) {
showSnackbar(noArchive)
} else {
val selected = showNoButton {
ArchiveList(
funds = funds,
items = archiveList,
onItemClick = { resume(it) },
)
}
EhEngine.downloadArchive(gid, token, selected.res, selected.isHAtH)?.let {
val uri = Uri.parse(it)
val intent = Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, "application/zip")
}
val name = "$gid-${EhUtils.getSuitableTitle(galleryDetail)}.zip"
try {
startActivity(intent)
withUIContext { addTextToClipboard(name, true) }
} catch (_: ActivityNotFoundException) {
val r = DownloadManager.Request(uri)
r.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name),
)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
downloadManager.enqueue(r)
}
if (Settings.archiveMetadata) {
SpiderDen(galleryDetail).apply {
initDownloadDir()
writeComicInfo()
}
}
}
showSnackbar(downloadStarted)
}
}.onFailure {
when (it) {
is NoHAtHClientException -> showSnackbar(failureNoHath)
is EhException -> showSnackbar(it.displayString())
else -> {
logcat(it)
showSnackbar(downloadFailed)
}
}
}
}
}
}
Scaffold(
topBar = {
LargeTopAppBar(
@@ -248,12 +158,6 @@ fun AnimatedVisibilityScope.GalleryDetailScreen(args: GalleryDetailScreenArgs, n
},
scrollBehavior = scrollBehavior,
actions = {
IconButton(onClick = ::showArchiveDialog) {
Icon(
imageVector = Icons.Default.FolderZip,
contentDescription = null,
)
}
IconButton(
onClick = {
AppHelper.share(implicit<MainActivity>(), galleryDetailUrl)
@@ -344,7 +248,7 @@ fun AnimatedVisibilityScope.GalleryDetailScreen(args: GalleryDetailScreenArgs, n
onClick = {
dropdown = false
launchIO {
val downloadInfo = EhDownloadManager.getDownloadInfo(gid)
val downloadInfo = DownloadManager.getDownloadInfo(gid)
val canExport = downloadInfo?.state == DownloadInfo.STATE_FINISH
if (!canExport) {
awaitConfirmationOrCancel(
+1
View File
@@ -286,6 +286,7 @@
<string name="just_now">Gerade</string>
<string name="yesterday">Gestern</string>
<string name="some_days_ago">Vor %d Tagen</string>
<string name="archive">Archivdateien</string>
<string name="no_archives">Keine Archivdatei</string>
<string name="download_archive_started">Archivdatei wird heruntergeladen</string>
<string name="download_archive_failure">Fehler beim Herunterladen der Archivdatei</string>
+1
View File
@@ -341,6 +341,7 @@
<string name="just_now">Ahora</string>
<string name="yesterday">Ayer</string>
<string name="some_days_ago">Hace %d días atrás</string>
<string name="archive">Archivo</string>
<string name="no_archives">Sin archivos</string>
<string name="download_archive_started">Descarga de archivos iniciada</string>
<string name="download_archive_failure">Error al descargar archivo</string>
+1
View File
@@ -381,6 +381,7 @@
<string name="just_now">En ce moment</string>
<string name="yesterday">Hier</string>
<string name="some_days_ago">Il y a %d jours</string>
<string name="archive">Fiches archives</string>
<string name="no_archives">Aucun fiche archives</string>
<string name="download_archive_started">Téléchargement du fiche archives a commencé</string>
<string name="download_archive_failure">Téléchargement du fiche archives a échoué</string>
+1
View File
@@ -420,6 +420,7 @@
<string name="just_now">たった今</string>
<string name="yesterday">昨日</string>
<string name="some_days_ago">%d 日前</string>
<string name="archive">圧縮パッケージ</string>
<string name="no_archives">アーカイブなし</string>
<string name="download_archive_started">アーカイブのダウンロードを開始しました</string>
<string name="download_archive_failure">アーカイブをダウンロードできませんでした</string>
+1
View File
@@ -354,6 +354,7 @@
<string name="just_now">방금</string>
<string name="yesterday">어제</string>
<string name="some_days_ago">%d일 전</string>
<string name="archive">아카이브</string>
<string name="no_archives">아카이브 없음</string>
<string name="download_archive_started">아카이브 다운로드가 시작되었습니다.</string>
<string name="download_archive_failure">아카이브 다운로드에 실패했습니다.</string>
+1
View File
@@ -369,6 +369,7 @@
<string name="just_now">เดี๋ยวนี้</string>
<string name="yesterday">เมื่อวาน</string>
<string name="some_days_ago">%d วันที่ผ่านมา</string>
<string name="archive">การบีบอัด</string>
<string name="no_archives">ยังไม่มีไฟล์บีบอัด</string>
<string name="download_archive_started">เริ่มการดาวน์โหลดบีบอัด</string>
<string name="download_archive_failure">การดาวน์โหลดไฟล์บีบอัดล้มเหลว</string>
+4 -3
View File
@@ -414,12 +414,13 @@
<string name="just_now">刚刚</string>
<string name="yesterday">昨天</string>
<string name="some_days_ago">%d 天前</string>
<string name="no_archives">没有压缩包</string>
<string name="download_archive_started">开始下载压缩包</string>
<string name="download_archive_failure">无法下载压缩包</string>
<string name="archive">压缩包</string>
<string name="archive_free">免费</string>
<string name="archive_original">原始</string>
<string name="archive_resample">重采样</string>
<string name="no_archives">没有压缩包</string>
<string name="download_archive_started">开始下载压缩包</string>
<string name="download_archive_failure">无法下载压缩包</string>
<string name="download_archive_failure_no_hath">下载压缩包需要 H@H 客户端</string>
<string name="current_funds">当前资金:</string>
<string name="insufficient_funds">余额不足</string>
@@ -405,6 +405,7 @@
<string name="just_now">剛剛</string>
<string name="yesterday">昨天</string>
<string name="some_days_ago">%d 天前</string>
<string name="archive">壓縮包</string>
<string name="no_archives">沒有壓縮包</string>
<string name="download_archive_started">開始下載壓縮包</string>
<string name="download_archive_failure">無法下載壓縮包</string>
+4 -3
View File
@@ -410,12 +410,13 @@
<string name="just_now">剛剛</string>
<string name="yesterday">昨天</string>
<string name="some_days_ago">%d 天前</string>
<string name="no_archives">沒有壓縮檔</string>
<string name="download_archive_started">開始下載壓縮檔</string>
<string name="download_archive_failure">下載失敗</string>
<string name="archive">壓縮檔</string>
<string name="archive_free">免費</string>
<string name="archive_original">原始</string>
<string name="archive_resample">重新採樣</string>
<string name="no_archives">沒有壓縮檔</string>
<string name="download_archive_started">開始下載壓縮檔</string>
<string name="download_archive_failure">下載失敗</string>
<string name="download_archive_failure_no_hath">下載壓縮檔需要 H@H 客戶端</string>
<string name="current_funds">目前資金:</string>
<string name="insufficient_funds">餘額不足</string>
+4 -3
View File
@@ -435,12 +435,13 @@
<string name="just_now">Just now</string>
<string name="yesterday">Yesterday</string>
<string name="some_days_ago">%d days ago</string>
<string name="no_archives">No Archives</string>
<string name="download_archive_started">Archive download started</string>
<string name="download_archive_failure">Failed to download archive</string>
<string name="archive">Archive</string>
<string name="archive_free">Free</string>
<string name="archive_original">Original</string>
<string name="archive_resample">Resample</string>
<string name="no_archives">No Archives</string>
<string name="download_archive_started">Archive download started</string>
<string name="download_archive_failure">Failed to download archive</string>
<string name="download_archive_failure_no_hath">Need H@H client for archive download</string>
<string name="current_funds">Current Funds:</string>
<string name="insufficient_funds">Insufficient Funds</string>