Skip to content

Commit

Permalink
Added placeholder image for files attachments and implemented database
Browse files Browse the repository at this point in the history
scripts to add their support
  • Loading branch information
federicoiosue committed Apr 1, 2014
1 parent 77be860 commit ea2f884
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 76 deletions.
13 changes: 8 additions & 5 deletions assets/sql/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@ CREATE
alarm INTEGER DEFAULT null,
latitude REAL,
longitude REAL,
tag_id INTEGER DEFAUL null,
tag_id INTEGER DEFAUL null,
locked INTEGER,
checklist INTEGER
);



-- Create table for attachments
-- Create table for ATTACHMENTS
CREATE
TABLE attachments
(
attachment_id INTEGER PRIMARY KEY AUTOINCREMENT,
uri TEXT,
name TEXT,
size INTEGER,
lenght INTEGER,
mime_type TEXT,
note_id INTEGER
);



-- Create table for tags
-- Create table for TAGS
CREATE
TABLE tags
(
tag_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
description TEXT,
color TEXT
description TEXT,
color TEXT
);
41 changes: 0 additions & 41 deletions assets/sql/create.sql~

This file was deleted.

2 changes: 0 additions & 2 deletions assets/sql/upgrade-414.sql~

This file was deleted.

118 changes: 118 additions & 0 deletions etc/files.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions etc/play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/ic_note_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/drawable/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/drawable/stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions src/it/feio/android/omninotes/DetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -1467,16 +1467,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Crouton.makeText(mActivity, R.string.error_saving_attachments,
ONStyle.WARN).show();
break;
}

}
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// final int takeFlags = intent.getFlags()
// & (Intent.FLAG_GRANT_READ_URI_PERMISSION
// | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// // Check for the freshest data.
// getContentResolver().takePersistableUriPermission(intent.getData(), takeFlags);
// }

// }
attachment = new Attachment(intent.getData(), mimeType);
noteTmp.getAttachmentsList().add(attachment);
mAttachmentAdapter.notifyDataSetChanged();
Expand Down Expand Up @@ -1508,11 +1506,20 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode == Activity.RESULT_OK) {
Uri filesUri = intent.getData();
// A check on the existence of the file is done
if ( new File(FileHelper.getPath(mActivity, filesUri)).exists() ) {
attachment = new Attachment(filesUri, Constants.MIME_TYPE_FILES);
noteTmp.getAttachmentsList().add(attachment);
mAttachmentAdapter.notifyDataSetChanged();
mGridView.autoresize();
if (FileHelper.getPath(mActivity, filesUri) != null) {
File f = new File(FileHelper.getPath(mActivity, filesUri));
if (f.exists()) {
// attachment = new Attachment(filesUri, Constants.MIME_TYPE_FILES);
attachment = new Attachment(Uri.fromFile(f), Constants.MIME_TYPE_FILES);
attachment.setName(f.getName());
attachment.setSize(f.length());
noteTmp.getAttachmentsList().add(attachment);
mAttachmentAdapter.notifyDataSetChanged();
mGridView.autoresize();
} else {
Crouton.makeText(mActivity, R.string.error_saving_attachments,
ONStyle.ALERT).show();
}
} else {
Crouton.makeText(mActivity, R.string.error_saving_attachments,
ONStyle.ALERT).show();
Expand Down
15 changes: 10 additions & 5 deletions src/it/feio/android/omninotes/db/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

public class DbHelper extends SQLiteOpenHelper {

// Database name
private static final String DATABASE_NAME = Constants.DATABASE_NAME;
// Database version aligned if possible to software version
private static final int DATABASE_VERSION = 414;
private static final int DATABASE_VERSION = 450;
// Sql query file directory
private static final String SQL_DIR = "sql" ;

Expand All @@ -69,6 +68,8 @@ public class DbHelper extends SQLiteOpenHelper {
// Attachments table columns
public static final String KEY_ATTACHMENT_ID = "attachment_id";
public static final String KEY_ATTACHMENT_URI = "uri";
public static final String KEY_ATTACHMENT_NAME = "name";
public static final String KEY_ATTACHMENT_SIZE = "size";
public static final String KEY_ATTACHMENT_MIME_TYPE = "mime_type";
public static final String KEY_ATTACHMENT_NOTE_ID = "note_id";

Expand Down Expand Up @@ -199,6 +200,8 @@ public Note updateNote(Note note, boolean updateLastModification) {
valuesAttachments.put(KEY_ATTACHMENT_URI, attachment.getUri().toString());
valuesAttachments.put(KEY_ATTACHMENT_MIME_TYPE, attachment.getMime_type());
valuesAttachments.put(KEY_ATTACHMENT_NOTE_ID, (note.get_id() != 0 ? note.get_id() : resNote) );
valuesAttachments.put(KEY_ATTACHMENT_NAME, attachment.getName());
valuesAttachments.put(KEY_ATTACHMENT_SIZE, attachment.getSize());
resAttachment = db.insert(TABLE_ATTACHMENTS, null, valuesAttachments);
Log.d(Constants.TAG, "Saved new attachment with uri '"
+ attachment.getUri().toString() + "' with id: " + resAttachment);
Expand Down Expand Up @@ -560,6 +563,8 @@ public ArrayList<Attachment> getAttachments(String whereCondition) {
String sql = "SELECT "
+ KEY_ATTACHMENT_ID + ","
+ KEY_ATTACHMENT_URI + ","
+ KEY_ATTACHMENT_NAME + ","
+ KEY_ATTACHMENT_SIZE + ","
+ KEY_ATTACHMENT_MIME_TYPE
+ " FROM " + TABLE_ATTACHMENTS
+ whereCondition;
Expand All @@ -574,9 +579,9 @@ public ArrayList<Attachment> getAttachments(String whereCondition) {
// Looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
attachmentsList.add(new Attachment(Integer.valueOf(cursor
.getInt(0)), Uri.parse(cursor.getString(1)), cursor
.getString(2)));
attachmentsList.add(new Attachment(Integer.valueOf(cursor.getInt(0)),
Uri.parse(cursor.getString(1)), cursor.getString(2), Integer.valueOf(cursor.getInt(3)),
cursor.getString(4)));
} while (cursor.moveToNext());
}

Expand Down
Loading

0 comments on commit ea2f884

Please sign in to comment.