mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
HistoryChart: Customizable first day of week
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 31 KiB |
@@ -50,7 +50,7 @@ public class ScoreChartTest extends BaseViewTest
|
||||
fixtures.purgeHabits(habitList);
|
||||
habit = fixtures.createLongHabit();
|
||||
presenter = new ScoreCardPresenter();
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekday(), 0);
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekdayInt(), 0);
|
||||
|
||||
view = new ScoreChart(targetContext);
|
||||
view.setScores(model.getScores());
|
||||
@@ -84,7 +84,7 @@ public class ScoreChartTest extends BaseViewTest
|
||||
@Test
|
||||
public void testRender_withMonthlyBucket() throws Throwable
|
||||
{
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekday(), 2);
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekdayInt(), 2);
|
||||
view.setScores(model.getScores());
|
||||
view.setBucketSize(model.getBucketSize());
|
||||
view.invalidate();
|
||||
@@ -102,7 +102,7 @@ public class ScoreChartTest extends BaseViewTest
|
||||
@Test
|
||||
public void testRender_withYearlyBucket() throws Throwable
|
||||
{
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekday(), 4);
|
||||
ScoreCardViewModel model = presenter.present(habit, prefs.getFirstWeekdayInt(), 4);
|
||||
view.setScores(model.getScores());
|
||||
view.setBucketSize(model.getBucketSize());
|
||||
view.invalidate();
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import org.isoron.platform.time.DayOfWeek.SUNDAY
|
||||
import org.isoron.uhabits.BaseViewTest
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.views.HistoryCardPresenter
|
||||
@@ -47,7 +48,7 @@ class HistoryCardViewTest : BaseViewTest() {
|
||||
view.update(
|
||||
HistoryCardPresenter().present(
|
||||
habit = habit,
|
||||
firstWeekday = 1,
|
||||
firstWeekday = SUNDAY,
|
||||
isSkipEnabled = false,
|
||||
theme = LightTheme(),
|
||||
)
|
||||
|
||||
@@ -29,8 +29,6 @@ import org.isoron.uhabits.core.models.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class HistoryWidgetTest extends BaseViewTest
|
||||
@@ -49,7 +47,7 @@ public class HistoryWidgetTest extends BaseViewTest
|
||||
prefs.setWidgetOpacity(255);
|
||||
|
||||
habit = fixtures.createVeryLongHabit();
|
||||
HistoryWidget widget = new HistoryWidget(targetContext, 0, habit, Calendar.SUNDAY);
|
||||
HistoryWidget widget = new HistoryWidget(targetContext, 0, habit);
|
||||
view = convertToView(widget, 400, 400);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ package org.isoron.uhabits.activities.common.dialogs;
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.util.*;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.*;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.*;
|
||||
import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
|
||||
@@ -47,15 +47,12 @@ class HistoryCardView(context: Context, attrs: AttributeSet) : LinearLayout(cont
|
||||
today = data.today,
|
||||
paletteColor = data.color,
|
||||
theme = data.theme,
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault())
|
||||
).apply {
|
||||
series = data.series
|
||||
}
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
||||
series = data.series,
|
||||
firstWeekday = data.firstWeekday,
|
||||
)
|
||||
|
||||
// binding.historyChart.setFirstWeekday(data.firstWeekday)
|
||||
// binding.historyChart.setSkipEnabled(data.isSkipEnabled)
|
||||
// binding.historyChart.setEntries(data.entries)
|
||||
// binding.historyChart.setColor(androidColor)
|
||||
// if (data.isNumerical) {
|
||||
// binding.historyChart.setNumerical(true)
|
||||
// }
|
||||
|
||||
@@ -177,7 +177,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private void updateWeekdayPreference()
|
||||
{
|
||||
ListPreference weekdayPref = (ListPreference) findPreference("pref_first_weekday");
|
||||
int currentFirstWeekday = prefs.getFirstWeekday();
|
||||
int currentFirstWeekday = prefs.getFirstWeekday().getDaysSinceSunday() + 1;
|
||||
String[] dayNames = DateUtils.getLongWeekdayNames(Calendar.SATURDAY);
|
||||
String[] dayValues = {"7", "1", "2", "3", "4", "5", "6"};
|
||||
weekdayPref.setEntries(dayNames);
|
||||
|
||||
@@ -28,7 +28,7 @@ class FrequencyWidgetProvider : BaseWidgetProvider() {
|
||||
context,
|
||||
id,
|
||||
habits[0],
|
||||
preferences.firstWeekday
|
||||
preferences.firstWeekdayInt
|
||||
)
|
||||
else return StackWidget(context, id, StackWidgetType.FREQUENCY, habits)
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ import java.util.Locale
|
||||
class HistoryWidget(
|
||||
context: Context,
|
||||
id: Int,
|
||||
private val habit: Habit,
|
||||
private val firstWeekday: Int
|
||||
private val habit: Habit
|
||||
) : BaseWidget(context, id) {
|
||||
|
||||
override fun getOnClickPendingIntent(context: Context): PendingIntent {
|
||||
@@ -66,7 +65,9 @@ class HistoryWidget(
|
||||
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
||||
paletteColor = habit.color,
|
||||
theme = WidgetTheme(),
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault())
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
||||
firstWeekday = prefs.firstWeekday,
|
||||
series = listOf(),
|
||||
)
|
||||
}
|
||||
).apply {
|
||||
|
||||
@@ -26,8 +26,7 @@ class HistoryWidgetProvider : BaseWidgetProvider() {
|
||||
if (habits.size == 1) return HistoryWidget(
|
||||
context,
|
||||
id,
|
||||
habits[0],
|
||||
preferences.firstWeekday
|
||||
habits[0]
|
||||
)
|
||||
else return StackWidget(context, id, StackWidgetType.HISTORY, habits)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ScoreWidget(
|
||||
val presenter = ScoreCardPresenter()
|
||||
val viewModel = presenter.present(
|
||||
habit = habit,
|
||||
firstWeekday = prefs.firstWeekday,
|
||||
firstWeekday = prefs.firstWeekdayInt,
|
||||
spinnerPosition = prefs.scoreCardSpinnerPosition
|
||||
)
|
||||
val widgetView = view as GraphWidgetView
|
||||
|
||||
@@ -97,11 +97,11 @@ class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory
|
||||
case CHECKMARK:
|
||||
return new CheckmarkWidget(context, widgetId, habit);
|
||||
case FREQUENCY:
|
||||
return new FrequencyWidget(context, widgetId, habit, prefs.getFirstWeekday());
|
||||
return new FrequencyWidget(context, widgetId, habit, prefs.getFirstWeekdayInt());
|
||||
case SCORE:
|
||||
return new ScoreWidget(context, widgetId, habit);
|
||||
case HISTORY:
|
||||
return new HistoryWidget(context, widgetId, habit, prefs.getFirstWeekday());
|
||||
return new HistoryWidget(context, widgetId, habit);
|
||||
case STREAKS:
|
||||
return new StreakWidget(context, widgetId, habit);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class TargetWidget(
|
||||
if (preferedBackgroundAlpha >= 255) widgetView.setShadowAlpha(0x4f)
|
||||
val chart = (widgetView.dataView as TargetChart)
|
||||
val presenter = TargetCardPresenter()
|
||||
val data = presenter.present(habit, prefs.firstWeekday)
|
||||
val data = presenter.present(habit, prefs.firstWeekdayInt)
|
||||
chart.setColor(data.color.toThemedAndroidColor(context))
|
||||
chart.setTargets(data.targets)
|
||||
chart.setLabels(data.intervals.map { intervalToLabel(context.resources, it) })
|
||||
|
||||
Reference in New Issue
Block a user