Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/gc issue #419

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.esafirm.imagepicker.R
import com.esafirm.imagepicker.helper.getImageSize
import com.esafirm.imagepicker.model.Image

class DefaultImageLoader : ImageLoader {
override fun loadImage(image: Image, imageView: ImageView, imageType: ImageType) {
Glide.with(imageView.context)
.load(image.uri)
.override(imageView.context.getImageSize())
.apply(RequestOptions
.placeholderOf(if (imageType == ImageType.FOLDER) R.drawable.ef_folder_placeholder else R.drawable.ef_image_placeholder)
.error(if (imageType == ImageType.FOLDER) R.drawable.ef_folder_placeholder else R.drawable.ef_image_placeholder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import androidx.recyclerview.widget.RecyclerView
import com.esafirm.imagepicker.R
import com.esafirm.imagepicker.adapter.FolderPickerAdapter
import com.esafirm.imagepicker.adapter.ImagePickerAdapter
import com.esafirm.imagepicker.features.ImagePickerComponentsHolder
import com.esafirm.imagepicker.features.ImagePickerConfig
import com.esafirm.imagepicker.features.ImagePickerMode
import com.esafirm.imagepicker.features.IpCons
import com.esafirm.imagepicker.features.ReturnMode
import com.esafirm.imagepicker.features.*
import com.esafirm.imagepicker.helper.ConfigUtils
import com.esafirm.imagepicker.helper.getRecyclerViewColumn
import com.esafirm.imagepicker.listeners.OnFolderClickListener
import com.esafirm.imagepicker.listeners.OnImageClickListener
import com.esafirm.imagepicker.listeners.OnImageSelectedListener
Expand Down Expand Up @@ -56,7 +53,7 @@ class RecyclerViewManager(
* Set item size, column size base on the screen orientation
*/
fun changeOrientation(orientation: Int) {
imageColumns = if (orientation == Configuration.ORIENTATION_PORTRAIT) 3 else 5
imageColumns = context.getRecyclerViewColumn()
folderColumns = if (orientation == Configuration.ORIENTATION_PORTRAIT) 2 else 4
val shouldShowFolder = config.isFolderMode && isDisplayingFolderView
val columns = if (shouldShowFolder) folderColumns else imageColumns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
package com.esafirm.imagepicker.helper

import android.content.Context
import android.content.res.Configuration
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.View
import androidx.core.content.ContextCompat
import com.esafirm.imagepicker.R


const val GRID_3 = 3
const val GRID_5 = 5

object ViewUtils {
fun getArrowIcon(context: Context): Drawable? {
val backResourceId: Int = if (Build.VERSION.SDK_INT >= 17 && context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
// For right-to-left layouts, pick the drawable that points to the right (forward).
R.drawable.ef_ic_arrow_forward
} else {
// For left-to-right layouts, pick the drawable that points to the left (back).
R.drawable.ef_ic_arrow_back
}
val backResourceId: Int =
if (Build.VERSION.SDK_INT >= 17 && context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
// For right-to-left layouts, pick the drawable that points to the right (forward).
R.drawable.ef_ic_arrow_forward
} else {
// For left-to-right layouts, pick the drawable that points to the left (back).
R.drawable.ef_ic_arrow_back
}
return ContextCompat.getDrawable(context.applicationContext, backResourceId)
}
}

fun Context.getImageSize(): Int {
return this.resources.displayMetrics.widthPixels / getRecyclerViewColumn()
}

fun Context.getRecyclerViewColumn(): Int {
val orientation = this.resources.configuration.orientation
return if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
// In landscape
GRID_5
} else {
// In portrait
GRID_3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.esafirm.imagepicker.features.imageloader.ImageLoader
import com.esafirm.imagepicker.features.imageloader.ImageType
import com.esafirm.imagepicker.helper.getImageSize
import com.esafirm.imagepicker.model.Image

class GrayscaleImageLoader : ImageLoader {
override fun loadImage(image: Image, imageView: ImageView, imageType: ImageType) {
Glide.with(imageView)
.asBitmap()
.load(image.path)
.override(imageView.context.getImageSize())
.transition(BitmapTransitionOptions.withCrossFade())
.apply(REQUEST_OPTIONS)
.into(imageView)
Expand Down