mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Merge pull request #547 from recheej/rechee/add_notes
Add Notes to Habits.
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user