diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index debef57f9..e52297b56 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -2625,8 +2625,8 @@ + errorLine1=" ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts)" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + val drawable = try { + if (TextUtils.isEmpty(account.profilePictureUrl)) { + AppCompatResources.getDrawable(context, DR.drawable.avatar_default) + } else { + Glide.with(context) + .asDrawable() + .load(account.profilePictureUrl) + .error(DR.drawable.avatar_default) + .submit(innerSize, innerSize) + .get() + } + } catch (e: ExecutionException) { + // The `.error` handler isn't always used. For example, Glide throws + // ExecutionException if the URL does not point at an image. Fallback to + // the default avatar (https://github.com/bumptech/glide/issues/4672). + AppCompatResources.getDrawable(context, DR.drawable.avatar_default) + } ?: return@mapNotNull null + + // inset the loaded bitmap inside a 108dp transparent canvas so it looks good as adaptive icon + val outBmp = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888) + + val canvas = Canvas(outBmp) + val border = (outerSize - innerSize) / 2 + drawable.setBounds(border, border, border + innerSize, border + innerSize) + drawable.draw(canvas) + + val icon = IconCompat.createWithAdaptiveBitmap(outBmp) + + val person = Person.Builder() + .setIcon(icon) + .setName(account.displayName) + .setKey(account.identifier) + .build() + + // This intent will be sent when the user clicks on one of the launcher shortcuts. Intent from share sheet will be different + val intent = MainActivityIntent(context).apply { + action = Intent.ACTION_SEND + type = "text/plain" + putExtra(ShortcutManagerCompat.EXTRA_SHORTCUT_ID, account.id.toString()) } - } catch (e: ExecutionException) { - // The `.error` handler isn't always used. For example, Glide throws - // ExecutionException if the URL does not point at an image. Fallback to - // the default avatar (https://github.com/bumptech/glide/issues/4672). - Glide.with(context) - .asBitmap() - .load(DR.drawable.avatar_default) - .submit(innerSize, innerSize) - .get() + + ShortcutInfoCompat.Builder(context, account.id.toString()) + .setIntent(intent) + .setCategories(setOf("app.pachli.Share")) + .setShortLabel(account.displayName) + .setPerson(person) + .setLongLived(true) + .setIcon(icon) + .build() } - // inset the loaded bitmap inside a 108dp transparent canvas so it looks good as adaptive icon - val outBmp = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888) - - val canvas = Canvas(outBmp) - canvas.drawBitmap(bmp, (outerSize - innerSize).toFloat() / 2f, (outerSize - innerSize).toFloat() / 2f, null) - - val icon = IconCompat.createWithAdaptiveBitmap(outBmp) - - val person = Person.Builder() - .setIcon(icon) - .setName(account.displayName) - .setKey(account.identifier) - .build() - - // This intent will be sent when the user clicks on one of the launcher shortcuts. Intent from share sheet will be different - val intent = MainActivityIntent(context).apply { - action = Intent.ACTION_SEND - type = "text/plain" - putExtra(ShortcutManagerCompat.EXTRA_SHORTCUT_ID, account.id.toString()) - } - - val shortcutInfo = ShortcutInfoCompat.Builder(context, account.id.toString()) - .setIntent(intent) - .setCategories(setOf("app.pachli.Share")) - .setShortLabel(account.displayName) - .setPerson(person) - .setLongLived(true) - .setIcon(icon) - .build() - - ShortcutManagerCompat.addDynamicShortcuts(context, listOf(shortcutInfo)) + ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts) } fun removeShortcut(context: Context, account: AccountEntity) {