mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-13 05:37:48 +02:00
feat(core/ui): opera download icon
This commit is contained in:
@ -166,6 +166,10 @@
|
|||||||
"name": "Download Profile Pictures",
|
"name": "Download Profile Pictures",
|
||||||
"description": "Allows you to download Profile Pictures from the profile page"
|
"description": "Allows you to download Profile Pictures from the profile page"
|
||||||
},
|
},
|
||||||
|
"opera_download_button": {
|
||||||
|
"name": "Opera Download Button",
|
||||||
|
"description": "Adds a download button on the top right corner when viewing a Snap"
|
||||||
|
},
|
||||||
"chat_download_context_menu": {
|
"chat_download_context_menu": {
|
||||||
"name": "Chat Download Context Menu",
|
"name": "Chat Download Context Menu",
|
||||||
"description": "Allows you to download media from a conversation by long-pressing them"
|
"description": "Allows you to download media from a conversation by long-pressing them"
|
||||||
|
@ -42,6 +42,7 @@ class DownloaderConfig : ConfigContainer() {
|
|||||||
addFlags(ConfigFlag.NO_TRANSLATE)
|
addFlags(ConfigFlag.NO_TRANSLATE)
|
||||||
}
|
}
|
||||||
val downloadProfilePictures = boolean("download_profile_pictures") { requireRestart() }
|
val downloadProfilePictures = boolean("download_profile_pictures") { requireRestart() }
|
||||||
|
val operaDownloadButton = boolean("opera_download_button") { requireRestart() }
|
||||||
val chatDownloadContextMenu = boolean("chat_download_context_menu")
|
val chatDownloadContextMenu = boolean("chat_download_context_menu")
|
||||||
val ffmpegOptions = container("ffmpeg_options", FFMpegOptions()) { addNotices(FeatureNotice.UNSTABLE) }
|
val ffmpegOptions = container("ffmpeg_options", FFMpegOptions()) { addNotices(FeatureNotice.UNSTABLE) }
|
||||||
val logging = multiple("logging", "started", "success", "progress", "failure").apply {
|
val logging = multiple("logging", "started", "success", "progress", "failure").apply {
|
||||||
|
@ -27,9 +27,10 @@ class MenuViewInjector : Feature("MenuViewInjector", loadParams = FeatureLoadPar
|
|||||||
|
|
||||||
@SuppressLint("ResourceType")
|
@SuppressLint("ResourceType")
|
||||||
override fun asyncOnActivityCreate() {
|
override fun asyncOnActivityCreate() {
|
||||||
|
menuMap[OperaContextActionMenu::class] = OperaContextActionMenu()
|
||||||
|
menuMap[OperaDownloadIconMenu::class] = OperaDownloadIconMenu()
|
||||||
menuMap[SettingsGearInjector::class] = SettingsGearInjector()
|
menuMap[SettingsGearInjector::class] = SettingsGearInjector()
|
||||||
menuMap[FriendFeedInfoMenu::class] = FriendFeedInfoMenu()
|
menuMap[FriendFeedInfoMenu::class] = FriendFeedInfoMenu()
|
||||||
menuMap[OperaContextActionMenu::class] = OperaContextActionMenu()
|
|
||||||
menuMap[ChatActionMenu::class] = ChatActionMenu()
|
menuMap[ChatActionMenu::class] = ChatActionMenu()
|
||||||
menuMap[SettingsMenu::class] = SettingsMenu()
|
menuMap[SettingsMenu::class] = SettingsMenu()
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ class MenuViewInjector : Feature("MenuViewInjector", loadParams = FeatureLoadPar
|
|||||||
val actionMenu = context.resources.getIdentifier("action_menu", "id")
|
val actionMenu = context.resources.getIdentifier("action_menu", "id")
|
||||||
val componentsHolder = context.resources.getIdentifier("components_holder", "id")
|
val componentsHolder = context.resources.getIdentifier("components_holder", "id")
|
||||||
val feedNewChat = context.resources.getIdentifier("feed_new_chat", "id")
|
val feedNewChat = context.resources.getIdentifier("feed_new_chat", "id")
|
||||||
|
val contextMenuButtonIconView = context.resources.getIdentifier("context_menu_button_icon_view", "id")
|
||||||
|
|
||||||
context.event.subscribe(AddViewEvent::class) { event ->
|
context.event.subscribe(AddViewEvent::class) { event ->
|
||||||
val originalAddView: (View) -> Unit = {
|
val originalAddView: (View) -> Unit = {
|
||||||
@ -57,6 +59,10 @@ class MenuViewInjector : Feature("MenuViewInjector", loadParams = FeatureLoadPar
|
|||||||
val childView: View = event.view
|
val childView: View = event.view
|
||||||
menuMap[OperaContextActionMenu::class]!!.inject(viewGroup, childView, originalAddView)
|
menuMap[OperaContextActionMenu::class]!!.inject(viewGroup, childView, originalAddView)
|
||||||
|
|
||||||
|
if (childView.id == contextMenuButtonIconView) {
|
||||||
|
menuMap[OperaDownloadIconMenu::class]!!.inject(viewGroup, childView, originalAddView)
|
||||||
|
}
|
||||||
|
|
||||||
if (event.parent.id == componentsHolder && childView.id == feedNewChat) {
|
if (event.parent.id == componentsHolder && childView.id == feedNewChat) {
|
||||||
menuMap[SettingsGearInjector::class]!!.inject(viewGroup, childView, originalAddView)
|
menuMap[SettingsGearInjector::class]!!.inject(viewGroup, childView, originalAddView)
|
||||||
return@subscribe
|
return@subscribe
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package me.rhunk.snapenhance.core.ui.menu.impl
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.ImageView
|
||||||
|
import me.rhunk.snapenhance.core.features.impl.downloader.MediaDownloader
|
||||||
|
import me.rhunk.snapenhance.core.ui.menu.AbstractMenu
|
||||||
|
import me.rhunk.snapenhance.core.util.ktx.getDimens
|
||||||
|
import me.rhunk.snapenhance.core.util.ktx.getDrawable
|
||||||
|
|
||||||
|
class OperaDownloadIconMenu : AbstractMenu() {
|
||||||
|
private val downloadSvgDrawable by lazy { context.resources.getDrawable("svg_download", context.androidContext.theme) }
|
||||||
|
private val actionMenuIconSize by lazy { context.resources.getDimens("action_menu_icon_size") }
|
||||||
|
private val actionMenuIconMargin by lazy { context.resources.getDimens("action_menu_icon_margin") }
|
||||||
|
private val actionMenuIconMarginTop by lazy { context.resources.getDimens("action_menu_icon_margin_top") }
|
||||||
|
|
||||||
|
override fun inject(parent: ViewGroup, view: View, viewConsumer: (View) -> Unit) {
|
||||||
|
if (!context.config.downloader.operaDownloadButton.get()) return
|
||||||
|
|
||||||
|
parent.addView(ImageView(view.context).apply {
|
||||||
|
setImageDrawable(downloadSvgDrawable)
|
||||||
|
setColorFilter(Color.WHITE)
|
||||||
|
layoutParams = FrameLayout.LayoutParams(
|
||||||
|
actionMenuIconSize,
|
||||||
|
actionMenuIconSize
|
||||||
|
).apply {
|
||||||
|
setMargins(0, actionMenuIconMarginTop * 2 + actionMenuIconSize, 0, 0)
|
||||||
|
marginEnd = actionMenuIconMargin
|
||||||
|
gravity = Gravity.TOP or Gravity.END
|
||||||
|
}
|
||||||
|
setOnClickListener {
|
||||||
|
this@OperaDownloadIconMenu.context.feature(MediaDownloader::class).downloadLastOperaMediaAsync()
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user