Permalink
Browse files

Clean up code

  • Loading branch information...
1 parent 5814bbb commit 28bc3ebd80c34f2532f16b110deed3fddff73151 @axelson axelson committed Dec 8, 2011
@@ -21,15 +21,10 @@ public void onCreate(Bundle icicle) {
elements = scheduleRetriever.getElements();
}
catch (IOException e) {
- // TODO Auto-generated catch block
+ // TODO: Maybe show user error in this case.
e.printStackTrace();
}
- // String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
- // "Blackberry",
- // "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
- // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- // android.R.layout.simple_list_item_1, values);
ArrayAdapter<ScheduleElement> adapter = new ArrayAdapter<ScheduleElement>(this,
android.R.layout.simple_list_item_1, elements);
this.setListAdapter(adapter);
@@ -38,6 +33,7 @@ public void onCreate(Bundle icicle) {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ScheduleElement item = (ScheduleElement) getListAdapter().getItem(position);
- Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
+ String description = item.getFullDescription() + "selected";
+ Toast.makeText(this, description, Toast.LENGTH_LONG).show();
}
}
@@ -22,17 +22,18 @@ public FileScheduleRetriever(AssetManager manager) {
/** {@inheritDoc} */
@Override
public List<ScheduleElement> getElements() throws IOException {
- BufferedReader br = null;
- br = new BufferedReader(new InputStreamReader(mManager.open("data.txt")));
+ ArrayList<ScheduleElement> scheduleListToReturn = new ArrayList<ScheduleElement>();
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(mManager.open("data.txt")));
System.out.println(br.readLine());
- ArrayList<ScheduleElement> scheduleList = new ArrayList<ScheduleElement>();
+
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
ScheduleElement scheduleElement = ScheduleElement.parseFromString(line);
- scheduleList.add(scheduleElement);
+ scheduleListToReturn.add(scheduleElement);
}
- return scheduleList;
+ return scheduleListToReturn;
}
}
@@ -18,10 +18,15 @@ public static ScheduleElement parseFromString(String input) {
}
public String getShortDescription() {
- String string = mTime + mTitle;
+ String string = this.getFullDescription();
return string.substring(0, 20);
}
+ public String getFullDescription() {
+ String string = mTime + mTitle;
+ return string;
+ }
+
/** {@inheritDoc} */
@Override
public String toString() {
@@ -10,7 +10,7 @@
public interface ScheduleRetriever {
/**
- * @return
+ * @return elements in the schedule
* @throws IOException
*/
public List<ScheduleElement> getElements() throws IOException;

0 comments on commit 28bc3eb

Please sign in to comment.