Use metadata objects for files control set

pull/14/head
Sam Bosley 13 years ago
parent 7e8438ac74
commit 33c318befc

@ -1,7 +1,9 @@
package com.todoroo.astrid.files;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Metadata;
public class FileMetadata {
@ -16,16 +18,19 @@ public class FileMetadata {
public static final StringProperty FILE_PATH = new StringProperty(Metadata.TABLE,
Metadata.VALUE1.name);
public static final LongProperty FILE_TYPE = new LongProperty(Metadata.TABLE,
public static final IntegerProperty FILE_TYPE = new IntegerProperty(Metadata.TABLE,
Metadata.VALUE2.name);
public static final LongProperty ATTACH_DATE = new LongProperty(Metadata.TABLE,
Metadata.VALUE3.name);
public static Metadata createNewFileMetadata(long taskId, String filePath, long fileType) {
public static Metadata createNewFileMetadata(long taskId, String filePath, int fileType) {
Metadata metadata = new Metadata();
metadata.setValue(Metadata.KEY, METADATA_KEY);
metadata.setValue(Metadata.TASK, taskId);
metadata.setValue(FILE_PATH, filePath);
metadata.setValue(FILE_TYPE, fileType);
metadata.setValue(ATTACH_DATE, DateUtilities.now());
return metadata;
}

@ -1,6 +1,5 @@
package com.todoroo.astrid.files;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
@ -30,7 +29,7 @@ public class FilesControlSet extends PopupControlSet {
@Autowired
private MetadataService metadataService;
private final ArrayList<File> files = new ArrayList<File>();
private final ArrayList<Metadata> files = new ArrayList<Metadata>();
private final LinearLayout fileList;
public FilesControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) {
@ -44,16 +43,16 @@ public class FilesControlSet extends PopupControlSet {
@Override
protected void refreshDisplayView() {
fileList.removeAllViews();
for (final File f : files) {
for (final Metadata m : files) {
TextView textView = new TextView(activity);
String name = parseName(f.getName());
String name = parseName(m);
textView.setText(name);
textView.setTextAppearance(activity, R.style.TextAppearance_EditRowDisplay);
if (name.contains("audio")) { //$NON-NLS-1$
if (m.getValue(FileMetadata.FILE_TYPE) == FileMetadata.FILE_TYPE_AUDIO) {
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RecognizerApi.play(f.getAbsolutePath());
RecognizerApi.play(m.getValue(FileMetadata.FILE_PATH));
}
});
}
@ -72,11 +71,10 @@ public class FilesControlSet extends PopupControlSet {
.where(MetadataCriteria.byTaskAndwithKey(model.getId(), FileMetadata.METADATA_KEY)));
try {
files.clear();
Metadata metadata = new Metadata();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
Metadata metadata = new Metadata();
metadata.readFromCursor(cursor);
File file = new File(metadata.getValue(FileMetadata.FILE_PATH));
files.add(file);
files.add(metadata);
}
} finally {
cursor.close();
@ -105,11 +103,25 @@ public class FilesControlSet extends PopupControlSet {
return null;
}
private String parseName(String filename) {
String[] components = filename.split("_");
long date = Long.parseLong(components[1]);
String dateString = DateUtilities.getDateString(activity, new Date(date));
return components[2] + " " + dateString;
@SuppressWarnings("nls")
private String parseName(Metadata metadata) {
int prefix = 0;
switch(metadata.getValue(FileMetadata.FILE_TYPE)) {
case FileMetadata.FILE_TYPE_AUDIO:
prefix = R.string.files_type_audio;
break;
case FileMetadata.FILE_TYPE_PDF:
prefix = R.string.files_type_pdf;
break;
}
String prefixStr = "";
if (prefix > 0) {
prefixStr = activity.getString(prefix) + " ";
}
long date = metadata.getValue(FileMetadata.ATTACH_DATE);
return prefixStr + DateUtilities.getDateString(activity, new Date(date));
}
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- See the file "LICENSE" for the full license governing this code. -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string name="files_type_audio">Audio</string>
<string name="files_type_pdf">PDF</string>
</resources>
Loading…
Cancel
Save