Using extension icon instead of letter for catalogues

This commit is contained in:
Jay 2020-03-20 01:52:03 -04:00
parent b3ece8c9c9
commit fe7bd2a7bb
7 changed files with 48 additions and 13 deletions

View File

@ -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.
*/

View File

@ -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<List<Page>>
}
suspend fun Source.fetchMangaDetails(manga: SManga): SManga? {
return withContext(Dispatchers.IO) {
fetchMangaDetails(manga).toBlocking().single()
}
}
fun Source.icon(): Drawable? =
Injekt.get<ExtensionManager>().getAppIconForSource(this)

View File

@ -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

View File

@ -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)
}
}
}

View File

@ -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) {

View File

@ -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

View File

@ -222,6 +222,7 @@
<style name="Theme.Widget.Button.Borderless" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">?attr/colorAccent</item>
<item name="rippleColor">@color/fullRippleColor</item>
</style>
<style name="Theme.Widget.Button.Borderless.Negative">