Update main header more frequently

pull/30/head
Alinson S. Xavier 10 years ago
parent 65668cb9e9
commit 77c01ceac9

@ -47,6 +47,7 @@ import org.isoron.uhabits.models.Habit;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.Random;
import java.util.TimeZone; import java.util.TimeZone;
public class ListHabitsFragment extends Fragment public class ListHabitsFragment extends Fragment
@ -94,32 +95,52 @@ public class ListHabitsFragment extends Fragment
listView.setOnTouchListener(controller); listView.setOnTouchListener(controller);
listView.setDragEnabled(true); listView.setDragEnabled(true);
Typeface fontawesome = Typeface fontawesome = Typeface.createFromAsset(getActivity().getAssets(),
Typeface.createFromAsset(getActivity().getAssets(), "fontawesome-webfont.ttf"); "fontawesome-webfont.ttf");
((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(fontawesome); ((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(fontawesome);
llEmpty = view.findViewById(R.id.llEmpty); llEmpty = view.findViewById(R.id.llEmpty);
updateEmptyMessage(); updateEmptyMessage();
mainActivity = (MainActivity) getActivity();
setHasOptionsMenu(true);
return view;
}
@Override
public void onResume()
{
super.onResume();
updateHeader();
}
private void updateHeader()
{
LayoutInflater inflater = mainActivity.getLayoutInflater();
View view = getView();
if(view == null) return;
GregorianCalendar day = new GregorianCalendar(TimeZone.getTimeZone("GMT")); GregorianCalendar day = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
day.setTimeInMillis(DateHelper.getStartOfDay(DateHelper.getLocalTime())); day.setTimeInMillis(DateHelper.getStartOfDay(DateHelper.getLocalTime()));
LinearLayout llButtonsHeader = (LinearLayout) view.findViewById(R.id.llButtonsHeader);
llButtonsHeader.removeAllViews();
Random r = new Random();
for (int i = 0; i < button_count; i++) for (int i = 0; i < button_count; i++)
{ {
View check = inflater.inflate(R.layout.list_habits_header_check, null); View check = inflater.inflate(R.layout.list_habits_header_check, null);
Button btCheck = (Button) check.findViewById(R.id.tvCheck); Button btCheck = (Button) check.findViewById(R.id.tvCheck);
btCheck.setText( btCheck.setText(day.getDisplayName(GregorianCalendar.DAY_OF_WEEK,
day.getDisplayName(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.SHORT, GregorianCalendar.SHORT, Locale.US) + "\n" +
Locale.US) + "\n" + Integer.toString(day.get(GregorianCalendar.DAY_OF_MONTH)));
Integer.toString(day.get(GregorianCalendar.DAY_OF_MONTH))); llButtonsHeader.addView(check);
((LinearLayout) view.findViewById(R.id.llButtonsHeader)).addView(check);
day.add(GregorianCalendar.DAY_OF_MONTH, -1); day.add(GregorianCalendar.DAY_OF_MONTH, -1);
} }
mainActivity = (MainActivity) getActivity();
setHasOptionsMenu(true);
return view;
} }
@Override @Override
@ -251,7 +272,7 @@ public class ListHabitsFragment extends Fragment
{ {
String msg = ""; String msg = "";
int starCount = Habit.getStarCount(); int starCount = Habit.getStarCount();
if (starCount == 1) msg = String.format("%d star", starCount); if (starCount == 1) msg = String.format("%d star", starCount);
else if (starCount > 1) msg = String.format("%d stars", starCount); else if (starCount > 1) msg = String.format("%d stars", starCount);
@ -295,14 +316,14 @@ public class ListHabitsFragment extends Fragment
{ {
final Habit habit = (Habit) getItem(position); final Habit habit = (Habit) getItem(position);
if (view == null || if (view == null || (Long) view.getTag(R.id.KEY_TIMESTAMP) !=
(Long) view.getTag(R.id.KEY_TIMESTAMP) != DateHelper.getStartOfToday()) DateHelper.getStartOfToday())
{ {
view = inflater.inflate(R.layout.list_habits_item, null); view = inflater.inflate(R.layout.list_habits_item, null);
((TextView) view.findViewById(R.id.tvStar)).setTypeface(fontawesome); ((TextView) view.findViewById(R.id.tvStar)).setTypeface(fontawesome);
LinearLayout.LayoutParams params = LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tvNameWidth,
new LinearLayout.LayoutParams(tvNameWidth, LayoutParams.WRAP_CONTENT, 1); LayoutParams.WRAP_CONTENT, 1);
((TextView) view.findViewById(R.id.tvName)).setLayoutParams(params); ((TextView) view.findViewById(R.id.tvName)).setLayoutParams(params);
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
@ -310,9 +331,8 @@ public class ListHabitsFragment extends Fragment
Point size = new Point(); Point size = new Point();
display.getSize(size); display.getSize(size);
LinearLayout.LayoutParams llp = LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutParams.WRAP_CONTENT);
llp.setMargins(2, 0, 2, 0); llp.setMargins(2, 0, 2, 0);
for (int i = 0; i < button_count; i++) for (int i = 0; i < button_count; i++)

Loading…
Cancel
Save