diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index aff7d10e2a..b1924bdcf2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -57,8 +57,6 @@ class NotificationReceiver : BroadcastReceiver() { } // Clear the download queue ACTION_CLEAR_DOWNLOADS -> downloadManager.clearQueue(true) - // Show message notification created - ACTION_SHORTCUT_CREATED -> context.toast(R.string.shortcut_created) // Launch share activity and dismiss notification ACTION_SHARE_IMAGE -> shareImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION), intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1)) @@ -230,9 +228,6 @@ class NotificationReceiver : BroadcastReceiver() { // Called to clear downloads. private const val ACTION_CLEAR_DOWNLOADS = "$ID.$NAME.ACTION_CLEAR_DOWNLOADS" - // Called to notify user shortcut is created. - private const val ACTION_SHORTCUT_CREATED = "$ID.$NAME.ACTION_SHORTCUT_CREATED" - // Called to dismiss notification. private const val ACTION_DISMISS_NOTIFICATION = "$ID.$NAME.ACTION_DISMISS_NOTIFICATION" @@ -290,13 +285,6 @@ class NotificationReceiver : BroadcastReceiver() { return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } - internal fun shortcutCreatedBroadcast(context: Context): PendingIntent { - val intent = Intent(context, NotificationReceiver::class.java).apply { - action = ACTION_SHORTCUT_CREATED - } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) - } - /** * Returns [PendingIntent] that starts a service which dismissed the notification * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/ChooseShapeDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/ChooseShapeDialog.kt deleted file mode 100644 index 642293e6f3..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/ChooseShapeDialog.kt +++ /dev/null @@ -1,36 +0,0 @@ -package eu.kanade.tachiyomi.ui.manga - -import android.app.Dialog -import android.os.Bundle -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.list.listItemsSingleChoice -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.ui.base.controller.DialogController - -/** - * Dialog to choose a shape for the icon. - */ -class ChooseShapeDialog(bundle: Bundle? = null) : DialogController(bundle) { - - constructor(target: MangaDetailsController) : this() { - targetController = target - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val modes = intArrayOf( - R.string.circular, - R.string.rounded, - R.string.square, - R.string.star) - - return MaterialDialog(activity!!) - .title(R.string.icon_shape) - .negativeButton(android.R.string.cancel) - .listItemsSingleChoice( - items = modes.map { activity?.getString(it) as CharSequence }, - waitForPositiveButton = false) { _, i, _ -> - (targetController as? MangaDetailsController)?.createShortcutForShape(i) - dismissDialog() - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 3f60957ee1..37a1963443 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -6,7 +6,6 @@ import android.animation.AnimatorSet import android.animation.ObjectAnimator import android.animation.ValueAnimator import android.app.Activity -import android.app.PendingIntent import android.content.ClipData import android.content.ClipboardManager import android.content.Context @@ -35,10 +34,7 @@ import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat -import androidx.core.content.pm.ShortcutInfoCompat -import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.graphics.ColorUtils -import androidx.core.graphics.drawable.IconCompat import androidx.core.math.MathUtils import androidx.palette.graphics.Palette import androidx.recyclerview.widget.ItemTouchHelper @@ -53,7 +49,6 @@ import com.afollestad.materialdialogs.list.listItems import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.signature.ObjectKey @@ -110,8 +105,6 @@ import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative -import jp.wasabeef.glide.transformations.CropSquareTransformation -import jp.wasabeef.glide.transformations.MaskTransformation import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.manga_details_controller.* import kotlinx.android.synthetic.main.manga_header_item.* @@ -216,6 +209,10 @@ class MangaDetailsController : BaseController, return if (toolbarIsColored && !isTablet) manga?.title else null } + override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { + return inflater.inflate(R.layout.manga_details_controller, container, false) + } + override fun onViewCreated(view: View) { super.onViewCreated(view) coverColor = null @@ -758,7 +755,6 @@ class MangaDetailsController : BaseController, R.string.edit else R.string.edit_cover) menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch && manga?.source != LocalSource.ID - menu.findItem(R.id.action_add_to_home_screen).isVisible = !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_read).isVisible = presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_unread).isVisible = @@ -830,7 +826,6 @@ class MangaDetailsController : BaseController, } } R.id.action_open_in_web_view -> openInWebView() - R.id.action_add_to_home_screen -> addToHomeScreen() R.id.action_refresh_tracking -> presenter.refreshTrackers() R.id.action_migrate -> PreMigrationController.navigateToMigration( @@ -979,101 +974,11 @@ class MangaDetailsController : BaseController, } } - /** - * Add a shortcut of the manga to the home screen - */ - private fun addToHomeScreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // TODO are transformations really unsupported or is it just the Pixel Launcher? - createShortcutForShape() - } else { - ChooseShapeDialog(this).showDialog(router) - } - } - - /** - * Retrieves the bitmap of the shortcut with the requested shape and calls [createShortcut] when - * the resource is available. - * - * @param i The shape index to apply. Defaults to circle crop transformation. - */ - fun createShortcutForShape(i: Int = 0) { - if (activity == null) return - GlideApp.with(activity!!) - .asBitmap() - .load(presenter.manga) - .diskCacheStrategy(DiskCacheStrategy.NONE) - .apply { - when (i) { - 0 -> circleCrop() - 1 -> transform(RoundedCorners(5)) - 2 -> transform(CropSquareTransformation()) - 3 -> centerCrop().transform(MaskTransformation(R.drawable.mask_star)) - } - } - .into(object : CustomTarget(128, 128) { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - createShortcut(resource) - } - - override fun onLoadCleared(placeholder: Drawable?) { } - - override fun onLoadFailed(errorDrawable: Drawable?) { - activity?.toast(R.string.could_not_create_shortcut) - } - }) - } - - /** - * Create shortcut using ShortcutManager. - * - * @param icon The image of the shortcut. - */ - private fun createShortcut(icon: Bitmap) { - val activity = activity ?: return - - // Create the shortcut intent. - val shortcutIntent = activity.intent - .setAction(MainActivity.SHORTCUT_MANGA) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - .putExtra(MANGA_EXTRA, presenter.manga.id) - - // Check if shortcut placement is supported - if (ShortcutManagerCompat.isRequestPinShortcutSupported(activity)) { - val shortcutId = "manga-shortcut-${presenter.manga.title}-${presenter.source.name}" - - // Create shortcut info - val shortcutInfo = ShortcutInfoCompat.Builder(activity, shortcutId) - .setShortLabel(presenter.manga.title) - .setIcon(IconCompat.createWithBitmap(icon)) - .setIntent(shortcutIntent) - .build() - - val successCallback = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // Create the CallbackIntent. - val intent = ShortcutManagerCompat.createShortcutResultIntent(activity, shortcutInfo) - - // Configure the intent so that the broadcast receiver gets the callback successfully. - PendingIntent.getBroadcast(activity, 0, intent, 0) - } else { - NotificationReceiver.shortcutCreatedBroadcast(activity) - } - - // Request shortcut. - ShortcutManagerCompat.requestPinShortcut(activity, shortcutInfo, - successCallback.intentSender) - } - } - override fun startDownloadRange(position: Int) { if (actionMode == null) createActionModeIfNeeded() onItemClick(null, position) } - override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - return inflater.inflate(R.layout.manga_details_controller, container, false) - } - override fun coverColor(): Int? = coverColor override fun topCoverHeight(): Int = headerHeight diff --git a/app/src/main/res/menu/manga_details.xml b/app/src/main/res/menu/manga_details.xml index f7cc051d19..3cb320d585 100644 --- a/app/src/main/res/menu/manga_details.xml +++ b/app/src/main/res/menu/manga_details.xml @@ -78,9 +78,4 @@ android:title="@string/migrate" app:showAsAction="never" /> - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f18ab544d6..29f237beb6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -332,14 +332,6 @@ Added to library Add to Library Removed from library - Icon shape - Circular - Rounded - Square - Star - Add to home screen - Shortcut was added to home screen. - Could not create shortcut %1$s copied to clipboard Source not installed: %1$s No description