Skip to content

Commit

Permalink
Try to solve crashes while scrolling through details.
Browse files Browse the repository at this point in the history
Added calls to holder.mMapView.onDetach(), to avoid java.lang.IllegalStateException: Too many receivers, total of 1000 at matchentries.MatchesRecyclerViewAdapter.onCreateViewHolder
  • Loading branch information
mh- committed Jan 9, 2022
1 parent da6331c commit 3611e80
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
Expand Down Expand Up @@ -118,16 +117,27 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
}

@Override
public void onViewDetachedFromWindow(ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
super.onViewDetachedFromWindow(holder);
holder.mMapView.onDetach();
}

holder.mMapView.onPause();
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
super.onViewRecycled(holder);
holder.mMapView.onDetach();
}

@Override
public void onViewAttachedToWindow(ViewHolder holder) {
super.onViewAttachedToWindow(holder);
public boolean onFailedToRecycleView(@NonNull ViewHolder holder) {
boolean result = super.onFailedToRecycleView(holder);
holder.mMapView.onDetach();
return result;
}

@Override
public void onViewAttachedToWindow(@NonNull ViewHolder holder) {
super.onViewAttachedToWindow(holder);
holder.mMapView.onResume();
}

Expand Down Expand Up @@ -713,14 +723,11 @@ public ViewHolder(View view, boolean showMap, Context context) {
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.getZoomController().setVisibility(Visibility.ALWAYS);
mMapView.setMultiTouchControls(true);
mMapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Don't allow scrolling in map for simplicity and consistency.
// To support vertical scrolling, we would have to create
// a custom MapView that overrides RecyclerView scrolling.
return true;
}
mMapView.setOnTouchListener((v, event) -> {
// Don't allow scrolling in map for simplicity and consistency.
// To support vertical scrolling, we would have to create
// a custom MapView that overrides RecyclerView scrolling.
return true;
});
}
else {
Expand All @@ -735,11 +742,13 @@ public String toString() {
}
}

@SuppressLint("NotifyDataSetChanged")
public void toggleShowAllScans() {
this.showAllScans = !this.showAllScans;
this.notifyDataSetChanged();
}

@SuppressLint("NotifyDataSetChanged")
public void toggleShowMap() {
this.mapDisplayAllowed = !this.mapDisplayAllowed;
this.notifyDataSetChanged();
Expand Down

0 comments on commit 3611e80

Please sign in to comment.