mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
allow creating file shortcuts from the thumbnail view
This commit is contained in:
parent
0c14a82284
commit
230d028227
4 changed files with 53 additions and 12 deletions
|
@ -15,7 +15,6 @@ import android.graphics.Color
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
import android.media.ExifInterface
|
import android.media.ExifInterface
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
|
@ -666,9 +665,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val path = medium.path
|
val path = medium.path
|
||||||
val drawable = resources.getDrawable(R.drawable.shortcut_image).mutate()
|
val drawable = resources.getDrawable(R.drawable.shortcut_image).mutate()
|
||||||
getShortcutImage(path, drawable) {
|
getShortcutImage(path, drawable) {
|
||||||
val intent = Intent(this, PhotoVideoActivity::class.java)
|
val intent = Intent(this, ViewPagerActivity::class.java).apply {
|
||||||
intent.action = Intent.ACTION_VIEW
|
putExtra(PATH, path)
|
||||||
intent.data = Uri.fromFile(File(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)
|
val shortcut = ShortcutInfo.Builder(this, path)
|
||||||
.setShortLabel(medium.name)
|
.setShortLabel(medium.name)
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package com.simplemobiletools.gallery.pro.adapters
|
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.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
@ -14,16 +19,15 @@ import com.simplemobiletools.commons.dialogs.RenameDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.pro.R
|
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.dialogs.DeleteWithRememberDialog
|
||||||
import com.simplemobiletools.gallery.pro.extensions.*
|
import com.simplemobiletools.gallery.pro.extensions.*
|
||||||
import com.simplemobiletools.gallery.pro.helpers.SHOW_ALL
|
import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
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.interfaces.MediaOperationsListener
|
import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener
|
||||||
import com.simplemobiletools.gallery.pro.models.Medium
|
import com.simplemobiletools.gallery.pro.models.Medium
|
||||||
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
||||||
|
@ -122,6 +126,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
findItem(R.id.cab_open_with).isVisible = isOneItemSelected
|
findItem(R.id.cab_open_with).isVisible = isOneItemSelected
|
||||||
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
|
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
|
||||||
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.recycleBinPath) }
|
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.recycleBinPath) }
|
||||||
|
findItem(R.id.cab_create_shortcut).isVisible = isOreoPlus() && isOneItemSelected
|
||||||
|
|
||||||
checkHideBtnVisibility(this, selectedItems)
|
checkHideBtnVisibility(this, selectedItems)
|
||||||
checkFavoriteBtnVisibility(this, selectedItems)
|
checkFavoriteBtnVisibility(this, selectedItems)
|
||||||
|
@ -149,6 +154,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
R.id.cab_rotate_one_eighty -> rotateSelection(180)
|
R.id.cab_rotate_one_eighty -> rotateSelection(180)
|
||||||
R.id.cab_copy_to -> copyMoveTo(true)
|
R.id.cab_copy_to -> copyMoveTo(true)
|
||||||
R.id.cab_move_to -> moveFilesTo()
|
R.id.cab_move_to -> moveFilesTo()
|
||||||
|
R.id.cab_create_shortcut -> createShortcut()
|
||||||
R.id.cab_select_all -> selectAll()
|
R.id.cab_select_all -> selectAll()
|
||||||
R.id.cab_open_with -> openPath()
|
R.id.cab_open_with -> openPath()
|
||||||
R.id.cab_fix_date_taken -> fixDateTaken()
|
R.id.cab_fix_date_taken -> fixDateTaken()
|
||||||
|
@ -347,6 +353,33 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private fun createShortcut() {
|
||||||
|
val manager = activity.getSystemService(ShortcutManager::class.java)
|
||||||
|
if (manager.isRequestPinShortcutSupported) {
|
||||||
|
val path = getSelectedPaths().first()
|
||||||
|
val drawable = resources.getDrawable(R.drawable.shortcut_image).mutate()
|
||||||
|
activity.getShortcutImage(path, drawable) {
|
||||||
|
val intent = Intent(activity, 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(activity, path)
|
||||||
|
.setShortLabel(path.getFilenameFromPath())
|
||||||
|
.setIcon(Icon.createWithBitmap(drawable.convertToBitmap()))
|
||||||
|
.setIntent(intent)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
manager.requestPinShortcut(shortcut, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun fixDateTaken() {
|
private fun fixDateTaken() {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
activity.fixDateTaken(getSelectedPaths(), true) {
|
activity.fixDateTaken(getSelectedPaths(), true) {
|
||||||
|
|
|
@ -44,6 +44,10 @@
|
||||||
android:id="@+id/cab_move_to"
|
android:id="@+id/cab_move_to"
|
||||||
android:title="@string/move_to"
|
android:title="@string/move_to"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_create_shortcut"
|
||||||
|
android:title="@string/create_shortcut"
|
||||||
|
app:showAsAction="never"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_empty_recycle_bin"
|
android:id="@+id/cab_empty_recycle_bin"
|
||||||
android:title="@string/empty_recycle_bin"
|
android:title="@string/empty_recycle_bin"
|
||||||
|
@ -64,10 +68,6 @@
|
||||||
android:id="@+id/cab_unlock"
|
android:id="@+id/cab_unlock"
|
||||||
android:title="@string/unlock_folder"
|
android:title="@string/unlock_folder"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
<item
|
|
||||||
android:id="@+id/cab_create_shortcut"
|
|
||||||
android:title="@string/create_shortcut"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_change_cover_image"
|
android:id="@+id/cab_change_cover_image"
|
||||||
android:title="@string/change_cover_image"
|
android:title="@string/change_cover_image"
|
||||||
|
|
|
@ -61,6 +61,10 @@
|
||||||
android:id="@+id/cab_move_to"
|
android:id="@+id/cab_move_to"
|
||||||
android:title="@string/move_to"
|
android:title="@string/move_to"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/cab_create_shortcut"
|
||||||
|
android:title="@string/create_shortcut"
|
||||||
|
app:showAsAction="never"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/cab_edit"
|
android:id="@+id/cab_edit"
|
||||||
android:icon="@drawable/ic_edit_vector"
|
android:icon="@drawable/ic_edit_vector"
|
||||||
|
|
Loading…
Reference in a new issue