Merge pull request #547 from recheej/rechee/add_notes

Add Notes to Habits.
This commit is contained in:
2020-03-01 15:11:38 -05:00
committed by GitHub
39 changed files with 437 additions and 110 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -39,6 +39,7 @@ import static androidx.test.uiautomator.UiDevice.*;
public class BaseUserInterfaceTest
{
private static final String PKG = "org.isoron.uhabits";
public static final String EMPTY_DESCRIPTION_HABIT_NAME = "Read books";
public static UiDevice device;
@@ -96,25 +97,29 @@ public class BaseUserInterfaceTest
Habit h1 = fixtures.createEmptyHabit();
h1.setName("Wake up early");
h1.setDescription("Did you wake up early today?");
h1.setQuestion("Did you wake up early today?");
h1.setDescription("test description 1");
h1.setColor(5);
habitList.update(h1);
Habit h2 = fixtures.createShortHabit();
h2.setName("Track time");
h2.setDescription("Did you track your time?");
h2.setQuestion("Did you track your time?");
h2.setDescription("test description 2");
h2.setColor(5);
habitList.update(h2);
Habit h3 = fixtures.createLongHabit();
h3.setName("Meditate");
h3.setDescription("Did meditate today?");
h3.setQuestion("Did meditate today?");
h3.setDescription("test description 3");
h3.setColor(10);
habitList.update(h3);
Habit h4 = fixtures.createEmptyHabit();
h4.setName("Read books");
h4.setDescription("Did you read books today?");
h4.setName(EMPTY_DESCRIPTION_HABIT_NAME);
h4.setQuestion("Did you read books today?");
h4.setDescription("");
h4.setColor(2);
habitList.update(h4);
}

View File

@@ -52,7 +52,8 @@ public class HabitFixtures
{
Habit habit = modelFactory.buildHabit();
habit.setName("Meditate");
habit.setDescription("Did you meditate this morning?");
habit.setQuestion("Did you meditate this morning?");
habit.setDescription("This is a test description");
habit.setColor(5);
habit.setFrequency(Frequency.DAILY);
habit.setId(id);
@@ -81,7 +82,7 @@ public class HabitFixtures
{
Habit habit = modelFactory.buildHabit();
habit.setName("Take a walk");
habit.setDescription("How many steps did you walk today?");
habit.setQuestion("How many steps did you walk today?");
habit.setType(Habit.NUMBER_HABIT);
habit.setTargetType(Habit.AT_LEAST);
habit.setTargetValue(200.0);
@@ -103,7 +104,7 @@ public class HabitFixtures
{
Habit habit = modelFactory.buildHabit();
habit.setName("Wake up early");
habit.setDescription("Did you wake up before 6am?");
habit.setQuestion("Did you wake up before 6am?");
habit.setFrequency(new Frequency(2, 3));
habitList.add(habit);

View File

@@ -20,7 +20,6 @@
package org.isoron.uhabits.acceptance;
import androidx.test.filters.*;
import androidx.test.runner.*;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -39,7 +38,16 @@ import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*;
public class HabitsTest extends BaseUserInterfaceTest
{
@Test
public void shouldCreateHabit() throws Exception
public void shouldCreateHabit() throws Exception {
shouldCreateHabit("this is a test description");
}
@Test
public void shouldCreateHabitBlankDescription() throws Exception {
shouldCreateHabit("");
}
private void shouldCreateHabit(String description) throws Exception
{
launchApp();
@@ -47,14 +55,16 @@ public class HabitsTest extends BaseUserInterfaceTest
clickMenu(ADD);
verifyShowsScreen(EDIT_HABIT);
typeName("Hello world");
String testName = "Hello world";
typeName(testName);
typeQuestion("Did you say hello to the world today?");
typeDescription(description);
pickFrequency("Every week");
pickColor(5);
clickSave();
verifyShowsScreen(LIST_HABITS);
verifyDisplaysText("Hello world");
verifyDisplaysText(testName);
}
@Test
@@ -81,7 +91,16 @@ public class HabitsTest extends BaseUserInterfaceTest
}
@Test
public void shouldEditHabit() throws Exception
public void shouldEditHabit() throws Exception {
shouldEditHabit("this is a test description");
}
@Test
public void shouldEditHabitBlankDescription() throws Exception {
shouldEditHabit("");
}
private void shouldEditHabit(String description) throws Exception
{
launchApp();
@@ -92,6 +111,7 @@ public class HabitsTest extends BaseUserInterfaceTest
verifyShowsScreen(EDIT_HABIT);
typeName("Take a walk");
typeQuestion("Did you take a walk today?");
typeDescription(description);
clickSave();
verifyShowsScreen(LIST_HABITS);
@@ -174,4 +194,12 @@ public class HabitsTest extends BaseUserInterfaceTest
verifyDisplaysText("Track time");
verifyDisplaysText("Wake up early");
}
@Test
public void shouldHideNotesCard() throws Exception
{
launchApp();
clickText(EMPTY_DESCRIPTION_HABIT_NAME);
verifyShowsScreen(SHOW_HABIT, false);
}
}

View File

@@ -19,14 +19,16 @@
package org.isoron.uhabits.acceptance.steps;
import android.view.View;
import androidx.annotation.StringRes;
import androidx.test.espresso.*;
import androidx.test.espresso.contrib.*;
import androidx.test.uiautomator.*;
import androidx.appcompat.widget.*;
import androidx.recyclerview.widget.RecyclerView;
import org.hamcrest.Matcher;
import org.isoron.uhabits.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.activities.habits.list.*;
@@ -153,7 +155,11 @@ public class CommonSteps extends BaseUserInterfaceTest
LIST_HABITS, SHOW_HABIT, EDIT_HABIT
}
public static void verifyShowsScreen(Screen screen)
public static void verifyShowsScreen(Screen screen) {
verifyShowsScreen(screen, true);
}
public static void verifyShowsScreen(Screen screen, boolean notesCardVisibleExpected)
{
switch(screen)
{
@@ -163,10 +169,14 @@ public class CommonSteps extends BaseUserInterfaceTest
break;
case SHOW_HABIT:
Matcher<View> noteCardViewMatcher = notesCardVisibleExpected ? isDisplayed() :
withEffectiveVisibility(Visibility.GONE);
onView(withId(R.id.subtitleCard)).check(matches(isDisplayed()));
onView(withId(R.id.notesCard)).check(matches(noteCardViewMatcher));
break;
case EDIT_HABIT:
onView(withId(R.id.tvQuestion)).check(matches(isDisplayed()));
onView(withId(R.id.tvDescription)).check(matches(isDisplayed()));
break;
}

View File

@@ -55,7 +55,12 @@ public class EditHabitSteps
public static void typeQuestion(String name)
{
typeTextWithId(R.id.tvDescription, name);
typeTextWithId(R.id.tvQuestion, name);
}
public static void typeDescription(String description)
{
typeTextWithId(R.id.tvDescription, description);
}
public static void setReminder()

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 Á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.activities.habits.show.views;
import android.view.LayoutInflater;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;
import org.isoron.uhabits.BaseViewTest;
import org.isoron.uhabits.R;
import org.isoron.uhabits.core.models.Habit;
import org.isoron.uhabits.core.models.Reminder;
import org.isoron.uhabits.core.models.WeekdayList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class NotesCardTest extends BaseViewTest
{
public static final String PATH = "habits/show/NotesCard/";
private NotesCard view;
private Habit habit;
@Before
@Override
public void setUp()
{
super.setUp();
habit = fixtures.createLongHabit();
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
view = LayoutInflater
.from(targetContext)
.inflate(R.layout.show_habit, null)
.findViewById(R.id.notesCard);
view.setHabit(habit);
view.refreshData();
measureView(view, 800, 200);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
@Test
public void testRenderEmptyDescription() throws Exception
{
habit.setDescription("");
view.refreshData();
assertRenders(view, PATH + "render-empty-description.png");
}
}

View File

@@ -49,7 +49,7 @@ public class SubtitleCardTest extends BaseViewTest
habit = fixtures.createLongHabit();
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
view = (SubtitleCard) LayoutInflater
view = LayoutInflater
.from(targetContext)
.inflate(R.layout.show_habit, null)
.findViewById(R.id.subtitleCard);

View File

@@ -187,6 +187,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
habit.copyFrom(originalHabit);
habit.setName(namePanel.getName());
habit.setDescription(namePanel.getDescription());
habit.setQuestion(namePanel.getQuestion());
habit.setColor(namePanel.getColor());
habit.setReminder(reminderPanel.getReminder());
habit.setFrequency(frequencyPanel.getFrequency());

View File

@@ -24,6 +24,7 @@ import android.text.*;
import android.util.*;
import android.view.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;
@@ -82,7 +83,7 @@ public class ExampleEditText extends AppCompatEditText
updateText();
}
public void setRealText(String realText)
public void setRealText(@NonNull String realText)
{
this.realText = realText;
updateText();

View File

@@ -42,6 +42,9 @@ public class NameDescriptionPanel extends FrameLayout
@BindView(R.id.tvName)
EditText tvName;
@BindView(R.id.tvQuestion)
ExampleEditText tvQuestion;
@BindView(R.id.tvDescription)
ExampleEditText tvDescription;
@@ -79,6 +82,12 @@ public class NameDescriptionPanel extends FrameLayout
return tvDescription.getRealText().trim();
}
@NonNull
public String getQuestion()
{
return tvQuestion.getRealText().trim();
}
@NonNull
public String getName()
{
@@ -90,12 +99,13 @@ public class NameDescriptionPanel extends FrameLayout
Resources res = getResources();
if(habit.isNumerical())
tvDescription.setExample(res.getString(R.string.example_question_numerical));
tvQuestion.setExample(res.getString(R.string.example_question_numerical));
else
tvDescription.setExample(res.getString(R.string.example_question_boolean));
tvQuestion.setExample(res.getString(R.string.example_question_boolean));
setColor(habit.getColor());
tvName.setText(habit.getName());
tvQuestion.setRealText(habit.getQuestion());
tvDescription.setRealText(habit.getDescription());
}

View File

@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.show;
import android.content.*;
import android.os.*;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.*;
@@ -52,6 +53,12 @@ public class ShowHabitRootView extends BaseRootView
@BindView(R.id.subtitleCard)
SubtitleCard subtitleCard;
@BindView(R.id.notesCard)
NotesCard notesCard;
@BindView(R.id.habitNotes)
TextView habitNotes;
@BindView(R.id.overviewCard)
OverviewCard overviewCard;
@@ -136,6 +143,7 @@ public class ShowHabitRootView extends BaseRootView
private void initCards()
{
subtitleCard.setHabit(habit);
notesCard.setHabit(habit);
overviewCard.setHabit(habit);
scoreCard.setHabit(habit);
historyCard.setHabit(habit);

View File

@@ -0,0 +1,26 @@
package org.isoron.uhabits.activities.habits.show.views
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.TextView
import org.isoron.uhabits.R
import org.isoron.uhabits.core.tasks.Task
class NotesCard(context: Context?, attrs: AttributeSet?) : HabitCard(context, attrs) {
private val notesTextView: TextView
init {
View.inflate(getContext(), R.layout.show_habit_notes, this)
notesTextView = findViewById(R.id.habitNotes)
}
override fun refreshData() {
notesTextView.text = habit.description
visibility = if(habit.description.isEmpty()) View.GONE else View.VISIBLE
notesTextView.visibility = visibility
}
override fun createRefreshTask(): Task = error("refresh task should never be called.")
}

View File

@@ -59,12 +59,12 @@ public class SubtitleCard extends HabitCard
questionLabel.setVisibility(VISIBLE);
questionLabel.setTextColor(color);
questionLabel.setText(habit.getDescription());
questionLabel.setText(habit.getQuestion());
frequencyLabel.setText(toText(habit.getFrequency()));
if (habit.hasReminder()) updateReminderText(habit.getReminder());
if (habit.getDescription().isEmpty()) questionLabel.setVisibility(GONE);
if (habit.getQuestion().isEmpty()) questionLabel.setVisibility(GONE);
invalidate();
}

View File

@@ -112,7 +112,7 @@ class AndroidNotificationTray
val builder = NotificationCompat.Builder(context, REMINDERS_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(habit.name)
.setContentText(if(habit.description.isBlank()) defaultText else habit.description)
.setContentText(if(habit.question.isBlank()) defaultText else habit.question)
.setContentIntent(pendingIntents.showHabit(habit))
.setDeleteIntent(pendingIntents.dismissNotification(habit))
.addAction(addRepetitionAction)

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
@@ -18,53 +17,82 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://isoron.org/android"
xmlns:app1="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
style="@style/dialogFormRow">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6">
<EditText
android:id="@+id/tvName"
style="@style/dialogFormInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name">
<requestFocus/>
</EditText>
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="@+id/buttonPickColor"
style="@style/dialogFormInputColor"
android:layout_weight="1"
android:contentDescription="@string/color_picker_default_title"
android:src="?dialogIconChangeColor"/>
</LinearLayout>
android:layout_height="wrap_content"
android:minWidth="300dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/tilName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app1:layout_constraintEnd_toStartOf="@+id/buttonPickColor"
app1:layout_constraintHorizontal_weight="6"
app1:layout_constraintStart_toStartOf="parent"
app1:layout_constraintTop_toTopOf="parent">
<EditText
android:id="@+id/tvName"
style="@style/dialogFormInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:gravity="center_vertical"
android:hint="@string/name">
<requestFocus />
</EditText>
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="@+id/buttonPickColor"
style="@style/dialogFormInputColor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/color_picker_default_title"
android:src="?dialogIconChangeColor"
app1:layout_constraintBottom_toBottomOf="@id/tilName"
app1:layout_constraintEnd_toEndOf="parent"
app1:layout_constraintHorizontal_weight="1"
app1:layout_constraintStart_toEndOf="@+id/tilName"
app1:layout_constraintTop_toTopOf="@id/tilName" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilQuestion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/question"
app1:layout_constraintEnd_toEndOf="parent"
app1:layout_constraintStart_toStartOf="parent"
app1:layout_constraintTop_toBottomOf="@id/tilName">
<org.isoron.uhabits.activities.habits.edit.views.ExampleEditText
android:id="@+id/tvQuestion"
style="@style/dialogFormInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:example="@string/example_question_numerical" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/notes"
app1:layout_constraintBottom_toBottomOf="parent"
app1:layout_constraintEnd_toEndOf="parent"
app1:layout_constraintStart_toStartOf="parent"
app1:layout_constraintTop_toBottomOf="@id/tilQuestion">
<org.isoron.uhabits.activities.habits.edit.views.ExampleEditText
android:id="@+id/tvDescription"
style="@style/dialogFormInputMultiline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/question"
app:example="@string/example_question_numerical"/>
android:gravity="top"
app:example="@string/example_notes" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -38,6 +38,11 @@
android:id="@+id/subtitleCard"
style="@style/ShowHabit.Subtitle"/>
<org.isoron.uhabits.activities.habits.show.views.NotesCard
android:id="@+id/notesCard"
style="@style/Card"
android:gravity="center" />
<View
android:id="@+id/headerShadow"
style="@style/ToolbarShadow"/>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2016 Á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/>.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:layout_height="wrap_content"
tools:layout_width="match_parent"
tools:orientation="vertical"
tools:parentTag="android.widget.LinearLayout">
<TextView
android:id="@+id/habitNotes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="?highContrastTextColor"
android:visibility="gone"
tools:text="This is some example text for the notes" />
</merge>

View File

@@ -18,7 +18,12 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.widget.LinearLayout"
tools:orientation="vertical"
tools:layout_width="match_parent"
tools:layout_height="wrap_content">
<TextView
android:id="@+id/questionLabel"
android:layout_width="match_parent"
@@ -26,6 +31,7 @@
android:layout_marginBottom="8dp"
android:textColor="?mediumContrastTextColor"
android:textSize="@dimen/regularTextSize"
tools:text="Have you worked out today?"
/>
<LinearLayout
@@ -33,7 +39,8 @@
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
android:orientation="horizontal"
tools:visibility="visible">
<ImageView
android:id="@+id/frequencyIcon"
@@ -42,8 +49,7 @@
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:alpha="0.3"
android:src="?iconFrequency"
/>
android:src="?iconFrequency" />
<TextView
android:id="@+id/frequencyLabel"
@@ -51,20 +57,18 @@
android:layout_height="wrap_content"
android:text="@string/every_day"
android:textColor="?mediumContrastTextColor"
android:textSize="@dimen/smallTextSize"
/>
android:textSize="@dimen/smallTextSize" />
<ImageView
android:id="@+id/reminderIcon"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginEnd="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:alpha="0.3"
android:src="?iconReminder"
/>
android:src="?iconReminder" />
<TextView
android:id="@+id/reminderLabel"
@@ -72,8 +76,7 @@
android:layout_height="wrap_content"
android:paddingTop="1dp"
android:textColor="?mediumContrastTextColor"
android:textSize="@dimen/smallTextSize"
/>
android:textSize="@dimen/smallTextSize" />
</LinearLayout>
</merge>

View File

@@ -244,5 +244,7 @@
<string name="widget_opacity_description">Makes widgets more transparent or more opaque in your home screen.</string>
<string name="first_day_of_the_week">First day of the week</string>
<string name="default_reminder_question">Have you completed this habit today?</string>
<string name="notes">Notes</string>
<string name="example_notes">You can put whatever you want here!</string>
</resources>