package net.tasksnow.view; import android.content.Intent; import android.view.View; import android.widget.ListView; import net.tasksnow.model.cards.CalendarItem; import net.tasksnow.model.cards.Label; import net.tasksnow.model.cards.Project; import net.tasksnow.model.cards.Task; import net.tasksnow.model.cards.TaskItem; import net.tasksnow.view.reuse.GenericListAdapter; import net.tasksnow.view.task.TaskEditActivity; import com.luma.android.andrologger.Logger; import java.util.Date; /** * @author LuMa * @since 00:27:58 - 27.03.2013 * @project TasksNow */ public class TasksListFragment extends CardsListFragment { // =========================================================== // Constants // =========================================================== public static final String LABEL_FILTER_KEY = "label_filter"; public static final String PROJECT_FILTER_KEY = "project_filter"; // =========================================================== // Fields // =========================================================== // =========================================================== // Constructors // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public void onListItemClick(ListView l, View v, int position, long id) { Logger.i("ListItemClick"); super.onListItemClick(l, v, position, id); Object item = l.getAdapter().getItem(position); if (item instanceof TaskItem) { TaskItem listItem = (TaskItem) item; Task task = listItem.getTask(); Intent intent = new Intent(this.getActivity(), TaskEditActivity.class); intent.putExtra(TaskEditActivity.TASKID_KEY, task.getId()); this.startActivity(intent); } } @Override protected int getDiffItemCount() { return 10; } @Override protected void fillListAdapter(GenericListAdapter mCardsAdapter) { //Jumps into if when subcategory in the sidemenu was chosen if (this.getArguments() != null) { Label labelFilter = (Label) this.getArguments().getSerializable(LABEL_FILTER_KEY); if (labelFilter != null) { for (Task sampleTask : this.getApplication().getDbHandler().getTasksOfLabel(labelFilter)) { mCardsAdapter.add(new TaskItem(sampleTask)); } } Project projectFilter = (Project) this.getArguments().getSerializable(PROJECT_FILTER_KEY); if (projectFilter != null) { for (Task sampleTask : this.getApplication().getDbHandler().getTasksOfProject(projectFilter)) { mCardsAdapter.add(new TaskItem(sampleTask)); } } } //Jumps into else if its in the "recent" section cause there a FragmentList has been created without //any arguments else { // mCardsAdapter.add(new CalendarItem("Meeting with Benny", "DHBW Karlsruhe", new Date())); for (Task sampleTask : this.getApplication().getDbHandler().getAllTasks()) { mCardsAdapter.add(new TaskItem(sampleTask)); } mCardsAdapter.add(new CalendarItem("Meeting with Benny", "DHBW Karlsruhe", new Date())); } } // =========================================================== // Methods // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }