allow changing the day with the datepicker
This commit is contained in:
parent
b22351dc88
commit
d790cfd81a
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.calendar.activities;
|
package com.simplemobiletools.calendar.activities;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
@ -7,6 +8,7 @@ import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.CoordinatorLayout;
|
import android.support.design.widget.CoordinatorLayout;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
|
@ -16,6 +18,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.DatePicker;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -110,6 +113,30 @@ public class DayActivity extends AppCompatActivity
|
||||||
switchToDay(tomorrowCode);
|
switchToDay(tomorrowCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.top_text)
|
||||||
|
public void pickDay() {
|
||||||
|
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this, R.style.MyAlertDialog);
|
||||||
|
final View view = getLayoutInflater().inflate(R.layout.date_picker, null);
|
||||||
|
final DatePicker datePicker = (DatePicker) view.findViewById(R.id.date_picker);
|
||||||
|
|
||||||
|
final DateTime dateTime = Formatter.getDateTimeFromCode(mDayCode);
|
||||||
|
datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(), null);
|
||||||
|
|
||||||
|
alertDialog.setView(view);
|
||||||
|
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
final int month = datePicker.getMonth() + 1;
|
||||||
|
final int year = datePicker.getYear();
|
||||||
|
final int day = datePicker.getDayOfMonth();
|
||||||
|
final DateTime newDateTime = dateTime.withDayOfMonth(day).withMonthOfYear(month).withYear(year);
|
||||||
|
String newDayCode = Formatter.getDayCodeFromDateTime(newDateTime);
|
||||||
|
switchToDay(newDayCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void switchToDay(String dayCode) {
|
private void switchToDay(String dayCode) {
|
||||||
final Intent intent = new Intent(getApplicationContext(), DayActivity.class);
|
final Intent intent = new Intent(getApplicationContext(), DayActivity.class);
|
||||||
intent.putExtra(Constants.DAY_CODE, dayCode);
|
intent.putExtra(Constants.DAY_CODE, dayCode);
|
||||||
|
|
Loading…
Reference in New Issue