mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Setting custom start of the day (#621)
This commit is contained in:
@@ -92,6 +92,7 @@ public class BaseAndroidTest extends TestCase
|
||||
testContext = InstrumentationRegistry.getInstrumentation().getContext();
|
||||
|
||||
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
DateUtils.setStartDayOffset(0, 0);
|
||||
setResolution(2.0f);
|
||||
setTheme(R.style.AppBaseTheme);
|
||||
setLocale("en", "US");
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.core.database.*
|
||||
import org.isoron.uhabits.core.reminders.*
|
||||
import org.isoron.uhabits.core.ui.*
|
||||
import org.isoron.uhabits.core.utils.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
import org.isoron.uhabits.widgets.*
|
||||
import java.io.*
|
||||
@@ -59,6 +60,7 @@ class HabitsApplication : Application() {
|
||||
db.renameTo(File(db.absolutePath + ".invalid"))
|
||||
DatabaseUtils.initializeDatabase(context)
|
||||
}
|
||||
DateUtils.setStartDayOffset(3, 0)
|
||||
|
||||
widgetUpdater = component.widgetUpdater
|
||||
widgetUpdater.startListening()
|
||||
|
||||
@@ -396,7 +396,7 @@ public class BarChart extends ScrollableChart
|
||||
private float getMaxDayWidth()
|
||||
{
|
||||
float maxDayWidth = 0;
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
|
||||
for (int i = 0; i < 28; i++)
|
||||
{
|
||||
@@ -411,7 +411,7 @@ public class BarChart extends ScrollableChart
|
||||
private float getMaxMonthWidth()
|
||||
{
|
||||
float maxMonthWidth = 0;
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
@@ -153,7 +153,7 @@ public class FrequencyChart extends ScrollableChart
|
||||
pGraph.setColor(primaryColor);
|
||||
prevRect.setEmpty();
|
||||
|
||||
GregorianCalendar currentDate = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar currentDate = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
currentDate.set(Calendar.DAY_OF_MONTH, 1);
|
||||
currentDate.add(Calendar.MONTH, -nColumns + 2 - getDataOffset());
|
||||
|
||||
@@ -274,7 +274,7 @@ public class FrequencyChart extends ScrollableChart
|
||||
private float getMaxMonthWidth()
|
||||
{
|
||||
float maxMonthWidth = 0;
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ public class HistoryChart extends ScrollableChart
|
||||
final Timestamp timestamp = positionToTimestamp(x, y);
|
||||
if (timestamp == null) return false;
|
||||
|
||||
Timestamp today = DateUtils.getToday();
|
||||
Timestamp today = DateUtils.getTodayWithOffset();
|
||||
int newValue = YES_MANUAL;
|
||||
int offset = timestamp.daysUntil(today);
|
||||
if (offset < checkmarks.length)
|
||||
@@ -522,20 +522,20 @@ public class HistoryChart extends ScrollableChart
|
||||
Calendar date = (Calendar) baseDate.clone();
|
||||
date.add(Calendar.DAY_OF_YEAR, offset);
|
||||
|
||||
if (DateUtils.getStartOfDay(date.getTimeInMillis()) >
|
||||
DateUtils.getStartOfToday()) return null;
|
||||
if (DateUtils.getStartOfDayWithOffset(date.getTimeInMillis()) >
|
||||
DateUtils.getStartOfTodayWithOffset()) return null;
|
||||
|
||||
return new Timestamp(date.getTimeInMillis());
|
||||
}
|
||||
|
||||
private void updateDate()
|
||||
{
|
||||
baseDate = DateUtils.getStartOfTodayCalendar();
|
||||
baseDate = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
baseDate.add(Calendar.DAY_OF_YEAR, -(getDataOffset() - 1) * 7);
|
||||
|
||||
nDays = (nColumns - 1) * 7;
|
||||
int realWeekday =
|
||||
DateUtils.getStartOfTodayCalendar().get(Calendar.DAY_OF_WEEK);
|
||||
DateUtils.getStartOfTodayCalendarWithOffset().get(Calendar.DAY_OF_WEEK);
|
||||
todayPositionInColumn =
|
||||
(7 + realWeekday - firstWeekday) % 7;
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ public class ScoreChart extends ScrollableChart
|
||||
private float getMaxDayWidth()
|
||||
{
|
||||
float maxDayWidth = 0;
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
|
||||
for (int i = 0; i < 28; i++)
|
||||
{
|
||||
@@ -372,7 +372,7 @@ public class ScoreChart extends ScrollableChart
|
||||
private float getMaxMonthWidth()
|
||||
{
|
||||
float maxMonthWidth = 0;
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ class CheckmarkPanelView(
|
||||
|
||||
@Synchronized
|
||||
override fun setupButtons() {
|
||||
val today = DateUtils.getToday()
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
|
||||
buttons.forEachIndexed { index, button ->
|
||||
val timestamp = today.minus(index + dataOffset)
|
||||
|
||||
@@ -172,7 +172,7 @@ class HabitCardView(
|
||||
}
|
||||
|
||||
fun triggerRipple(timestamp: Timestamp) {
|
||||
val today = DateUtils.getToday()
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
val offset = timestamp.daysUntil(today) - dataOffset
|
||||
val button = checkmarkPanel.buttons[offset]
|
||||
val y = button.height / 2.0f
|
||||
|
||||
@@ -106,7 +106,7 @@ class HeaderView(
|
||||
}
|
||||
|
||||
fun draw(canvas: Canvas) {
|
||||
val day = getStartOfTodayCalendar()
|
||||
val day = getStartOfTodayCalendarWithOffset()
|
||||
val width = dim(R.dimen.checkmarkWidth)
|
||||
val height = dim(R.dimen.checkmarkHeight)
|
||||
val isReversed = prefs.isCheckmarkSequenceReversed
|
||||
|
||||
@@ -67,7 +67,7 @@ class NumberPanelView(
|
||||
|
||||
@Synchronized
|
||||
override fun setupButtons() {
|
||||
val today = DateUtils.getToday()
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
|
||||
buttons.forEachIndexed { index, button ->
|
||||
val timestamp = today.minus(index + dataOffset)
|
||||
|
||||
@@ -153,7 +153,7 @@ public class OverviewCard extends HabitCard
|
||||
|
||||
ScoreList scores = habit.getScores();
|
||||
|
||||
Timestamp today = DateUtils.getToday();
|
||||
Timestamp today = DateUtils.getTodayWithOffset();
|
||||
Timestamp lastMonth = today.minus(30);
|
||||
Timestamp lastYear = today.minus(365);
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class TargetCard extends HabitCard
|
||||
public void onPostExecute()
|
||||
{
|
||||
if (isCanceled()) return;
|
||||
Calendar cal = DateUtils.getStartOfTodayCalendar();
|
||||
Calendar cal = DateUtils.getStartOfTodayCalendarWithOffset();
|
||||
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
int daysInQuarter = 91;
|
||||
int daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
|
||||
|
||||
@@ -48,7 +48,7 @@ class FireSettingReceiver : BroadcastReceiver() {
|
||||
.build()
|
||||
allHabits = app.component.habitList
|
||||
val args = SettingUtils.parseIntent(intent, allHabits) ?: return
|
||||
val timestamp = DateUtils.getToday()
|
||||
val timestamp = DateUtils.getTodayWithOffset()
|
||||
val controller = component.widgetController
|
||||
|
||||
when (args.action) {
|
||||
|
||||
@@ -38,7 +38,7 @@ class IntentParser
|
||||
|
||||
fun copyIntentData(source: Intent, destination: Intent) {
|
||||
destination.data = source.data;
|
||||
destination.putExtra("timestamp", source.getLongExtra("timestamp", DateUtils.getToday().unixTime))
|
||||
destination.putExtra("timestamp", source.getLongExtra("timestamp", DateUtils.getTodayWithOffset().unixTime))
|
||||
}
|
||||
|
||||
private fun parseHabit(uri: Uri): Habit {
|
||||
@@ -48,7 +48,7 @@ class IntentParser
|
||||
}
|
||||
|
||||
private fun parseTimestamp(intent: Intent): Timestamp {
|
||||
val today = DateUtils.getToday().unixTime
|
||||
val today = DateUtils.getTodayWithOffset().unixTime
|
||||
var timestamp = intent.getLongExtra("timestamp", today)
|
||||
timestamp = DateUtils.getStartOfDay(timestamp)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
Log.i(TAG, String.format("Received intent: %s", intent.toString()));
|
||||
|
||||
Habit habit = null;
|
||||
long today = DateUtils.getStartOfToday();
|
||||
long today = DateUtils.getStartOfTodayWithOffset();
|
||||
|
||||
if (intent.getData() != null)
|
||||
habit = habits.getById(parseId(intent.getData()));
|
||||
|
||||
@@ -64,7 +64,7 @@ class WidgetUpdater
|
||||
}
|
||||
|
||||
fun scheduleStartDayWidgetUpdate() {
|
||||
val timestamp = DateUtils.getStartOfTomorrow()
|
||||
val timestamp = DateUtils.getStartOfTomorrowWithOffset()
|
||||
intentScheduler.scheduleWidgetUpdate(timestamp);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class BaseAndroidJVMTest
|
||||
{
|
||||
long fixed_local_time = 1422172800000L;
|
||||
DateUtils.setFixedLocalTime(fixed_local_time);
|
||||
|
||||
DateUtils.setStartDayOffset(0, 0);
|
||||
modelFactory = new MemoryModelFactory();
|
||||
habitList = spy(modelFactory.buildHabitList());
|
||||
fixtures = new HabitFixtures(modelFactory, habitList);
|
||||
@@ -59,6 +59,7 @@ public class BaseAndroidJVMTest
|
||||
public void tearDown()
|
||||
{
|
||||
DateUtils.setFixedLocalTime(null);
|
||||
DateUtils.setStartDayOffset(0, 0);
|
||||
}
|
||||
|
||||
public long timestamp(int year, int month, int day)
|
||||
|
||||
Reference in New Issue
Block a user