Move remaining model classes

pull/87/merge
Alinson S. Xavier 8 years ago
parent d23b59ced2
commit 51ca4aa98e

@ -25,7 +25,6 @@ import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.widgets.*;
import org.junit.*;
import org.junit.runner.*;

@ -25,7 +25,6 @@ import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.widgets.*;
import org.junit.*;
import org.junit.runner.*;

@ -445,9 +445,9 @@ public class BarChart extends ScrollableChart
return;
}
dfYear = DateFormats.fromSkeleton("yyyy");
dfMonth = DateFormats.fromSkeleton("MMM");
dfDay = DateFormats.fromSkeleton("d");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfDay = AndroidDateFormats.fromSkeleton("d");
}
private void initPaints()

@ -299,8 +299,8 @@ public class FrequencyChart extends ScrollableChart
private void initDateFormats()
{
dfMonth = DateFormats.fromSkeleton("MMM");
dfYear = DateFormats.fromSkeleton("yyyy");
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
}
private void initRects()

@ -413,8 +413,8 @@ public class HistoryChart extends ScrollableChart
private void initDateFormats()
{
dfMonth = DateFormats.fromSkeleton("MMM");
dfYear = DateFormats.fromSkeleton("yyyy");
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
}
private void initRects()

@ -410,9 +410,9 @@ public class ScoreChart extends ScrollableChart
private void initDateFormats()
{
dfYear = DateFormats.fromSkeleton("yyyy");
dfMonth = DateFormats.fromSkeleton("MMM");
dfDay = DateFormats.fromSkeleton("d");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfDay = AndroidDateFormats.fromSkeleton("d");
}
private void initPaints()

@ -32,11 +32,10 @@ import org.isoron.uhabits.R;
import org.isoron.uhabits.activities.common.dialogs.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import butterknife.*;
import static org.isoron.uhabits.utils.DateUtils.*;
public class ReminderPanel extends FrameLayout
implements TimePickerDialog.OnTimeSetListener,
WeekdayPickerDialog.OnWeekdaysPickedListener
@ -86,12 +85,12 @@ public class ReminderPanel extends FrameLayout
}
Context ctx = getContext();
String time = formatTime(ctx, reminder.getHour(), reminder.getMinute());
String time = AndroidDateUtils.formatTime(ctx, reminder.getHour(), reminder.getMinute());
tvReminderTime.setText(time);
llReminderDays.setVisibility(View.VISIBLE);
boolean weekdays[] = reminder.getDays().toArray();
tvReminderDays.setText(formatWeekdayList(ctx, weekdays));
tvReminderDays.setText(AndroidDateUtils.formatWeekdayList(ctx, weekdays));
}
@Override

@ -108,7 +108,7 @@ public class SubtitleCard extends HabitCard
private void updateReminderText(Reminder reminder)
{
reminderLabel.setText(
DateUtils.formatTime(getContext(), reminder.getHour(),
AndroidDateUtils.formatTime(getContext(), reminder.getHour(),
reminder.getMinute()));
}
}

@ -83,7 +83,7 @@ public class IntentFactory
public Intent startShowHabitActivity(Context context, Habit habit)
{
Intent intent = new Intent(context, ShowHabitActivity.class);
intent.setData(habit.getUri());
intent.setData(Uri.parse(habit.getUriString()));
return intent;
}

@ -51,7 +51,7 @@ public class PendingIntentFactory
@Nullable Long timestamp)
{
Intent checkIntent = new Intent(context, WidgetReceiver.class);
checkIntent.setData(habit.getUri());
checkIntent.setData(Uri.parse(habit.getUriString()));
checkIntent.setAction(WidgetReceiver.ACTION_ADD_REPETITION);
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
return PendingIntent.getBroadcast(context, 1, checkIntent,
@ -62,7 +62,7 @@ public class PendingIntentFactory
{
Intent deleteIntent = new Intent(context, ReminderReceiver.class);
deleteIntent.setAction(WidgetReceiver.ACTION_DISMISS_REMINDER);
deleteIntent.setData(habit.getUri());
deleteIntent.setData(Uri.parse(habit.getUriString()));
return PendingIntent.getBroadcast(context, 0, deleteIntent,
FLAG_UPDATE_CURRENT);
}
@ -81,7 +81,7 @@ public class PendingIntentFactory
@Nullable Long reminderTime,
long timestamp)
{
Uri uri = habit.getUri();
Uri uri = Uri.parse(habit.getUriString());
Intent intent = new Intent(context, ReminderReceiver.class);
intent.setAction(ReminderReceiver.ACTION_SHOW_REMINDER);
@ -95,7 +95,7 @@ public class PendingIntentFactory
public PendingIntent snoozeNotification(@NonNull Habit habit)
{
Uri data = habit.getUri();
Uri data = Uri.parse(habit.getUriString());
Intent snoozeIntent = new Intent(context, ReminderReceiver.class);
snoozeIntent.setData(data);
snoozeIntent.setAction(ReminderReceiver.ACTION_SNOOZE_REMINDER);
@ -106,7 +106,7 @@ public class PendingIntentFactory
public PendingIntent toggleCheckmark(@NonNull Habit habit,
@Nullable Long timestamp)
{
Uri data = habit.getUri();
Uri data = Uri.parse(habit.getUriString());
Intent checkIntent = new Intent(context, WidgetReceiver.class);
checkIntent.setData(data);
checkIntent.setAction(WidgetReceiver.ACTION_TOGGLE_REPETITION);

@ -25,7 +25,6 @@ import android.support.annotation.*;
import com.google.auto.factory.*;
import org.isoron.uhabits.AppContext;
import org.isoron.uhabits.activities.ActivityContext;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;

@ -0,0 +1,37 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.utils;
import android.support.annotation.*;
import java.text.*;
import java.util.*;
import static android.text.format.DateFormat.getBestDateTimePattern;
public class AndroidDateFormats
{
@NonNull
public static SimpleDateFormat fromSkeleton(@NonNull String skeleton)
{
Locale locale = Locale.getDefault();
skeleton = getBestDateTimePattern(locale, skeleton);
return DateFormats.fromSkeleton(skeleton, locale);
}
}

@ -0,0 +1,72 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.utils;
import android.content.*;
import android.text.format.*;
import org.isoron.uhabits.*;
import java.util.*;
public class AndroidDateUtils
{
public static String formatTime(Context context, int hours, int minutes)
{
int reminderMilliseconds = (hours * 60 + minutes) * 60 * 1000;
Date date = new Date(reminderMilliseconds);
java.text.DateFormat df = DateFormat.getTimeFormat(context);
df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(date);
}
public static String formatWeekdayList(Context context, boolean weekday[])
{
String shortDayNames[] = DateUtils.getShortDayNames();
String longDayNames[] = DateUtils.getLongDayNames();
StringBuilder buffer = new StringBuilder();
int count = 0;
int first = 0;
boolean isFirst = true;
for (int i = 0; i < 7; i++)
{
if (weekday[i])
{
if (isFirst) first = i;
else buffer.append(", ");
buffer.append(shortDayNames[i]);
isFirst = false;
count++;
}
}
if (count == 1) return longDayNames[first];
if (count == 2 && weekday[0] && weekday[1])
return context.getString(R.string.weekends);
if (count == 5 && !weekday[0] && !weekday[1])
return context.getString(R.string.any_weekday);
if (count == 7) return context.getString(R.string.any_day);
return buffer.toString();
}
}

@ -25,21 +25,6 @@ import android.util.*;
public abstract class ColorUtils
{
public static String CSV_PALETTE[] = {
"#D32F2F", // 0 red
"#E64A19", // 1 orange
"#F9A825", // 2 yellow
"#AFB42B", // 3 light green
"#388E3C", // 4 dark green
"#00897B", // 5 teal
"#00ACC1", // 6 cyan
"#039BE5", // 7 blue
"#5E35B1", // 8 deep purple
"#8E24AA", // 9 purple
"#D81B60", // 10 pink
"#303030", // 11 dark grey
"#aaaaaa" // 12 light grey
};
public static int colorToPaletteIndex(Context context, int color)
{

@ -26,6 +26,10 @@ dependencies {
implementation 'com.google.auto.factory:auto-factory:1.0-beta3'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.apache.commons:commons-lang3:3.5'
implementation ('com.opencsv:opencsv:3.9') {
exclude group: 'commons-logging', module: 'commons-logging'
}
}
sourceCompatibility = "1.8"

@ -27,9 +27,9 @@ import java.io.*;
import java.text.*;
import java.util.*;
import static org.isoron.uhabits.models.Checkmark.CHECKED_EXPLICITLY;
import static org.isoron.uhabits.models.Checkmark.CHECKED_IMPLICITLY;
import javax.annotation.concurrent.*;
import static org.isoron.uhabits.models.Checkmark.*;
/**
* The collection of {@link Checkmark}s belonging to a habit.
*/

@ -19,7 +19,6 @@
package org.isoron.uhabits.models;
import android.net.*;
import android.support.annotation.*;
import org.apache.commons.lang3.builder.*;
@ -281,12 +280,11 @@ public class Habit
/**
* Returns the public URI that identifies this habit
*
* @return the uri
* @return the URI
*/
public Uri getUri()
public String getUriString()
{
String s = String.format(Locale.US, HABIT_URI_FORMAT, getId());
return Uri.parse(s);
return String.format(Locale.US, HABIT_URI_FORMAT, getId());
}
public synchronized boolean hasId()

@ -230,7 +230,7 @@ public abstract class HabitList implements Iterable<Habit>
habit.getDescription(),
Integer.toString(freq.getNumerator()),
Integer.toString(freq.getDenominator()),
ColorUtils.CSV_PALETTE[habit.getColor()]
ColorConstants.CSV_PALETTE[habit.getColor()]
};
csv.writeNext(cols, false);

@ -36,7 +36,7 @@ public class HabitMatcherBuilder
private static List<Integer> allColors()
{
List<Integer> colors = new ArrayList<>();
for(int i = 0; i < ColorUtils.CSV_PALETTE.length; i++)
for(int i = 0; i < ColorConstants.CSV_PALETTE.length; i++)
colors.add(i);
return colors;
}

@ -0,0 +1,20 @@
package org.isoron.uhabits.utils;
public class ColorConstants
{
public static String[] CSV_PALETTE = {
"#D32F2F", // 0 red
"#E64A19", // 1 orange
"#F9A825", // 2 yellow
"#AFB42B", // 3 light green
"#388E3C", // 4 dark green
"#00897B", // 5 teal
"#00ACC1", // 6 cyan
"#039BE5", // 7 blue
"#5E35B1", // 8 deep purple
"#8E24AA", // 9 purple
"#D81B60", // 10 pink
"#303030", // 11 dark grey
"#aaaaaa" // 12 light grey
};
}

@ -24,12 +24,10 @@ import android.support.annotation.*;
import java.text.*;
import java.util.*;
import static android.text.format.DateFormat.*;
public class DateFormats
{
@NonNull
private static SimpleDateFormat fromSkeleton(@NonNull String skeleton,
public static SimpleDateFormat fromSkeleton(@NonNull String skeleton,
@NonNull Locale locale)
{
SimpleDateFormat df = new SimpleDateFormat(skeleton, locale);
@ -37,14 +35,6 @@ public class DateFormats
return df;
}
@NonNull
public static SimpleDateFormat fromSkeleton(@NonNull String skeleton)
{
Locale locale = Locale.getDefault();
skeleton = getBestDateTimePattern(locale, skeleton);
return fromSkeleton(skeleton, locale);
}
public static SimpleDateFormat getBackupDateFormat()
{
return fromSkeleton("yyyy-MM-dd HHmmss", Locale.US);

@ -19,11 +19,6 @@
package org.isoron.uhabits.utils;
import android.content.*;
import android.text.format.*;
import org.isoron.uhabits.*;
import java.util.*;
import static java.util.Calendar.*;
@ -54,48 +49,6 @@ public abstract class DateUtils
return dayOfWeek + "\n" + dayOfMonth;
}
public static String formatTime(Context context, int hours, int minutes)
{
int reminderMilliseconds = (hours * 60 + minutes) * 60 * 1000;
Date date = new Date(reminderMilliseconds);
java.text.DateFormat df = DateFormat.getTimeFormat(context);
df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(date);
}
public static String formatWeekdayList(Context context, boolean weekday[])
{
String shortDayNames[] = getShortDayNames();
String longDayNames[] = getLongDayNames();
StringBuilder buffer = new StringBuilder();
int count = 0;
int first = 0;
boolean isFirst = true;
for (int i = 0; i < 7; i++)
{
if (weekday[i])
{
if (isFirst) first = i;
else buffer.append(", ");
buffer.append(shortDayNames[i]);
isFirst = false;
count++;
}
}
if (count == 1) return longDayNames[first];
if (count == 2 && weekday[0] && weekday[1])
return context.getString(R.string.weekends);
if (count == 5 && !weekday[0] && !weekday[1])
return context.getString(R.string.any_weekday);
if (count == 7) return context.getString(R.string.any_day);
return buffer.toString();
}
public static GregorianCalendar getCalendar(long timestamp)
{
GregorianCalendar day =
Loading…
Cancel
Save