mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 00:51:49 +01:00
Using extension icon instead of letter for catalogues (closes #2261)
This commit is contained in:
parent
224f08279b
commit
f115fe47fe
@ -4,6 +4,7 @@ import android.app.PendingIntent
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -48,7 +49,7 @@ object NotificationHandler {
|
|||||||
*/
|
*/
|
||||||
fun installApkPendingActivity(context: Context, uri: Uri): PendingIntent {
|
fun installApkPendingActivity(context: Context, uri: Uri): PendingIntent {
|
||||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
setDataAndType(uri, "application/vnd.android.package-archive")
|
setDataAndType(uri, ExtensionInstaller.APK_MIME)
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
}
|
}
|
||||||
return PendingIntent.getActivity(context, 0, intent, 0)
|
return PendingIntent.getActivity(context, 0, intent, 0)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.extension
|
package eu.kanade.tachiyomi.extension
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import com.jakewharton.rxrelay.BehaviorRelay
|
import com.jakewharton.rxrelay.BehaviorRelay
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
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.ExtensionInstallReceiver
|
||||||
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller
|
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller
|
||||||
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
||||||
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.util.lang.launchNow
|
import eu.kanade.tachiyomi.util.lang.launchNow
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
@ -57,6 +59,12 @@ class ExtensionManager(
|
|||||||
installedExtensionsRelay.call(value)
|
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.
|
* Relay used to notify the available extensions.
|
||||||
*/
|
*/
|
||||||
|
@ -159,7 +159,7 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
*
|
*
|
||||||
* @param pkgName The package name of the download to delete.
|
* @param pkgName The package name of the download to delete.
|
||||||
*/
|
*/
|
||||||
fun deleteDownload(pkgName: String) {
|
private fun deleteDownload(pkgName: String) {
|
||||||
val downloadId = activeDownloads.remove(pkgName)
|
val downloadId = activeDownloads.remove(pkgName)
|
||||||
if (downloadId != null) {
|
if (downloadId != null) {
|
||||||
downloadManager.remove(downloadId)
|
downloadManager.remove(downloadId)
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.source
|
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.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import rx.Observable
|
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...
|
* A basic interface for creating a source. It could be an online source, a local source, etc...
|
||||||
@ -41,3 +45,5 @@ interface Source {
|
|||||||
*/
|
*/
|
||||||
fun fetchPageList(chapter: SChapter): Observable<List<Page>>
|
fun fetchPageList(chapter: SChapter): Observable<List<Page>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
|
||||||
|
@ -2,10 +2,11 @@ package eu.kanade.tachiyomi.ui.catalogue
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.kanade.tachiyomi.R
|
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.BaseFlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
|
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.gone
|
||||||
|
import eu.kanade.tachiyomi.util.view.roundTextIcon
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
import io.github.mthli.slice.Slice
|
import io.github.mthli.slice.Slice
|
||||||
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.card
|
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.card
|
||||||
@ -44,7 +45,9 @@ class SourceHolder(view: View, override val adapter: CatalogueAdapter) :
|
|||||||
|
|
||||||
// Set circle letter image.
|
// Set circle letter image.
|
||||||
itemView.post {
|
itemView.post {
|
||||||
image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(), false))
|
val icon = source.icon()
|
||||||
|
if (icon != null) image.setImageDrawable(icon)
|
||||||
|
else image.roundTextIcon(source.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
source_browse.setText(R.string.browse)
|
source_browse.setText(R.string.browse)
|
||||||
|
@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.category
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
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.categories_item.image
|
import kotlinx.android.synthetic.main.categories_item.image
|
||||||
import kotlinx.android.synthetic.main.categories_item.reorder
|
import kotlinx.android.synthetic.main.categories_item.reorder
|
||||||
import kotlinx.android.synthetic.main.categories_item.title
|
import kotlinx.android.synthetic.main.categories_item.title
|
||||||
@ -37,7 +37,7 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleVie
|
|||||||
|
|
||||||
// Update circle letter image.
|
// Update circle letter image.
|
||||||
itemView.post {
|
itemView.post {
|
||||||
image.setImageDrawable(image.getRound(category.name.take(1).toUpperCase(), false))
|
image.roundTextIcon(category.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package eu.kanade.tachiyomi.ui.migration
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.kanade.tachiyomi.R
|
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.BaseFlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
|
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.gone
|
||||||
|
import eu.kanade.tachiyomi.util.view.roundTextIcon
|
||||||
import io.github.mthli.slice.Slice
|
import io.github.mthli.slice.Slice
|
||||||
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.card
|
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.card
|
||||||
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.image
|
import kotlinx.android.synthetic.main.catalogue_main_controller_card_item.image
|
||||||
@ -41,7 +42,9 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) :
|
|||||||
|
|
||||||
// Set circle letter image.
|
// Set circle letter image.
|
||||||
itemView.post {
|
itemView.post {
|
||||||
image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(), false))
|
val icon = source.icon()
|
||||||
|
if (icon != null) image.setImageDrawable(icon)
|
||||||
|
else image.roundTextIcon(source.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.view.Gravity
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.MenuRes
|
import androidx.annotation.MenuRes
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
@ -78,19 +79,18 @@ inline fun View.visibleIf(block: () -> Boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a TextDrawable determined by input
|
* Sets a round TextDrawable into an ImageView determined by input.
|
||||||
*
|
*
|
||||||
* @param text text of [TextDrawable]
|
* @param text text of [TextDrawable]
|
||||||
* @param random random color
|
|
||||||
*/
|
*/
|
||||||
fun View.getRound(text: String, random: Boolean = true): TextDrawable {
|
fun ImageView.roundTextIcon(text: String) {
|
||||||
|
val letter = text.take(1).toUpperCase()
|
||||||
val size = min(this.width, this.height)
|
val size = min(this.width, this.height)
|
||||||
return TextDrawable.builder()
|
|
||||||
.beginConfig()
|
setImageDrawable(
|
||||||
.width(size)
|
TextDrawable.builder().beginConfig().width(size).height(size).textColor(Color.WHITE)
|
||||||
.height(size)
|
.useFont(Typeface.DEFAULT).endConfig().buildRound(
|
||||||
.textColor(Color.WHITE)
|
letter, ColorGenerator.MATERIAL.getColor(letter)
|
||||||
.useFont(Typeface.DEFAULT)
|
)
|
||||||
.endConfig()
|
)
|
||||||
.buildRound(text, if (random) ColorGenerator.MATERIAL.randomColor else ColorGenerator.MATERIAL.getColor(text))
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user