clockbyte / admobadapter

It wraps your Adapter to display Admob native ads and banners in a ListView/RecyclerView data set. It based on the Yahoo fetchr project https://github.com/yahoo/fetchr
Apache License 2.0
236 stars 75 forks source link

Wrong position of recyclerview items #49

Closed gssinghgautam closed 7 years ago

gssinghgautam commented 7 years ago

when ads are not loading in recyclerview the position of the item on click is wrong ..its not giving me the correct value

kot331107 commented 7 years ago

@gssinghgautam We'll check it a bit later and return back to you...

gssinghgautam commented 7 years ago

can you please check the error, why its giving wrong position when ads are not visible

aa-contorra commented 7 years ago

@gssinghgautam I'm also facing same issue when trying to get pos like this https://github.com/clockbyte/admobadapter/wiki/Cookbook#in-case-you-stucked-with-getting-the-correct-itemindex-of-a-source-collection-in-a-listviewrecyclerview-click-handler so it's look like method getOriginalContentPosition() works wrong. You can use this workaround:

int fetchedAdsCnt = adapterWrapper.getFetchedAdsCount();
int originalPos; 
  if (fetchedAdsCnt > 0) {\\we have some ads, need to use adapterCalc's method
      int sourceCnt = adapterWrapper.getAdapter().getCount();
      originalPos = adapterCalc.getOriginalContentPosition(position, fetchedAdsCnt, sourceCnt);
  } else { \\no ads, can use orignal pos
      originalPos = pos; \\if you are in onItemClick() method of ListView
     \\ originalPos = holder.getAdapterPosition(); \\ if you are in setOnClickListener of your RecycleView
  }
kot331107 commented 7 years ago

@aa-contorra hi,

thx a lot for your contribution, we will include a fix for the getOriginalContentPosition() according to this issue to the next maven release. Guys sorry for slow reaction, I haven't much time to support this lib at the moment.

KR

aa-contorra commented 7 years ago

also there is another bug here: while ads loading method getFetchedAdsCount() returns same value as for "no ads loaded" case, but adapter has placeholers with "ad id loading" text, so it's no way to get proper index of clicked element. Also it casuses IndexOfBounds exception in some cases...

kot331107 commented 7 years ago

@aa-contorra I'm afraid at the moment you'd change the source of AdapterWrapper class a bit. Add the new method public int getFetchingAdsCount(){ return adFetcher.getFetchingAdsCount();} to AdapterWrapper and try to use it instead. It returns a size taking into account placeholders for ads...

gssinghgautam commented 7 years ago

the workaround suggested by kot331107 is working fine

aimiliano commented 7 years ago

i suppose this is the same ? :

Exception java.lang.ArrayIndexOutOfBoundsException: length=36; index=36 android.widget.AbsListView$RecycleBin.addScrapView (AbsListView.java:8362) android.widget.AbsListView.trackMotionScroll (AbsListView.java:6684) android.widget.AbsListView$FlingRunnable.run (AbsListView.java:5750) android.view.Choreographer$CallbackRecord.run (Choreographer.java:803) android.view.Choreographer.doCallbacks (Choreographer.java:603) android.view.Choreographer.doFrame (Choreographer.java:572) android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:789) android.os.Handler.handleCallback (Handler.java:733) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:136) android.app.ActivityThread.main (ActivityThread.java:5476) java.lang.reflect.Method.invokeNative (Method.java) java.lang.reflect.Method.invoke (Method.java:515) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099) dalvik.system.NativeStart.main (NativeStart.java)

kot331107 commented 7 years ago

@aimiliano don't think so. Please open a separate issue for that.

kot331107 commented 7 years ago

Guys, I've updated wiki https://github.com/clockbyte/admobadapter/wiki/Cookbook#in-case-you-stucked-with-getting-the-correct-itemindex-of-a-source-collection-in-a-listviewrecyclerview-click-handler and released https://github.com/clockbyte/admobadapter/releases/tag/v1.3.1 containing a workaround for this issue.

Up: also it's now available at maven-central as 1.3.1