Skip to content

Instantly share code, notes, and snippets.

@cornwe19
Created August 15, 2014 16:27
Show Gist options
  • Save cornwe19/6be23fde488c577691d3 to your computer and use it in GitHub Desktop.
Save cornwe19/6be23fde488c577691d3 to your computer and use it in GitHub Desktop.
Temporarily masks the indices of deleted items from a source cursor
package com.techsmith.utilities;
import android.database.AbstractCursor;
import android.database.Cursor;
public class IndexMaskingCursor extends AbstractCursor {
private final Cursor mCursor;
private final int[] mMaskedPositions;
public MaskingCursor( Cursor cursor, int[] maskedPositions ) {
mCursor = cursor;
mMaskedPositions = maskedPositions;
}
@Override
public int getCount() {
return mCursor.getCount() - mMaskedPositions.length;
}
@Override
public String[] getColumnNames() {
return mCursor.getColumnNames();
}
@Override
public String getString( int i ) {
return mCursor.getString( i );
}
@Override
public short getShort( int i ) {
return mCursor.getShort( i );
}
@Override
public int getInt( int i ) {
return mCursor.getInt( i );
}
@Override
public long getLong( int i ) {
return mCursor.getLong( i );
}
@Override
public float getFloat( int i ) {
return mCursor.getFloat( i );
}
@Override
public double getDouble( int i ) {
return mCursor.getDouble( i );
}
@Override
public boolean isNull( int i ) {
return mCursor.isNull( i );
}
@Override
public boolean onMove( int oldPosition, int newPosition ) {
int offset = 0;
for ( int position : mMaskedPositions ) {
if ( newPosition >= position ) {
offset++;
}
}
return mCursor.moveToPosition( newPosition + offset );
}
@Override
public void close() {
mCursor.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment