|
|
|
@ -23,15 +23,17 @@ import android.content.*;
|
|
|
|
|
import android.content.res.*;
|
|
|
|
|
import android.support.annotation.*;
|
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
|
import android.util.*;
|
|
|
|
|
import android.view.*;
|
|
|
|
|
import android.widget.*;
|
|
|
|
|
|
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
|
import org.isoron.uhabits.activities.*;
|
|
|
|
|
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
|
|
|
|
import org.isoron.uhabits.activities.habits.list.model.*;
|
|
|
|
|
import org.isoron.uhabits.activities.habits.list.views.*;
|
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
|
import org.isoron.uhabits.tasks.*;
|
|
|
|
|
import org.isoron.uhabits.utils.*;
|
|
|
|
|
|
|
|
|
|
import javax.inject.*;
|
|
|
|
@ -40,7 +42,7 @@ import butterknife.*;
|
|
|
|
|
|
|
|
|
|
@ActivityScope
|
|
|
|
|
public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
implements ModelObservable.Listener
|
|
|
|
|
implements ModelObservable.Listener, TaskRunner.Listener
|
|
|
|
|
{
|
|
|
|
|
public static final int MAX_CHECKMARK_COUNT = 21;
|
|
|
|
|
|
|
|
|
@ -68,10 +70,13 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
@NonNull
|
|
|
|
|
private final HabitCardListAdapter listAdapter;
|
|
|
|
|
|
|
|
|
|
private final TaskRunner runner;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public ListHabitsRootView(@ActivityContext Context context,
|
|
|
|
|
@NonNull HintListFactory hintListFactory,
|
|
|
|
|
@NonNull HabitCardListAdapter listAdapter)
|
|
|
|
|
@NonNull HabitCardListAdapter listAdapter,
|
|
|
|
|
@NonNull TaskRunner runner)
|
|
|
|
|
{
|
|
|
|
|
super(context);
|
|
|
|
|
addView(inflate(getContext(), R.layout.list_habits, null));
|
|
|
|
@ -81,13 +86,16 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
listView.setAdapter(listAdapter);
|
|
|
|
|
listAdapter.setListView(listView);
|
|
|
|
|
|
|
|
|
|
this.runner = runner;
|
|
|
|
|
progressBar.setIndeterminate(true);
|
|
|
|
|
tvStarEmpty.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
|
|
|
|
|
initToolbar();
|
|
|
|
|
|
|
|
|
|
String hints[] =
|
|
|
|
|
getContext().getResources().getStringArray(R.array.hints);
|
|
|
|
|
HintList hintList = hintListFactory.create(hints);
|
|
|
|
|
hintView.setHints(hintList);
|
|
|
|
|
|
|
|
|
|
initToolbar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@ -103,6 +111,20 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
updateEmptyView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTaskFinished(Task task)
|
|
|
|
|
{
|
|
|
|
|
updateProgressBar();
|
|
|
|
|
Log.d("RootView", "onTaskFinished");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTaskStarted(Task task)
|
|
|
|
|
{
|
|
|
|
|
updateProgressBar();
|
|
|
|
|
Log.d("RootView", "onTaskStarted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setController(@NonNull ListHabitsController controller,
|
|
|
|
|
@NonNull ListHabitsSelectionMenu menu)
|
|
|
|
|
{
|
|
|
|
@ -119,6 +141,8 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
protected void onAttachedToWindow()
|
|
|
|
|
{
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
runner.addListener(this);
|
|
|
|
|
updateProgressBar();
|
|
|
|
|
listAdapter.getObservable().addListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,9 +150,19 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
protected void onDetachedFromWindow()
|
|
|
|
|
{
|
|
|
|
|
listAdapter.getObservable().removeListener(this);
|
|
|
|
|
runner.removeListener(this);
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
|
|
|
|
{
|
|
|
|
|
int count = getCheckmarkCount();
|
|
|
|
|
header.setButtonCount(count);
|
|
|
|
|
listView.setCheckmarkCount(count);
|
|
|
|
|
super.onSizeChanged(w, h, oldw, oldh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getCheckmarkCount()
|
|
|
|
|
{
|
|
|
|
|
Resources res = getResources();
|
|
|
|
@ -144,12 +178,11 @@ public class ListHabitsRootView extends BaseRootView
|
|
|
|
|
listAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
|
|
|
|
private void updateProgressBar()
|
|
|
|
|
{
|
|
|
|
|
int count = getCheckmarkCount();
|
|
|
|
|
header.setButtonCount(count);
|
|
|
|
|
listView.setCheckmarkCount(count);
|
|
|
|
|
super.onSizeChanged(w, h, oldw, oldh);
|
|
|
|
|
postDelayed(() -> {
|
|
|
|
|
progressBar.setVisibility(
|
|
|
|
|
runner.getActiveTaskCount() > 0 ? VISIBLE : GONE);
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|