Kouhai Work: add URL intent (#10146)
This commit is contained in:
		
							parent
							
								
									10e2610636
								
							
						
					
					
						commit
						b62726e1a6
					
				@ -1,2 +1,19 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<manifest package="eu.kanade.tachiyomi.extension" />
 | 
			
		||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
          package="eu.kanade.tachiyomi.extension">
 | 
			
		||||
    <application>
 | 
			
		||||
        <activity android:name=".en.kouhaiwork.KouhaiActivity"
 | 
			
		||||
                  android:theme="@android:style/Theme.NoDisplay"
 | 
			
		||||
                  android:exported="true"
 | 
			
		||||
                  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:host="kouhai.work"
 | 
			
		||||
                      android:pathPattern="/series/..*"
 | 
			
		||||
                      android:scheme="https" />
 | 
			
		||||
            </intent-filter>
 | 
			
		||||
        </activity>
 | 
			
		||||
    </application>
 | 
			
		||||
</manifest>
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ ext {
 | 
			
		||||
    extName = 'Kouhai Work'
 | 
			
		||||
    pkgNameSuffix = 'en.kouhaiwork'
 | 
			
		||||
    extClass = '.KouhaiWork'
 | 
			
		||||
    extVersionCode = 4
 | 
			
		||||
    extVersionCode = 5
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
apply from: "$rootDir/common.gradle"
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,8 @@ import java.text.DecimalFormat
 | 
			
		||||
import java.text.SimpleDateFormat
 | 
			
		||||
import java.util.Locale
 | 
			
		||||
 | 
			
		||||
const val ID_QUERY = "id:"
 | 
			
		||||
 | 
			
		||||
const val API_URL = "https://api.kouhai.work/v3"
 | 
			
		||||
 | 
			
		||||
const val STORAGE_URL = "https://api.kouhai.work/storage/"
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,35 @@
 | 
			
		||||
package eu.kanade.tachiyomi.extension.en.kouhaiwork
 | 
			
		||||
 | 
			
		||||
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 `{baseUrl}/series/{id}`
 | 
			
		||||
 * intents and redirects them to the main Tachiyomi process.
 | 
			
		||||
 */
 | 
			
		||||
class KouhaiActivity : Activity() {
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
        val segments = intent?.data?.pathSegments
 | 
			
		||||
        if (segments != null && segments.size > 1) {
 | 
			
		||||
            val activity = Intent().apply {
 | 
			
		||||
                action = "eu.kanade.tachiyomi.SEARCH"
 | 
			
		||||
                putExtra("query", ID_QUERY + segments[1])
 | 
			
		||||
                putExtra("filter", packageName)
 | 
			
		||||
            }
 | 
			
		||||
            try {
 | 
			
		||||
                startActivity(activity)
 | 
			
		||||
            } catch (ex: ActivityNotFoundException) {
 | 
			
		||||
                Log.e("KouhaiActivity", ex.message, ex)
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            Log.e("KouhaiActivity", "Failed to parse URI from intent: $intent")
 | 
			
		||||
        }
 | 
			
		||||
        finish()
 | 
			
		||||
        exitProcess(0)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -64,6 +64,23 @@ class KouhaiWork : HttpSource() {
 | 
			
		||||
            }
 | 
			
		||||
        }.let { MangasPage(it, false) }
 | 
			
		||||
 | 
			
		||||
    override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
 | 
			
		||||
        if (!query.startsWith(ID_QUERY)) {
 | 
			
		||||
            super.fetchSearchManga(page, query, filters)
 | 
			
		||||
        } else {
 | 
			
		||||
            val id = query.substringAfter(ID_QUERY)
 | 
			
		||||
            val req = GET("$API_URL/manga/get/$id", headers)
 | 
			
		||||
            client.newCall(req).asObservableSuccess().map {
 | 
			
		||||
                val series = it.decode<KouhaiSeries>()
 | 
			
		||||
                val manga = SManga.create().apply {
 | 
			
		||||
                    url = series.url
 | 
			
		||||
                    title = series.title
 | 
			
		||||
                    thumbnail_url = series.thumbnail
 | 
			
		||||
                }
 | 
			
		||||
                MangasPage(listOf(manga), false)
 | 
			
		||||
            }!!
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    // Request the actual manga URL for the webview
 | 
			
		||||
    override fun mangaDetailsRequest(manga: SManga) =
 | 
			
		||||
        GET("$baseUrl/series/${manga.url}", headers)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user