Search in sources :

Example 1 with Attachment

use of ve.com.abicelis.remindy.model.attachment.Attachment in project Remindy by abicelis.

the class RemindyDAO method insertAttachmentsOfTask.

/**
     * Inserts a List of Attachments associated to an Task, into the database.
     * @param taskId The id of the Task associated to the Attachments
     * @param attachments The List of Attachments to be inserted
     */
public long[] insertAttachmentsOfTask(int taskId, List<Attachment> attachments) throws CouldNotInsertDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    long[] newRowIds = new long[attachments.size()];
    for (int i = 0; i < attachments.size(); i++) {
        Attachment attachment = attachments.get(i);
        attachment.setTaskId(taskId);
        ContentValues values = getValuesFromAttachment(attachment);
        newRowIds[i] = db.insert(RemindyContract.AttachmentTable.TABLE_NAME, null, values);
        if (newRowIds[i] == -1)
            throw new CouldNotInsertDataException("There was a problem inserting the Attachment: " + attachments.toString());
    }
    return newRowIds;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 2 with Attachment

use of ve.com.abicelis.remindy.model.attachment.Attachment in project Remindy by abicelis.

the class AttachmentAdapter method deleteAttachment.

public void deleteAttachment(int position) {
    //Called from viewHolders when deleting an attachment
    Attachment attachment = mAttachments.get(position);
    switch(attachment.getType()) {
        case AUDIO:
            String audioFilename = ((AudioAttachment) attachment).getAudioFilename();
            FileUtil.deleteAudioAttachment(mActivity, audioFilename);
            break;
        case IMAGE:
            String imageFilename = ((ImageAttachment) attachment).getImageFilename();
            FileUtil.deleteImageAttachment(mActivity, imageFilename);
    }
    mAttachments.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, getItemCount());
    if (mRealTimeDataPersistence) {
        triggerAttachmentDataUpdatedListener();
    }
}
Also used : AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 3 with Attachment

use of ve.com.abicelis.remindy.model.attachment.Attachment in project Remindy by abicelis.

the class AttachmentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    Attachment current = mAttachments.get(position);
    switch(current.getType()) {
        case TEXT:
            TextAttachmentViewHolder tvh = (TextAttachmentViewHolder) holder;
            tvh.setData(this, mActivity, (TextAttachment) current, position, mRealTimeDataPersistence);
            tvh.setListeners();
            break;
        case LIST:
            ListAttachmentViewHolder listvh = (ListAttachmentViewHolder) holder;
            listvh.setData(this, mActivity, (ListAttachment) current, position, mRealTimeDataPersistence);
            listvh.setListeners();
            break;
        case LINK:
            LinkAttachmentViewHolder lvh = (LinkAttachmentViewHolder) holder;
            lvh.setData(this, mActivity, (LinkAttachment) current, position, mRealTimeDataPersistence);
            lvh.setListeners();
            break;
        case AUDIO:
            AudioAttachmentViewHolder avh = (AudioAttachmentViewHolder) holder;
            avh.setData(this, mActivity, (AudioAttachment) current, position, mRealTimeDataPersistence);
            //avh.setListeners();
            break;
        case IMAGE:
            ImageAttachmentViewHolder ivh = (ImageAttachmentViewHolder) holder;
            ivh.setData(this, mActivity, (ImageAttachment) current, position, mRealTimeDataPersistence);
            ivh.setListeners();
            break;
        default:
            throw new InvalidParameterException("Wrong viewType passed to onCreateViewHolder in AttachmentAdapter");
    }
}
Also used : LinkAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.LinkAttachmentViewHolder) InvalidParameterException(java.security.InvalidParameterException) ImageAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.ImageAttachmentViewHolder) ListAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.ListAttachmentViewHolder) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) AudioAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.AudioAttachmentViewHolder) TextAttachmentViewHolder(ve.com.abicelis.remindy.app.holders.TextAttachmentViewHolder)

Example 4 with Attachment

use of ve.com.abicelis.remindy.model.attachment.Attachment in project Remindy by abicelis.

the class FileUtil method deleteAttachmentFiles.

/**
     * Deletes the images and audio files from a list of attachments
     */
public static void deleteAttachmentFiles(Activity activity, List<Attachment> attachments) {
    for (Attachment attachment : attachments) {
        switch(attachment.getType()) {
            case AUDIO:
                String audioFilename = ((AudioAttachment) attachment).getAudioFilename();
                deleteAudioAttachment(activity, audioFilename);
                break;
            case IMAGE:
                String imageFilename = ((ImageAttachment) attachment).getImageFilename();
                deleteImageAttachment(activity, imageFilename);
                break;
        }
    }
}
Also used : AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment)

Example 5 with Attachment

use of ve.com.abicelis.remindy.model.attachment.Attachment in project Remindy by abicelis.

the class RemindyDAO method getAttachmentsOfTask.

/**
     * Returns a List of Attachments associated to a Task.
     * @param taskId The id of the Task
     */
public ArrayList<Attachment> getAttachmentsOfTask(int taskId) {
    ArrayList<Attachment> attachments = new ArrayList<>();
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    Cursor cursor = db.query(RemindyContract.AttachmentTable.TABLE_NAME, null, RemindyContract.AttachmentTable.COLUMN_NAME_TASK_FK.getName() + "=?", new String[] { String.valueOf(taskId) }, null, null, null);
    try {
        while (cursor.moveToNext()) {
            attachments.add(getAttachmentFromCursor(cursor));
        }
    } finally {
        cursor.close();
    }
    return attachments;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Attachment(ve.com.abicelis.remindy.model.attachment.Attachment) LinkAttachment(ve.com.abicelis.remindy.model.attachment.LinkAttachment) ListAttachment(ve.com.abicelis.remindy.model.attachment.ListAttachment) AudioAttachment(ve.com.abicelis.remindy.model.attachment.AudioAttachment) TextAttachment(ve.com.abicelis.remindy.model.attachment.TextAttachment) ImageAttachment(ve.com.abicelis.remindy.model.attachment.ImageAttachment) Cursor(android.database.Cursor)

Aggregations

Attachment (ve.com.abicelis.remindy.model.attachment.Attachment)5 AudioAttachment (ve.com.abicelis.remindy.model.attachment.AudioAttachment)5 ImageAttachment (ve.com.abicelis.remindy.model.attachment.ImageAttachment)5 LinkAttachment (ve.com.abicelis.remindy.model.attachment.LinkAttachment)4 ListAttachment (ve.com.abicelis.remindy.model.attachment.ListAttachment)4 TextAttachment (ve.com.abicelis.remindy.model.attachment.TextAttachment)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 AudioAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.AudioAttachmentViewHolder)1 ImageAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.ImageAttachmentViewHolder)1 LinkAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.LinkAttachmentViewHolder)1 ListAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.ListAttachmentViewHolder)1 TextAttachmentViewHolder (ve.com.abicelis.remindy.app.holders.TextAttachmentViewHolder)1 CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)1