Search in sources :

Example 11 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class SaveDiaryTask method doInBackground.

@Override
protected Integer doInBackground(Long... params) {
    int saveResult = RESULT_INSERT_SUCCESSFUL;
    long topicId = params[0];
    try {
        dbManager.opeDB();
        dbManager.beginTransaction();
        //Save info
        long diaryId = dbManager.insertDiaryInfo(time, title, moodPosition, weatherPosition, attachment, topicId, locationName);
        //Save content
        diaryFileManager = new FileManager(mContext, topicId, diaryId);
        //Check no any garbage in this diary.
        diaryFileManager.clearDir();
        if (diaryId != -1) {
            for (int i = 0; i < diaryItemHelper.getItemSize(); i++) {
                //Copy photo from temp to diary dir
                if (diaryItemHelper.get(i).getType() == IDairyRow.TYPE_PHOTO) {
                    savePhoto(diaryItemHelper.get(i).getContent());
                }
                //Save data
                dbManager.insertDiaryContent(diaryItemHelper.get(i).getType(), i, diaryItemHelper.get(i).getContent(), diaryId);
            }
            dbManager.setTransactionSuccessful();
        } else {
            saveResult = RESULT_INSERT_ERROR;
        }
    } catch (Exception e) {
        //Revert the Data
        diaryFileManager.clearDir();
        saveResult = RESULT_INSERT_ERROR;
    } finally {
        dbManager.endTransaction();
        dbManager.closeDB();
    }
    return saveResult;
}
Also used : FileManager(com.kiminonawa.mydiary.shared.FileManager)

Example 12 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class CopyDiaryToEditCacheTask method doInBackground.

@Override
protected Integer doInBackground(Long... params) {
    int copyResult = RESULT_COPY_SUCCESSFUL;
    long topicId = params[0];
    long diaryId = params[1];
    try {
        FileManager diaryFileManager = new FileManager(mContext, topicId, diaryId);
        File[] childrenPhoto = diaryFileManager.getDir().listFiles();
        for (int i = 0; i < diaryFileManager.getDir().listFiles().length; i++) {
            copyPhoto(childrenPhoto[i].getName(), diaryFileManager);
        }
    } catch (Exception e) {
        e.printStackTrace();
        copyResult = RESULT_COPY_ERROR;
    }
    return copyResult;
}
Also used : File(java.io.File) FileManager(com.kiminonawa.mydiary.shared.FileManager)

Example 13 with FileManager

use of com.kiminonawa.mydiary.shared.FileManager in project MyDiary by erttyy8821.

the class DiaryDeleteDialogFragment method deleteDiary.

private void deleteDiary() {
    //Delete the db
    DBManager dbManager = new DBManager(getActivity());
    dbManager.opeDB();
    dbManager.delDiary(diaryId);
    dbManager.closeDB();
    //Delete photo data
    try {
        deleteDirectory(new FileManager(getActivity(), topicId, diaryId).getDir());
    } catch (IOException e) {
        //just do nothing
        e.printStackTrace();
    }
}
Also used : DBManager(com.kiminonawa.mydiary.db.DBManager) IOException(java.io.IOException) FileManager(com.kiminonawa.mydiary.shared.FileManager)

Aggregations

FileManager (com.kiminonawa.mydiary.shared.FileManager)13 File (java.io.File)5 IOException (java.io.IOException)5 Uri (android.net.Uri)2 DBManager (com.kiminonawa.mydiary.db.DBManager)2 UCrop (com.yalantis.ucrop.UCrop)2 Cursor (android.database.Cursor)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 DiaryActivity (com.kiminonawa.mydiary.entries.DiaryActivity)1