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;
}
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;
}
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();
}
}
Aggregations