replace Picasso with Glide everywhere once again

This commit is contained in:
tibbi 2017-03-18 21:57:49 +01:00
parent d277dee1b9
commit a150e5da04
10 changed files with 39 additions and 84 deletions

View file

@ -32,13 +32,12 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.13.3'
compile 'com.simplemobiletools:commons:2.13.4'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.github.chrisbanes:PhotoView:1.3.1'
compile 'it.sephiroth.android.exif:library:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

View file

@ -4,13 +4,11 @@ import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.support.v4.app.ActivityCompat
import android.support.v7.widget.GridLayoutManager
import android.util.DisplayMetrics
import android.view.Menu
import android.view.MenuItem
import com.google.gson.Gson
@ -52,14 +50,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
companion object {
var thumbnailSize = 0
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
updateThumbnailSize()
mIsPickImageIntent = isPickImageIntent(intent)
mIsPickVideoIntent = isPickVideoIntent(intent)
@ -124,17 +117,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
config.isFirstRun = false
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
updateThumbnailSize()
}
private fun updateThumbnailSize() {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
thumbnailSize = metrics.widthPixels / config.dirColumnCnt
}
private fun tryloadGallery() {
if (hasWriteStoragePermission()) {
if (config.showAll)
@ -235,13 +217,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun increaseColumnCount() {
config.dirColumnCnt = ++(directories_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailSize()
}
private fun reduceColumnCount() {
config.dirColumnCnt = --(directories_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailSize()
}
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))

View file

@ -3,12 +3,10 @@ package com.simplemobiletools.gallery.activities
import android.app.Activity
import android.app.WallpaperManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.util.DisplayMetrics
import android.util.Log
import android.view.Menu
import android.view.MenuItem
@ -48,10 +46,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private var mLoadedInitialPhotos = false
private var mStoredAnimateGifs = true
companion object {
var thumbnailSize = 0
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_media)
@ -61,7 +55,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false)
}
updateThumbnailSize()
media_refresh_layout.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY)
mStoredAnimateGifs = config.animateGifs
@ -97,17 +90,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
updateThumbnailSize()
}
private fun updateThumbnailSize() {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
thumbnailSize = metrics.widthPixels / config.mediaColumnCnt
}
private fun initializeGallery() {
if (isDirEmpty())
return
@ -277,13 +259,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun increaseColumnCount() {
config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailSize()
}
private fun reduceColumnCount() {
config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailSize()
}
override fun deleteFiles(files: ArrayList<File>) {

View file

@ -182,6 +182,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) {
view_pager?.apply {
offscreenPageLimit = 2
adapter = pagerAdapter
currentItem = mPos
addOnPageChangeListener(this@ViewPagerActivity)

View file

@ -18,7 +18,6 @@ import com.simplemobiletools.commons.extensions.isImageVideoGif
import com.simplemobiletools.commons.extensions.needsStupidWritePermissions
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.MainActivity
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
@ -330,7 +329,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
photo_cnt.text = directory.mediaCnt.toString()
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
toggleItemSelection(this, markedItems.contains(pos), pos)
activity.loadImage(directory.thumbnail, MainActivity.thumbnailSize, dir_thumbnail)
activity.loadImage(directory.thumbnail, dir_thumbnail)
setOnClickListener { viewClicked(multiSelector, directory, pos) }
setOnLongClickListener {

View file

@ -245,7 +245,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
photo_name.beVisibleIf(displayFilenames)
photo_name.text = medium.name
toggleItemSelection(this, markedItems.contains(pos), pos)
activity.loadImage(medium.path, MediaActivity.thumbnailSize, medium_thumbnail)
activity.loadImage(medium.path, medium_thumbnail)
setOnClickListener { viewClicked(multiSelector, medium, pos) }
setOnLongClickListener {

View file

@ -11,6 +11,7 @@ import android.view.KeyEvent
import android.view.View
import android.view.ViewConfiguration
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -23,7 +24,6 @@ import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER
import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.views.MySquareImageView
import com.squareup.picasso.Picasso
import java.io.File
import java.util.*
@ -139,7 +139,7 @@ fun Activity.hasNavBar(): Boolean {
fun SimpleActivity.launchAbout() {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL
or LICENSE_PHOTOVIEW or LICENSE_PICASSO, BuildConfig.VERSION_NAME)
or LICENSE_PHOTOVIEW, BuildConfig.VERSION_NAME)
}
fun AppCompatActivity.showSystemUI() {
@ -186,20 +186,24 @@ fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) {
}
}
fun Activity.loadImage(path: String, size: Int, target: MySquareImageView) {
if (path.isImageFast()) {
Picasso.with(this)
.load("file:$path")
.resize(size, size)
fun Activity.loadImage(path: String, target: MySquareImageView) {
if (path.isImageFast() || path.isVideoFast()) {
if (path.isPng()) {
Glide.with(this)
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.format(DecodeFormat.PREFER_ARGB_8888)
.centerCrop()
.into(target)
} else if (path.isVideoFast()) {
} else {
Glide.with(this)
.load(path)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.centerCrop()
.crossFade()
.into(target)
}
} else if (path.isGif()) {
if (MediaAdapter.animateGifs) {
Glide.with(this)

View file

@ -11,16 +11,14 @@ import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.extensions.getRealPathFromURI
import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium
import com.squareup.picasso.Picasso
import it.sephiroth.android.library.exif2.ExifInterface
import kotlinx.android.synthetic.main.pager_photo_item.view.*
import uk.co.senab.photoview.PhotoViewAttacher
@ -32,6 +30,7 @@ class PhotoFragment : ViewPagerFragment() {
lateinit var medium: Medium
lateinit var view: ViewGroup
private var isFragmentVisible = false
private var wasInit = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
view = inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup
@ -73,7 +72,6 @@ class PhotoFragment : ViewPagerFragment() {
}
}
view.gif_holder.setOnClickListener { photoClicked() }
view.photo_view.setOnPhotoTapListener(object : PhotoViewAttacher.OnPhotoTapListener {
override fun onPhotoTap(view: View?, x: Float, y: Float) {
photoClicked()
@ -88,6 +86,7 @@ class PhotoFragment : ViewPagerFragment() {
activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
listener?.systemUiVisibilityChanged(visibility)
}
wasInit = true
return view
}
@ -119,28 +118,26 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() {
if (medium.isGif()) {
view.photo_view.beGone()
view.gif_holder.beVisible()
Glide.with(this)
.load(medium.path)
.asGif()
.crossFade()
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(view.gif_holder)
.into(view.photo_view)
} else {
loadBitmap()
}
}
private fun loadBitmap(degrees: Float = 0f) {
val density = ViewPagerActivity.screenDensity
Picasso.with(activity)
.load("file:${medium.path}")
.resize((ViewPagerActivity.screenWidth * density).toInt(), (ViewPagerActivity.screenHeight * density).toInt())
.priority(if (isFragmentVisible) Picasso.Priority.HIGH else Picasso.Priority.LOW)
.rotate(degrees)
.centerInside()
Glide.with(this)
.load(medium.path)
.asBitmap()
.transform(GlideRotateTransformation(context, degrees))
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
.thumbnail(0.1f)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(view.photo_view)
}
@ -150,7 +147,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() {
super.onDestroyView()
Glide.clear(view.gif_holder)
Glide.clear(view.photo_view)
}
override fun onConfigurationChanged(newConfig: Configuration?) {

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.models
import com.simplemobiletools.commons.extensions.isGif
import com.simplemobiletools.commons.extensions.isPng
import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.gallery.helpers.SORT_BY_NAME
import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE
@ -15,7 +16,7 @@ data class Medium(val name: String, var path: String, val isVideo: Boolean, val
fun isGif() = path.isGif()
fun isPng() = path.endsWith(".png", true)
fun isPng() = path.isPng()
fun isImage() = !isGif() && !isVideo

View file

@ -5,12 +5,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/gif_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<uk.co.senab.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"