Show target in SubtitleCard; replace some bitmap icons by FontAwesome

pull/605/head
Alinson S. Xavier 5 years ago
parent 6d48b53861
commit 3ba503604b

@ -1,121 +0,0 @@
/*
* 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.annotation.*;
import android.content.*;
import android.content.res.*;
import android.util.*;
import android.widget.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.tasks.*;
import org.isoron.uhabits.utils.*;
import butterknife.*;
public class SubtitleCard extends HabitCard
{
@BindView(R.id.questionLabel)
TextView questionLabel;
@BindView(R.id.frequencyLabel)
TextView frequencyLabel;
@BindView(R.id.reminderLabel)
TextView reminderLabel;
public SubtitleCard(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}
@Override
protected void refreshData()
{
Habit habit = getHabit();
int color = PaletteUtils.getColor(getContext(), habit.getColor());
reminderLabel.setText(getResources().getString(R.string.reminder_off));
questionLabel.setVisibility(VISIBLE);
questionLabel.setTextColor(color);
questionLabel.setText(habit.getQuestion());
frequencyLabel.setText(toText(habit.getFrequency()));
if (habit.hasReminder()) updateReminderText(habit.getReminder());
if (habit.getQuestion().isEmpty()) questionLabel.setVisibility(GONE);
invalidate();
}
private void init()
{
inflate(getContext(), R.layout.show_habit_subtitle, this);
ButterKnife.bind(this);
if (isInEditMode()) initEditMode();
}
@SuppressLint("SetTextI18n")
private void initEditMode()
{
questionLabel.setTextColor(PaletteUtils.getAndroidTestColor(1));
questionLabel.setText("Have you meditated today?");
reminderLabel.setText("08:00");
}
private String toText(Frequency freq)
{
Resources resources = getResources();
Integer num = freq.getNumerator();
Integer den = freq.getDenominator();
if (num.equals(den)) return resources.getString(R.string.every_day);
if (num == 1)
{
if (den == 7) return resources.getString(R.string.every_week);
if (den % 7 == 0)
return resources.getString(R.string.every_x_weeks, den / 7);
return resources.getString(R.string.every_x_days, den);
}
String times_every = resources.getString(R.string.times_every);
return String.format("%d %s %d %s", num, times_every, den,
resources.getString(R.string.days));
}
private void updateReminderText(Reminder reminder)
{
reminderLabel.setText(
AndroidDateUtils.formatTime(getContext(), reminder.getHour(),
reminder.getMinute()));
}
@Override
protected Task createRefreshTask() {
// Never called
throw new IllegalStateException();
}
}

@ -0,0 +1,104 @@
/*
* 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.annotation.*
import android.content.*
import android.util.*
import android.view.*
import org.isoron.androidbase.utils.*
import org.isoron.uhabits.*
import org.isoron.uhabits.activities.habits.list.views.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.tasks.*
import org.isoron.uhabits.databinding.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.utils.PaletteUtils.getAndroidTestColor
import org.isoron.uhabits.utils.PaletteUtils.getColor
import java.util.*
class SubtitleCard(context: Context?, attrs: AttributeSet?) : HabitCard(context, attrs) {
init {
init()
}
private lateinit var binding: ShowHabitSubtitleBinding
public override fun refreshData() {
val habit = habit
val color = getColor(context, habit.color)
if (habit.isNumerical) {
binding.targetText.text = "${habit.targetValue.toShortString()} ${habit.unit}"
} else {
binding.targetIcon.visibility = View.GONE
binding.targetText.visibility = View.GONE
}
binding.reminderLabel.text = resources.getString(R.string.reminder_off)
binding.questionLabel.visibility = View.VISIBLE
binding.questionLabel.setTextColor(color)
binding.questionLabel.text = habit.question
binding.frequencyLabel.text = toText(habit.frequency)
if (habit.hasReminder()) updateReminderText(habit.reminder)
if (habit.question.isEmpty()) binding.questionLabel.visibility = View.GONE
invalidate()
}
private fun init() {
val fontAwesome = InterfaceUtils.getFontAwesome(context)
binding = ShowHabitSubtitleBinding.inflate(LayoutInflater.from(context), this)
binding.targetIcon.typeface = fontAwesome
binding.frequencyIcon.typeface = fontAwesome
binding.reminderIcon.typeface = fontAwesome
if (isInEditMode) initEditMode()
}
@SuppressLint("SetTextI18n")
private fun initEditMode() {
binding.questionLabel.setTextColor(getAndroidTestColor(1))
binding.questionLabel.text = "Have you meditated today?"
binding.reminderLabel.text = "08:00"
}
private fun toText(freq: Frequency): String {
val resources = resources
val num = freq.numerator
val den = freq.denominator
if (num == den) return resources.getString(R.string.every_day)
if (num == 1) {
if (den == 7) return resources.getString(R.string.every_week)
if (den % 7 == 0) return resources.getString(R.string.every_x_weeks, den / 7)
return if (den >= 30) resources.getString(R.string.every_month) else resources.getString(R.string.every_x_days, den)
}
val times_every = resources.getString(R.string.times_every)
return String.format(Locale.US, "%d %s %d %s", num, times_every, den,
resources.getString(R.string.days))
}
private fun updateReminderText(reminder: Reminder) {
binding.reminderLabel.text = AndroidDateUtils.formatTime(context, reminder.hour,
reminder.minute)
}
override fun createRefreshTask(): Task {
// Never called
throw IllegalStateException()
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 B

@ -24,6 +24,7 @@
tools:orientation="vertical" tools:orientation="vertical"
tools:layout_width="match_parent" tools:layout_width="match_parent"
tools:layout_height="wrap_content"> tools:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/questionLabel" android:id="@+id/questionLabel"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -37,19 +38,37 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="5dp" android:layout_marginBottom="2dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
tools:visibility="visible"> tools:visibility="visible">
<ImageView <TextView
android:id="@+id/targetIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fa_arrow_circle_up"
android:textColor="?mediumContrastTextColor"
android:textSize="16sp" />
<TextView
android:id="@+id/targetText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8.5k"
android:textColor="?mediumContrastTextColor"
android:textSize="@dimen/smallTextSize"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
/>
<TextView
android:id="@+id/frequencyIcon" android:id="@+id/frequencyIcon"
android:layout_width="18dp" android:layout_width="wrap_content"
android:layout_height="18dp" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:text="@string/fa_calendar"
android:layout_marginRight="5dp" android:textColor="?mediumContrastTextColor"
android:alpha="0.3" android:textSize="@dimen/smallTextSize" />
android:src="?iconFrequency" />
<TextView <TextView
android:id="@+id/frequencyLabel" android:id="@+id/frequencyLabel"
@ -57,18 +76,17 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/every_day" android:text="@string/every_day"
android:textColor="?mediumContrastTextColor" android:textColor="?mediumContrastTextColor"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:textSize="@dimen/smallTextSize" /> android:textSize="@dimen/smallTextSize" />
<ImageView <TextView
android:id="@+id/reminderIcon" android:id="@+id/reminderIcon"
android:layout_width="18dp" android:layout_width="wrap_content"
android:layout_height="18dp" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:text="@string/fa_bell_o"
android:layout_marginLeft="10dp" android:textColor="?mediumContrastTextColor"
android:layout_marginEnd="5dp" android:textSize="@dimen/smallTextSize" />
android:layout_marginRight="5dp"
android:alpha="0.3"
android:src="?iconReminder" />
<TextView <TextView
android:id="@+id/reminderLabel" android:id="@+id/reminderLabel"
@ -76,6 +94,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="1dp" android:paddingTop="1dp"
android:textColor="?mediumContrastTextColor" android:textColor="?mediumContrastTextColor"
android:text="8:00 AM"
android:layout_marginStart="4dp"
android:textSize="@dimen/smallTextSize" /> android:textSize="@dimen/smallTextSize" />
</LinearLayout> </LinearLayout>

@ -41,8 +41,6 @@
<attr name="iconEdit" format="reference"/> <attr name="iconEdit" format="reference"/>
<attr name="iconUnarchive" format="reference"/> <attr name="iconUnarchive" format="reference"/>
<attr name="dialogIconChangeColor" format="reference"/> <attr name="dialogIconChangeColor" format="reference"/>
<attr name="iconReminder" format="reference"/>
<attr name="iconFrequency" format="reference"/>
<attr name="iconFilter" format="reference"/> <attr name="iconFilter" format="reference"/>
<attr name="toolbarPopupTheme" format="reference"/> <attr name="toolbarPopupTheme" format="reference"/>

@ -21,11 +21,16 @@
<resources> <resources>
<string translatable="false" name="fa_star">&#xf005;</string> <string translatable="false" name="fa_star">&#xf005;</string>
<string translatable="false" name="fa_star_o">&#xf006;</string> <string translatable="false" name="fa_star_o">&#xf006;</string>
<!--<string translatable="false" name="fa_star_half">&#xf089;</string>--> <string translatable="false" name="fa_star_half">&#xf089;</string>
<string translatable="false" name="fa_star_half_o">&#xf123;</string> <string translatable="false" name="fa_star_half_o">&#xf123;</string>
<string translatable="false" name="fa_arrow_circle_up">&#xf0aa;</string>
<string translatable="false" name="fa_check">&#xf00c;</string> <string translatable="false" name="fa_check">&#xf00c;</string>
<string translatable="false" name="fa_times">&#xf00d;</string> <string translatable="false" name="fa_times">&#xf00d;</string>
<string translatable="false" name="fa_archive">&#xf187;</string> <string translatable="false" name="fa_archive">&#xf187;</string>
<string translatable="false" name="fa_bell">&#xf0f3;</string>
<string translatable="false" name="fa_bell_o">&#xf0a2;</string>
<string translatable="false" name="fa_calendar">&#xf073;</string>
<string translatable="false" name="fa_retweet">&#xf079;</string>
<!--<string translatable="false" name="fa_glass">&#xf000;</string>--> <!--<string translatable="false" name="fa_glass">&#xf000;</string>-->
<!--<string translatable="false" name="fa_music">&#xf001;</string>--> <!--<string translatable="false" name="fa_music">&#xf001;</string>-->
@ -131,13 +136,11 @@
<!--<string translatable="false" name="fa_eye_slash">&#xf070;</string>--> <!--<string translatable="false" name="fa_eye_slash">&#xf070;</string>-->
<!--<string translatable="false" name="fa_exclamation_triangle">&#xf071;</string>--> <!--<string translatable="false" name="fa_exclamation_triangle">&#xf071;</string>-->
<!--<string translatable="false" name="fa_plane">&#xf072;</string>--> <!--<string translatable="false" name="fa_plane">&#xf072;</string>-->
<!--<string translatable="false" name="fa_calendar">&#xf073;</string>-->
<!--<string translatable="false" name="fa_random">&#xf074;</string>--> <!--<string translatable="false" name="fa_random">&#xf074;</string>-->
<!--<string translatable="false" name="fa_comment">&#xf075;</string>--> <!--<string translatable="false" name="fa_comment">&#xf075;</string>-->
<!--<string translatable="false" name="fa_magnet">&#xf076;</string>--> <!--<string translatable="false" name="fa_magnet">&#xf076;</string>-->
<!--<string translatable="false" name="fa_chevron_up">&#xf077;</string>--> <!--<string translatable="false" name="fa_chevron_up">&#xf077;</string>-->
<!--<string translatable="false" name="fa_chevron_down">&#xf078;</string>--> <!--<string translatable="false" name="fa_chevron_down">&#xf078;</string>-->
<!--<string translatable="false" name="fa_retweet">&#xf079;</string>-->
<!--<string translatable="false" name="fa_shopping_cart">&#xf07a;</string>--> <!--<string translatable="false" name="fa_shopping_cart">&#xf07a;</string>-->
<!--<string translatable="false" name="fa_folder">&#xf07b;</string>--> <!--<string translatable="false" name="fa_folder">&#xf07b;</string>-->
<!--<string translatable="false" name="fa_folder_open">&#xf07c;</string>--> <!--<string translatable="false" name="fa_folder_open">&#xf07c;</string>-->
@ -174,7 +177,6 @@
<!--<string translatable="false" name="fa_rss">&#xf09e;</string>--> <!--<string translatable="false" name="fa_rss">&#xf09e;</string>-->
<!--<string translatable="false" name="fa_hdd_o">&#xf0a0;</string>--> <!--<string translatable="false" name="fa_hdd_o">&#xf0a0;</string>-->
<!--<string translatable="false" name="fa_bullhorn">&#xf0a1;</string>--> <!--<string translatable="false" name="fa_bullhorn">&#xf0a1;</string>-->
<!--<string translatable="false" name="fa_bell">&#xf0f3;</string>-->
<!--<string translatable="false" name="fa_certificate">&#xf0a3;</string>--> <!--<string translatable="false" name="fa_certificate">&#xf0a3;</string>-->
<!--<string translatable="false" name="fa_hand_o_right">&#xf0a4;</string>--> <!--<string translatable="false" name="fa_hand_o_right">&#xf0a4;</string>-->
<!--<string translatable="false" name="fa_hand_o_left">&#xf0a5;</string>--> <!--<string translatable="false" name="fa_hand_o_left">&#xf0a5;</string>-->
@ -182,7 +184,6 @@
<!--<string translatable="false" name="fa_hand_o_down">&#xf0a7;</string>--> <!--<string translatable="false" name="fa_hand_o_down">&#xf0a7;</string>-->
<!--<string translatable="false" name="fa_arrow_circle_left">&#xf0a8;</string>--> <!--<string translatable="false" name="fa_arrow_circle_left">&#xf0a8;</string>-->
<!--<string translatable="false" name="fa_arrow_circle_right">&#xf0a9;</string>--> <!--<string translatable="false" name="fa_arrow_circle_right">&#xf0a9;</string>-->
<!--<string translatable="false" name="fa_arrow_circle_up">&#xf0aa;</string>-->
<!--<string translatable="false" name="fa_arrow_circle_down">&#xf0ab;</string>--> <!--<string translatable="false" name="fa_arrow_circle_down">&#xf0ab;</string>-->
<!--<string translatable="false" name="fa_globe">&#xf0ac;</string>--> <!--<string translatable="false" name="fa_globe">&#xf0ac;</string>-->
<!--<string translatable="false" name="fa_wrench">&#xf0ad;</string>--> <!--<string translatable="false" name="fa_wrench">&#xf0ad;</string>-->
@ -238,7 +239,6 @@
<!--<string translatable="false" name="fa_user_md">&#xf0f0;</string>--> <!--<string translatable="false" name="fa_user_md">&#xf0f0;</string>-->
<!--<string translatable="false" name="fa_stethoscope">&#xf0f1;</string>--> <!--<string translatable="false" name="fa_stethoscope">&#xf0f1;</string>-->
<!--<string translatable="false" name="fa_suitcase">&#xf0f2;</string>--> <!--<string translatable="false" name="fa_suitcase">&#xf0f2;</string>-->
<!--<string translatable="false" name="fa_bell_o">&#xf0a2;</string>-->
<!--<string translatable="false" name="fa_coffee">&#xf0f4;</string>--> <!--<string translatable="false" name="fa_coffee">&#xf0f4;</string>-->
<!--<string translatable="false" name="fa_cutlery">&#xf0f5;</string>--> <!--<string translatable="false" name="fa_cutlery">&#xf0f5;</string>-->
<!--<string translatable="false" name="fa_file_text_o">&#xf0f6;</string>--> <!--<string translatable="false" name="fa_file_text_o">&#xf0f6;</string>-->

@ -58,8 +58,6 @@
<item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item> <item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item>
<item name="iconChangeColor">@drawable/ic_action_color_dark</item> <item name="iconChangeColor">@drawable/ic_action_color_dark</item>
<item name="iconFilter">@drawable/ic_action_filter_dark</item> <item name="iconFilter">@drawable/ic_action_filter_dark</item>
<item name="iconFrequency">@drawable/ic_repeat_black</item>
<item name="iconReminder">@drawable/ic_alarm_black</item>
<item name="dialogIconChangeColor">@drawable/ic_action_color_light</item> <item name="dialogIconChangeColor">@drawable/ic_action_color_light</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
@ -112,8 +110,6 @@
<item name="iconFilter">@drawable/ic_action_filter_dark</item> <item name="iconFilter">@drawable/ic_action_filter_dark</item>
<item name="iconChangeColor">@drawable/ic_action_color_dark</item> <item name="iconChangeColor">@drawable/ic_action_color_dark</item>
<item name="dialogIconChangeColor">@drawable/ic_action_color_dark</item> <item name="dialogIconChangeColor">@drawable/ic_action_color_dark</item>
<item name="iconFrequency">@drawable/ic_repeat_white</item>
<item name="iconReminder">@drawable/ic_alarm_white</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>

Loading…
Cancel
Save