-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load app banner using a custom Coil fetcher
- Loading branch information
Showing
12 changed files
with
107 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tv/src/main/java/com/afzaln/besttvlauncher/image/AppBannerFetcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.afzaln.besttvlauncher.image | ||
|
||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.net.Uri | ||
import coil.ImageLoader | ||
import coil.decode.DataSource | ||
import coil.fetch.DrawableResult | ||
import coil.fetch.FetchResult | ||
import coil.fetch.Fetcher | ||
import coil.request.Options | ||
import com.afzaln.besttvlauncher.data.models.AppInfo | ||
|
||
private const val SCHEME_APPINFO = "appinfo" | ||
|
||
class AppBannerFetcher(val context: Context, val data: Uri) : Fetcher { | ||
override suspend fun fetch(): FetchResult? { | ||
if (data.scheme != SCHEME_APPINFO) return null | ||
|
||
val packageName = data.host ?: return null | ||
val activityName = data.lastPathSegment ?: return null | ||
val packageManager = context.packageManager | ||
|
||
val drawable = packageManager.getActivityBanner(ComponentName.createRelative(packageName, activityName)) | ||
drawable ?: return null | ||
|
||
return DrawableResult(drawable, false, DataSource.DISK) | ||
} | ||
|
||
class Factory(private val context: Context) : Fetcher.Factory<Uri> { | ||
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher = | ||
AppBannerFetcher(context, data) | ||
} | ||
} | ||
|
||
fun AppInfo.toPackageUri() = "$SCHEME_APPINFO://$packageName/$activityName" |
18 changes: 18 additions & 0 deletions
18
tv/src/main/java/com/afzaln/besttvlauncher/image/AppInfoImageLoaderFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.afzaln.besttvlauncher.image | ||
|
||
import android.content.Context | ||
import coil.Coil | ||
import coil.ImageLoader | ||
import coil.ImageLoaderFactory | ||
|
||
class AppInfoImageLoaderFactory(val context: Context) : ImageLoaderFactory { | ||
fun init() { | ||
Coil.setImageLoader(this) | ||
} | ||
|
||
override fun newImageLoader(): ImageLoader = ImageLoader.Builder(context) | ||
.components { | ||
add(AppBannerFetcher.Factory(context)) | ||
} | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters