Skip to content

Conversation

choppeh
Copy link
Contributor

@choppeh choppeh commented Aug 16, 2025

Closes #10149

Checklist:

  • Updated extVersionCode value in build.gradle for individual extensions
  • Updated overrideVersionCode or baseVersionCode as needed for all multisrc extensions
  • Referenced all related issues in the PR body (e.g. "Closes #xyz")
  • Added the isNsfw = true flag in build.gradle when appropriate
  • Have not changed source names
  • Have explicitly kept the id if a source's name or language were changed
  • Have tested the modifications by compiling and running the extension through Android Studio
  • Have removed web_hi_res_512.png when adding a new extension

Comment on lines +145 to 163
private fun loadFromCache(): ResponseWrapper<List<MangaDto>>? {
val jsonValue = preferences.getString(STORAGE_PREF, null) ?: return null
val storage = jsonValue.parseAs<Storage>()
return storage.takeIf { !it.isExpired() }?.mangas
}

private fun upsetCookie(cookie: Cookie) {
preferences.edit()
.putString(COOKIE_STORAGE_PREF, json.encodeToString(cookie))
.apply()
private fun loadFromNetwork(): ResponseWrapper<List<MangaDto>> {
return client.newCall(GET("$apiUrl/dados"))
.execute()
.parseAs<ResponseWrapper<List<MangaDto>>>()
.also {
Storage().apply {
update(it)
preferences.edit()
.putString(STORAGE_PREF, json.encodeToString(this))
.apply()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow these steps to use a disk cache instead of persisting 10MB+ of data into SharedPreferences:

  1. Tweak this.client's interceptors:
    .apply {
    val index = networkInterceptors().indexOfFirst { it is BrotliInterceptor }
    if (index >= 0) interceptors().add(networkInterceptors().removeAt(index))
    }

    dependencies {
    compileOnly("com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.11")
    }
  2. private val dataClient = this.client.newBuilder() and add a separate cache. The data is currently 4.5MB gzipped, so you can set a 10MB limit.
    .cache(
    Cache(
    directory = File(Injekt.get<Application>().externalCacheDir, "network_cache_${name.lowercase()}"),
    maxSize = 50L * 1024 * 1024, // 50 MiB
    ),
    )
  3. This dataClient should also use addNetworkInterceptor to rewrite the response. Remove these headers: Cache-Control, Expires, Pragma.
  4. Finally, make the request with dataClient with the expiration period as you wish:
    val request = GET(
    "$baseUrl/$apiPath/creators",
    headers,
    CacheControl.Builder().maxStale(30, TimeUnit.MINUTES).build(),
    )
  5. Remember to enable logging in the app's advanced settings and verify the cache is working. Enter the browse page multiple times to see if only the first request is sent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make fields private wherever possible.

Comment on lines +131 to 139
private fun tryCompatibility(manga: SManga): SManga {
val substring = mangaSubStrings.first { manga.url.contains(it, ignoreCase = true) }
val slug = manga.url
.substringAfterLast("$substring/")
.substringBeforeLast("/")
return database.values.firstOrNull { it.slug == slug }
?.toSManga()
?: throw IOException("Migrate a obra para a $name")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code suggests the URL format has changed to using an ID. You should bump the versionId to force users to migrate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also preferred to clear the old preferences:

init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// Delete old preferences for "6漫画/zh/1"
Injekt.get<Application>().deleteSharedPreferences("source_7259486566651312186")
}
}

@stevenyomi stevenyomi marked this pull request as draft August 17, 2025 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manhastro Redesign (HTTP 405, NullPointerException)
2 participants