mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Allow cards to be rendered by the layout editor
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
package org.isoron.uhabits.activities.habits.show.views;
|
package org.isoron.uhabits.activities.habits.show.views;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ public class FrequencyCard extends HabitCard
|
|||||||
@BindView(R.id.frequencyChart)
|
@BindView(R.id.frequencyChart)
|
||||||
FrequencyChart chart;
|
FrequencyChart chart;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
public FrequencyCard(Context context)
|
public FrequencyCard(Context context)
|
||||||
@@ -58,6 +60,7 @@ public class FrequencyCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
|
if(taskRunner == null) return;
|
||||||
taskRunner.execute(new RefreshTask());
|
taskRunner.execute(new RefreshTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +69,12 @@ public class FrequencyCard extends HabitCard
|
|||||||
inflate(getContext(), R.layout.show_habit_frequency, this);
|
inflate(getContext(), R.layout.show_habit_frequency, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
HabitsApplication app =
|
Context appContext = getContext().getApplicationContext();
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
if(appContext instanceof HabitsApplication)
|
||||||
taskRunner = app.getComponent().getTaskRunner();
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
taskRunner = app.getComponent().getTaskRunner();
|
||||||
|
}
|
||||||
|
|
||||||
if (isInEditMode()) initEditMode();
|
if (isInEditMode()) initEditMode();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class HistoryCard extends HabitCard
|
|||||||
@NonNull
|
@NonNull
|
||||||
private Controller controller;
|
private Controller controller;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
public HistoryCard(Context context)
|
public HistoryCard(Context context)
|
||||||
@@ -72,6 +73,7 @@ public class HistoryCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
|
if(taskRunner == null) return;
|
||||||
taskRunner.execute(new RefreshTask(getHabit()));
|
taskRunner.execute(new RefreshTask(getHabit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +82,13 @@ public class HistoryCard extends HabitCard
|
|||||||
inflate(getContext(), R.layout.show_habit_history, this);
|
inflate(getContext(), R.layout.show_habit_history, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
HabitsApplication app =
|
Context appContext = getContext().getApplicationContext();
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
if (appContext instanceof HabitsApplication)
|
||||||
taskRunner = app.getComponent().getTaskRunner();
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
taskRunner = app.getComponent().getTaskRunner();
|
||||||
|
}
|
||||||
|
|
||||||
controller = new Controller() {};
|
controller = new Controller() {};
|
||||||
if (isInEditMode()) initEditMode();
|
if (isInEditMode()) initEditMode();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import android.util.*;
|
|||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.activities.common.views.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
import org.isoron.uhabits.activities.common.views.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import butterknife.*;
|
import butterknife.*;
|
||||||
@@ -54,6 +54,7 @@ public class OverviewCard extends HabitCard
|
|||||||
|
|
||||||
private int color;
|
private int color;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
public OverviewCard(Context context)
|
public OverviewCard(Context context)
|
||||||
@@ -71,6 +72,7 @@ public class OverviewCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
|
if(taskRunner == null) return;
|
||||||
taskRunner.execute(new RefreshTask());
|
taskRunner.execute(new RefreshTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +84,13 @@ public class OverviewCard extends HabitCard
|
|||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
HabitsApplication app =
|
Context appContext = getContext().getApplicationContext();
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
if (appContext instanceof HabitsApplication)
|
||||||
taskRunner = app.getComponent().getTaskRunner();
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
taskRunner = app.getComponent().getTaskRunner();
|
||||||
|
}
|
||||||
|
|
||||||
inflate(getContext(), R.layout.show_habit_overview, this);
|
inflate(getContext(), R.layout.show_habit_overview, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
cache = new Cache();
|
cache = new Cache();
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ public class ScoreCard extends HabitCard
|
|||||||
|
|
||||||
private int bucketSize;
|
private int bucketSize;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
|
||||||
public ScoreCard(Context context)
|
public ScoreCard(Context context)
|
||||||
@@ -93,21 +95,25 @@ public class ScoreCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
|
if(taskRunner == null) return;
|
||||||
taskRunner.execute(new RefreshTask());
|
taskRunner.execute(new RefreshTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDefaultSpinnerPosition()
|
private int getDefaultSpinnerPosition()
|
||||||
{
|
{
|
||||||
if (isInEditMode()) return 0;
|
if(prefs == null) return 0;
|
||||||
return prefs.getDefaultScoreSpinnerPosition();
|
return prefs.getDefaultScoreSpinnerPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
HabitsApplication app =
|
Context appContext = getContext().getApplicationContext();
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
if (appContext instanceof HabitsApplication)
|
||||||
taskRunner = app.getComponent().getTaskRunner();
|
{
|
||||||
prefs = app.getComponent().getPreferences();
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
taskRunner = app.getComponent().getTaskRunner();
|
||||||
|
prefs = app.getComponent().getPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
inflate(getContext(), R.layout.show_habit_score, this);
|
inflate(getContext(), R.layout.show_habit_score, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
@@ -127,8 +133,7 @@ public class ScoreCard extends HabitCard
|
|||||||
|
|
||||||
private void setBucketSizeFromPosition(int position)
|
private void setBucketSizeFromPosition(int position)
|
||||||
{
|
{
|
||||||
if (isInEditMode()) return;
|
if(prefs == null) return;
|
||||||
|
|
||||||
prefs.setDefaultScoreSpinnerPosition(position);
|
prefs.setDefaultScoreSpinnerPosition(position);
|
||||||
bucketSize = BUCKET_SIZES[position];
|
bucketSize = BUCKET_SIZES[position];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package org.isoron.uhabits.activities.habits.show.views;
|
package org.isoron.uhabits.activities.habits.show.views;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ public class StreakCard extends HabitCard
|
|||||||
@BindView(R.id.streakChart)
|
@BindView(R.id.streakChart)
|
||||||
StreakChart streakChart;
|
StreakChart streakChart;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
public StreakCard(Context context)
|
public StreakCard(Context context)
|
||||||
@@ -60,14 +62,18 @@ public class StreakCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
|
if(taskRunner == null) return;
|
||||||
taskRunner.execute(new RefreshTask());
|
taskRunner.execute(new RefreshTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
HabitsApplication app =
|
Context appContext = getContext().getApplicationContext();
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
if (appContext instanceof HabitsApplication)
|
||||||
taskRunner = app.getComponent().getTaskRunner();
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
taskRunner = app.getComponent().getTaskRunner();
|
||||||
|
}
|
||||||
|
|
||||||
inflate(getContext(), R.layout.show_habit_streak, this);
|
inflate(getContext(), R.layout.show_habit_streak, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user