From 6c14402992c21b3ad5377fbd43ce58f69788215a Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 18 Apr 2020 16:06:31 -0400 Subject: [PATCH] Remove manga homescreen shortcuts --- app/build.gradle | 1 - .../data/notification/NotificationReceiver.kt | 12 -- .../ui/manga/info/MangaInfoController.kt | 148 ------------------ app/src/main/res/menu/manga_info.xml | 10 -- app/src/main/res/values/strings.xml | 8 - 5 files changed, 179 deletions(-) delete mode 100644 app/src/main/res/menu/manga_info.xml diff --git a/app/build.gradle b/app/build.gradle index 8af52a047..2de3ec21d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -204,7 +204,6 @@ dependencies { implementation "com.github.bumptech.glide:glide:$glide_version" implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version" kapt "com.github.bumptech.glide:compiler:$glide_version" - implementation 'jp.wasabeef:glide-transformations:4.1.0' // Logging implementation 'com.jakewharton.timber:timber:4.7.1' 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 ba6c91786..86085d049 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 @@ -51,8 +51,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)) @@ -219,9 +217,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" @@ -279,13 +274,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/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index f592619a4..83d19a876 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -1,50 +1,31 @@ package eu.kanade.tachiyomi.ui.manga.info -import android.app.Dialog -import android.app.PendingIntent import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Intent -import android.graphics.Bitmap -import android.graphics.drawable.Drawable -import android.os.Build -import android.os.Bundle import android.text.TextUtils import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.core.content.ContextCompat -import androidx.core.content.pm.ShortcutInfoCompat -import androidx.core.content.pm.ShortcutManagerCompat -import androidx.core.graphics.drawable.IconCompat -import com.afollestad.materialdialogs.MaterialDialog 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.google.android.material.chip.Chip import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp -import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.MangaInfoControllerBinding import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource -import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.LibraryController -import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController @@ -56,7 +37,6 @@ import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.toggle import eu.kanade.tachiyomi.util.view.visible -import jp.wasabeef.glide.transformations.CropSquareTransformation import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks import reactivecircus.flowbinding.android.view.longClicks @@ -76,11 +56,6 @@ class MangaInfoController(private val fromSource: Boolean = false) : private val preferences: PreferencesHelper by injectLazy() - init { - setHasOptionsMenu(true) - setOptionsMenuHidden(true) - } - override fun createPresenter(): MangaInfoPresenter { val ctrl = parentController as MangaController return MangaInfoPresenter(ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay) @@ -170,17 +145,6 @@ class MangaInfoController(private val fromSource: Boolean = false) : .launchInUI() } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - inflater.inflate(R.menu.manga_info, menu) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.action_add_to_home_screen -> addToHomeScreen() - } - return super.onOptionsItemSelected(item) - } - /** * Check if manga is initialized. * If true update view with manga information, @@ -506,75 +470,6 @@ class MangaInfoController(private val fromSource: Boolean = false) : activity?.toast(activity?.getString(R.string.manga_added_library)) } - /** - * 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) - } - } - - /** - * Dialog to choose a shape for the icon. - */ - private class ChooseShapeDialog(bundle: Bundle? = null) : DialogController(bundle) { - - constructor(target: MangaInfoController) : this() { - targetController = target - } - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val modes = intArrayOf(R.string.circular_icon, - R.string.rounded_icon, - R.string.square_icon) - - return MaterialDialog.Builder(activity!!) - .title(R.string.icon_shape) - .negativeText(android.R.string.cancel) - .items(modes.map { activity?.getString(it) }) - .itemsCallback { _, _, i, _ -> - (targetController as? MangaInfoController)?.createShortcutForShape(i) - } - .build() - } - } - - /** - * 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. - */ - private 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()) - } - } - .into(object : CustomTarget(96, 96) { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - createShortcut(resource) - } - - override fun onLoadFailed(errorDrawable: Drawable?) { - activity?.toast(R.string.icon_creation_fail) - } - - override fun onLoadCleared(placeholder: Drawable?) {} - }) - } - /** * Copies a string to clipboard * @@ -627,47 +522,4 @@ class MangaInfoController(private val fromSource: Boolean = false) : } } } - - /** - * Create shortcut using ShortcutManager. - * - * @param icon The image of the shortcut. - */ - private fun createShortcut(icon: Bitmap) { - val activity = activity ?: return - val mangaControllerArgs = parentController?.args ?: return - - // Create the shortcut intent. - val shortcutIntent = activity.intent - .setAction(MainActivity.SHORTCUT_MANGA) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - .putExtra(MangaController.MANGA_EXTRA, - mangaControllerArgs.getLong(MangaController.MANGA_EXTRA)) - - // 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) - } - } } diff --git a/app/src/main/res/menu/manga_info.xml b/app/src/main/res/menu/manga_info.xml deleted file mode 100644 index 1cdbdab56..000000000 --- a/app/src/main/res/menu/manga_info.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d3ff29958..661c44ca0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -78,7 +78,6 @@ Move Open in browser Open in WebView - Add to home screen Display mode Display Grid @@ -421,13 +420,6 @@ About Show more info Show less info - Circular - Rounded - Square - Shortcut title - Shortcut was added to home screen. - Icon shape - Could not create shortcut Delete downloaded chapters? %1$s copied to clipboard Source not installed: %1$s