mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Move more methods to helper
This commit is contained in:
@@ -36,7 +36,6 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -60,7 +59,6 @@ import org.isoron.uhabits.loaders.HabitListLoader;
|
|||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -74,10 +72,12 @@ public class ListHabitsFragment extends Fragment
|
|||||||
void onHabitClicked(Habit habit);
|
void onHabitClicked(Habit habit);
|
||||||
}
|
}
|
||||||
|
|
||||||
HabitListAdapter adapter;
|
private HabitListAdapter adapter;
|
||||||
DragSortListView listView;
|
private DragSortListView listView;
|
||||||
ReplayableActivity activity;
|
private ReplayableActivity activity;
|
||||||
TextView tvNameHeader;
|
private TextView tvNameHeader;
|
||||||
|
private LinearLayout llButtonsHeader;
|
||||||
|
|
||||||
long lastLongClick = 0;
|
long lastLongClick = 0;
|
||||||
|
|
||||||
private View llEmpty;
|
private View llEmpty;
|
||||||
@@ -161,9 +161,8 @@ public class ListHabitsFragment extends Fragment
|
|||||||
llHint.setOnClickListener(this);
|
llHint.setOnClickListener(this);
|
||||||
hintManager = new HintManager(activity, llHint);
|
hintManager = new HintManager(activity, llHint);
|
||||||
|
|
||||||
Typeface fontawesome = Typeface.createFromAsset(getActivity().getAssets(),
|
((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(helper.getFontawesome());
|
||||||
"fontawesome-webfont.ttf");
|
llButtonsHeader = (LinearLayout) view.findViewById(R.id.llButtonsHeader);
|
||||||
((TextView) view.findViewById(R.id.tvStarEmpty)).setTypeface(fontawesome);
|
|
||||||
llEmpty = view.findViewById(R.id.llEmpty);
|
llEmpty = view.findViewById(R.id.llEmpty);
|
||||||
|
|
||||||
loader.updateAllHabits(true);
|
loader.updateAllHabits(true);
|
||||||
@@ -192,42 +191,19 @@ public class ListHabitsFragment extends Fragment
|
|||||||
if (timestamp != null && timestamp != DateHelper.getStartOfToday())
|
if (timestamp != null && timestamp != DateHelper.getStartOfToday())
|
||||||
loader.updateAllHabits(true);
|
loader.updateAllHabits(true);
|
||||||
|
|
||||||
updateEmptyMessage();
|
helper.updateEmptyMessage(llEmpty);
|
||||||
updateHeader();
|
helper.updateHeader(llButtonsHeader);
|
||||||
hintManager.showHintIfAppropriate();
|
hintManager.showHintIfAppropriate();
|
||||||
|
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
isShortToggleEnabled = prefs.getBoolean("pref_short_toggle", false);
|
isShortToggleEnabled = prefs.getBoolean("pref_short_toggle", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateHeader()
|
|
||||||
{
|
|
||||||
LayoutInflater inflater = activity.getLayoutInflater();
|
|
||||||
View view = getView();
|
|
||||||
|
|
||||||
if (view == null) return;
|
|
||||||
|
|
||||||
GregorianCalendar day = DateHelper.getStartOfTodayCalendar();
|
|
||||||
|
|
||||||
LinearLayout llButtonsHeader = (LinearLayout) view.findViewById(R.id.llButtonsHeader);
|
|
||||||
llButtonsHeader.removeAllViews();
|
|
||||||
|
|
||||||
for (int i = 0; i < helper.getButtonCount(); i++)
|
|
||||||
{
|
|
||||||
View tvDay = inflater.inflate(R.layout.list_habits_header_check, null);
|
|
||||||
Button btCheck = (Button) tvDay.findViewById(R.id.tvCheck);
|
|
||||||
btCheck.setText(DateHelper.formatHeaderDate(day));
|
|
||||||
llButtonsHeader.addView(tvDay);
|
|
||||||
|
|
||||||
day.add(GregorianCalendar.DAY_OF_MONTH, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished()
|
public void onLoadFinished()
|
||||||
{
|
{
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
updateEmptyMessage();
|
helper.updateEmptyMessage(llEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -347,12 +323,6 @@ public class ListHabitsFragment extends Fragment
|
|||||||
if(actionMode != null) actionMode.finish();
|
if(actionMode != null) actionMode.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEmptyMessage()
|
|
||||||
{
|
|
||||||
if (loader.getLastLoadTimestamp() == null) llEmpty.setVisibility(View.GONE);
|
|
||||||
else llEmpty.setVisibility(loader.habits.size() > 0 ? View.GONE : View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v)
|
public boolean onLongClick(View v)
|
||||||
{
|
{
|
||||||
@@ -379,17 +349,14 @@ public class ListHabitsFragment extends Fragment
|
|||||||
private void toggleCheck(View v)
|
private void toggleCheck(View v)
|
||||||
{
|
{
|
||||||
Long tag = (Long) v.getTag(R.string.habit_key);
|
Long tag = (Long) v.getTag(R.string.habit_key);
|
||||||
Habit habit = loader.habits.get(tag);
|
Integer offset = (Integer) v.getTag(R.string.offset_key);
|
||||||
|
|
||||||
int offset = (Integer) v.getTag(R.string.offset_key);
|
|
||||||
long timestamp = DateHelper.getStartOfDay(
|
long timestamp = DateHelper.getStartOfDay(
|
||||||
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
|
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
|
||||||
|
|
||||||
if (v.getTag(R.string.toggle_key).equals(2))
|
Habit habit = loader.habits.get(tag);
|
||||||
helper.updateCheckmark(habit.color, (TextView) v, 0);
|
if(habit == null) return;
|
||||||
else
|
|
||||||
helper.updateCheckmark(habit.color, (TextView) v, 2);
|
|
||||||
|
|
||||||
|
helper.toggleCheckmarkView(v, habit);
|
||||||
executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
|
executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,19 @@ import android.graphics.Typeface;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.isoron.helpers.DateHelper;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.loaders.HabitListLoader;
|
import org.isoron.uhabits.loaders.HabitListLoader;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
import org.isoron.uhabits.models.Score;
|
import org.isoron.uhabits.models.Score;
|
||||||
|
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
public class ListHabitsHelper
|
public class ListHabitsHelper
|
||||||
{
|
{
|
||||||
public static final int INACTIVE_COLOR = Color.rgb(200, 200, 200);
|
public static final int INACTIVE_COLOR = Color.rgb(200, 200, 200);
|
||||||
@@ -161,4 +166,35 @@ public class ListHabitsHelper
|
|||||||
((LinearLayout) view.findViewById(R.id.llButtons)).addView(check);
|
((LinearLayout) view.findViewById(R.id.llButtons)).addView(check);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateHeader(ViewGroup header)
|
||||||
|
{
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(context);
|
||||||
|
GregorianCalendar day = DateHelper.getStartOfTodayCalendar();
|
||||||
|
header.removeAllViews();
|
||||||
|
|
||||||
|
for (int i = 0; i < getButtonCount(); i++)
|
||||||
|
{
|
||||||
|
View tvDay = inflater.inflate(R.layout.list_habits_header_check, null);
|
||||||
|
Button btCheck = (Button) tvDay.findViewById(R.id.tvCheck);
|
||||||
|
btCheck.setText(DateHelper.formatHeaderDate(day));
|
||||||
|
header.addView(tvDay);
|
||||||
|
|
||||||
|
day.add(GregorianCalendar.DAY_OF_MONTH, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEmptyMessage(View view)
|
||||||
|
{
|
||||||
|
if (loader.getLastLoadTimestamp() == null) view.setVisibility(View.GONE);
|
||||||
|
else view.setVisibility(loader.habits.size() > 0 ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleCheckmarkView(View v, Habit habit)
|
||||||
|
{
|
||||||
|
if (v.getTag(R.string.toggle_key).equals(2))
|
||||||
|
updateCheckmark(habit.color, (TextView) v, 0);
|
||||||
|
else
|
||||||
|
updateCheckmark(habit.color, (TextView) v, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user