mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Automatically change order of days on pre-lollipop
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
package org.isoron.uhabits.activities.habits.list.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
import android.support.annotation.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
@@ -32,7 +31,7 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HeaderView extends LinearLayout
|
||||
public class HeaderView extends LinearLayout implements Preferences.Listener
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
@@ -52,13 +51,19 @@ public class HeaderView extends LinearLayout
|
||||
}
|
||||
|
||||
Context appContext = context.getApplicationContext();
|
||||
if(appContext instanceof HabitsApplication)
|
||||
if (appContext instanceof HabitsApplication)
|
||||
{
|
||||
HabitsApplication app = (HabitsApplication) appContext;
|
||||
prefs = app.getComponent().getPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckmarkOrderChanged()
|
||||
{
|
||||
createButtons();
|
||||
}
|
||||
|
||||
public void setButtonCount(int buttonCount)
|
||||
{
|
||||
this.buttonCount = buttonCount;
|
||||
@@ -66,10 +71,28 @@ public class HeaderView extends LinearLayout
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
super.onAttachedToWindow();
|
||||
if (prefs != null) prefs.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
if (prefs != null) prefs.removeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void createButtons()
|
||||
{
|
||||
removeAllViews();
|
||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||
|
||||
for (int i = 0; i < buttonCount; i++)
|
||||
addView(
|
||||
inflate(context, R.layout.list_habits_header_checkmark, null));
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++)
|
||||
{
|
||||
int position = i;
|
||||
@@ -80,22 +103,11 @@ public class HeaderView extends LinearLayout
|
||||
label.setText(DateUtils.formatHeaderDate(day));
|
||||
day.add(GregorianCalendar.DAY_OF_MONTH, -1);
|
||||
}
|
||||
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
private void createButtons()
|
||||
{
|
||||
int layout = R.layout.list_habits_header_checkmark;
|
||||
|
||||
removeAllViews();
|
||||
for (int i = 0; i < buttonCount; i++)
|
||||
addView(inflate(context, layout, null));
|
||||
}
|
||||
|
||||
private boolean shouldReverseCheckmarks()
|
||||
{
|
||||
if(prefs == null) return false;
|
||||
if (prefs == null) return false;
|
||||
return prefs.shouldReverseCheckmarks();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user