From fe7bd2a7bb48721efd53c6421efd452cde8afdef Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 20 Mar 2020 01:52:03 -0400 Subject: [PATCH] Using extension icon instead of letter for catalogues --- .../tachiyomi/extension/ExtensionManager.kt | 9 +++++++++ .../java/eu/kanade/tachiyomi/source/Source.kt | 15 +++++++++++++++ .../kanade/tachiyomi/ui/catalogue/SourceHolder.kt | 7 +++++-- .../kanade/tachiyomi/ui/migration/SourceHolder.kt | 7 +++++-- .../manga/design/MigrationSourceHolder.kt | 7 +++++-- .../kanade/tachiyomi/util/view/ViewExtensions.kt | 15 ++++++++------- app/src/main/res/values/styles.xml | 1 + 7 files changed, 48 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index cfc3ae8339..e23a51ceee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.extension import android.content.Context +import android.graphics.drawable.Drawable import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault @@ -11,6 +12,7 @@ import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver import eu.kanade.tachiyomi.extension.util.ExtensionInstaller import eu.kanade.tachiyomi.extension.util.ExtensionLoader +import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.util.system.launchNow import kotlinx.coroutines.async @@ -57,6 +59,13 @@ class ExtensionManager( installedExtensionsRelay.call(value) } + fun getAppIconForSource(source: Source): Drawable? { + val pkgName = + installedExtensions.find { ext -> ext.sources.any { it.id == source.id } }?.pkgName + return if (pkgName != null) context.packageManager.getApplicationIcon(pkgName) + else null + } + /** * Relay used to notify the available extensions. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt index 93a8a809ec..91000505f5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt @@ -1,9 +1,15 @@ package eu.kanade.tachiyomi.source +import android.graphics.drawable.Drawable +import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import rx.Observable +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get /** * A basic interface for creating a source. It could be an online source, a local source, etc... @@ -41,3 +47,12 @@ interface Source { */ fun fetchPageList(chapter: SChapter): Observable> } + +suspend fun Source.fetchMangaDetails(manga: SManga): SManga? { + return withContext(Dispatchers.IO) { + fetchMangaDetails(manga).toBlocking().single() + } +} + +fun Source.icon(): Drawable? = + Injekt.get().getAppIconForSource(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt index ebaa1ddcc3..3245948790 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceHolder.kt @@ -2,11 +2,12 @@ package eu.kanade.tachiyomi.ui.catalogue import android.view.View import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.online.LoginSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder -import eu.kanade.tachiyomi.util.view.getRound import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.roundTextIcon import eu.kanade.tachiyomi.util.view.visible import io.github.mthli.slice.Slice import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.* @@ -41,7 +42,9 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) : // Set circle letter image. itemView.post { - edit_button.setImageDrawable(edit_button.getRound(source.name.take(1).toUpperCase(), false)) + val icon = source.icon() + if (icon != null) edit_button.setImageDrawable(source.icon()) + else edit_button.roundTextIcon(source.name) } // If source is login, show only login option diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt index f6c7571433..ba125cedff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt @@ -2,9 +2,10 @@ package eu.kanade.tachiyomi.ui.migration import android.view.View import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder -import eu.kanade.tachiyomi.util.view.getRound +import eu.kanade.tachiyomi.util.view.roundTextIcon import io.github.mthli.slice.Slice import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.* @@ -39,7 +40,9 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) : // Set circle letter image. itemView.post { - edit_button.setImageDrawable(edit_button.getRound(source.name.take(1).toUpperCase(), false)) + val icon = source.icon() + if (icon != null) edit_button.setImageDrawable(source.icon()) + else edit_button.roundTextIcon(source.name) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt index 7e075e62f7..bb75df7181 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt @@ -4,9 +4,10 @@ import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG import android.view.View import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder -import eu.kanade.tachiyomi.util.view.getRound +import eu.kanade.tachiyomi.util.view.roundTextIcon import kotlinx.android.synthetic.main.migration_source_item.* import uy.kohesive.injekt.injectLazy @@ -24,7 +25,9 @@ class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter) : title.text = sourceName // Update circle letter image. itemView.post { - edit_button.setImageDrawable(edit_button.getRound(source.name.take(1).toUpperCase(), false)) + val icon = source.icon() + if (icon != null) edit_button.setImageDrawable(source.icon()) + else edit_button.roundTextIcon(source.name) } if (sourceEnabled) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 983c8c4c31..0bd4988699 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -16,6 +16,7 @@ import android.view.ViewTreeObserver import android.view.WindowInsets import android.widget.Button import android.widget.FrameLayout +import android.widget.ImageView import android.widget.TextView import androidx.annotation.Px import androidx.appcompat.widget.SearchView @@ -142,15 +143,15 @@ inline fun View.visibleIf(show: Boolean) { * @param text text of [TextDrawable] * @param random random color */ -fun View.getRound(text: String, random: Boolean = true): TextDrawable { +fun ImageView.roundTextIcon(text: String) { val size = min(this.width, this.height) - return TextDrawable.builder().beginConfig().width(size).height(size).textColor(Color.WHITE) - .useFont(Typeface.DEFAULT).endConfig().buildRound( - text, - if (random) ColorGenerator.MATERIAL.randomColor else ColorGenerator.MATERIAL.getColor( - text + val letter = text.take(1).toUpperCase() + setImageDrawable( + TextDrawable.builder().beginConfig().width(size).height(size).textColor(Color.WHITE) + .useFont(Typeface.DEFAULT).endConfig().buildRound( + letter, ColorGenerator.MATERIAL.getColor(letter) ) - ) + ) } inline val View.marginTop: Int diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 730f68e3f1..c8ad9e5dbb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -222,6 +222,7 @@