Misc cleanup

pull/384/head
Alex Baker 9 years ago
parent 47d38374de
commit 75f3c509da

@ -1,6 +1,5 @@
package com.todoroo.astrid.reminders;
import android.annotation.SuppressLint;
import android.test.AndroidTestCase;
import com.todoroo.astrid.data.Task;
@ -9,30 +8,18 @@ import org.tasks.preferences.Preferences;
import org.tasks.scheduling.AlarmManager;
import org.tasks.time.DateTime;
import java.util.concurrent.TimeUnit;
import static com.todoroo.astrid.reminders.ReminderService.NO_ALARM;
import static org.mockito.Mockito.mock;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.Freeze.thaw;
import static org.tasks.date.DateTimeUtils.newDate;
public class NotifyAtDeadlineTest extends AndroidTestCase {
@SuppressLint("NewApi")
private static final int MILLIS_PER_HOUR = (int) TimeUnit.HOURS.toMillis(1);
private final Task dueAtNoon = new Task() {{
setDueDate(Task.URGENCY_SPECIFIC_DAY, newDate(2014, 1, 27).getMillis());
setReminderFlags(Task.NOTIFY_AT_DEADLINE);
}};
private ReminderService reminderService;
private Preferences preferences;
@Override
public void setUp() {
preferences = new Preferences(getContext(), null, null);
Preferences preferences = new Preferences(getContext(), null, null);
reminderService = new ReminderService(getContext(), preferences, mock(AlarmManager.class));
freezeAt(new DateTime(2014, 1, 24, 17, 23, 37));
}

@ -72,7 +72,7 @@ public class GtasksLoginActivity extends InjectingAppCompatActivity implements A
private void getAuthToken(String a, final ProgressDialog pd) {
accountManager.getAuthToken(this, a, new AccountManager.AuthResultHandler() {
@Override
public void authenticationSuccessful(String accountName, String authToken) {
public void authenticationSuccessful(String accountName) {
gtasksPreferenceService.setUserName(accountName);
gtasksInvoker.setUserName(accountName);
setResult(RESULT_OK);

@ -42,7 +42,7 @@ public class AccountManager {
}
public interface AuthResultHandler {
void authenticationSuccessful(String accountName, String authToken);
void authenticationSuccessful(String accountName);
void authenticationFailed(String message);
}
@ -85,7 +85,8 @@ public class AccountManager {
@Override
public void run() {
try {
handler.authenticationSuccessful(accountName, GoogleAuthUtil.getToken(activity, account, "oauth2:" + TasksScopes.TASKS, null));
GoogleAuthUtil.getToken(activity, account, "oauth2:" + TasksScopes.TASKS, null);
handler.authenticationSuccessful(accountName);
} catch(UserRecoverableAuthException e) {
Timber.e(e, e.getMessage());
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);

@ -260,37 +260,6 @@ public class AndroidUtilities {
}
}
/**
* Turn ContentValues into a string
*/
public static ContentValues contentValuesFromString(String string) {
if(string == null) {
return null;
}
String[] pairs = string.split("=");
ContentValues result = new ContentValues();
String key = null;
for(int i = 0; i < pairs.length; i++) {
String newKey;
int lastSpace = pairs[i].lastIndexOf(' ');
if(lastSpace != -1) {
newKey = pairs[i].substring(lastSpace + 1);
pairs[i] = pairs[i].substring(0, lastSpace);
} else {
newKey = pairs[i];
}
if(key != null) {
result.put(key.trim(), pairs[i].trim());
}
key = newKey;
}
return result;
}
/**
* Copy a file from one place to another
* @throws Exception

@ -1,55 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.andlib.utility;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import timber.log.Timber;
/**
* Helper class for reading and writing SharedPreferences
*
* @author Tim Su <tim@todoroo.com>
*
*/
@Deprecated
public class Preferences {
private static SharedPreferences preferences = null;
/** Get preferences object from the context */
private static SharedPreferences getPrefs(Context context) {
if(preferences != null) {
return preferences;
}
context = context.getApplicationContext();
try {
preferences = PreferenceManager.getDefaultSharedPreferences(context);
// try writing
preferences.edit().commit();
} catch (Exception e) {
Timber.e(e, e.getMessage());
String alternate = "preferences" + android.os.Process.myUid(); //$NON-NLS-1$
preferences = context.getSharedPreferences(alternate, Context.MODE_PRIVATE);
}
return preferences;
}
public static boolean getBoolean(Context context, int keyResources, boolean defValue) {
try {
return getPrefs(context).getBoolean(context.getString(keyResources), defValue);
} catch (ClassCastException e) {
Timber.e(e, e.getMessage());
return defValue;
}
}
}

@ -177,7 +177,6 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
private EditNoteActivity editNotes;
private HideUntilControlSet hideUntilControls;
private ReminderControlSet reminderControlSet;
private GCalControlSet gcalControl;
@Bind(R.id.title) EditText title;
@Bind(R.id.pager) ViewPager mPager;
@ -350,7 +349,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
RepeatControlSet repeatControls = new RepeatControlSet(preferences, getActivity(), dialogBuilder);
controlSetMap.put(getString(R.string.TEA_ctrl_repeat_pref), repeatControls);
gcalControl = new GCalControlSet(gcalHelper, preferences, this, permissionRequestor);
GCalControlSet gcalControl = new GCalControlSet(gcalHelper, preferences, this, permissionRequestor);
controlSetMap.put(getString(R.string.TEA_ctrl_gcal), gcalControl);
// The deadline control set contains the repeat controls and the
@ -799,7 +798,6 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
} else {
Timber.e("Invalid timestamp");
}
return;
} else if (requestCode == ReminderControlSet.REQUEST_NEW_ALARM && resultCode == Activity.RESULT_OK) {
long timestamp = data.getLongExtra(TimePickerActivity.EXTRA_TIMESTAMP, 0L);
if (timestamp > 0) {

@ -51,12 +51,6 @@ public class AlarmService {
private final MetadataDao metadataDao;
private final Context context;
private final AlarmManager alarmManager;
private final Callback<Metadata> scheduleAlarm = new Callback<Metadata>() {
@Override
public void apply(Metadata alarm) {
scheduleAlarm(alarm);
}
};
@Inject
public AlarmService(MetadataDao metadataDao, @ForApplication Context context, AlarmManager alarmManager) {
@ -119,14 +113,24 @@ public class AlarmService {
* Schedules all alarms
*/
public void scheduleAllAlarms() {
getActiveAlarms(scheduleAlarm);
getActiveAlarms(new Callback<Metadata>() {
@Override
public void apply(Metadata alarm) {
scheduleAlarm(alarm);
}
});
}
/**
* Schedules alarms for a single task
*/
private void scheduleAlarms(long taskId) {
getActiveAlarmsForTask(taskId, scheduleAlarm);
getActiveAlarmsForTask(taskId, new Callback<Metadata>() {
@Override
public void apply(Metadata alarm) {
scheduleAlarm(alarm);
}
});
}
private PendingIntent pendingIntentForAlarm(Metadata alarm, long taskId) {

@ -11,7 +11,6 @@ import android.text.TextUtils;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.CustomFilterActivity.CriterionInstance;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.data.StoreObject;

@ -86,9 +86,5 @@ public class StoreObjectDao {
public void createNew(StoreObject storeObject) {
dao.createNew(storeObject);
}
public StoreObject getById(long id) {
return dao.fetch(id, StoreObject.PROPERTIES);
}
}

@ -131,10 +131,6 @@ public final class TaskAttachment extends RemoteModel {
setValue(CONTENT_TYPE, contentType);
}
public String getUUID() {
return getValue(UUID);
}
public String getFilePath() {
return getValue(FILE_PATH);
}

@ -11,7 +11,6 @@ import android.os.Bundle;
import android.os.Environment;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import org.tasks.R;

@ -1,59 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.ui;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.drawable.shapes.Shape;
public class CustomBorderDrawable extends ShapeDrawable {
private final Paint fillpaint, strokepaint;
private final float strokeWidth;
public CustomBorderDrawable(Shape s, int fill, int stroke, int strokeWidth) {
super(s);
fillpaint = new Paint(this.getPaint());
fillpaint.setColor(fill);
strokepaint = new Paint(fillpaint);
strokepaint.setStyle(Paint.Style.STROKE);
strokepaint.setStrokeWidth(strokeWidth);
strokepaint.setColor(stroke);
this.strokeWidth = strokeWidth;
}
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
shape.resize(canvas.getClipBounds().right,
canvas.getClipBounds().bottom);
Matrix matrix = new Matrix();
matrix.setRectToRect(new RectF(0, 0, canvas.getClipBounds().right,
canvas.getClipBounds().bottom),
new RectF(strokeWidth/2, strokeWidth/2, canvas.getClipBounds().right - strokeWidth/2,
canvas.getClipBounds().bottom - strokeWidth/2),
Matrix.ScaleToFit.FILL);
canvas.concat(matrix);
shape.draw(canvas, fillpaint);
shape.draw(canvas, strokepaint);
}
public static StateListDrawable customButton(int tl, int tr, int br, int bl, int onColor, int offColor, int borderColor, int strokeWidth) {
Shape shape = new RoundRectShape(new float[] { tl, tl, tr, tr, br, br, bl, bl}, null, null);
ShapeDrawable sdOn = new CustomBorderDrawable(shape, onColor, borderColor, strokeWidth);
ShapeDrawable sdOff = new CustomBorderDrawable(shape, offColor, borderColor, strokeWidth);
StateListDrawable stld = new StateListDrawable();
stld.addState(new int[] { android.R.attr.state_pressed }, sdOn);
stld.addState(new int[] { android.R.attr.state_checked }, sdOn);
stld.addState(new int[] { android.R.attr.state_enabled }, sdOff);
return stld;
}
}

@ -1,49 +0,0 @@
package com.todoroo.astrid.ui;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
public class EditDialogOkBackground {
public static StateListDrawable getBg(int colorValue) {
final Paint p = new Paint();
p.setColor(Color.GRAY);
Drawable d = new Drawable() {
@Override
public void setColorFilter(ColorFilter cf) {
//
}
@Override
public void setAlpha(int alpha) {
//
}
@Override
public int getOpacity() {
return PixelFormat.OPAQUE;
}
@Override
public void draw(Canvas canvas) {
Rect r = canvas.getClipBounds();
canvas.drawLine(r.left, r.top, r.right, r.top, p);
}
};
ColorDrawable color = new ColorDrawable(colorValue);
StateListDrawable stld = new StateListDrawable();
stld.addState(new int[] { android.R.attr.state_pressed }, color);
stld.addState(new int[] { android.R.attr.state_enabled }, d);
return stld;
}
}

@ -8,7 +8,6 @@ import com.todoroo.astrid.dao.Database;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;

@ -11,7 +11,6 @@ import com.todoroo.astrid.utility.Flags;
import org.tasks.R;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.ActivityPreferences;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;

@ -16,9 +16,6 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.SynchronizeMetadataCallback;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

@ -14,6 +14,7 @@ import javax.inject.Inject;
import timber.log.Timber;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
public class PermissionChecker {
@ -50,7 +51,7 @@ public class PermissionChecker {
}
private boolean checkPermission(String permission) {
return checkPermissions(asList(permission));
return checkPermissions(singletonList(permission));
}
private boolean checkPermissions(List<String> permissions) {

@ -16,8 +16,6 @@ import java.util.Map;
import javax.inject.Inject;
import static org.tasks.date.DateTimeUtils.newDate;
public class DueDateFormatter {
private final Map<Long, String> dateCache = new HashMap<>();

Loading…
Cancel
Save