diff --git a/app/build.gradle b/app/build.gradle index 745a0145b..fce7af01f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index ed8b8446f..1ef92b6ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -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)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 8e52c7a3a..879c26d3a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 8941b48b1..51ae9a320 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 48d8e64d8..302998bdf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -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, 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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 564dde3a0..93f4d8279 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -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) - .centerCrop() - .into(target) - } else if (path.isVideoFast()) { - Glide.with(this) - .load(path) - .diskCacheStrategy(DiskCacheStrategy.RESULT) - .centerCrop() - .crossFade() - .into(target) +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 { + Glide.with(this) + .load(path) + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .centerCrop() + .crossFade() + .into(target) + } } else if (path.isGif()) { if (MediaAdapter.animateGifs) { Glide.with(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 5b6922a14..2ece5dbf4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -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?) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 368816b69..258e12e42 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -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 diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index a3b004a57..056e8b81a 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -5,12 +5,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - -