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

Remove android.text.format.Time usage. #467 #646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions opentasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ android {

dependencies {
implementation project(':opentasks-provider')
implementation project(':opentaskspal')
implementation 'com.android.support:appcompat-v7:' + SUPPORT_LIBRARY_VERSION
implementation 'com.android.support:design:' + SUPPORT_LIBRARY_VERSION
implementation('org.dmfs:android-xml-magic:0.1.1') {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.text.format.Time;

import com.google.android.apps.dashclock.api.DashClockExtension;
import com.google.android.apps.dashclock.api.ExtensionData;

import org.dmfs.provider.tasks.AuthorityUtil;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.EditTaskActivity;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.contract.TaskContract.Tasks;
import org.dmfs.tasks.model.TaskFieldAdapters;
import org.dmfs.tasks.model.adapters.TimeFieldAdapter;
import org.dmfs.tasks.model.adapters.CombinedDateTimeFieldAdapter;
import org.dmfs.tasks.model.adapters.FieldAdapter;
import org.dmfs.tasks.utils.DateFormatter;
import org.dmfs.tasks.utils.DateFormatter.DateFormatContext;

Expand Down Expand Up @@ -243,8 +244,8 @@ private String getTaskTitleDueString(Cursor c, boolean isAllDay)
}
else
{
TimeFieldAdapter timeFieldAdapter = new TimeFieldAdapter(Instances.DUE, Instances.TZ, Instances.IS_ALLDAY);
Time dueTime = timeFieldAdapter.get(c);
FieldAdapter<DateTime> dateTimeFieldAdapter = new CombinedDateTimeFieldAdapter(Instances.DUE, Instances.TZ, Instances.IS_ALLDAY);
DateTime dueTime = dateTimeFieldAdapter.get(c);
if (dueTime == null)
{
return null;
Expand All @@ -263,8 +264,8 @@ private String getTaskTitleStartString(Cursor c, boolean isAllDay)
}
else
{
TimeFieldAdapter timeFieldAdapter = new TimeFieldAdapter(Instances.DTSTART, Instances.TZ, Instances.IS_ALLDAY);
Time startTime = timeFieldAdapter.get(c);
FieldAdapter<DateTime> dateTimeFieldAdapter = new CombinedDateTimeFieldAdapter(Instances.DTSTART, Instances.TZ, Instances.IS_ALLDAY);
DateTime startTime = dateTimeFieldAdapter.get(c);
if (startTime == null)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package org.dmfs.tasks.groupings;

import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.model.adapters.TimeFieldAdapter;
import org.dmfs.tasks.model.adapters.CombinedDateTimeFieldAdapter;
import org.dmfs.tasks.model.adapters.FieldAdapter;
import org.dmfs.tasks.utils.ExpandableChildDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;

Expand All @@ -42,12 +44,14 @@ public abstract class AbstractGroupingFactory
/**
* An adapter to load the due date from the instances projection. This is used by most groupings
*/
public final static TimeFieldAdapter INSTANCE_DUE_ADAPTER = new TimeFieldAdapter(Instances.INSTANCE_DUE, Instances.TZ, Instances.IS_ALLDAY);
public final static FieldAdapter<DateTime> INSTANCE_DUE_ADAPTER = new CombinedDateTimeFieldAdapter(Instances.INSTANCE_DUE, Instances.TZ,
Instances.IS_ALLDAY);

/**
* An adapter to load the start date from the instances projection. This is used by most groupings
*/
public final static TimeFieldAdapter INSTANCE_START_ADAPTER = new TimeFieldAdapter(Instances.INSTANCE_START, Instances.TZ, Instances.IS_ALLDAY);
public final static FieldAdapter<DateTime> INSTANCE_START_ADAPTER = new CombinedDateTimeFieldAdapter(Instances.INSTANCE_START, Instances.TZ,
Instances.IS_ALLDAY);

/**
* The authority of the content provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
import android.database.Cursor;
import android.support.v4.util.SparseArrayCompat;
import android.text.TextUtils;
import android.text.format.Time;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.R;
import org.dmfs.tasks.model.TaskFieldAdapters;
import org.dmfs.tasks.utils.DateFormatter;
import org.dmfs.tasks.utils.DateFormatter.DateFormatContext;
import org.dmfs.tasks.utils.ViewDescriptor;

import java.util.TimeZone;


/**
* A base implementation of a {@link ViewDescriptor}. It has a number of commonly used methods.
Expand All @@ -42,53 +40,32 @@
public abstract class BaseTaskViewDescriptor implements ViewDescriptor
{

/**
* We use this to get the current time.
*/
protected Time mNow;


protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed)
// TODO Add Nullable, NonNull annotations
protected void setDueDate(TextView view, ImageView dueIcon, DateTime dueDate, boolean isClosed)
{
if (view != null && dueDate != null)
if (view == null)
{
Time now = mNow;
if (now == null)
{
now = mNow = new Time();
}
if (!now.timezone.equals(TimeZone.getDefault().getID()))
{
now.clear(TimeZone.getDefault().getID());
}

if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000)
{
now.setToNow();
now.normalize(true);
}
// TODO can this happen?
return;
}

dueDate.normalize(true);
if (dueDate != null)
{
// TODO cache nowAndHere of some time (it was 5 secs before)
DateTime nowAndHere = DateTime.nowAndHere();

view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW));
view.setText(new DateFormatter(view.getContext()).format(dueDate, nowAndHere, DateFormatContext.LIST_VIEW));
if (dueIcon != null)
{
dueIcon.setVisibility(View.VISIBLE);
}

// highlight overdue dates & times, handle allDay tasks separately
if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay
&& (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year))
&& !isClosed)
{
view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text);
}
else
{
view.setTextAppearance(view.getContext(), R.style.task_list_due_text);
}
// overdue tasks are highlighted
int textStyle = dueDate.after(nowAndHere) && !isClosed ? R.style.task_list_overdue_text : R.style.task_list_due_text;
view.setTextAppearance(view.getContext(), textStyle);

}
else if (view != null)
else
{
view.setText("");
if (dueIcon != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.text.format.Time;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.TimeRangeCursorFactory;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
TextView startDateField = getView(view, R.id.task_start_date);
if (startDateField != null)
{
Time startDate = INSTANCE_START_ADAPTER.get(cursor);
DateTime startDate = INSTANCE_START_ADAPTER.get(cursor);

if (startDate != null)
{
Expand Down
Loading