protected <TYPE extends AbstractModel> TYPE returnFetchResult(Class<TYPE> modelClass, SquidCursor<TYPE> cursor) { try { if (cursor.getCount() == 0) { return null; } TYPE toReturn = modelClass.newInstance(); toReturn.readPropertiesFromCursor(cursor); return toReturn; } catch (Exception e) { throw new RuntimeException(e); } finally { cursor.close(); } }
/** * Get a model instance representing the item at the specified position. The object returned by this method is a * singleton/shared instance. If you do this: * * <pre> * Model item0 = getItem(0); * Model item1 = getItem(1); * </pre> * * Then item0 and item1 will be the same object with the same values (those at position 1). We recommend you not * call getItem() outside of {@link #getView(int, android.view.View, android.view.ViewGroup) getView()} or on * different positions in the same method scope, and definitely don't call it from other threads. If you do need a * non-shared instance, you can clone the object returned by this method. * * @return the model object at the specified cursor position */ @Override public T getItem(int position) { if (this.cursor == null) { return null; } cursor.moveToPosition(position); model.readPropertiesFromCursor(cursor); return model; }
@Override public void onBindViewHolder(V holder, int position) { if (cursor == null || !cursor.moveToPosition(position)) { throw new IllegalStateException("this should only be called when the cursor is valid"); } holder.item.readPropertiesFromCursor(cursor); onBindSquidViewHolder(holder, position); }
protected <TYPE extends AbstractModel> TYPE returnFetchResult(Class<TYPE> modelClass, SquidCursor<TYPE> cursor) { try { if (cursor.getCount() == 0) { return null; } TYPE toReturn = modelClass.newInstance(); toReturn.readPropertiesFromCursor(cursor); return toReturn; } catch (Exception e) { throw new RuntimeException(e); } finally { cursor.close(); } }