diff --git a/android/uhabits-android/src/androidTest/assets/views/habits/show/FrequencyCard/render.png b/android/uhabits-android/src/androidTest/assets/views/habits/show/FrequencyCard/render.png index 81399e360..969c7ff28 100644 Binary files a/android/uhabits-android/src/androidTest/assets/views/habits/show/FrequencyCard/render.png and b/android/uhabits-android/src/androidTest/assets/views/habits/show/FrequencyCard/render.png differ diff --git a/android/uhabits-android/src/androidTest/assets/views/habits/show/ScoreCard/render.png b/android/uhabits-android/src/androidTest/assets/views/habits/show/ScoreCard/render.png index d09080300..872eda3c6 100644 Binary files a/android/uhabits-android/src/androidTest/assets/views/habits/show/ScoreCard/render.png and b/android/uhabits-android/src/androidTest/assets/views/habits/show/ScoreCard/render.png differ diff --git a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.java b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.java deleted file mode 100644 index d8ceac381..000000000 --- a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.show.views; - -import androidx.test.filters.*; -import androidx.test.runner.*; -import android.view.*; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.core.models.*; -import org.junit.*; -import org.junit.runner.*; - -@RunWith(AndroidJUnit4.class) -@MediumTest -public class FrequencyCardTest extends BaseViewTest -{ - public static final String PATH = "habits/show/FrequencyCard/"; - - private FrequencyCard view; - - private Habit habit; - - @Before - @Override - public void setUp() - { - super.setUp(); - habit = fixtures.createLongHabit(); - - view = (FrequencyCard) LayoutInflater - .from(targetContext) - .inflate(R.layout.show_habit, null) - .findViewById(R.id.frequencyCard); - - view.setHabit(habit); - view.refreshData(); - - measureView(view, 800, 600); - } - - @Test - public void testRender() throws Exception - { - assertRenders(view, PATH + "render.png"); - } -} diff --git a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.kt b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.kt new file mode 100644 index 000000000..9ed442ced --- /dev/null +++ b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCardTest.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * 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 . + */ +package org.isoron.uhabits.activities.habits.show.views + +import android.view.* +import androidx.test.ext.junit.runners.* +import androidx.test.filters.* +import org.isoron.uhabits.* +import org.junit.* +import org.junit.runner.* + +@RunWith(AndroidJUnit4::class) +@MediumTest +class FrequencyCardTest : BaseViewTest() { + val PATH = "habits/show/FrequencyCard/" + private lateinit var view: FrequencyCard + + @Before + override fun setUp() { + super.setUp() + val habit = fixtures.createLongHabit() + view = LayoutInflater + .from(targetContext) + .inflate(R.layout.show_habit, null) + .findViewById(R.id.frequencyCard) as FrequencyCard + view.update(FrequencyCardPresenter(habit, 0).present()) + measureView(view, 800f, 600f) + } + + @Test + fun testRender() { + assertRenders(view, PATH + "render.png") + } +} \ No newline at end of file diff --git a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.java b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.java deleted file mode 100644 index 51901e896..000000000 --- a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.show.views; - -import androidx.test.filters.*; -import androidx.test.runner.*; -import android.view.*; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.core.models.*; -import org.junit.*; -import org.junit.runner.*; - -@RunWith(AndroidJUnit4.class) -@MediumTest -public class ScoreCardTest extends BaseViewTest -{ - public static final String PATH = "habits/show/ScoreCard/"; - - private ScoreCard view; - - private Habit habit; - - @Before - @Override - public void setUp() - { - super.setUp(); - habit = fixtures.createLongHabit(); - - view = (ScoreCard) LayoutInflater - .from(targetContext) - .inflate(R.layout.show_habit, null) - .findViewById(R.id.scoreCard); - - view.setHabit(habit); - view.refreshData(); - measureView(view, 800, 600); - } - - @Test - public void testRender() throws Exception - { - assertRenders(view, PATH + "render.png"); - } -} diff --git a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.kt b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.kt new file mode 100644 index 000000000..15029f830 --- /dev/null +++ b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/ScoreCardTest.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * 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 . + */ +package org.isoron.uhabits.activities.habits.show.views + +import android.view.* +import androidx.test.ext.junit.runners.* +import androidx.test.filters.* +import org.isoron.uhabits.* +import org.junit.* +import org.junit.runner.* + +@RunWith(AndroidJUnit4::class) +@MediumTest +class ScoreCardTest : BaseViewTest() { + val PATH = "habits/show/ScoreCard/" + private lateinit var view: ScoreCard + + @Before + override fun setUp() { + super.setUp() + val habit = fixtures.createLongHabit() + view = LayoutInflater + .from(targetContext) + .inflate(R.layout.show_habit, null) + .findViewById(R.id.scoreCard) as ScoreCard + view.update(ScoreCardPresenter(habit, 0).present(0)) + measureView(view, 800f, 600f) + } + + @Test + fun testRender() { + assertRenders(view, PATH + "render.png") + } +} \ No newline at end of file diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index cf8fbc77b..77d9569fc 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -99,6 +99,7 @@ data class ShowHabitViewModel( val target: TargetCardViewModel, val streaks: StreakCardViewModel, val scores: ScoreCardViewModel, + val frequency: FrequencyCardViewModel, ) class ShowHabitView(context: Context) : FrameLayout(context) { @@ -119,6 +120,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) { binding.targetCard.update(data.target) binding.streakCard.update(data.streaks) binding.scoreCard.update(data.scores) + binding.frequencyCard.update(data.frequency) if (data.isNumerical) { binding.overviewCard.visibility = GONE binding.streakCard.visibility = GONE @@ -148,6 +150,8 @@ class ShowHabitPresenter( private val streakCartPresenter = StreakCartPresenter(habit) private val scoreCardPresenter = ScoreCardPresenter(habit = habit, firstWeekday = preferences.firstWeekday) + private val frequencyCardPresenter = FrequencyCardPresenter(habit = habit, + firstWeekday = preferences.firstWeekday) suspend fun present(): ShowHabitViewModel { return ShowHabitViewModel( @@ -159,7 +163,8 @@ class ShowHabitPresenter( notes = notesCardPresenter.present(), target = targetCardPresenter.present(), streaks = streakCartPresenter.present(), - scores = scoreCardPresenter.present(preferences.defaultScoreSpinnerPosition) + scores = scoreCardPresenter.present(preferences.defaultScoreSpinnerPosition), + frequency = frequencyCardPresenter.present(), ) } } \ No newline at end of file diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.java deleted file mode 100644 index 26ff7c810..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.show.views; - -import android.content.*; -import android.util.*; -import android.widget.*; - -import androidx.annotation.Nullable; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.R; -import org.isoron.uhabits.activities.common.views.*; -import org.isoron.uhabits.core.models.*; -import org.isoron.uhabits.core.preferences.*; -import org.isoron.uhabits.core.tasks.*; -import org.isoron.uhabits.utils.*; - -import java.util.*; - -import butterknife.*; - -public class FrequencyCard extends HabitCard -{ - @BindView(R.id.title) - TextView title; - - @BindView(R.id.frequencyChart) - FrequencyChart chart; - - @Nullable - private Preferences prefs; - - public FrequencyCard(Context context) - { - super(context); - init(); - } - - public FrequencyCard(Context context, AttributeSet attrs) - { - super(context, attrs); - init(); - } - - @Override - protected Task createRefreshTask() - { - return new RefreshTask(); - } - - private void init() - { - Context appContext = getContext().getApplicationContext(); - if (appContext instanceof HabitsApplication) - { - HabitsApplication app = (HabitsApplication) appContext; - prefs = app.getComponent().getPreferences(); - } - inflate(getContext(), R.layout.show_habit_frequency, this); - ButterKnife.bind(this); - if (isInEditMode()) initEditMode(); - } - - private void initEditMode() - { - int color = PaletteUtils.getAndroidTestColor(1); - title.setTextColor(color); - chart.setColor(color); - chart.populateWithRandomData(); - } - - private class RefreshTask extends CancelableTask - { - @Override - public void doInBackground() - { - if (isCanceled()) return; - RepetitionList reps = getHabit().getRepetitions(); - HashMap frequency = reps.getWeekdayFrequency(); - if(prefs != null) chart.setFirstWeekday(prefs.getFirstWeekday()); - chart.setFrequency(frequency); - } - - @Override - public void onPreExecute() - { - int color = PaletteUtilsKt.toThemedAndroidColor(getHabit().getColor(), getContext()); - title.setTextColor(color); - chart.setColor(color); - } - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.kt new file mode 100644 index 000000000..dfa3c4715 --- /dev/null +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/views/FrequencyCard.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * 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 . + */ +package org.isoron.uhabits.activities.habits.show.views + +import android.content.* +import android.util.* +import android.view.* +import android.widget.* +import org.isoron.uhabits.core.models.* +import org.isoron.uhabits.databinding.* +import org.isoron.uhabits.utils.* +import java.util.* + +data class FrequencyCardViewModel( + val frequency: HashMap>, + val firstWeekday: Int, + val color: PaletteColor, +) + +class FrequencyCard(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) { + + private var binding = ShowHabitFrequencyBinding.inflate(LayoutInflater.from(context), this) + + fun update(data: FrequencyCardViewModel) { + val androidColor = data.color.toThemedAndroidColor(context) + binding.frequencyChart.setFrequency(data.frequency) + binding.frequencyChart.setFirstWeekday(data.firstWeekday) + binding.title.setTextColor(androidColor) + binding.frequencyChart.setColor(androidColor) + } +} + +class FrequencyCardPresenter( + val habit: Habit, + val firstWeekday: Int, +) { + fun present() = FrequencyCardViewModel( + color = habit.color, + frequency = habit.repetitions.weekdayFrequency, + firstWeekday = firstWeekday, + ) +} \ No newline at end of file