Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Sep 9, 2024
2 parents 625037e + 00b7480 commit 88a2f8a
Show file tree
Hide file tree
Showing 46 changed files with 446 additions and 205 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
minSdkVersion 23
targetSdkVersion 34
versionCode 130 // is updated automatically by BitRise; only used when building locally
versionName '1.19.10'
versionName '1.19.11'

def includeObjectBoxBrowser = System.getenv("INCLUDE_OBJECTBOX_BROWSER") ?: "false"
def includeLeakCanary = System.getenv("INCLUDE_LEAK_CANARY") ?: "false"
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/assets/downloaded.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,29 @@
background-repeat: no-repeat;
z-index:auto;
pointer-events: none;
}

/* Custom styles to mark queued books*/
.watermarked-queued {

}

.watermarked-queued img {
filter: grayscale(100%) opacity(25%);
}

.watermarked-queued:after {
content: "";
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
background-image: url("https://bogus.com/hentoid-queuedmark.webp");
background-size: 75px 75px;
background-position: 50% 50%;
background-repeat: no-repeat;
z-index:auto;
pointer-events: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
// List of URLs of merged books for the current site
private val mergedBooksUrls: MutableList<String> = ArrayList()

// List of URLs of queued books for the current site
private val queuedBooksUrls: MutableList<String> = ArrayList()

// List of tags of Preference-browser-blocked tags
private var m_prefBlockedTags: MutableList<String> = ArrayList()

Expand Down Expand Up @@ -241,6 +244,7 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
Preferences.registerPrefsChangedListener(listener)
if (Preferences.isBrowserMarkDownloaded()) updateDownloadedBooksUrls()
if (Preferences.isBrowserMarkMerged()) updateMergedBooksUrls()
if (Preferences.isBrowserMarkQueued()) updateQueuedBooksUrls()
if (Preferences.isBrowserMarkBlockedTags()) updatePrefBlockedTags()
Timber.d("Loading site: %s", getStartSite())

Expand Down Expand Up @@ -1175,6 +1179,7 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
)
if (Preferences.isQueueAutostart()) resumeQueue(this)
setActionMode(ActionMode.VIEW_QUEUE)
if (webClient.isMarkQueued()) updateQueuedBooksUrls()
}

/**
Expand Down Expand Up @@ -1502,6 +1507,10 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
}
}

private fun clearDownloadedBooksUrls() {
downloadedBooksUrls.clear()
}

private fun updateMergedBooksUrls() {
synchronized(mergedBooksUrls) {
mergedBooksUrls.clear()
Expand All @@ -1521,6 +1530,25 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
}
}

private fun clearMergedBooksUrls() {
mergedBooksUrls.clear()
}

private fun updateQueuedBooksUrls() {
synchronized(queuedBooksUrls) {
queuedBooksUrls.clear()
queuedBooksUrls.addAll(
dao.selectQueueUrls(getStartSite())
.map { url -> simplifyUrl(url) }
.filterNot { obj: String -> obj.isEmpty() }
)
}
}

private fun clearQueueBooksUrls() {
queuedBooksUrls.clear()
}

private fun updatePrefBlockedTags() {
m_prefBlockedTags.clear()
m_prefBlockedTags.addAll(Settings.blockedTags)
Expand All @@ -1540,6 +1568,7 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
fun onDownloadEvent(event: DownloadEvent) {
if (event.eventType === DownloadEvent.Type.EV_COMPLETE) {
if (webClient.isMarkDownloaded()) updateDownloadedBooksUrls()
if (webClient.isMarkQueued()) updateQueuedBooksUrls()
if (event.content != null && event.content == currentContent && event.content!!.status == StatusContent.DOWNLOADED) {
setActionMode(ActionMode.READ)
}
Expand Down Expand Up @@ -1629,6 +1658,8 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
get() = downloadedBooksUrls.toMutableList() // Work on a copy to avoid any thread-synch issue
override val allMergedBooksUrls: List<String>
get() = mergedBooksUrls.toMutableList()
override val allQueuedBooksUrls: List<String>
get() = queuedBooksUrls.toMutableList()
override val prefBlockedTags: List<String>
get() = m_prefBlockedTags.toMutableList()
override val customCss: String
Expand All @@ -1641,7 +1672,7 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
private fun computeCustomCss(): String {
if (null == m_customCss) {
val sb = StringBuilder()
if (Preferences.isBrowserMarkDownloaded() || Preferences.isBrowserMarkMerged() || Preferences.isBrowserMarkBlockedTags()) getAssetAsString(
if (Preferences.isBrowserMarkDownloaded() || Preferences.isBrowserMarkMerged() || Preferences.isBrowserMarkQueued() || Preferences.isBrowserMarkBlockedTags()) getAssetAsString(
assets, "downloaded.css", sb
)
if (getStartSite() == Site.NHENTAI && Preferences.isBrowserNhentaiInvisibleBlacklist()) getAssetAsString(
Expand Down Expand Up @@ -1676,12 +1707,17 @@ abstract class BaseWebActivity : BaseActivity(), CustomWebViewClient.CustomWebAc
} else if (Preferences.Key.BROWSER_MARK_DOWNLOADED == key) {
m_customCss = null
webClient.setMarkDownloaded(Preferences.isBrowserMarkDownloaded())
if (webClient.isMarkDownloaded()) updateDownloadedBooksUrls()
if (webClient.isMarkDownloaded()) updateDownloadedBooksUrls() else clearDownloadedBooksUrls()
reload = true
} else if (Preferences.Key.BROWSER_MARK_MERGED == key) {
m_customCss = null
webClient.setMarkMerged(Preferences.isBrowserMarkMerged())
if (webClient.isMarkMerged()) updateMergedBooksUrls()
if (webClient.isMarkMerged()) updateMergedBooksUrls() else clearMergedBooksUrls()
reload = true
} else if (Preferences.Key.BROWSER_MARK_QUEUED == key) {
m_customCss = null
webClient.setMarkQueued(Preferences.isBrowserMarkQueued())
if (webClient.isMarkQueued()) updateQueuedBooksUrls() else clearQueueBooksUrls()
reload = true
} else if (Preferences.Key.BROWSER_MARK_BLOCKED == key) {
m_customCss = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ open class CustomWebViewClient : WebViewClient {
// Faster access to Preferences settings
private val markDownloaded = AtomicBoolean(Preferences.isBrowserMarkDownloaded())
private val markMerged = AtomicBoolean(Preferences.isBrowserMarkMerged())
private val markQueued = AtomicBoolean(Preferences.isBrowserMarkQueued())
private val markBlockedTags = AtomicBoolean(Preferences.isBrowserMarkBlockedTags())
private val dnsOverHttpsEnabled = AtomicBoolean(Preferences.getDnsOverHttps() > -1)

Expand Down Expand Up @@ -167,6 +168,15 @@ open class CustomWebViewClient : WebViewClient {
)
)

// this is for queued books
val QUEUED_MARK = bitmapToWebp(
tintBitmap(
getBitmapFromVectorDrawable(
HentoidApp.getInstance(), R.drawable.ic_action_queue
), ContextCompat.getColor(HentoidApp.getInstance(), R.color.secondary_light)
)
)

// this is for books with blocked tags;
val BLOCKED_MARK = bitmapToWebp(
tintBitmap(
Expand Down Expand Up @@ -495,6 +505,10 @@ open class CustomWebViewClient : WebViewClient {
WebResourceResponse(
MIME_IMAGE_WEBP, "utf-8", ByteArrayInputStream(MERGED_MARK)
)
} else if (isMarkQueued() && url.contains("hentoid-queuedmark")) {
WebResourceResponse(
MIME_IMAGE_WEBP, "utf-8", ByteArrayInputStream(QUEUED_MARK)
)
} else if (url.contains("hentoid-blockedmark")) {
WebResourceResponse(
MIME_IMAGE_WEBP, "utf-8", ByteArrayInputStream(BLOCKED_MARK)
Expand All @@ -511,7 +525,7 @@ open class CustomWebViewClient : WebViewClient {
// If we're here to remove removable elements or mark downloaded books, we only do it
// on HTML resources (URLs without extension) from the source's main domain
if ((removableElements.isNotEmpty() || jsContentBlacklist.isNotEmpty()
|| isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags()
|| isMarkDownloaded() || isMarkMerged() || isMarkQueued() || isMarkBlockedTags()
|| activity != null && activity.customCss.isNotEmpty())
&& (getExtensionFromUri(url).isEmpty()
|| getExtensionFromUri(url).equals("html", ignoreCase = true))
Expand Down Expand Up @@ -675,7 +689,7 @@ open class CustomWebViewClient : WebViewClient {
// Remove removable elements from HTML resources
activity?.let {
val customCss = it.customCss
if (removableElements.isNotEmpty() || jsContentBlacklist.isNotEmpty() || isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags() || customCss.isNotEmpty()) {
if (removableElements.isNotEmpty() || jsContentBlacklist.isNotEmpty() || isMarkDownloaded() || isMarkMerged() || isMarkQueued() || isMarkBlockedTags() || customCss.isNotEmpty()) {
browserStream = processHtml(
browserStream,
url,
Expand All @@ -684,6 +698,7 @@ open class CustomWebViewClient : WebViewClient {
jsContentBlacklist,
it.allSiteUrls,
it.allMergedBooksUrls,
it.allQueuedBooksUrls,
it.prefBlockedTags
)
}
Expand Down Expand Up @@ -789,6 +804,14 @@ open class CustomWebViewClient : WebViewClient {
markMerged.set(value)
}

fun isMarkQueued(): Boolean {
return markQueued.get()
}

fun setMarkQueued(value: Boolean) {
markQueued.set(value)
}

fun isMarkBlockedTags(): Boolean {
return markBlockedTags.get()
}
Expand All @@ -812,6 +835,7 @@ open class CustomWebViewClient : WebViewClient {
* @param jsContentBlacklist Blacklisted elements to detect script tags to remove
* @param siteUrls Urls of the covers or links to visually mark as downloaded
* @param mergedSiteUrls Urls of the covers or links to visually mark as merged
* @param queuedSiteUrls Urls of the covers or links to visually mark as queued
* @param blockedTags Tags of the preference-browser-blocked tag option to visually mark as blocked
* @return Stream containing the HTML document stripped from the elements to remove
*/
Expand All @@ -824,6 +848,7 @@ open class CustomWebViewClient : WebViewClient {
jsContentBlacklist: List<String>?,
siteUrls: List<String>?,
mergedSiteUrls: List<String>?,
queuedSiteUrls: List<String>?,
blockedTags: List<String>?
): InputStream {
val doc = Jsoup.parse(stream, null, baseUri)
Expand Down Expand Up @@ -858,8 +883,8 @@ open class CustomWebViewClient : WebViewClient {
}
}

// Mark downloaded books and merged books
if (siteUrls != null && mergedSiteUrls != null && (siteUrls.isNotEmpty() || mergedSiteUrls.isNotEmpty())) {
// Mark downloaded books, merged books and queued books
if (siteUrls != null && mergedSiteUrls != null && queuedSiteUrls != null && (siteUrls.isNotEmpty() || mergedSiteUrls.isNotEmpty() || queuedSiteUrls.isNotEmpty())) {
// Format elements
val plainLinks = doc.select("a")
val linkedImages = doc.select("a img")
Expand Down Expand Up @@ -927,6 +952,22 @@ open class CustomWebViewClient : WebViewClient {
break
}
}
for (url in queuedSiteUrls) {
if (key.endsWith(url)) {
// Linked images have priority over plain links
var markedElement = value.second
if (markedElement != null) { // Mark <site.bookCardDepth> levels above the image
var imgParent = markedElement.parent()
for (i in 0 until site.bookCardDepth - 1) if (imgParent != null) imgParent =
imgParent!!.parent()
if (imgParent != null) markedElement = imgParent
} else { // Mark plain link
markedElement = value.first
}
markedElement!!.addClass("watermarked-queued")
break
}
}
}
}

Expand Down Expand Up @@ -1026,6 +1067,7 @@ open class CustomWebViewClient : WebViewClient {
val allSiteUrls: List<String>

val allMergedBooksUrls: List<String>
val allQueuedBooksUrls: List<String>
val prefBlockedTags: List<String>
val customCss: String
val scope: CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EHentaiActivity : BaseWebActivity() {
}
}
}
return if (isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags())
return if (isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags() || isMarkQueued())
super.parseResponse(
url,
requestHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ExHentaiActivity : BaseWebActivity() {
}
}
}
return if (isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags())
return if (isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags() || isMarkQueued())
super.parseResponse(
url,
requestHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HitomiActivity : BaseWebActivity() {
request: WebResourceRequest
): WebResourceResponse? {
val url = request.url.toString()
if ((isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags()) && url.contains("galleryblock")) { // Process book blocks to mark existing ones
if ((isMarkDownloaded() || isMarkMerged() || isMarkBlockedTags() || isMarkQueued()) && url.contains("galleryblock")) { // Process book blocks to mark existing ones
val result = parseResponse(
url, request.requestHeaders,
analyzeForDownload = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package me.devsaki.hentoid.activities.sources

import me.devsaki.hentoid.enums.Site

const val PCX_GALLERY_PATTERN = "//www.porncomixonline.(com|net)/[\\w\\-]+/[%\\w\\-]+/$"
const val PCX_GALLERY_PATTERN = "//porncomix.online/[\\w\\-]+/[%\\w\\-]+/$"

private val DOMAIN_FILTER = arrayOf(
"porncomix.online",
"www.porncomixonline.net",
"www.porncomixonline.com",
"porncomicszone.net",
Expand All @@ -16,12 +17,12 @@ private val DOMAIN_FILTER = arrayOf(
)
private val GALLERY_FILTER = arrayOf(
PCX_GALLERY_PATTERN,
"//www.porncomixonline.(com|net)/(?!m-comic)([\\w\\-]+)/[\\w\\-]+/$",
"//www.porncomixonline.(com|net)/m-comic/[\\w\\-]+/[\\w\\-]+$",
"//www.porncomixonline.(com|net)/m-comic/[\\w\\-]+/[\\w\\-]+/$",
"//www.porncomixonline.(com|net)/xxxtoons/(?!page)[\\w\\-]+/[\\w\\-]+$",
"//www.porncomixonline.com/(?!m-comic)([\\w\\-]+)/[\\w\\-]+/$",
"//www.porncomixonline.com/m-comic/[\\w\\-]+/[\\w\\-]+$",
"//porncomix.online/(?!comic)([\\w\\-]+)/[\\w\\-]+/$",
"//porncomix.online/comic/[\\w\\-]+/[\\w\\-]+$",
"//porncomix.online/comic/[\\w\\-]+/[\\w\\-]+/$",
"//porncomix.online/xxxtoons/(?!page)[\\w\\-]+/[\\w\\-]+$",
"//porncomix.online/(?!comic)([\\w\\-]+)/[\\w\\-]+/$",
"//porncomix.online/comic/[\\w\\-]+/[\\w\\-]+$",
"//porncomicszone.net/[0-9]+/[\\w\\-]+/[0-9]+/$",
"//porncomixinfo.(com|net)/manga-comics/[\\w\\-]+/[\\w\\-]+/$",
"//porncomixinfo.(com|net)/chapter/[\\w\\-]+/[\\w\\-]+/$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ interface CollectionDAO {

fun selectQueueLive(query: String?, source: Site?): LiveData<List<QueueRecord>>

fun selectQueueUrls(site: Site): Set<String>

fun addContentToQueue(
content: Content,
sourceImageStatus: StatusContent?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ object DatabaseMaintenance {
}

private fun cleanContent(context: Context, emitter: (Float) -> Unit) {
val mdb = MaintenanceDAO()
try {
// Remove empty QueueRecords from the queue (still not sure how they appear in the first place)
Timber.i("Removing orphan Queue records : start")
val orphanIds = mdb.selectOrphanQueueRecordIds()
Timber.i("Removing orphan Queue records : %s items detected", orphanIds.size)
mdb.deleteQueueRecords(orphanIds)
Timber.i("Removing orphan Queue records : done")
} finally {
mdb.cleanup()
}

try {
// Set items that were being downloaded in previous session as paused
Timber.i("Updating queue status : start")
Expand Down Expand Up @@ -92,18 +104,6 @@ object DatabaseMaintenance {
} finally {
ObjectBoxDB.cleanup()
}

val mdb = MaintenanceDAO()
try {
// Remove empty QueueRecords from the queue (still not sure how they appear in the first place)
Timber.i("Removing orphan Queue records : start")
val orphanIds = mdb.selectOrphanQueueRecordIds()
Timber.i("Removing orphan Queue records : %s items detected", orphanIds.size)
mdb.deleteQueueRecords(orphanIds)
Timber.i("Removing orphan Queue records : done")
} finally {
mdb.cleanup()
}
}

private fun clearTempContent(context: Context, emitter: (Float) -> Unit) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/me/devsaki/hentoid/database/ObjectBoxDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ class ObjectBoxDAO : CollectionDAO {
return ObjectBoxDB.selectQueueRecordsQ().safeFind()
}

override fun selectQueueUrls(site: Site): Set<String> {
return ObjectBoxDB.selectQueueUrls(site)
}

override fun updateQueue(queue: List<QueueRecord>) {
ObjectBoxDB.updateQueue(queue)
}
Expand Down
Loading

0 comments on commit 88a2f8a

Please sign in to comment.