diff --git a/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java index d21a6ab07..c4c878a1c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java @@ -6,6 +6,7 @@ import java.util.Date; import android.app.Activity; import android.content.DialogInterface; +import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -34,7 +35,8 @@ public class FilesControlSet extends PopupControlSet { private MetadataService metadataService; private final ArrayList files = new ArrayList(); - private final LinearLayout fileList; + private final LinearLayout fileDisplayList; + private LinearLayout fileList; private final LayoutInflater inflater; public FilesControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) { @@ -42,50 +44,16 @@ public class FilesControlSet extends PopupControlSet { DependencyInjectionService.getInstance().inject(this); displayText.setText(activity.getString(R.string.TEA_control_files)); - fileList = (LinearLayout) getDisplayView().findViewById(R.id.files_list); + fileDisplayList = (LinearLayout) getDisplayView().findViewById(R.id.files_list); inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); } @Override protected void refreshDisplayView() { - fileList.removeAllViews(); + fileDisplayList.removeAllViews(); for (final Metadata m : files) { View fileRow = inflater.inflate(R.layout.file_row, null); - - TextView textView = (TextView) fileRow.findViewById(R.id.file_text); - String name = parseName(m); - textView.setText(name); - if (m.getValue(FileMetadata.FILE_TYPE) == FileMetadata.FILE_TYPE_AUDIO) { - textView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - RecognizerApi.play(m.getValue(FileMetadata.FILE_PATH)); - } - }); - } - - View clearFile = fileRow.findViewById(R.id.remove_file); - clearFile.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DialogUtilities.okCancelDialog(activity, "Are you sure? Cannont be undone", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - File f = new File(m.getValue(FileMetadata.FILE_PATH)); - if (f.delete()) { - metadataService.delete(m); - files.remove(m); - refreshDisplayView(); - } - } - }, null); - } - }); - - LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - lp.gravity = Gravity.RIGHT; - fileList.addView(fileRow, lp); + setUpFileRow(m, fileRow, fileDisplayList); } } @@ -115,39 +83,91 @@ public class FilesControlSet extends PopupControlSet { @Override protected String writeToModelAfterInitialized(Task task) { - // TODO Auto-generated method stub + // Nothing to write return null; } @Override protected void afterInflate() { - // TODO Auto-generated method stub + fileList = (LinearLayout) getView().findViewById(R.id.files_list); + final LinearLayout finalList = fileList; + for (final Metadata m : files) { + final View fileRow = inflater.inflate(R.layout.file_row, null); + + setUpFileRow(m, fileRow, fileList); + View name = fileRow.findViewById(R.id.file_text); + View clearFile = fileRow.findViewById(R.id.remove_file); + clearFile.setVisibility(View.VISIBLE); + if (m.getValue(FileMetadata.FILE_TYPE) == FileMetadata.FILE_TYPE_AUDIO) { + name.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + RecognizerApi.play(m.getValue(FileMetadata.FILE_PATH)); + } + }); + } + clearFile.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + DialogUtilities.okCancelDialog(activity, "Are you sure? Cannont be undone", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface d, int which) { + File f = new File(m.getValue(FileMetadata.FILE_PATH)); + if (f.delete()) { + metadataService.delete(m); + files.remove(m); + refreshDisplayView(); + finalList.removeView(fileRow); + } + } + }, null); + } + }); + } } - @Override - protected OnClickListener getDisplayClickListener() { - return null; + private void setUpFileRow(Metadata m, View row, LinearLayout parent) { + TextView nameView = (TextView) row.findViewById(R.id.file_text); + TextView typeView = (TextView) row.findViewById(R.id.file_type); + String name = getNameString(m); + String type = getTypeString(m); + nameView.setText(name); + + if (TextUtils.isEmpty(type)) + typeView.setVisibility(View.GONE); + else + typeView.setText(type); + + LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + lp.gravity = Gravity.RIGHT; + parent.addView(row, lp); } - @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; + private String getNameString(Metadata metadata) { + if (metadata.getValue(FileMetadata.FILE_TYPE) == FileMetadata.FILE_TYPE_AUDIO) { + Date date = new Date(metadata.getValue(FileMetadata.ATTACH_DATE)); + return DateUtilities.getDateStringWithTime(activity, date); + } else { + File f = new File(metadata.getValue(FileMetadata.FILE_PATH)); + String name = f.getName(); + int extension = name.lastIndexOf('.'); + if (extension < 0) + return name; + return name.substring(0, extension); } + } - String prefixStr = ""; - if (prefix > 0) { - prefixStr = activity.getString(prefix) + " "; - } + @SuppressWarnings("nls") + private String getTypeString(Metadata metadata) { + File f = new File(metadata.getValue(FileMetadata.FILE_PATH)); + String name = f.getName(); + + int extension = name.lastIndexOf('.'); + if (extension < 0 || extension + 1 >= name.length()) + return ""; + return name.substring(extension + 1).toUpperCase(); - long date = metadata.getValue(FileMetadata.ATTACH_DATE); - return prefixStr + DateUtilities.getDateString(activity, new Date(date)); } } diff --git a/astrid/res/drawable/file_type_background.xml b/astrid/res/drawable/file_type_background.xml new file mode 100644 index 000000000..2a436ba40 --- /dev/null +++ b/astrid/res/drawable/file_type_background.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/astrid/res/layout/control_set_files.xml b/astrid/res/layout/control_set_files.xml new file mode 100644 index 000000000..fd9a245f5 --- /dev/null +++ b/astrid/res/layout/control_set_files.xml @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/astrid/res/layout/file_row.xml b/astrid/res/layout/file_row.xml index 40d976cb8..e020c19df 100644 --- a/astrid/res/layout/file_row.xml +++ b/astrid/res/layout/file_row.xml @@ -10,10 +10,21 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.EditRowDisplay"/> + - + android:src="@drawable/close_clear_cancel" + android:layout_marginLeft="5dip" + android:layout_marginRight="5dip" + android:visibility="gone"/> \ No newline at end of file diff --git a/astrid/res/values/strings-premium.xml b/astrid/res/values/strings-premium.xml index faecec0d5..4ca9941e2 100644 --- a/astrid/res/values/strings-premium.xml +++ b/astrid/res/values/strings-premium.xml @@ -2,7 +2,4 @@ - Audio - PDF - diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java index e4c1d8d48..6205ba76c 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java @@ -552,7 +552,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl); FilesControlSet filesControl = new FilesControlSet(getActivity(), - -1, + R.layout.control_set_files, R.layout.control_set_files_display, R.string.TEA_control_files); controls.add(filesControl);