moving the shortcut image getter to an activity extension
This commit is contained in:
parent
e1834343fa
commit
df0dda96dd
2 changed files with 35 additions and 35 deletions
|
@ -4,16 +4,11 @@ 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
|
||||
|
@ -362,7 +357,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
val dir = getFirstSelectedItem() ?: return
|
||||
val path = dir.path
|
||||
val drawable = resources.getDrawable(R.drawable.shortcut_image).mutate()
|
||||
getShortcutImage(dir.tmb, drawable) {
|
||||
activity.getShortcutImage(dir.tmb, drawable) {
|
||||
val intent = Intent(activity, MediaActivity::class.java)
|
||||
intent.action = Intent.ACTION_VIEW
|
||||
intent.putExtra(DIRECTORY, path)
|
||||
|
@ -378,33 +373,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
}
|
||||
}
|
||||
|
||||
private fun getShortcutImage(tmb: String, drawable: Drawable, callback: () -> 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 {
|
||||
|
|
|
@ -7,6 +7,8 @@ import android.content.Intent
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.media.ExifInterface
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
|
@ -14,6 +16,9 @@ import android.util.DisplayMetrics
|
|||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -255,7 +260,7 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, mediumDa
|
|||
var out: OutputStream? = null
|
||||
try {
|
||||
out = getFileOutputStreamSync(destination, source.getMimeType())
|
||||
inputStream = getFileInputStreamSync(source)!!
|
||||
inputStream = getFileInputStreamSync(source)
|
||||
inputStream.copyTo(out!!)
|
||||
if (File(source).length() == File(destination).length()) {
|
||||
mediumDao.updateDeleted(destination.removePrefix(recycleBinPath), 0, "$RECYCLE_BIN$destination")
|
||||
|
@ -478,7 +483,7 @@ fun BaseSimpleActivity.copyFile(source: String, destination: String) {
|
|||
try {
|
||||
out = getFileOutputStreamSync(destination, source.getMimeType())
|
||||
inputStream = getFileInputStreamSync(source)
|
||||
inputStream?.copyTo(out!!)
|
||||
inputStream.copyTo(out!!)
|
||||
} finally {
|
||||
inputStream?.close()
|
||||
out?.close()
|
||||
|
@ -491,3 +496,30 @@ fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int)
|
|||
val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
||||
bmp.compress(path.getCompressionFormat(), 90, out)
|
||||
}
|
||||
|
||||
fun Activity.getShortcutImage(tmb: String, drawable: Drawable, callback: () -> Unit) {
|
||||
Thread {
|
||||
val options = RequestOptions()
|
||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||
.skipMemoryCache(true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.fitCenter()
|
||||
|
||||
val size = resources.getDimension(R.dimen.shortcut_size).toInt()
|
||||
val builder = Glide.with(this)
|
||||
.asDrawable()
|
||||
.load(tmb)
|
||||
.apply(options)
|
||||
.centerCrop()
|
||||
.into(size, size)
|
||||
|
||||
try {
|
||||
(drawable as LayerDrawable).setDrawableByLayerId(R.id.shortcut_image, builder.get())
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
callback()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue