mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Show more information on score overview
This commit is contained in:
@@ -79,6 +79,13 @@ public class ShowHabitFragment extends Fragment
|
|||||||
|
|
||||||
private int previousScoreInterval;
|
private int previousScoreInterval;
|
||||||
|
|
||||||
|
private float todayScore;
|
||||||
|
private float lastMonthScore;
|
||||||
|
private float lastYearScore;
|
||||||
|
|
||||||
|
private int activeColor;
|
||||||
|
private int inactiveColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
{
|
{
|
||||||
@@ -91,7 +98,10 @@ public class ShowHabitFragment extends Fragment
|
|||||||
{
|
{
|
||||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||||
activity = (ShowHabitActivity) getActivity();
|
activity = (ShowHabitActivity) getActivity();
|
||||||
|
|
||||||
habit = activity.getHabit();
|
habit = activity.getHabit();
|
||||||
|
activeColor = ColorHelper.getColor(getContext(), habit.color);
|
||||||
|
inactiveColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||||
|
|
||||||
updateHeader(view);
|
updateHeader(view);
|
||||||
|
|
||||||
@@ -153,8 +163,6 @@ public class ShowHabitFragment extends Fragment
|
|||||||
{
|
{
|
||||||
if(habit == null) return;
|
if(habit == null) return;
|
||||||
|
|
||||||
int activeColor = ColorHelper.getColor(getContext(), habit.color);
|
|
||||||
|
|
||||||
TextView questionLabel = (TextView) view.findViewById(R.id.questionLabel);
|
TextView questionLabel = (TextView) view.findViewById(R.id.questionLabel);
|
||||||
questionLabel.setTextColor(activeColor);
|
questionLabel.setTextColor(activeColor);
|
||||||
questionLabel.setText(habit.description);
|
questionLabel.setText(habit.description);
|
||||||
@@ -198,19 +206,34 @@ public class ShowHabitFragment extends Fragment
|
|||||||
refreshData();
|
refreshData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScoreRing(View view)
|
private void updateScore(View view)
|
||||||
{
|
{
|
||||||
if(habit == null) return;
|
if(habit == null) return;
|
||||||
if(view == null) return;
|
if(view == null) return;
|
||||||
|
|
||||||
float todayValue = (float) habit.scores.getTodayValue();
|
float todayPercentage = todayScore / Score.MAX_VALUE;
|
||||||
float percentage = todayValue / Score.MAX_VALUE;
|
float monthDiff = todayPercentage - (lastMonthScore / Score.MAX_VALUE);
|
||||||
|
float yearDiff = todayPercentage - (lastYearScore / Score.MAX_VALUE);
|
||||||
|
|
||||||
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
||||||
int androidColor = ColorHelper.getColor(getActivity(), habit.color);
|
int androidColor = ColorHelper.getColor(getActivity(), habit.color);
|
||||||
scoreRing.setColor(androidColor);
|
scoreRing.setColor(androidColor);
|
||||||
scoreRing.setPercentage(percentage);
|
scoreRing.setPercentage(todayPercentage);
|
||||||
scoreRing.setText(String.format("%.0f%%", 100 * percentage));
|
|
||||||
|
TextView scoreLabel = (TextView) view.findViewById(R.id.scoreLabel);
|
||||||
|
TextView monthDiffLabel = (TextView) view.findViewById(R.id.monthDiffLabel);
|
||||||
|
TextView yearDiffLabel = (TextView) view.findViewById(R.id.yearDiffLabel);
|
||||||
|
|
||||||
|
scoreLabel.setText(String.format("%.0f%%", todayPercentage * 100));
|
||||||
|
|
||||||
|
String minus = "\u2212";
|
||||||
|
monthDiffLabel.setText(String.format("%s%.0f%%", (monthDiff >= 0 ? "+" : minus),
|
||||||
|
Math.abs(monthDiff) * 100));
|
||||||
|
yearDiffLabel.setText(
|
||||||
|
String.format("%s%.0f%%", (yearDiff >= 0 ? "+" : minus), Math.abs(yearDiff) * 100));
|
||||||
|
|
||||||
|
monthDiffLabel.setTextColor(monthDiff >= 0 ? activeColor : inactiveColor);
|
||||||
|
yearDiffLabel.setTextColor(yearDiff >= 0 ? activeColor : inactiveColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateHeaders(View view)
|
private void updateHeaders(View view)
|
||||||
@@ -220,6 +243,7 @@ public class ShowHabitFragment extends Fragment
|
|||||||
updateColor(view, R.id.tvStrength);
|
updateColor(view, R.id.tvStrength);
|
||||||
updateColor(view, R.id.tvStreaks);
|
updateColor(view, R.id.tvStreaks);
|
||||||
updateColor(view, R.id.tvWeekdayFreq);
|
updateColor(view, R.id.tvWeekdayFreq);
|
||||||
|
updateColor(view, R.id.scoreLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColor(View view, int viewId)
|
private void updateColor(View view, int viewId)
|
||||||
@@ -281,25 +305,32 @@ public class ShowHabitFragment extends Fragment
|
|||||||
{
|
{
|
||||||
new BaseTask()
|
new BaseTask()
|
||||||
{
|
{
|
||||||
float percentage;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInBackground()
|
protected void doInBackground()
|
||||||
{
|
{
|
||||||
|
if(habit == null) return;
|
||||||
if(dataViews == null) return;
|
if(dataViews == null) return;
|
||||||
|
|
||||||
|
long today = DateHelper.getStartOfToday();
|
||||||
|
long lastMonth = today - 30 * DateHelper.millisecondsInOneDay;
|
||||||
|
long lastYear = today - 365 * DateHelper.millisecondsInOneDay;
|
||||||
|
|
||||||
|
todayScore = (float) habit.scores.getTodayValue();
|
||||||
|
lastMonthScore = (float) habit.scores.getValue(lastMonth);
|
||||||
|
lastYearScore = (float) habit.scores.getValue(lastYear);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(HabitDataView view : dataViews)
|
for(HabitDataView view : dataViews)
|
||||||
{
|
{
|
||||||
view.refreshData();
|
view.refreshData();
|
||||||
onProgressUpdate(count++);
|
publishProgress(count++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(Integer... values)
|
protected void onProgressUpdate(Integer... values)
|
||||||
{
|
{
|
||||||
updateScoreRing(getView());
|
updateScore(getView());
|
||||||
if(dataViews == null) return;
|
if(dataViews == null) return;
|
||||||
dataViews.get(values[0]).postInvalidate();
|
dataViews.get(values[0]).postInvalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:habit="http://isoron.org/android"
|
xmlns:habit="http://isoron.org/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
|
||||||
@@ -40,34 +39,34 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?headerBackgroundColor"
|
android:background="?headerBackgroundColor"
|
||||||
android:elevation="2dp"
|
android:elevation="2dp"
|
||||||
android:paddingTop="15dp"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="10dp"
|
||||||
android:paddingLeft="60dp"
|
android:paddingLeft="60dp"
|
||||||
android:orientation="vertical">
|
android:paddingTop="15dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/questionLabel"
|
android:id="@+id/questionLabel"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
android:textColor="?mediumContrastTextColor"
|
android:textColor="?mediumContrastTextColor"
|
||||||
android:textSize="@dimen/regularTextSize"
|
android:textSize="@dimen/regularTextSize"
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<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:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal">
|
||||||
android:layout_marginBottom="5dp">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/frequencyIcon"
|
android:id="@+id/frequencyIcon"
|
||||||
android:layout_width="18dp"
|
android:layout_width="18dp"
|
||||||
android:layout_height="18dp"
|
android:layout_height="18dp"
|
||||||
android:src="@drawable/ic_repeat_black"
|
|
||||||
android:alpha="0.3"
|
|
||||||
android:layout_marginRight="5dp"
|
android:layout_marginRight="5dp"
|
||||||
|
android:alpha="0.3"
|
||||||
|
android:src="@drawable/ic_repeat_black"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -83,10 +82,10 @@
|
|||||||
android:id="@+id/reminderIcon"
|
android:id="@+id/reminderIcon"
|
||||||
android:layout_width="18dp"
|
android:layout_width="18dp"
|
||||||
android:layout_height="18dp"
|
android:layout_height="18dp"
|
||||||
android:src="@drawable/ic_alarm_black"
|
|
||||||
android:alpha="0.3"
|
|
||||||
android:layout_marginRight="5dp"
|
|
||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:alpha="0.3"
|
||||||
|
android:src="@drawable/ic_alarm_black"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -104,6 +103,7 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/Card"
|
style="@style/Card"
|
||||||
|
android:paddingTop="12dp"
|
||||||
android:gravity="start">
|
android:gravity="start">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -116,24 +116,81 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<org.isoron.uhabits.views.RingView
|
<FrameLayout
|
||||||
android:id="@+id/scoreRing"
|
|
||||||
android:layout_width="75dp"
|
|
||||||
android:layout_height="75dp"
|
|
||||||
android:layout_margin="10dp"
|
|
||||||
habit:percentage="0"
|
|
||||||
habit:textSize="12"
|
|
||||||
habit:thickness="10"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/habit_strength"
|
android:minWidth="100dp">
|
||||||
android:textColor="?mediumContrastTextColor"
|
|
||||||
android:textSize="@dimen/smallTextSize"/>
|
|
||||||
|
|
||||||
|
<org.isoron.uhabits.views.RingView
|
||||||
|
android:id="@+id/scoreRing"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
habit:percentage="0"
|
||||||
|
habit:textSize="12"
|
||||||
|
habit:thickness="5"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="80dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/scoreLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/score"
|
||||||
|
android:textColor="?mediumContrastTextColor"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="80dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/monthDiffLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/month"
|
||||||
|
android:textColor="?mediumContrastTextColor"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="80dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/yearDiffLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/year"
|
||||||
|
android:textColor="?mediumContrastTextColor"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user