mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Refactor HeaderView; update list on resume
This commit is contained in:
@@ -100,4 +100,6 @@ public interface BaseComponent
|
|||||||
void inject(ListHabitsMenu listHabitsMenu);
|
void inject(ListHabitsMenu listHabitsMenu);
|
||||||
|
|
||||||
void inject(PebbleReceiver receiver);
|
void inject(PebbleReceiver receiver);
|
||||||
|
|
||||||
|
void inject(HeaderView headerView);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ public class ListHabitsActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
|
adapter.refresh();
|
||||||
|
rootView.postInvalidate();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
package org.isoron.uhabits.ui.habits.list.views;
|
package org.isoron.uhabits.ui.habits.list.views;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.preference.*;
|
import android.graphics.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
@@ -30,20 +30,29 @@ import org.isoron.uhabits.utils.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
public class HeaderView extends LinearLayout
|
public class HeaderView extends LinearLayout
|
||||||
{
|
{
|
||||||
private static final int CHECKMARK_LEFT_TO_RIGHT = 0;
|
|
||||||
|
|
||||||
private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
|
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
private int buttonCount;
|
private int buttonCount;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Preferences prefs;
|
||||||
|
|
||||||
public HeaderView(Context context, AttributeSet attrs)
|
public HeaderView(Context context, AttributeSet attrs)
|
||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
|
if (isInEditMode())
|
||||||
|
{
|
||||||
|
setButtonCount(5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HabitsApplication.getComponent().inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setButtonCount(int buttonCount)
|
public void setButtonCount(int buttonCount)
|
||||||
@@ -52,6 +61,25 @@ public class HeaderView extends LinearLayout
|
|||||||
createButtons();
|
createButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas)
|
||||||
|
{
|
||||||
|
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||||
|
|
||||||
|
for (int i = 0; i < getChildCount(); i++)
|
||||||
|
{
|
||||||
|
int position = i;
|
||||||
|
if (shouldReverseCheckmarks()) position = getChildCount() - i - 1;
|
||||||
|
|
||||||
|
View button = getChildAt(position);
|
||||||
|
TextView label = (TextView) button.findViewById(R.id.tvCheck);
|
||||||
|
label.setText(DateUtils.formatHeaderDate(day));
|
||||||
|
day.add(GregorianCalendar.DAY_OF_MONTH, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDraw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||||
{
|
{
|
||||||
@@ -61,32 +89,16 @@ public class HeaderView extends LinearLayout
|
|||||||
|
|
||||||
private void createButtons()
|
private void createButtons()
|
||||||
{
|
{
|
||||||
|
int layout = R.layout.list_habits_header_checkmark;
|
||||||
|
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
|
||||||
|
|
||||||
for (int i = 0; i < buttonCount; i++)
|
for (int i = 0; i < buttonCount; i++)
|
||||||
{
|
addView(inflate(context, layout, null));
|
||||||
int position = 0;
|
|
||||||
|
|
||||||
if (getCheckmarkOrder() == CHECKMARK_LEFT_TO_RIGHT) position = i;
|
|
||||||
|
|
||||||
View tvDay =
|
|
||||||
inflate(context, R.layout.list_habits_header_checkmark, null);
|
|
||||||
TextView btCheck = (TextView) tvDay.findViewById(R.id.tvCheck);
|
|
||||||
btCheck.setText(DateUtils.formatHeaderDate(day));
|
|
||||||
addView(tvDay, position);
|
|
||||||
day.add(GregorianCalendar.DAY_OF_MONTH, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCheckmarkOrder()
|
private boolean shouldReverseCheckmarks()
|
||||||
{
|
{
|
||||||
if (isInEditMode()) return CHECKMARK_LEFT_TO_RIGHT;
|
if (isInEditMode()) return false;
|
||||||
|
return prefs.shouldReverseCheckmarks();
|
||||||
SharedPreferences prefs =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
||||||
boolean reverse =
|
|
||||||
prefs.getBoolean("pref_checkmark_reverse_order", false);
|
|
||||||
return reverse ? CHECKMARK_RIGHT_TO_LEFT : CHECKMARK_LEFT_TO_RIGHT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user