diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index c0428f37c..81fb5f796 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -1,9 +1,19 @@ 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.Drawable +import android.graphics.drawable.Icon +import android.graphics.drawable.LayerDrawable import android.view.Menu import android.view.View import android.view.ViewGroup import com.bumptech.glide.Glide +import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.request.RequestOptions import com.google.gson.Gson import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter @@ -12,10 +22,12 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.dialogs.RenameItemsDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.isNougatMR1Plus 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.MediaActivity import com.simplemobiletools.gallery.pro.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.pro.dialogs.PickMediumDialog import com.simplemobiletools.gallery.pro.extensions.* @@ -75,6 +87,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList copyMoveTo(true) R.id.cab_move_to -> moveFilesTo() R.id.cab_select_all -> selectAll() + R.id.cab_create_shortcut -> createShortcut() R.id.cab_delete -> askConfirmDelete() R.id.cab_select_photo -> changeAlbumCover(false) R.id.cab_use_default -> changeAlbumCover(true) @@ -340,6 +355,56 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Unit) { + Thread { + val options = RequestOptions() + .format(DecodeFormat.PREFER_ARGB_8888) + .skipMemoryCache(true) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .fitCenter() + + val size = activity.resources.getDimension(R.dimen.shortcut_size).toInt() + val builder = Glide.with(activity) + .asDrawable() + .load(tmb) + .apply(options) + .centerCrop() + .into(size, size) + + try { + (drawable as LayerDrawable).setDrawableByLayerId(R.id.shortcut_image, builder.get()) + } catch (e: Exception) { + } + + activity.runOnUiThread { + callback() + } + }.start() + } + private fun askConfirmDelete() { when { config.isDeletePasswordProtectionOn -> activity.handleDeletePasswordProtection { diff --git a/app/src/main/res/drawable/shortcut_image.xml b/app/src/main/res/drawable/shortcut_image.xml new file mode 100644 index 000000000..20dde1a45 --- /dev/null +++ b/app/src/main/res/drawable/shortcut_image.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/app/src/main/res/menu/cab_directories.xml b/app/src/main/res/menu/cab_directories.xml index e2e19a58b..64e9cdc4d 100644 --- a/app/src/main/res/menu/cab_directories.xml +++ b/app/src/main/res/menu/cab_directories.xml @@ -61,6 +61,10 @@ android:icon="@drawable/ic_select_all" android:title="@string/select_all" app:showAsAction="ifRoom"/> +