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 float todayScore;
|
||||
private float lastMonthScore;
|
||||
private float lastYearScore;
|
||||
|
||||
private int activeColor;
|
||||
private int inactiveColor;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
@@ -91,7 +98,10 @@ public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||
activity = (ShowHabitActivity) getActivity();
|
||||
|
||||
habit = activity.getHabit();
|
||||
activeColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
inactiveColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
|
||||
updateHeader(view);
|
||||
|
||||
@@ -153,8 +163,6 @@ public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
if(habit == null) return;
|
||||
|
||||
int activeColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
|
||||
TextView questionLabel = (TextView) view.findViewById(R.id.questionLabel);
|
||||
questionLabel.setTextColor(activeColor);
|
||||
questionLabel.setText(habit.description);
|
||||
@@ -198,19 +206,34 @@ public class ShowHabitFragment extends Fragment
|
||||
refreshData();
|
||||
}
|
||||
|
||||
private void updateScoreRing(View view)
|
||||
private void updateScore(View view)
|
||||
{
|
||||
if(habit == null) return;
|
||||
if(view == null) return;
|
||||
|
||||
float todayValue = (float) habit.scores.getTodayValue();
|
||||
float percentage = todayValue / Score.MAX_VALUE;
|
||||
float todayPercentage = todayScore / 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);
|
||||
int androidColor = ColorHelper.getColor(getActivity(), habit.color);
|
||||
scoreRing.setColor(androidColor);
|
||||
scoreRing.setPercentage(percentage);
|
||||
scoreRing.setText(String.format("%.0f%%", 100 * percentage));
|
||||
scoreRing.setPercentage(todayPercentage);
|
||||
|
||||
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)
|
||||
@@ -220,6 +243,7 @@ public class ShowHabitFragment extends Fragment
|
||||
updateColor(view, R.id.tvStrength);
|
||||
updateColor(view, R.id.tvStreaks);
|
||||
updateColor(view, R.id.tvWeekdayFreq);
|
||||
updateColor(view, R.id.scoreLabel);
|
||||
}
|
||||
|
||||
private void updateColor(View view, int viewId)
|
||||
@@ -281,25 +305,32 @@ public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
new BaseTask()
|
||||
{
|
||||
float percentage;
|
||||
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
if(habit == 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;
|
||||
for(HabitDataView view : dataViews)
|
||||
{
|
||||
view.refreshData();
|
||||
onProgressUpdate(count++);
|
||||
publishProgress(count++);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values)
|
||||
{
|
||||
updateScoreRing(getView());
|
||||
updateScore(getView());
|
||||
if(dataViews == null) return;
|
||||
dataViews.get(values[0]).postInvalidate();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
<ScrollView
|
||||
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:tools="http://schemas.android.com/tools"
|
||||
|
||||
@@ -40,34 +39,34 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?headerBackgroundColor"
|
||||
android:elevation="2dp"
|
||||
android:paddingTop="15dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingLeft="60dp"
|
||||
android:orientation="vertical">
|
||||
android:paddingTop="15dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/questionLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textColor="?mediumContrastTextColor"
|
||||
android:textSize="@dimen/regularTextSize"
|
||||
android:layout_marginBottom="8dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="5dp">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/frequencyIcon"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:src="@drawable/ic_repeat_black"
|
||||
android:alpha="0.3"
|
||||
android:layout_marginRight="5dp"
|
||||
android:alpha="0.3"
|
||||
android:src="@drawable/ic_repeat_black"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
@@ -83,10 +82,10 @@
|
||||
android:id="@+id/reminderIcon"
|
||||
android:layout_width="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_marginRight="5dp"
|
||||
android:alpha="0.3"
|
||||
android:src="@drawable/ic_alarm_black"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
@@ -104,6 +103,7 @@
|
||||
|
||||
<LinearLayout
|
||||
style="@style/Card"
|
||||
android:paddingTop="12dp"
|
||||
android:gravity="start">
|
||||
|
||||
<TextView
|
||||
@@ -116,24 +116,81 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<org.isoron.uhabits.views.RingView
|
||||
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
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/habit_strength"
|
||||
android:textColor="?mediumContrastTextColor"
|
||||
android:textSize="@dimen/smallTextSize"/>
|
||||
android:minWidth="100dp">
|
||||
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user