{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/601","labels_url":"https://api.github.com/repos/bumptech/glide/issues/601/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/601/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/601/events","html_url":"https://github.com/bumptech/glide/issues/601","id":103650923,"number":601,"title":"Wrong images being loaded in Recycler View's grid on Some devices","user":{"login":"gauravlnx","id":3042207,"avatar_url":"https://avatars.githubusercontent.com/u/3042207?v=3","gravatar_id":"","url":"https://api.github.com/users/gauravlnx","html_url":"https://github.com/gauravlnx","followers_url":"https://api.github.com/users/gauravlnx/followers","following_url":"https://api.github.com/users/gauravlnx/following{/other_user}","gists_url":"https://api.github.com/users/gauravlnx/gists{/gist_id}","starred_url":"https://api.github.com/users/gauravlnx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gauravlnx/subscriptions","organizations_url":"https://api.github.com/users/gauravlnx/orgs","repos_url":"https://api.github.com/users/gauravlnx/repos","events_url":"https://api.github.com/users/gauravlnx/events{/privacy}","received_events_url":"https://api.github.com/users/gauravlnx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-08-28T05:31:57Z","updated_at":"2015-08-29T10:44:50Z","closed_at":null,"body":"In my app, I have a Recycler view with GridLayoutManager. The code I am using to load images bindImage method of recycler view adapter:\r\n\r\n     @Override\r\n        public void onBindViewHolder(ImageViewHolder holder, int position) {\r\n            GSImage dbImage = mLandscapeImagesList.get(position);\r\n            File imageFile = new File(mImageDirectoryFile, dbImage.getImageName());\r\n\r\n      Glide.with(MyImageFragement.this).load(imageFile).centerCrop().into(holder.imageView);\r\n\r\n            int indexInSelectedImagesSet = mSelectedLandscapeImages.indexOf(dbImage);\r\n            if (indexInSelectedImagesSet>-1){\r\n                holder.itemView.setSelected(true);\r\n            }else {\r\n                holder.itemView.setSelected(false);\r\n            }\r\n\r\n        }\r\n\r\nThe Cell layout I am using is:\r\n\r\n    <?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n    <RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\r\n         xmlns:app=\"http://schemas.android.com/apk/res-auto\"\r\n          android:layout_width=\"wrap_content\"\r\n          android:layout_height=\"wrap_content\"\r\n          android:background=\"@drawable/images_background\"\r\n          android:layout_marginTop=\"9dp\"\r\n          android:layout_marginLeft=\"10dp\"\r\n          android:layout_marginRight=\"0dp\"\r\n          android:layout_marginBottom=\"0dp\"\r\n          android:padding=\"2dp\">\r\n\r\n          <com.gaurav.myProject.commons.AspectRatioImageView\r\n                     android:id=\"@+id/image_thumb\"\r\n                     android:layout_width=\"match_parent\"\r\n                     android:layout_height=\"wrap_content\"\r\n                     android:scaleType=\"fitXY\"\r\n                     app:viewAspectRatio=\"1.33\"/>\r\n\r\n    </RelativeLayout>\r\n\r\nHere AspectRatioImageView(subclass of ImageView) automatically resizes the height of image view according to the provided aspect ratio.\r\n\r\nThe above code is working fine on my devices (Xiaomi MiPad, ViewSonic Tablet, Android emaulators and Samsung Galaxy S3) but is not working correctly on my client's device (Samsung 10.1 inch tablet).\r\nIn his end, images are being duplicated in the recycler grid. Also the the duplicates mostly occurs in adjacent recycler grid positions. I can't share any code as I even unable to reproduce the issue on my devices. \r\n\r\nDo you guys have any idea what could the cause of this? Can you please suggest me any thing that I can try?\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/135970091","html_url":"https://github.com/bumptech/glide/issues/601#issuecomment-135970091","issue_url":"https://api.github.com/repos/bumptech/glide/issues/601","id":135970091,"user":{"login":"TWiStErRob","id":2906988,"avatar_url":"https://avatars.githubusercontent.com/u/2906988?v=3","gravatar_id":"","url":"https://api.github.com/users/TWiStErRob","html_url":"https://github.com/TWiStErRob","followers_url":"https://api.github.com/users/TWiStErRob/followers","following_url":"https://api.github.com/users/TWiStErRob/following{/other_user}","gists_url":"https://api.github.com/users/TWiStErRob/gists{/gist_id}","starred_url":"https://api.github.com/users/TWiStErRob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TWiStErRob/subscriptions","organizations_url":"https://api.github.com/users/TWiStErRob/orgs","repos_url":"https://api.github.com/users/TWiStErRob/repos","events_url":"https://api.github.com/users/TWiStErRob/events{/privacy}","received_events_url":"https://api.github.com/users/TWiStErRob/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T10:44:50Z","updated_at":"2015-08-29T10:44:50Z","body":"Which method do you use to notify the adapter?\r\n\r\n> My SaveImageTask works just like this.\r\n\r\nThat debunks my theory :( it sounded convincing though. I'm out of ideas. @sjudd, anything to add?\r\n\r\n> All the videos that I have seen about this issue looked like are produced using small images.\r\n\r\nAnother idea to consistently reproduce this is to put a `Thread.sleep(500);` at the end of `onBindViewHolder` so a lot of Glide requests can be finished in the background. Also whenever you try to reproduce timing issues, make sure you don't use Debug mode, the debugging overhead may hide the issue; I usually use just logging to see the order of execution.\r\n\r\n> So SimpleTarget could be the problem here?\r\n\r\n`onResourceReady` is called on the UI thread too so it is ordered. Maybe RecyclerView doesn't like multiple quick inserts, however I checked the sources and didn't see anything that would warrant this behavior. Are you using the latest support libs (22.2.1 or 23.0.0)?\r\n\r\nI remembered the `asBytes()` syntax incorrectly, here's what I meant:\r\n```java\r\nIOTools.writeAllBytes(fileInImageDirectory, Glide\r\n\t\t.with(this)\r\n\t\t.load(sourceUri) // can be a random content Uri too held in Intent.getData()\r\n\t\t.asBitmap()\r\n\t\t.toBytes(CompressFormat.JPEG, 80) // forwarded to Bitmap.compress\r\n\t\t.diskCacheStrategy(DiskCacheStrategy.NONE) // no point in caching because it's saved to a File anyway\r\n\t\t.skipMemoryCache(true) // make sure to re-read if original image changed\r\n\t\t.atMost() // together with into() no image dimension will be bigger than the requested max\r\n\t\t.into(2048, 2048) // both the same, but aspect will be kept\r\n\t\t.get() // makes the Glide call sync, but has to be called on a background thread\r\n);\r\npublishProgress(fileInImageDirectory);\r\n```\r\nI use something like this myself to load user picked content from Gallery (or any other external app)."}}