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