From 230d028227a5f9714b1404b71b47cab362c7c4c6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 12 Dec 2019 10:35:23 +0100 Subject: [PATCH] allow creating file shortcuts from the thumbnail view --- .../pro/activities/ViewPagerActivity.kt | 12 ++++-- .../gallery/pro/adapters/MediaAdapter.kt | 41 +++++++++++++++++-- app/src/main/res/menu/cab_directories.xml | 8 ++-- app/src/main/res/menu/cab_media.xml | 4 ++ 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 845235403..aa3f88bbc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -15,7 +15,6 @@ import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Icon import android.media.ExifInterface -import android.net.Uri import android.os.Bundle import android.os.Handler import android.provider.MediaStore @@ -666,9 +665,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val path = medium.path val drawable = resources.getDrawable(R.drawable.shortcut_image).mutate() getShortcutImage(path, drawable) { - val intent = Intent(this, PhotoVideoActivity::class.java) - intent.action = Intent.ACTION_VIEW - intent.data = Uri.fromFile(File(path)) + val intent = Intent(this, ViewPagerActivity::class.java).apply { + putExtra(PATH, path) + putExtra(SHOW_ALL, config.showAll) + putExtra(SHOW_FAVORITES, path == FAVORITES) + putExtra(SHOW_RECYCLE_BIN, path == RECYCLE_BIN) + action = Intent.ACTION_VIEW + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } val shortcut = ShortcutInfo.Builder(this, path) .setShortLabel(medium.name) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 2eeae31fc..743d2127d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -1,5 +1,10 @@ package com.simplemobiletools.gallery.pro.adapters +import android.annotation.SuppressLint +import android.content.Intent +import android.content.pm.ShortcutInfo +import android.content.pm.ShortcutManager +import android.graphics.drawable.Icon import android.os.Handler import android.os.Looper import android.view.Menu @@ -14,16 +19,15 @@ import com.simplemobiletools.commons.dialogs.RenameDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.pro.R +import com.simplemobiletools.gallery.pro.activities.ViewPagerActivity import com.simplemobiletools.gallery.pro.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.pro.extensions.* -import com.simplemobiletools.gallery.pro.helpers.SHOW_ALL -import com.simplemobiletools.gallery.pro.helpers.TYPE_GIFS -import com.simplemobiletools.gallery.pro.helpers.TYPE_RAWS -import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_LIST +import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.ThumbnailItem @@ -122,6 +126,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList rotateSelection(180) R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> moveFilesTo() + R.id.cab_create_shortcut -> createShortcut() R.id.cab_select_all -> selectAll() R.id.cab_open_with -> openPath() R.id.cab_fix_date_taken -> fixDateTaken() @@ -347,6 +353,33 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList + - +