use Picasso for loading fullscreen images

This commit is contained in:
tibbi 2017-03-17 19:46:44 +01:00
parent a6622ef9e3
commit 6a97a47d76
5 changed files with 14 additions and 28 deletions

View file

@ -38,6 +38,7 @@ dependencies {
compile 'com.google.code.gson:gson:2.8.0' compile 'com.google.code.gson:gson:2.8.0'
compile 'com.github.chrisbanes:PhotoView:1.3.1' compile 'com.github.chrisbanes:PhotoView:1.3.1'
compile 'it.sephiroth.android.exif:library:1.0.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" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
} }

View file

@ -1,19 +1,2 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in $ANDROID_HOME/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class com.simplemobiletools.** { *; } -keep class com.simplemobiletools.** { *; }
-dontwarn com.simplemobiletools.** -dontwarn com.simplemobiletools.**

View file

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

View file

@ -6,19 +6,20 @@ import android.graphics.BitmapFactory
import android.graphics.Matrix import android.graphics.Matrix
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.simplemobiletools.gallery.extensions.getRealPathFromURI
import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import com.squareup.picasso.Picasso
import it.sephiroth.android.library.exif2.ExifInterface import it.sephiroth.android.library.exif2.ExifInterface
import kotlinx.android.synthetic.main.pager_photo_item.view.* import kotlinx.android.synthetic.main.pager_photo_item.view.*
import uk.co.senab.photoview.PhotoViewAttacher import uk.co.senab.photoview.PhotoViewAttacher
@ -118,6 +119,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() { private fun loadImage() {
if (medium.isGif()) { if (medium.isGif()) {
view.photo_view.beGone() view.photo_view.beGone()
view.gif_holder.beVisible()
Glide.with(this) Glide.with(this)
.load(medium.path) .load(medium.path)
.asGif() .asGif()
@ -130,13 +132,12 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun loadBitmap(degrees: Float = 0f) { private fun loadBitmap(degrees: Float = 0f) {
Glide.with(this) val metrics = DisplayMetrics()
.load(medium.path) activity.windowManager.defaultDisplay.getMetrics(metrics)
.asBitmap() Picasso.with(activity)
.transform(GlideRotateTransformation(context, degrees)) .load("file:${medium.path}")
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565) .resize(metrics.widthPixels * 2, metrics.heightPixels * 2)
.thumbnail(0.2f) .centerInside()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(view.photo_view) .into(view.photo_view)
} }
@ -146,7 +147,6 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
Glide.clear(view.photo_view)
Glide.clear(view.gif_holder) Glide.clear(view.gif_holder)
} }

View file

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