allow changing the event date and time
This commit is contained in:
parent
f67b4ec2f5
commit
c5faeb92cd
|
@ -38,6 +38,11 @@
|
|||
android:label="@string/details"
|
||||
android:screenOrientation="portrait"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.EventActivity"
|
||||
android:label="@string/event"
|
||||
android:screenOrientation="portrait"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.LicenseActivity"
|
||||
android:label="@string/third_party_licences"
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
package com.simplemobiletools.calendar;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
public class Formatter {
|
||||
private static final String EVENT_PATTERN = "d MMMM YYYY";
|
||||
private static final String EVENT_DATE_PATTERN = "MMMM d YYYY";
|
||||
private static final String EVENT_TIME_PATTERN = "HH:mm";
|
||||
|
||||
public static String getEventDate(String dayCode) {
|
||||
return getDateTime(dayCode).toString(EVENT_DATE_PATTERN);
|
||||
}
|
||||
|
||||
public static String getEventDate(DateTime dateTime) {
|
||||
return dateTime.toString(EVENT_DATE_PATTERN);
|
||||
}
|
||||
|
||||
public static String getEventTime(DateTime dateTime) {
|
||||
return dateTime.toString(EVENT_TIME_PATTERN);
|
||||
}
|
||||
|
||||
public static DateTime getDateTime(String dayCode) {
|
||||
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(Constants.DATE_PATTERN);
|
||||
return dateTimeFormatter.parseDateTime(dayCode).toString(EVENT_PATTERN);
|
||||
return dateTimeFormatter.parseDateTime(dayCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ import butterknife.OnClick;
|
|||
public class DetailsActivity extends AppCompatActivity {
|
||||
@BindView(R.id.details_date) TextView mDateTV;
|
||||
|
||||
private static final int ADD_EVENT = 1;
|
||||
private String dayCode;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -27,7 +30,7 @@ public class DetailsActivity extends AppCompatActivity {
|
|||
if (intent == null)
|
||||
return;
|
||||
|
||||
final String dayCode = intent.getStringExtra(Constants.DAY_CODE);
|
||||
dayCode = intent.getStringExtra(Constants.DAY_CODE);
|
||||
if (dayCode == null || dayCode.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -37,6 +40,8 @@ public class DetailsActivity extends AppCompatActivity {
|
|||
|
||||
@OnClick(R.id.details_fab)
|
||||
public void fabClicked(View view) {
|
||||
|
||||
final Intent intent = new Intent(getApplicationContext(), EventActivity.class);
|
||||
intent.putExtra(Constants.DAY_CODE, dayCode);
|
||||
startActivityForResult(intent, ADD_EVENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
package com.simplemobiletools.calendar.activities;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import com.simplemobiletools.calendar.Constants;
|
||||
import com.simplemobiletools.calendar.Formatter;
|
||||
import com.simplemobiletools.calendar.R;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class EventActivity extends AppCompatActivity {
|
||||
@BindView(R.id.event_start_date) TextView mStartDate;
|
||||
@BindView(R.id.event_start_time) TextView mStartTime;
|
||||
@BindView(R.id.event_end_date) TextView mEndDate;
|
||||
@BindView(R.id.event_end_time) TextView mEndTime;
|
||||
|
||||
private DateTime mEventStartDateTime;
|
||||
private DateTime mEventEndDateTime;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_event);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent == null)
|
||||
return;
|
||||
|
||||
final String dayCode = intent.getStringExtra(Constants.DAY_CODE);
|
||||
if (dayCode == null || dayCode.isEmpty())
|
||||
return;
|
||||
|
||||
mEventStartDateTime = Formatter.getDateTime(dayCode);
|
||||
updateStartDate();
|
||||
updateStartTime();
|
||||
|
||||
mEventEndDateTime = Formatter.getDateTime(dayCode);
|
||||
updateEndDate();
|
||||
updateEndTime();
|
||||
}
|
||||
|
||||
private void updateStartDate() {
|
||||
mStartDate.setText(Formatter.getEventDate(mEventStartDateTime));
|
||||
}
|
||||
|
||||
private void updateStartTime() {
|
||||
mStartTime.setText(Formatter.getEventTime(mEventStartDateTime));
|
||||
}
|
||||
|
||||
private void updateEndDate() {
|
||||
mEndDate.setText(Formatter.getEventDate(mEventEndDateTime));
|
||||
}
|
||||
|
||||
private void updateEndTime() {
|
||||
mEndTime.setText(Formatter.getEventTime(mEventEndDateTime));
|
||||
}
|
||||
|
||||
@OnClick(R.id.event_start_date)
|
||||
public void startDateClicked(View view) {
|
||||
new DatePickerDialog(this, startDateSetListener, mEventStartDateTime.getYear(), mEventStartDateTime.getMonthOfYear() - 1,
|
||||
mEventStartDateTime.getDayOfMonth()).show();
|
||||
}
|
||||
|
||||
@OnClick(R.id.event_start_time)
|
||||
public void startTimeClicked(View view) {
|
||||
new TimePickerDialog(this, startTimeSetListener, mEventStartDateTime.getHourOfDay(), mEventStartDateTime.getMinuteOfHour(), true)
|
||||
.show();
|
||||
}
|
||||
|
||||
@OnClick(R.id.event_end_date)
|
||||
public void endDateClicked(View view) {
|
||||
new DatePickerDialog(this, endDateSetListener, mEventEndDateTime.getYear(), mEventEndDateTime.getMonthOfYear() - 1,
|
||||
mEventEndDateTime.getDayOfMonth()).show();
|
||||
}
|
||||
|
||||
@OnClick(R.id.event_end_time)
|
||||
public void endTimeClicked(View view) {
|
||||
new TimePickerDialog(this, endTimeSetListener, mEventEndDateTime.getHourOfDay(), mEventEndDateTime.getMinuteOfHour(), true).show();
|
||||
}
|
||||
|
||||
private final DatePickerDialog.OnDateSetListener startDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
dateSet(year, monthOfYear, dayOfMonth, true);
|
||||
}
|
||||
};
|
||||
|
||||
private TimePickerDialog.OnTimeSetListener startTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
timeSet(hourOfDay, minute, true);
|
||||
}
|
||||
};
|
||||
|
||||
private DatePickerDialog.OnDateSetListener endDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
dateSet(year, monthOfYear, dayOfMonth, false);
|
||||
}
|
||||
};
|
||||
|
||||
private TimePickerDialog.OnTimeSetListener endTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
timeSet(hourOfDay, minute, false);
|
||||
}
|
||||
};
|
||||
|
||||
private void dateSet(int year, int month, int day, boolean isStart) {
|
||||
if (isStart) {
|
||||
mEventStartDateTime = mEventStartDateTime.withYear(year).withMonthOfYear(month + 1).withDayOfMonth(day);
|
||||
updateStartDate();
|
||||
} else {
|
||||
mEventEndDateTime = mEventEndDateTime.withYear(year).withMonthOfYear(month + 1).withDayOfMonth(day);
|
||||
updateEndDate();
|
||||
}
|
||||
}
|
||||
|
||||
private void timeSet(int hours, int minutes, boolean isStart) {
|
||||
if (isStart) {
|
||||
mEventStartDateTime = mEventStartDateTime.withHourOfDay(hours).withMinuteOfHour(minutes);
|
||||
updateStartTime();
|
||||
} else {
|
||||
mEventEndDateTime = mEventEndDateTime.withHourOfDay(hours).withMinuteOfHour(minutes);
|
||||
updateEndTime();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -193,7 +193,6 @@ public class MainActivity extends AppCompatActivity implements Calendar {
|
|||
|
||||
private void updateMonth(String month) {
|
||||
mMonthTV.setText(month);
|
||||
mMonthTV.setTextColor(mTextColor);
|
||||
}
|
||||
|
||||
private void setupLabels() {
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout android:id="@+id/event_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_start_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/start"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_start_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_start_label"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="January 1 1970"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_start_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_start_label"
|
||||
android:layout_toRightOf="@id/event_start_date"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="00:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_end_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_start_date"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:text="@string/end"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_end_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_end_label"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="January 1 1970"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_end_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_end_label"
|
||||
android:layout_toRightOf="@id/event_end_date"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="00:00"
|
||||
android:textSize="@dimen/day_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,8 +1,13 @@
|
|||
<resources>
|
||||
<string name="app_name">Simple Calendar</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Event</string>
|
||||
|
||||
<!-- Details -->
|
||||
<string name="details">Details</string>
|
||||
<string name="start">Start</string>
|
||||
<string name="end">End</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">About</string>
|
||||
|
|
Loading…
Reference in New Issue