mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Remove manga homescreen shortcuts
This commit is contained in:
parent
b53d571a1c
commit
b08a5d6596
@ -57,8 +57,6 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
// Clear the download queue
|
// Clear the download queue
|
||||||
ACTION_CLEAR_DOWNLOADS -> downloadManager.clearQueue(true)
|
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
|
// Launch share activity and dismiss notification
|
||||||
ACTION_SHARE_IMAGE -> shareImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION),
|
ACTION_SHARE_IMAGE -> shareImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION),
|
||||||
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1))
|
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1))
|
||||||
@ -230,9 +228,6 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
// Called to clear downloads.
|
// Called to clear downloads.
|
||||||
private const val ACTION_CLEAR_DOWNLOADS = "$ID.$NAME.ACTION_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.
|
// Called to dismiss notification.
|
||||||
private const val ACTION_DISMISS_NOTIFICATION = "$ID.$NAME.ACTION_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)
|
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
|
* Returns [PendingIntent] that starts a service which dismissed the notification
|
||||||
*
|
*
|
||||||
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import android.animation.AnimatorSet
|
|||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -35,10 +34,7 @@ import androidx.appcompat.view.ActionMode
|
|||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.content.ContextCompat
|
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.ColorUtils
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
|
||||||
import androidx.core.math.MathUtils
|
import androidx.core.math.MathUtils
|
||||||
import androidx.palette.graphics.Palette
|
import androidx.palette.graphics.Palette
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
@ -53,7 +49,6 @@ import com.afollestad.materialdialogs.list.listItems
|
|||||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||||
import com.bluelinelabs.conductor.ControllerChangeType
|
import com.bluelinelabs.conductor.ControllerChangeType
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
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.target.CustomTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
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.snack
|
||||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
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.main_activity.*
|
||||||
import kotlinx.android.synthetic.main.manga_details_controller.*
|
import kotlinx.android.synthetic.main.manga_details_controller.*
|
||||||
import kotlinx.android.synthetic.main.manga_header_item.*
|
import kotlinx.android.synthetic.main.manga_header_item.*
|
||||||
@ -216,6 +209,10 @@ class MangaDetailsController : BaseController,
|
|||||||
return if (toolbarIsColored && !isTablet) manga?.title else null
|
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) {
|
override fun onViewCreated(view: View) {
|
||||||
super.onViewCreated(view)
|
super.onViewCreated(view)
|
||||||
coverColor = null
|
coverColor = null
|
||||||
@ -758,7 +755,6 @@ class MangaDetailsController : BaseController,
|
|||||||
R.string.edit else R.string.edit_cover)
|
R.string.edit else R.string.edit_cover)
|
||||||
menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch &&
|
menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch &&
|
||||||
manga?.source != LocalSource.ID
|
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 =
|
menu.findItem(R.id.action_mark_all_as_read).isVisible =
|
||||||
presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch
|
presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch
|
||||||
menu.findItem(R.id.action_mark_all_as_unread).isVisible =
|
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_open_in_web_view -> openInWebView()
|
||||||
R.id.action_add_to_home_screen -> addToHomeScreen()
|
|
||||||
R.id.action_refresh_tracking -> presenter.refreshTrackers()
|
R.id.action_refresh_tracking -> presenter.refreshTrackers()
|
||||||
R.id.action_migrate ->
|
R.id.action_migrate ->
|
||||||
PreMigrationController.navigateToMigration(
|
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<Bitmap>(128, 128) {
|
|
||||||
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
|
||||||
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) {
|
override fun startDownloadRange(position: Int) {
|
||||||
if (actionMode == null) createActionModeIfNeeded()
|
if (actionMode == null) createActionModeIfNeeded()
|
||||||
onItemClick(null, position)
|
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 coverColor(): Int? = coverColor
|
||||||
override fun topCoverHeight(): Int = headerHeight
|
override fun topCoverHeight(): Int = headerHeight
|
||||||
|
|
||||||
|
@ -78,9 +78,4 @@
|
|||||||
android:title="@string/migrate"
|
android:title="@string/migrate"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_add_to_home_screen"
|
|
||||||
android:title="@string/add_to_home_screen"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -332,14 +332,6 @@
|
|||||||
<string name="added_to_library">Added to library</string>
|
<string name="added_to_library">Added to library</string>
|
||||||
<string name="add_to_library">Add to Library</string>
|
<string name="add_to_library">Add to Library</string>
|
||||||
<string name="removed_from_library">Removed from library</string>
|
<string name="removed_from_library">Removed from library</string>
|
||||||
<string name="icon_shape">Icon shape</string>
|
|
||||||
<string name="circular">Circular</string>
|
|
||||||
<string name="rounded">Rounded</string>
|
|
||||||
<string name="square">Square</string>
|
|
||||||
<string name="star">Star</string>
|
|
||||||
<string name="add_to_home_screen">Add to home screen</string>
|
|
||||||
<string name="shortcut_created">Shortcut was added to home screen.</string>
|
|
||||||
<string name="could_not_create_shortcut">Could not create shortcut</string>
|
|
||||||
<string name="_copied_to_clipboard">%1$s copied to clipboard</string>
|
<string name="_copied_to_clipboard">%1$s copied to clipboard</string>
|
||||||
<string name="source_not_installed_">Source not installed: %1$s</string>
|
<string name="source_not_installed_">Source not installed: %1$s</string>
|
||||||
<string name="no_description">No description</string>
|
<string name="no_description">No description</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user