mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 02:01:56 +00:00
Works when creating a new task
TODO: -Add a today button to the calendar -Make sure it works for edit a task
This commit is contained in:
parent
ff99df4a3f
commit
7aa2e4238a
2 changed files with 87 additions and 89 deletions
|
|
@ -1,6 +1,5 @@
|
|||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
|
@ -290,7 +289,7 @@
|
|||
<LinearLayout
|
||||
android:id="@+id/task_startdate_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="140dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="vertical">
|
||||
|
|
@ -303,13 +302,14 @@
|
|||
android:text="@string/start_date"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/task_startdate_picker"
|
||||
android:layout_width="wrap_content"
|
||||
<EditText
|
||||
android:id="@+id/startdate_text_edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:calendarViewShown="false"
|
||||
android:datePickerMode="spinner"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/start_date"
|
||||
android:textColor="@android:color/black"
|
||||
android:focusable="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -328,47 +328,27 @@
|
|||
android:text="@string/due_date"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/todo_has_duedate"
|
||||
android:id="@+id/duedate_checkbox" />
|
||||
<DatePicker
|
||||
android:id="@+id/task_duedate_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:calendarViewShown="false"
|
||||
android:datePickerMode="spinner"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
<LinearLayout
|
||||
android:id="@+id/task_duedate_picker_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:orientation="horizontal" >
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/emoji.toggle.btn_duedate"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_emoticon_grey600_24dp"
|
||||
android:background="@drawable/md_transparent"
|
||||
android:contentDescription="Toogle Emoji"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true" />
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/todo_has_duedate"
|
||||
android:id="@+id/duedate_checkbox" />
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
<EditText
|
||||
android:id="@+id/duedate_text_edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||
|
||||
<com.github.data5tream.emojilib.EmojiEditText
|
||||
android:id="@+id/duedate_text_edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:hint="@string/text"
|
||||
android:textColor="@android:color/black"
|
||||
android:inputType="textCapSentences" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:hint="@string/due_date"
|
||||
android:textColor="@android:color/black"
|
||||
android:focusable="false" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -57,13 +57,11 @@ import com.raizlabs.android.dbflow.sql.language.Select;
|
|||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
||||
|
|
@ -88,8 +86,6 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
private List<CharSequence> userSelectedTags;
|
||||
private List<CheckBox> allTags;
|
||||
private List<String> userSelectedTagIds;
|
||||
private DatePickerDialog dueDatePickerDialog;
|
||||
private SimpleDateFormat dateFormatter;
|
||||
|
||||
@Bind(R.id.task_value_edittext)
|
||||
EditText taskValue;
|
||||
|
|
@ -100,9 +96,6 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
@Bind(R.id.task_checklist_wrapper)
|
||||
LinearLayout checklistWrapper;
|
||||
|
||||
@Bind(R.id.task_startdate_picker)
|
||||
DatePicker startDatePicker;
|
||||
|
||||
@Bind(R.id.task_difficulty_wrapper)
|
||||
LinearLayout difficultyWrapper;
|
||||
|
||||
|
|
@ -168,18 +161,23 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
|
||||
|
||||
ImageButton emojiToggle2;
|
||||
|
||||
@Bind(R.id.task_duedate_layout)
|
||||
LinearLayout dueDateLayout;
|
||||
|
||||
@Bind(R.id.task_duedate_picker_layout)
|
||||
LinearLayout dueDatePickerLayout;
|
||||
|
||||
@Bind(R.id.duedate_checkbox)
|
||||
CheckBox dueDateCheckBox;
|
||||
|
||||
@Bind(R.id.task_duedate_picker)
|
||||
DatePicker dueDatePicker;
|
||||
|
||||
@Bind(R.id.startdate_text_edittext)
|
||||
EditText startDatePickerText;
|
||||
DateEditTextListener startDateListener;
|
||||
|
||||
@Bind(R.id.duedate_text_edittext)
|
||||
EmojiEditText dueDatePickerText;
|
||||
EditText dueDatePickerText;
|
||||
DateEditTextListener dueDateListener;
|
||||
|
||||
@Bind(R.id.task_tags_wrapper)
|
||||
LinearLayout tagsWrapper;
|
||||
|
|
@ -212,25 +210,8 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
return;
|
||||
}
|
||||
|
||||
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
|
||||
Calendar datePickerCalendar = Calendar.getInstance();
|
||||
|
||||
dueDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
Calendar newDate = Calendar.getInstance();
|
||||
newDate.set(year, monthOfYear, dayOfMonth);
|
||||
dueDatePickerText.setText(dateFormatter.format(newDate.getTime()));
|
||||
}
|
||||
|
||||
}, datePickerCalendar.get(Calendar.YEAR),
|
||||
datePickerCalendar.get(Calendar.MONTH),
|
||||
datePickerCalendar.get(Calendar.DAY_OF_MONTH));
|
||||
dueDatePickerText.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
dueDatePickerDialog.show();
|
||||
}
|
||||
});
|
||||
dueDateListener = new DateEditTextListener(dueDatePickerText);
|
||||
startDateListener = new DateEditTextListener(startDatePickerText);
|
||||
|
||||
btnDelete.setEnabled(false);
|
||||
ViewHelper.SetBackgroundTint(btnDelete, ContextCompat.getColor(this, R.color.worse_10));
|
||||
|
|
@ -309,15 +290,15 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
}
|
||||
|
||||
if (taskType.equals("todo")) {
|
||||
dueDateLayout.removeView(dueDatePicker);
|
||||
dueDatePickerLayout.removeView(dueDatePickerText);
|
||||
//Allows user to decide if they want to add a due date or not
|
||||
dueDateCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.isChecked()) {
|
||||
dueDateLayout.addView(dueDatePicker);
|
||||
dueDatePickerLayout.addView(dueDatePickerText);
|
||||
} else {
|
||||
dueDateLayout.removeView(dueDatePicker);
|
||||
dueDatePickerLayout.removeView(dueDatePickerText);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -449,6 +430,51 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
}
|
||||
}
|
||||
|
||||
private class DateEditTextListener implements View.OnClickListener {
|
||||
Calendar calendar;
|
||||
DatePickerDialog datePickerDialog;
|
||||
EditText datePickerText;
|
||||
DateFormat dateFormatter;
|
||||
|
||||
|
||||
public DateEditTextListener(EditText dateText) {
|
||||
calendar = Calendar.getInstance();
|
||||
this.datePickerText = dateText;
|
||||
this.datePickerText.setOnClickListener(this);
|
||||
this.dateFormatter = DateFormat.getDateInstance();
|
||||
// TODO add a today button
|
||||
this.datePickerDialog = new DatePickerDialog(datePickerText.getContext(), new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
calendar.set(year, monthOfYear, dayOfMonth);
|
||||
updateDateText();
|
||||
}
|
||||
|
||||
}, calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH));
|
||||
updateDateText();
|
||||
}
|
||||
|
||||
|
||||
public void onClick(View view) {
|
||||
datePickerDialog.show();
|
||||
}
|
||||
|
||||
public Calendar getCalendar() {
|
||||
return (Calendar) calendar.clone();
|
||||
}
|
||||
|
||||
public void setCalendar(Date date) {
|
||||
calendar.setTime(date);
|
||||
updateDateText();
|
||||
}
|
||||
|
||||
private void updateDateText() {
|
||||
datePickerText.setText(dateFormatter.format(calendar.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
private class emojiClickListener implements View.OnClickListener {
|
||||
|
||||
EmojiEditText view;
|
||||
|
|
@ -683,9 +709,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
if (task.type.equals("daily")) {
|
||||
|
||||
if (task.getStartDate() != null) {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(task.getStartDate());
|
||||
startDatePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
|
||||
startDateListener.setCalendar(task.getStartDate());
|
||||
}
|
||||
|
||||
if (task.getFrequency().equals("weekly")) {
|
||||
|
|
@ -710,9 +734,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
if (task.type.equals("todo")) {
|
||||
if (task.getDueDate() != null) {
|
||||
dueDateCheckBox.setChecked(true);
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(task.getDueDate());
|
||||
dueDatePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
|
||||
dueDateListener.setCalendar(task.getDueDate());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -781,9 +803,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
break;
|
||||
|
||||
case "daily": {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.set(startDatePicker.getYear(), startDatePicker.getMonth(), startDatePicker.getDayOfMonth());
|
||||
task.setStartDate(new Date(calendar.getTimeInMillis()));
|
||||
task.setStartDate(new Date(startDateListener.getCalendar().getTimeInMillis()));
|
||||
|
||||
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||
task.setFrequency("weekly");
|
||||
|
|
@ -809,9 +829,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
|
||||
case "todo": {
|
||||
if (dueDateCheckBox.isChecked()) {
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(dueDatePicker.getYear(), dueDatePicker.getMonth(), dueDatePicker.getDayOfMonth());
|
||||
task.setDueDate(new Date(calendar.getTimeInMillis()));
|
||||
task.setDueDate(new Date(dueDateListener.getCalendar().getTimeInMillis()));
|
||||
} else {
|
||||
task.setDueDate(null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue