Skip to content

Commit

Permalink
Merge branch 'agenda-query-type-agenda' of https://github.com/imd/mob…
Browse files Browse the repository at this point in the history
…ileorg-android into agenda
  • Loading branch information
hdweiss committed Jan 19, 2014
2 parents 43e8a4a + a9d1729 commit bfcd3b5
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 25 deletions.
Expand Up @@ -11,13 +11,16 @@ public class OrgNodeDateTest extends AndroidTestCase {
private static final String dateString = "2000-11-24";
private static final String timeBeginString = "13:15";
private static final String timeEndString = "15:15";
private static final String timeMidnight = "00:00";
private Calendar getDefaultCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2000);
cal.set(Calendar.MONTH, 10);
cal.set(Calendar.DAY_OF_MONTH, 24);
cal.set(Calendar.HOUR_OF_DAY, 13);
cal.set(Calendar.MINUTE, 15);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
}

Expand Down Expand Up @@ -48,4 +51,26 @@ public void testGetDateTimeSpan() {
assertEquals(dateString + " " + timeBeginString + "-" + timeEndString, date);
}

/**
* Tests that the start time of dates with a begin time are equal to
* the time in milliseconds of an equivalent Calendar.
*/
public void testDateEqualsCalendar() {
OrgNodeDate date = new OrgNodeDate(dateString + " " + timeBeginString);
long calTime = getDefaultCalendar().getTimeInMillis();

assertEquals(date.beginTime, calTime);
}

/**
* Tests that the start time of dates without a time part (all-day
* events) are equal to the start time of dates that start at
* midnight.
*/
public void testAllDayEqualsMidnight() {
OrgNodeDate allDay = new OrgNodeDate(dateString);
OrgNodeDate midnight = new OrgNodeDate(dateString + " " + timeMidnight);

assertEquals(allDay.beginTime, midnight.beginTime);
}
}
Expand Up @@ -4,9 +4,14 @@
import java.util.Arrays;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
Expand All @@ -22,6 +27,9 @@ public class AgendaEntrySetting extends SherlockActivity {
private int entryPos;

private EditText titleView;
private Spinner typeView;
private Spinner spanView;
private EditText spanCustomView;
private EditText payloadView;
private EditText todoView;
private EditText priorityView;
Expand All @@ -30,13 +38,17 @@ public class AgendaEntrySetting extends SherlockActivity {

private CheckBox activeTodosView;
private LinearLayout fileListView;
private EditText deadlineWarningDaysView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agenda_entry_setting);

this.titleView = (EditText) findViewById(R.id.agenda_entry_title);
this.typeView = (Spinner) findViewById(R.id.agenda_entry_type);
this.spanView = (Spinner) findViewById(R.id.agenda_entry_span);
this.spanCustomView = (EditText) findViewById(R.id.agenda_entry_span_custom);
this.priorityView = (EditText) findViewById(R.id.agenda_entry_priority);
this.todoView = (EditText) findViewById(R.id.agenda_entry_todo);
this.tagsView = (EditText) findViewById(R.id.agenda_entry_tag);
Expand All @@ -49,25 +61,67 @@ protected void onCreate(Bundle savedInstanceState) {
this.entryPos = getIntent().getIntExtra(ENTRY_NUMBER, -1);

this.fileListView = (LinearLayout) findViewById(R.id.agenda_entry_files);
this.deadlineWarningDaysView =
(EditText) findViewById(R.id.agenda_entry_deadline_warning_days);

setupSettings(OrgAgenda.getAgendaEntry(agendaPos, entryPos, this));
}

public void setupSettings(OrgQueryBuilder agenda) {
int spinnerItem = android.R.layout.simple_spinner_item;
int spinnerDropdownItem = android.R.layout.simple_spinner_dropdown_item;
int queryTypes = R.array.agendaQueryTypes;
int spanValues = R.array.agendaSpanValues;
ArrayAdapter<CharSequence> typeAdapter =
ArrayAdapter.createFromResource(this, queryTypes, spinnerItem);
ArrayAdapter<CharSequence> spanAdapter =
ArrayAdapter.createFromResource(this, spanValues, spinnerItem);

titleView.setText(agenda.title);

typeAdapter.setDropDownViewResource(spinnerDropdownItem);
typeView.setAdapter(typeAdapter);
typeView.setSelection(agenda.type.ordinal());
spanAdapter.setDropDownViewResource(spinnerDropdownItem);
spanView.setAdapter(spanAdapter);
spanView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView,
View selectedItemView, int position,
long id) {
String selected =
parentView.getItemAtPosition(position).toString();
if (selected.equalsIgnoreCase("Custom")) {
spanCustomView.setVisibility(View.VISIBLE);
} else {
spanCustomView.setVisibility(View.INVISIBLE);
spanCustomView.setText(selected);
}
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
spanView.setSelection(spanAdapter.getPosition(agenda.span));
payloadView.setText(combineToString(agenda.payloads));
todoView.setText(combineToString(agenda.todos));
priorityView.setText(combineToString(agenda.priorities));
tagsView.setText(combineToString(agenda.tags));
filterHabitsView.setChecked(agenda.filterHabits);
activeTodosView.setChecked(agenda.activeTodos);
deadlineWarningDaysView
.setText(String.valueOf(agenda.deadlineWarningDays));

setupFileList(agenda);
}

public OrgQueryBuilder getQueryFromSettings() {
OrgQueryBuilder agenda = new OrgQueryBuilder(titleView.getText().toString());
int selPos = typeView.getSelectedItemPosition();

agenda.type = OrgQueryBuilder.Type.values()[selPos];
agenda.span = spanCustomView.getText().toString();
agenda.tags = splitToArrayList(tagsView.getText().toString());
agenda.payloads = splitToArrayList(payloadView.getText().toString());
agenda.priorities = splitToArrayList(priorityView.getText().toString());
Expand All @@ -76,6 +130,8 @@ public OrgQueryBuilder getQueryFromSettings() {
agenda.activeTodos = activeTodosView.isChecked();

agenda.files = getFileList();
agenda.deadlineWarningDays =
Integer.parseInt(deadlineWarningDaysView.getText().toString());

return agenda;
}
Expand Down
Expand Up @@ -41,6 +41,12 @@ public void onResume() {
super.onResume();
showBlockAgenda(agendaPos);
}

@Override
public void onDestroyView() {
super.onDestroyView();
db.close();
}

public void showBlockAgenda(int agendaPos) {
this.mergeAdapter = new MergeAdapter();
Expand Down

0 comments on commit bfcd3b5

Please sign in to comment.