mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
BarChart: allow user to pick interval
This commit is contained in:
@@ -77,7 +77,6 @@ public class BarChart extends ScrollableChart
|
||||
|
||||
private int primaryColor;
|
||||
|
||||
@Deprecated
|
||||
private int bucketSize = 7;
|
||||
|
||||
private int backgroundColor;
|
||||
@@ -127,7 +126,6 @@ public class BarChart extends ScrollableChart
|
||||
setTarget(0.5);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBucketSize(int bucketSize)
|
||||
{
|
||||
this.bucketSize = bucketSize;
|
||||
@@ -298,7 +296,6 @@ public class BarChart extends ScrollableChart
|
||||
|
||||
boolean shouldPrintYear = true;
|
||||
if (yearText.equals(previousYearText)) shouldPrintYear = false;
|
||||
if (bucketSize >= 365 && (year % 2) != 0) shouldPrintYear = false;
|
||||
|
||||
if (skipYear > 0)
|
||||
{
|
||||
@@ -306,6 +303,8 @@ public class BarChart extends ScrollableChart
|
||||
shouldPrintYear = false;
|
||||
}
|
||||
|
||||
if (bucketSize >= 365) shouldPrintYear = true;
|
||||
|
||||
if (shouldPrintYear)
|
||||
{
|
||||
previousYearText = yearText;
|
||||
@@ -314,6 +313,8 @@ public class BarChart extends ScrollableChart
|
||||
pText.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(yearText, rect.centerX(), rect.bottom + em * 2.2f, pText);
|
||||
skipYear = 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (bucketSize < 365)
|
||||
|
||||
@@ -29,15 +29,25 @@ import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
import static org.isoron.uhabits.activities.habits.show.views.ScoreCard.getTruncateField;
|
||||
|
||||
public class BarCard extends HabitCard
|
||||
{
|
||||
public static final int[] NUMERICAL_BUCKET_SIZES = {1, 7, 31, 92, 365};
|
||||
public static final int[] BOOLEAN_BUCKET_SIZES = {7, 31, 92, 365};
|
||||
|
||||
@BindView(R.id.numericalSpinner)
|
||||
Spinner numericalSpinner;
|
||||
|
||||
@BindView(R.id.boolSpinner)
|
||||
Spinner boolSpinner;
|
||||
|
||||
@BindView(R.id.barChart)
|
||||
BarChart chart;
|
||||
|
||||
@@ -47,6 +57,8 @@ public class BarCard extends HabitCard
|
||||
@Nullable
|
||||
private TaskRunner taskRunner;
|
||||
|
||||
private int bucketSize;
|
||||
|
||||
public BarCard(Context context)
|
||||
{
|
||||
super(context);
|
||||
@@ -59,6 +71,20 @@ public class BarCard extends HabitCard
|
||||
init();
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.numericalSpinner)
|
||||
public void onNumericalItemSelected(int position)
|
||||
{
|
||||
bucketSize = NUMERICAL_BUCKET_SIZES[position];
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.boolSpinner)
|
||||
public void onBoolItemSelected(int position)
|
||||
{
|
||||
bucketSize = BOOLEAN_BUCKET_SIZES[position];
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
@@ -71,22 +97,16 @@ public class BarCard extends HabitCard
|
||||
inflate(getContext(), R.layout.show_habit_bar, this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
boolSpinner.setSelection(1);
|
||||
numericalSpinner.setSelection(2);
|
||||
bucketSize = 7;
|
||||
|
||||
Context appContext = getContext().getApplicationContext();
|
||||
if (appContext instanceof HabitsApplication)
|
||||
{
|
||||
HabitsApplication app = (HabitsApplication) appContext;
|
||||
taskRunner = app.getComponent().getTaskRunner();
|
||||
}
|
||||
|
||||
if (isInEditMode()) initEditMode();
|
||||
}
|
||||
|
||||
private void initEditMode()
|
||||
{
|
||||
int color = PaletteUtils.getAndroidTestColor(1);
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
chart.populateWithRandomData();
|
||||
}
|
||||
|
||||
private class RefreshTask implements Task
|
||||
@@ -101,10 +121,11 @@ public class BarCard extends HabitCard
|
||||
@Override
|
||||
public void doInBackground()
|
||||
{
|
||||
Timestamp today = DateUtils.getToday();
|
||||
List<Checkmark> checkmarks = habit.getCheckmarks().groupBy(
|
||||
DateUtils.TruncateField.MONTH);
|
||||
List<Checkmark> checkmarks;
|
||||
if (bucketSize == 1) checkmarks = habit.getCheckmarks().getAll();
|
||||
else checkmarks = habit.getCheckmarks().groupBy(getTruncateField(bucketSize));
|
||||
chart.setCheckmarks(checkmarks);
|
||||
chart.setBucketSize(bucketSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,10 +134,16 @@ public class BarCard extends HabitCard
|
||||
int color = PaletteUtils.getColor(getContext(), habit.getColor());
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
if(habit.isNumerical())
|
||||
if (habit.isNumerical())
|
||||
{
|
||||
boolSpinner.setVisibility(GONE);
|
||||
chart.setTarget(habit.getTargetValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
numericalSpinner.setVisibility(GONE);
|
||||
chart.setTarget(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,20 +17,46 @@
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="0dp">
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/CardHeader"
|
||||
android:text="@string/history"/>
|
||||
|
||||
<org.isoron.uhabits.activities.common.views.BarChart
|
||||
android:id="@+id/barChart"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="220dp"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/numericalSpinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="22dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:entries="@array/strengthIntervalNames"
|
||||
android:theme="@style/SmallSpinner" />
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/boolSpinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="22dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:entries="@array/strengthIntervalNamesWithoutDay"
|
||||
android:theme="@style/SmallSpinner" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/CardHeader"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="@string/history" />
|
||||
|
||||
<org.isoron.uhabits.activities.common.views.BarChart
|
||||
android:id="@+id/barChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="220dp"
|
||||
android:layout_below="@id/title"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</merge>
|
||||
@@ -98,6 +98,13 @@
|
||||
<item>@string/year</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="strengthIntervalNamesWithoutDay" translatable="false">
|
||||
<item>@string/week</item>
|
||||
<item>@string/month</item>
|
||||
<item>@string/quarter</item>
|
||||
<item>@string/year</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="strenghtIntervalValues" translatable="false">
|
||||
<item>1</item>
|
||||
<item>7</item>
|
||||
|
||||
Reference in New Issue
Block a user