parent
							
								
									36f5609434
								
							
						
					
					
						commit
						019f12b61d
					
				
							
								
								
									
										18
									
								
								src/all/hitomi/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/all/hitomi/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <application>
 | 
			
		||||
        <activity
 | 
			
		||||
            android:name=".HitomiActivity"
 | 
			
		||||
            android:theme="@android:style/Theme.NoDisplay"
 | 
			
		||||
            android:excludeFromRecents="true">
 | 
			
		||||
            <intent-filter>
 | 
			
		||||
                <action android:name="android.intent.action.VIEW" />
 | 
			
		||||
                <category android:name="android.intent.category.DEFAULT" />
 | 
			
		||||
                <category android:name="android.intent.category.BROWSABLE" />
 | 
			
		||||
                <data android:scheme="https"
 | 
			
		||||
                      android:host="hitomi.la"
 | 
			
		||||
                      android:pathPattern="/cg/..*"/>
 | 
			
		||||
            </intent-filter>
 | 
			
		||||
        </activity>
 | 
			
		||||
    </application>
 | 
			
		||||
</manifest>
 | 
			
		||||
@ -5,7 +5,7 @@ ext {
 | 
			
		||||
    extName = 'Hitomi.la'
 | 
			
		||||
    pkgNameSuffix = 'all.hitomi'
 | 
			
		||||
    extClass = '.HitomiFactory'
 | 
			
		||||
    extVersionCode = 2
 | 
			
		||||
    extVersionCode = 3
 | 
			
		||||
    libVersion = '1.2'
 | 
			
		||||
    containsNsfw = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -157,46 +157,52 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
 | 
			
		||||
        val splitQuery = query.split(" ")
 | 
			
		||||
 | 
			
		||||
        val positive = splitQuery.filter { !it.startsWith('-') }.toMutableList()
 | 
			
		||||
        if (nozomiLang != "all") positive += "language:$nozomiLang"
 | 
			
		||||
        val negative = (splitQuery - positive).map { it.removePrefix("-") }
 | 
			
		||||
 | 
			
		||||
        // TODO Cache the results coming out of HitomiNozomi (this TODO dates back to TachiyomiEH)
 | 
			
		||||
        val hn = Single.zip(tagIndexVersion(), galleryIndexVersion()) { tv, gv -> tv to gv }
 | 
			
		||||
            .map { HitomiNozomi(client, it.first, it.second) }
 | 
			
		||||
 | 
			
		||||
        var base = if (positive.isEmpty()) {
 | 
			
		||||
            hn.flatMap { n -> n.getGalleryIdsFromNozomi(null, "index", "all").map { n to it.toSet() } }
 | 
			
		||||
        return if (query.startsWith(PREFIX_ID_SEARCH)) {
 | 
			
		||||
            val id = query.removePrefix(PREFIX_ID_SEARCH)
 | 
			
		||||
            client.newCall(GET("$baseUrl/cg/$id", headers)).asObservableSuccess()
 | 
			
		||||
                .map { MangasPage(listOf(mangaDetailsParse(it).apply { url = "/cg/$id" }), false) }
 | 
			
		||||
        } else {
 | 
			
		||||
            val q = positive.removeAt(0)
 | 
			
		||||
            hn.flatMap { n -> n.getGalleryIdsForQuery(q).map { n to it.toSet() } }
 | 
			
		||||
        }
 | 
			
		||||
            val splitQuery = query.split(" ")
 | 
			
		||||
 | 
			
		||||
        base = positive.fold(base) { acc, q ->
 | 
			
		||||
            acc.flatMap { (nozomi, mangas) ->
 | 
			
		||||
                nozomi.getGalleryIdsForQuery(q).map {
 | 
			
		||||
                    nozomi to mangas.intersect(it)
 | 
			
		||||
            val positive = splitQuery.filter { !it.startsWith('-') }.toMutableList()
 | 
			
		||||
            if (nozomiLang != "all") positive += "language:$nozomiLang"
 | 
			
		||||
            val negative = (splitQuery - positive).map { it.removePrefix("-") }
 | 
			
		||||
 | 
			
		||||
            // TODO Cache the results coming out of HitomiNozomi (this TODO dates back to TachiyomiEH)
 | 
			
		||||
            val hn = Single.zip(tagIndexVersion(), galleryIndexVersion()) { tv, gv -> tv to gv }
 | 
			
		||||
                .map { HitomiNozomi(client, it.first, it.second) }
 | 
			
		||||
 | 
			
		||||
            var base = if (positive.isEmpty()) {
 | 
			
		||||
                hn.flatMap { n -> n.getGalleryIdsFromNozomi(null, "index", "all").map { n to it.toSet() } }
 | 
			
		||||
            } else {
 | 
			
		||||
                val q = positive.removeAt(0)
 | 
			
		||||
                hn.flatMap { n -> n.getGalleryIdsForQuery(q).map { n to it.toSet() } }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            base = positive.fold(base) { acc, q ->
 | 
			
		||||
                acc.flatMap { (nozomi, mangas) ->
 | 
			
		||||
                    nozomi.getGalleryIdsForQuery(q).map {
 | 
			
		||||
                        nozomi to mangas.intersect(it)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        base = negative.fold(base) { acc, q ->
 | 
			
		||||
            acc.flatMap { (nozomi, mangas) ->
 | 
			
		||||
                nozomi.getGalleryIdsForQuery(q).map {
 | 
			
		||||
                    nozomi to (mangas - it)
 | 
			
		||||
            base = negative.fold(base) { acc, q ->
 | 
			
		||||
                acc.flatMap { (nozomi, mangas) ->
 | 
			
		||||
                    nozomi.getGalleryIdsForQuery(q).map {
 | 
			
		||||
                        nozomi to (mangas - it)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            base.flatMap { (_, ids) ->
 | 
			
		||||
                val chunks = ids.chunked(PAGE_SIZE)
 | 
			
		||||
 | 
			
		||||
                nozomiIdsToMangas(chunks[page - 1]).map { mangas ->
 | 
			
		||||
                    MangasPage(mangas, page < chunks.size)
 | 
			
		||||
                }
 | 
			
		||||
            }.toObservable()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return base.flatMap { (_, ids) ->
 | 
			
		||||
            val chunks = ids.chunked(PAGE_SIZE)
 | 
			
		||||
 | 
			
		||||
            nozomiIdsToMangas(chunks[page - 1]).map { mangas ->
 | 
			
		||||
                MangasPage(mangas, page < chunks.size)
 | 
			
		||||
            }
 | 
			
		||||
        }.toObservable()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = throw UnsupportedOperationException("Not used")
 | 
			
		||||
@ -307,6 +313,8 @@ open class Hitomi(override val lang: String, private val nozomiLang: String) : H
 | 
			
		||||
        private const val INDEX_VERSION_CACHE_TIME_MS = 1000 * 60 * 10
 | 
			
		||||
        private const val PAGE_SIZE = 25
 | 
			
		||||
 | 
			
		||||
        const val PREFIX_ID_SEARCH = "id:"
 | 
			
		||||
 | 
			
		||||
        // From HitomiSearchMetaData
 | 
			
		||||
        const val LTN_BASE_URL = "https://ltn.hitomi.la"
 | 
			
		||||
        const val BASE_URL = "https://hitomi.la"
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,38 @@
 | 
			
		||||
package eu.kanade.tachiyomi.extension.all.hitomi
 | 
			
		||||
 | 
			
		||||
import android.app.Activity
 | 
			
		||||
import android.content.ActivityNotFoundException
 | 
			
		||||
import android.content.Intent
 | 
			
		||||
import android.os.Bundle
 | 
			
		||||
import android.util.Log
 | 
			
		||||
import kotlin.system.exitProcess
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Springboard that accepts https://hitomi.la/cg/xxxx intents
 | 
			
		||||
 * and redirects them to the main Tachiyomi process.
 | 
			
		||||
 */
 | 
			
		||||
class HitomiActivity : Activity() {
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
        val pathSegments = intent?.data?.pathSegments
 | 
			
		||||
        if (pathSegments != null && pathSegments.size > 1) {
 | 
			
		||||
            val id = pathSegments[1]
 | 
			
		||||
            val mainIntent = Intent().apply {
 | 
			
		||||
                action = "eu.kanade.tachiyomi.SEARCH"
 | 
			
		||||
                putExtra("query", "${Hitomi.PREFIX_ID_SEARCH}$id")
 | 
			
		||||
                putExtra("filter", packageName)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                startActivity(mainIntent)
 | 
			
		||||
            } catch (e: ActivityNotFoundException) {
 | 
			
		||||
                Log.e("HitomiActivity", e.toString())
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            Log.e("HitomiActivity", "Could not parse URI from intent $intent")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        finish()
 | 
			
		||||
        exitProcess(0)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user