Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SourceBackup(
@SerialName("added_in") val addedIn: Int,
@SerialName("pinned") val isPinned: Boolean = false,
@SerialName("enabled") val isEnabled: Boolean = true, // for compatibility purposes, should be only true
@SerialName("title") val title: String? = null,
) {

constructor(entity: MangaSourceEntity) : this(
Expand All @@ -21,6 +22,7 @@ class SourceBackup(
addedIn = entity.addedIn,
isPinned = entity.isPinned,
isEnabled = entity.isEnabled,
title = entity.title,
)

fun toEntity() = MangaSourceEntity(
Expand All @@ -31,5 +33,6 @@ class SourceBackup(
lastUsedAt = lastUsedAt,
isPinned = isPinned,
cfState = 0,
title = title,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.github.landwarderer.futon.core.db.migrations.Migration24To25
import io.github.landwarderer.futon.core.db.migrations.Migration25To26
import io.github.landwarderer.futon.core.db.migrations.Migration26To27
import io.github.landwarderer.futon.core.db.migrations.Migration27To28
import io.github.landwarderer.futon.core.db.migrations.Migration28To29
import io.github.landwarderer.futon.core.db.migrations.Migration2To3
import io.github.landwarderer.futon.core.db.migrations.Migration3To4
import io.github.landwarderer.futon.core.db.migrations.Migration4To5
Expand Down Expand Up @@ -73,7 +74,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch

const val DATABASE_VERSION = 28
const val DATABASE_VERSION = 29

@Database(
entities = [
Expand Down Expand Up @@ -148,6 +149,7 @@ fun getDatabaseMigrations(context: Context): Array<Migration> = arrayOf(
Migration25To26(),
Migration26To27(),
Migration27To28(),
Migration28To29(),
)

fun MangaDatabase(context: Context): MangaDatabase = Room
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,28 @@ abstract class MangaSourcesDao {
@Query("UPDATE sources SET used_at = :value WHERE source = :source")
abstract suspend fun setLastUsed(source: String, value: Long)

@Query("UPDATE sources SET title = :title WHERE source = :source")
abstract suspend fun setTitle(source: String, title: String?)

@Transaction
open suspend fun setPinned(source: String, isPinned: Boolean) {
if (updateIsPinned(source, isPinned) == 0) {
val entity = MangaSourceEntity(
source = source,
isEnabled = false,
sortKey = getMaxSortKey() + 1,
addedIn = BuildConfig.VERSION_CODE,
lastUsedAt = 0,
isPinned = isPinned,
cfState = CloudFlareHelper.PROTECTION_NOT_DETECTED,
title = null,
)
upsert(entity)
}
}

@Query("UPDATE sources SET pinned = :isPinned WHERE source = :source")
abstract suspend fun setPinned(source: String, isPinned: Boolean)
protected abstract suspend fun updateIsPinned(source: String, isPinned: Boolean): Int

@Query("UPDATE sources SET cf_state = :state WHERE source = :source")
abstract suspend fun setCfState(source: String, state: Int)
Expand Down Expand Up @@ -88,6 +108,7 @@ abstract class MangaSourcesDao {
lastUsedAt = 0,
isPinned = false,
cfState = CloudFlareHelper.PROTECTION_NOT_DETECTED,
title = null,
)
upsert(entity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ data class MangaSourceEntity(
@ColumnInfo(name = "used_at") val lastUsedAt: Long,
@ColumnInfo(name = "pinned") val isPinned: Boolean,
@ColumnInfo(name = "cf_state") val cfState: Int,
@ColumnInfo(name = "title") val title: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.landwarderer.futon.core.db.migrations

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

class Migration28To29 : Migration(28, 29) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE sources ADD COLUMN title TEXT")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import org.koitharu.kotatsu.parsers.model.MangaParserSource
import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.util.splitTwoParts
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap

private val MIHON_TITLES = ConcurrentHashMap<String, String>()

fun updateMihonTitle(name: String, title: String) {
MIHON_TITLES[name] = title
}

data object LocalMangaSource : MangaSource {
override val name = "LOCAL"
Expand All @@ -34,7 +41,7 @@ data object TestMangaSource : MangaSource {
override val name = "TEST"
}

fun MangaSource(name: String?): MangaSource {
fun MangaSource(name: String?, title: String? = null): MangaSource {
when (name ?: return UnknownMangaSource) {
UnknownMangaSource.name -> return UnknownMangaSource
LocalMangaSource.name -> return LocalMangaSource
Expand All @@ -45,17 +52,20 @@ fun MangaSource(name: String?): MangaSource {
return ExternalMangaSource(packageName = parts.first, authority = parts.second)
}
if (name.startsWith("mihon:") || name.startsWith("MIHON_")) {
return AnonymousMangaSource(name)
return AnonymousMangaSource(name, title)
}
MangaParserSource.entries.forEach {
if (it.name == name) return it
}
return UnknownMangaSource
}

private data class AnonymousMangaSource(override val name: String) : MangaSource
data class AnonymousMangaSource(
override val name: String,
val title: String? = null
) : MangaSource

fun Collection<String>.toMangaSources() = map(::MangaSource)
fun Collection<String>.toMangaSources() = map { MangaSource(it) }

fun MangaSource.isNsfw(): Boolean = when (val source = unwrap()) {
is MangaSourceInfo -> source.mangaSource.isNsfw()
Expand Down Expand Up @@ -127,7 +137,8 @@ fun MangaSource.getTitle(context: Context): String = when (val source = unwrap()
LocalMangaSource -> context.getString(R.string.local_storage)
TestMangaSource -> context.getString(R.string.test_parser)
is ExternalMangaSource -> source.resolveName(context)
is MihonMangaSource -> source.displayName
is MihonMangaSource -> source.displayName.also { updateMihonTitle(source.name, it) }
is AnonymousMangaSource -> MIHON_TITLES[source.name] ?: source.title ?: context.getString(R.string.unknown)
else -> context.getString(R.string.unknown)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class AppRouter private constructor(

/** Activities **/

fun openList(source: MangaSource, filter: MangaListFilter?, sortOrder: SortOrder?) {
startActivity(listIntent(contextOrNull() ?: return, source, filter, sortOrder))
fun openList(source: MangaSource, filter: MangaListFilter?, sortOrder: SortOrder?, sourceTitle: String? = null) {
startActivity(listIntent(contextOrNull() ?: return, source, filter, sortOrder, sourceTitle))
}

fun openList(tag: MangaTag) = openList(tag.source, MangaListFilter(tags = setOf(tag)), null)
Expand All @@ -142,8 +142,8 @@ class AppRouter private constructor(

fun openSearch(source: MangaSource, query: String) = openList(source, MangaListFilter(query = query), null)

fun openDetails(manga: Manga) {
startActivity(detailsIntent(contextOrNull() ?: return, manga))
fun openDetails(manga: Manga, sourceTitle: String? = null) {
startActivity(detailsIntent(contextOrNull() ?: return, manga, sourceTitle))
}

fun openDetails(mangaId: Long) {
Expand Down Expand Up @@ -696,18 +696,20 @@ class AppRouter private constructor(
(view.context.findActivity() as? FragmentActivity)?.let(::AppRouter)
}

fun detailsIntent(context: Context, manga: Manga) = Intent(context, DetailsActivity::class.java)
fun detailsIntent(context: Context, manga: Manga, sourceTitle: String? = null) = Intent(context, DetailsActivity::class.java)
.putExtra(KEY_MANGA, ParcelableManga(manga))
.putExtra(KEY_SOURCE_TITLE, sourceTitle)
.setData(shortMangaUrl(manga.id))

fun detailsIntent(context: Context, mangaId: Long) = Intent(context, DetailsActivity::class.java)
.putExtra(KEY_ID, mangaId)
.setData(shortMangaUrl(mangaId))

fun listIntent(context: Context, source: MangaSource, filter: MangaListFilter?, sortOrder: SortOrder?): Intent =
fun listIntent(context: Context, source: MangaSource, filter: MangaListFilter?, sortOrder: SortOrder?, sourceTitle: String? = null): Intent =
Intent(context, MangaListActivity::class.java)
.setAction(ACTION_MANGA_EXPLORE)
.putExtra(KEY_SOURCE, source.name)
.putExtra(KEY_SOURCE_TITLE, sourceTitle)
.apply {
if (!filter.isNullOrEmpty()) {
putExtra(KEY_FILTER, ParcelableMangaListFilter(filter))
Expand Down Expand Up @@ -832,6 +834,7 @@ class AppRouter private constructor(
const val KEY_READER_MODE = "reader_mode"
const val KEY_SORT_ORDER = "sort_order"
const val KEY_SOURCE = "source"
const val KEY_SOURCE_TITLE = "source_title"
const val KEY_TAB = "tab"
const val KEY_TITLE = "title"
const val KEY_URL = "url"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.SavedStateHandle
import io.github.landwarderer.futon.core.model.parcelable.ParcelableManga
import io.github.landwarderer.futon.core.nav.AppRouter.Companion.KEY_ID
import io.github.landwarderer.futon.core.nav.AppRouter.Companion.KEY_MANGA
import io.github.landwarderer.futon.core.nav.AppRouter.Companion.KEY_SOURCE_TITLE
import io.github.landwarderer.futon.core.util.ext.getParcelableCompat
import io.github.landwarderer.futon.core.util.ext.getParcelableExtraCompat
import org.koitharu.kotatsu.parsers.model.Manga
Expand All @@ -15,24 +16,28 @@ class MangaIntent private constructor(
@JvmField val manga: Manga?,
@JvmField val id: Long,
@JvmField val uri: Uri?,
@JvmField val sourceTitle: String?,
) {

constructor(intent: Intent?) : this(
manga = intent?.getParcelableExtraCompat<ParcelableManga>(KEY_MANGA)?.manga,
id = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
uri = intent?.data,
sourceTitle = intent?.getStringExtra(KEY_SOURCE_TITLE),
)

constructor(savedStateHandle: SavedStateHandle) : this(
manga = savedStateHandle.get<ParcelableManga>(KEY_MANGA)?.manga,
id = savedStateHandle[KEY_ID] ?: ID_NONE,
uri = savedStateHandle[AppRouter.KEY_DATA],
sourceTitle = savedStateHandle[KEY_SOURCE_TITLE],
)

constructor(args: Bundle?) : this(
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
id = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
uri = null,
sourceTitle = args?.getString(KEY_SOURCE_TITLE),
)

val mangaId: Long
Expand All @@ -42,6 +47,6 @@ class MangaIntent private constructor(

const val ID_NONE = 0L

fun of(manga: Manga) = MangaIntent(manga, manga.id, null)
fun of(manga: Manga) = MangaIntent(manga, manga.id, null, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class DetailsActivity :
ListItemType.MANGA_GRID,
mangaGridItemAD(
sizeResolver = StaticItemSizeResolver(resources.getDimensionPixelSize(R.dimen.smaller_grid_width)),
) { item, view ->
) { item, _ ->
router.openDetails(item.toMangaWithOverride())
},
).also { rv.adapter = it }
Expand Down Expand Up @@ -460,7 +460,12 @@ class DetailsActivity :
textViewSource.isVisible = false
textViewSourceLabel.isVisible = false
} else {
textViewSource.textAndVisible = manga.source.getTitle(this@DetailsActivity)
val sourceTitle = manga.source.getTitle(this@DetailsActivity)
textViewSource.textAndVisible = if (sourceTitle == getString(R.string.unknown)) {
viewModel.sourceTitle ?: sourceTitle
} else {
sourceTitle
}
textViewSource.setTooltipCompat(manga.source.getSummary(this@DetailsActivity))
textViewSourceLabel.isVisible = textViewSource.isVisible == true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class DetailsViewModel @Inject constructor(
private val intent = MangaIntent(savedStateHandle)
private var loadingJob: Job
val mangaId = intent.mangaId
val sourceTitle = intent.sourceTitle
private val scrobblers: Set<@JvmSuppressWildcards Scrobbler> by lazy { scrobblersProvider.get() }

init {
Expand Down
Loading
Loading