Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opentask view Support #1279

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ this app would be just a dream. So thanks to them!
## Features
- Month view.
- Week, day & agenda view.
- view task on day, week, month and agenda view
- Uses Android calendar sync. Works with Google Calendar, Exchange, etc.
- Material designed.
- Support offline calendar.
- Agenda widget.
- Agenda and task widget.
- Multilingual UI.

## How to use Etar
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="org.dmfs.permission.READ_TASKS" />
<uses-permission android:name="org.dmfs.permission.WRITE_TASKS" />

<queries>
<package android:name="at.bitfire.davdroid" />
Expand All @@ -53,6 +55,8 @@
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<provider android:authorities="org.tasks" android:exported="false" />
<provider android:authorities="org.dmfs.tasks" android:exported="false" />
</queries>

<application android:name="com.android.calendar.CalendarApplication"
Expand Down
135 changes: 130 additions & 5 deletions app/src/main/java/com/android/calendar/AllInOneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import com.android.calendar.agenda.AgendaFragment;
import com.android.calendar.alerts.AlertService;
import com.android.calendar.month.MonthByWeekFragment;
import com.android.calendar.persistence.tasks.DmfsOpenTasksContract;
import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
import com.android.calendar.settings.GeneralPreferences;
import com.android.calendar.settings.SettingsActivity;
Expand Down Expand Up @@ -208,6 +209,8 @@ public void onAnimationStart(android.animation.Animator animation) {
private MenuItem mSearchMenu;
private MenuItem mControlsMenu;
private MenuItem mViewSettings;
private MenuItem mViewAgendaEvents;
private MenuItem mViewAgendaTasks;
private Menu mOptionsMenu;
private QueryHandler mHandler;
private final Runnable mHomeTimeUpdater = new Runnable() {
Expand Down Expand Up @@ -398,13 +401,19 @@ private void checkAppPermissions() {
!= PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)) {
!= PackageManager.PERMISSION_GRANTED) ||
ContextCompat.checkSelfPermission(this, DmfsOpenTasksContract.TASK_READ_PERMISSION)
!= PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, DmfsOpenTasksContract.TASK_WRITE_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {

ArrayList<String> permissionsList = new ArrayList<>(Arrays.asList(
Manifest.permission.WRITE_CALENDAR,
Manifest.permission.READ_CALENDAR,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
);
Manifest.permission.WRITE_EXTERNAL_STORAGE,
DmfsOpenTasksContract.TASK_READ_PERMISSION,
DmfsOpenTasksContract.TASK_WRITE_PERMISSION
));

// Permission for calendar notifications
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
Expand Down Expand Up @@ -824,6 +833,31 @@ protected void updateViewSettingsVisiblility() {
}
}

protected void updateViewAgentaSwitchVisibility() {
if (ContextCompat.checkSelfPermission(this, DmfsOpenTasksContract.TASK_READ_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {
if (mViewAgendaTasks != null) {
mViewAgendaTasks.setVisible(false);
mViewAgendaTasks.setEnabled(false);
}
if (mViewAgendaEvents != null) {
mViewAgendaEvents.setVisible(false);
mViewAgendaEvents.setEnabled(false);
}
return;
}

boolean viewAgendaSwitchVisible = mController.getViewType() == ViewType.AGENDA;
if (mViewAgendaTasks != null) {
mViewAgendaTasks.setVisible(viewAgendaSwitchVisible);
mViewAgendaTasks.setEnabled(viewAgendaSwitchVisible);
}
if (mViewAgendaEvents != null) {
mViewAgendaEvents.setVisible(viewAgendaSwitchVisible && !mViewAgendaTasks.isVisible());
mViewAgendaEvents.setEnabled(viewAgendaSwitchVisible);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
Expand Down Expand Up @@ -868,6 +902,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
mViewSettings = menu.findItem(R.id.action_view_settings);
updateViewSettingsVisiblility();

mViewAgendaEvents = menu.findItem(R.id.action_view_agenda_events);
mViewAgendaTasks = menu.findItem(R.id.action_view_agenda_tasks);
updateViewAgentaSwitchVisibility();

mebitek marked this conversation as resolved.
Show resolved Hide resolved
MenuItem menuItem = menu.findItem(R.id.action_today);

Expand Down Expand Up @@ -966,8 +1003,28 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth
startActivity(intent);
} else if (itemId == R.id.action_info) {
checkAndRequestDisablingDoze();
} else if (itemId == R.id.action_view_agenda_tasks || itemId == R.id.action_view_agenda_events) {
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
long millis = Utils.timeFromIntentInMillis(getIntent());
AgendaFragment frag = new AgendaFragment(millis, false);

if (itemId == R.id.action_view_agenda_tasks) {
frag.isTask = true;
mOptionsMenu.findItem(R.id.action_view_agenda_events).setVisible(true);
} else if (itemId == R.id.action_view_agenda_events) {
frag.isTask = false;
mOptionsMenu.findItem(R.id.action_view_agenda_tasks).setVisible(true);
}
item.setVisible(false);

transaction.replace(R.id.main_pane, frag);
mController.registerEventHandler(R.id.main_pane, (EventHandler) frag);
transaction.commit();

return false;
} else {
return mExtensions.handleItemSelected(item, this);
return mExtensions.handleItemSelected(item, this);
}

return true;
Expand Down Expand Up @@ -1272,7 +1329,7 @@ private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {

@Override
public long getSupportedEventTypes() {
return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE | EventType.VIEW_TASK;
}

@Override
Expand Down Expand Up @@ -1339,6 +1396,7 @@ public void handleEvent(EventInfo event) {
}
}
updateViewSettingsVisiblility();
updateViewAgentaSwitchVisibility();
jspricke marked this conversation as resolved.
Show resolved Hide resolved
displayTime = event.selectedTime != null ? event.selectedTime.toMillis()
: event.startTime.toMillis();
if (!mIsTabletConfig) {
Expand Down Expand Up @@ -1408,6 +1466,73 @@ public void handleEvent(EventInfo event) {
}
}
displayTime = event.startTime.toMillis();
} else if (event.eventType == EventType.VIEW_TASK) {

// If in Agenda view and "show_event_details_with_agenda" is "true",
// do not create the event info fragment here, it will be created by the Agenda
// fragment

if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
if (event.startTime != null && event.endTime != null) {
// Event is all day , adjust the goto time to local time
if (event.isAllDay()) {
Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(), mTimeZone);
Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(), mTimeZone);
}
mController.sendEvent(this, EventType.GO_TO,
event.startTime, event.endTime, event.selectedTime,
event.id, ViewType.AGENDA,
CalendarController.EXTRA_GOTO_TIME, null, null);
} else if (event.selectedTime != null) {
mController.sendEvent(this, EventType.GO_TO,
event.selectedTime, event.selectedTime, event.id,
ViewType.AGENDA);
}
} else {
// TODO Fix the temp hack below: && mCurrentView !=
mebitek marked this conversation as resolved.
Show resolved Hide resolved
// ViewType.AGENDA
if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
mController.sendEvent(this, EventType.GO_TO,
event.selectedTime, event.selectedTime, -1,
ViewType.CURRENT);
}
int response = event.getResponse();
if ((mCurrentView == ViewType.AGENDA &&
mShowEventInfoFullScreenAgenda) || ((mCurrentView
== ViewType.DAY || (mCurrentView ==
ViewType.WEEK) || mCurrentView ==
ViewType.MONTH) &&
mShowEventInfoFullScreen)) {
// start event info as activity
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri eventUri = ContentUris.withAppendedId(DmfsOpenTasksContract.Tasks.PROVIDER_URI, event.id);
intent.setData(eventUri);
intent.setClass(this, EventInfoActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis());
intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis());
intent.putExtra(ATTENDEE_STATUS, response);
startActivity(intent);
} else {
// start event info as a dialog
EventInfoFragment fragment = new EventInfoFragment(this,
event.id, event.startTime.toMillis(),
event.endTime.toMillis(), response, true,
EventInfoFragment.DIALOG_WINDOW_STYLE,
null /* No reminders to explicitly pass in. */);
fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
// if we have an old popup replace it
Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
if (fOld != null && fOld.isAdded()) {
ft.remove(fOld);
}
ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
ft.commit();
}
}
displayTime = event.startTime.toMillis();
} else if (event.eventType == EventType.UPDATE_TITLE) {
setTitleInActionBar(event);
if (!mIsTabletConfig) {
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/java/com/android/calendar/CalendarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.util.Pair;

import com.android.calendar.event.EditEventActivity;
import com.android.calendar.persistence.tasks.DmfsOpenTasksContract;
import com.android.calendar.settings.GeneralPreferences;
import com.android.calendar.settings.SettingsActivity;
import com.android.calendarcommon2.Time;
Expand Down Expand Up @@ -426,6 +427,10 @@ public void sendEvent(Object sender, final EventInfo event) {
launchViewEvent(event.id, event.startTime.toMillis(), endTime,
event.getResponse());
return;
} else if (event.eventType == EventType.VIEW_TASK) {
launchViewTask(event.id, event.startTime.toMillis(), endTime,
event.getResponse());
return;
} else if (event.eventType == EventType.EDIT_EVENT) {
launchEditEvent(event.id, event.startTime.toMillis(), endTime, true);
return;
Expand Down Expand Up @@ -589,6 +594,18 @@ public void launchViewEvent(long eventId, long startMillis, long endMillis, int
mContext.startActivity(intent);
}

public void launchViewTask(long eventId, long startMillis, long endMillis, int response) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri eventUri = ContentUris.withAppendedId(DmfsOpenTasksContract.Tasks.PROVIDER_URI, eventId);
intent.setData(eventUri);
intent.setClass(mContext, AllInOneActivity.class);
intent.putExtra(EXTRA_EVENT_BEGIN_TIME, startMillis);
intent.putExtra(EXTRA_EVENT_END_TIME, endMillis);
intent.putExtra(ATTENDEE_STATUS, response);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
}

private void launchEditEvent(long eventId, long startMillis, long endMillis, boolean edit) {
Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
Intent intent = new Intent(Intent.ACTION_EDIT, uri);
Expand Down Expand Up @@ -661,6 +678,8 @@ private String eventInfoToString(EventInfo eventInfo) {
tmp = "View details";
} else if ((eventInfo.eventType & EventType.EDIT_EVENT) != 0) {
tmp = "Edit event";
} else if ((eventInfo.eventType & EventType.VIEW_TASK) != 0) {
tmp = "View task";
} else if ((eventInfo.eventType & EventType.DELETE_EVENT) != 0) {
tmp = "Delete event";
} else if ((eventInfo.eventType & EventType.LAUNCH_SETTINGS) != 0) {
Expand Down Expand Up @@ -722,6 +741,8 @@ public interface EventType {

// date range has changed, update the title
final long UPDATE_TITLE = 1L << 10;

final long VIEW_TASK = 1L << 11;
}

/**
Expand Down Expand Up @@ -833,7 +854,7 @@ public boolean isAllDay() {
}

public int getResponse() {
if (eventType != EventType.VIEW_EVENT) {
if (eventType != EventType.VIEW_EVENT && eventType != EventType.VIEW_TASK) {
Log.wtf(TAG, "illegal call to getResponse , wrong event type " + eventType);
return Attendees.ATTENDEE_STATUS_NONE;
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/android/calendar/DayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ public void run() {
@Override
public void run() {
if (mClickedEvent != null) {
mController.sendEventRelatedEvent(this, EventType.VIEW_EVENT, mClickedEvent.id,
long eventType = EventType.VIEW_EVENT;
if (mClickedEvent.isTask()) {
eventType = EventType.VIEW_TASK;
}
mController.sendEventRelatedEvent(this, eventType, mClickedEvent.id,
mClickedEvent.startMillis, mClickedEvent.endMillis,
DayView.this.getWidth() / 2, mClickedYLocation,
getSelectedTimeInMillis());
Expand Down
Loading