mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Code cleanup
This commit is contained in:
@@ -28,9 +28,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DateHelper
|
||||
@@ -159,37 +157,13 @@ public class DateHelper
|
||||
|
||||
|
||||
/**
|
||||
* Throughout the code, it is assumed that the weekdays are numbered
|
||||
* from 0 (Saturday) to 6 (Friday).
|
||||
*
|
||||
* see https://github.com/iSoron/uhabits/issues/74
|
||||
*
|
||||
* In the Java Calendar they are numbered from 1 (Sunday) to 7 (Saturday)
|
||||
*
|
||||
* <table>
|
||||
* <thead>
|
||||
* <tr><th>day</th><th>dayNumber</th><th>wdaysIndex</th></tr>
|
||||
* <thead>
|
||||
* <tbody>
|
||||
* <tr><td>Su</td><td>1</td><td>1</td></tr>
|
||||
* <tr><td>Mo</td><td>2</td><td>2</td></tr>
|
||||
* <tr><td>Tu</td><td>3</td><td>3</td></tr>
|
||||
* <tr><td>We</td><td>4</td><td>4</td></tr>
|
||||
* <tr><td>Th</td><td>5</td><td>5</td></tr>
|
||||
* <tr><td>Fr</td><td>6</td><td>6</td></tr>
|
||||
* <tr><td>Sa</td><td>7</td><td>0</td></tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
*
|
||||
* So we have {@code wdaysIndex = dayNumber % 7}
|
||||
* Throughout the code, it is assumed that the weekdays are numbered from 0 (Saturday) to 6
|
||||
* (Friday). In the Java Calendar they are numbered from 1 (Sunday) to 7 (Saturday). This
|
||||
* function converts from Java to our internal representation.
|
||||
*
|
||||
* @return weekday number in the internal interpretation
|
||||
*
|
||||
* @see #getWeekday(long)
|
||||
* @see java.util.Calendar#SUNDAY
|
||||
*
|
||||
*/
|
||||
public static int weekDayNumber2wdays(int number)
|
||||
public static int javaWeekdayToLoopWeekday(int number)
|
||||
{
|
||||
return number % 7;
|
||||
}
|
||||
@@ -199,26 +173,21 @@ public class DateHelper
|
||||
String[] wdays = new String[7];
|
||||
|
||||
Calendar day = new GregorianCalendar();
|
||||
// we start with Saturday
|
||||
day.set(GregorianCalendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
||||
|
||||
for (int i = 0; i < wdays.length; i++)
|
||||
{
|
||||
wdays[i] = day.getDisplayName(GregorianCalendar.DAY_OF_WEEK, format,
|
||||
Locale.getDefault());
|
||||
// advance in time by one day
|
||||
day.add(GregorianCalendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
return wdays;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array with weekday names starting according to locale settings,
|
||||
* e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Europe
|
||||
*
|
||||
*/
|
||||
public static String[] getLocaleDayNames(int format)
|
||||
{
|
||||
@@ -230,7 +199,6 @@ public class DateHelper
|
||||
{
|
||||
days[i] = calendar.getDisplayName(GregorianCalendar.DAY_OF_WEEK, format,
|
||||
Locale.getDefault());
|
||||
// advance in time by one day
|
||||
calendar.add(GregorianCalendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
@@ -238,42 +206,22 @@ public class DateHelper
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array with week days numbers starting according to locale settings,
|
||||
* e.g. [2,3,4,5,6,7,1] in Europe
|
||||
*
|
||||
* @see java.util.Calendar#SUNDAY
|
||||
*
|
||||
*/
|
||||
public static Integer[] getLocaleWeekdayList()
|
||||
{
|
||||
Integer[] dayNumbers = new Integer[7];
|
||||
// a dummy calendar
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
// set staring day according to locale
|
||||
calendar.set(GregorianCalendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
|
||||
for (int i = 0; i < dayNumbers.length; i++) {
|
||||
for (int i = 0; i < dayNumbers.length; i++)
|
||||
{
|
||||
dayNumbers[i] = calendar.get(GregorianCalendar.DAY_OF_WEEK);
|
||||
// advance in time by one day
|
||||
calendar.add(GregorianCalendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
return dayNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* here we create the mapping of week days numbers into the "wdays"-indices
|
||||
*
|
||||
* @see DateHelper#getDayNames(int)
|
||||
*/
|
||||
public static Map<Integer, Integer> getWeekdayMap()
|
||||
{
|
||||
Map<Integer, Integer> number2wdays = new HashMap<>();
|
||||
for (Integer number : getLocaleWeekdayList()) {
|
||||
number2wdays.put(number, number % 7);
|
||||
}
|
||||
return number2wdays;
|
||||
}
|
||||
|
||||
public static String formatWeekdayList(Context context, boolean weekday[])
|
||||
{
|
||||
String shortDayNames[] = getShortDayNames();
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class HabitFrequencyView extends ScrollableDataView implements HabitDataView
|
||||
@@ -234,7 +233,7 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
||||
rect.set(0, 0, baseSize, baseSize);
|
||||
rect.offset(prevRect.left, prevRect.top + columnWidth * j);
|
||||
|
||||
int i = DateHelper.weekDayNumber2wdays(localeWeekdayList[j]);
|
||||
int i = DateHelper.javaWeekdayToLoopWeekday(localeWeekdayList[j]);
|
||||
if(values != null)
|
||||
drawMarker(canvas, rect, values[i]);
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.isoron.uhabits.tasks.ToggleRepetitionTask;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class HabitHistoryView extends ScrollableDataView implements HabitDataView,
|
||||
@@ -277,7 +276,8 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
{
|
||||
if (!(column == nColumns - 2 && getDataOffset() == 0 && j > todayPositionInColumn))
|
||||
{
|
||||
int checkmarkOffset = getDataOffset() * 7 + nDays - 7 * (column + 1) + todayPositionInColumn - j;
|
||||
int checkmarkOffset = getDataOffset() * 7 + nDays - 7 * (column + 1) +
|
||||
todayPositionInColumn - j;
|
||||
drawSquare(canvas, location, date, checkmarkOffset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user