|
|
@ -19,22 +19,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.isoron.uhabits.ui.habits.list.views;
|
|
|
|
package org.isoron.uhabits.ui.habits.list.views;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.*;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.*;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v7.widget.*;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.*;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.*;
|
|
|
|
import android.widget.ListAdapter;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mobeta.android.dslv.*;
|
|
|
|
import com.mobeta.android.dslv.DragSortController;
|
|
|
|
|
|
|
|
import com.mobeta.android.dslv.DragSortListView;
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
|
|
|
|
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
|
|
|
import org.isoron.uhabits.models.Habit;
|
|
|
|
import org.isoron.uhabits.ui.habits.list.model.*;
|
|
|
|
import org.isoron.uhabits.ui.habits.list.controllers.CheckmarkButtonController;
|
|
|
|
|
|
|
|
import org.isoron.uhabits.ui.habits.list.controllers.HabitCardController;
|
|
|
|
public class HabitCardListView extends RecyclerView
|
|
|
|
import org.isoron.uhabits.ui.habits.list.model.HabitCardListAdapter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class HabitCardListView extends DragSortListView
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
|
private HabitCardListAdapter adapter;
|
|
|
|
private HabitCardListAdapter adapter;
|
|
|
@ -45,9 +42,11 @@ public class HabitCardListView extends DragSortListView
|
|
|
|
public HabitCardListView(Context context, AttributeSet attrs)
|
|
|
|
public HabitCardListView(Context context, AttributeSet attrs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super(context, attrs);
|
|
|
|
super(context, attrs);
|
|
|
|
setFloatViewManager(new ViewManager());
|
|
|
|
// setFloatViewManager(new ViewManager());
|
|
|
|
setDragEnabled(true);
|
|
|
|
// setDragEnabled(true);
|
|
|
|
setLongClickable(true);
|
|
|
|
setLongClickable(true);
|
|
|
|
|
|
|
|
setHasFixedSize(true);
|
|
|
|
|
|
|
|
setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -63,14 +62,12 @@ public class HabitCardListView extends DragSortListView
|
|
|
|
* @param selected true if the card is selected, false otherwise
|
|
|
|
* @param selected true if the card is selected, false otherwise
|
|
|
|
* @return the HabitCardView generated
|
|
|
|
* @return the HabitCardView generated
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public View buildCardView(@Nullable HabitCardView cardView,
|
|
|
|
public View bindCardView(@NonNull HabitCardView cardView,
|
|
|
|
@NonNull Habit habit,
|
|
|
|
@NonNull Habit habit,
|
|
|
|
int score,
|
|
|
|
int score,
|
|
|
|
int[] checkmarks,
|
|
|
|
int[] checkmarks,
|
|
|
|
boolean selected)
|
|
|
|
boolean selected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (cardView == null) cardView = new HabitCardView(getContext());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cardView.setHabit(habit);
|
|
|
|
cardView.setHabit(habit);
|
|
|
|
cardView.setSelected(selected);
|
|
|
|
cardView.setSelected(selected);
|
|
|
|
cardView.setCheckmarkValues(checkmarks);
|
|
|
|
cardView.setCheckmarkValues(checkmarks);
|
|
|
@ -87,8 +84,13 @@ public class HabitCardListView extends DragSortListView
|
|
|
|
return cardView;
|
|
|
|
return cardView;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public View createCardView()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new HabitCardView(getContext());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setAdapter(ListAdapter adapter)
|
|
|
|
public void setAdapter(RecyclerView.Adapter adapter)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.adapter = (HabitCardListAdapter) adapter;
|
|
|
|
this.adapter = (HabitCardListAdapter) adapter;
|
|
|
|
super.setAdapter(adapter);
|
|
|
|
super.setAdapter(adapter);
|
|
|
@ -97,18 +99,18 @@ public class HabitCardListView extends DragSortListView
|
|
|
|
public void setController(@Nullable Controller controller)
|
|
|
|
public void setController(@Nullable Controller controller)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.controller = controller;
|
|
|
|
this.controller = controller;
|
|
|
|
setDropListener(controller);
|
|
|
|
// setDropListener(controller);
|
|
|
|
setDragListener(controller);
|
|
|
|
// setDragListener(controller);
|
|
|
|
setOnItemClickListener(null);
|
|
|
|
// setOnItemClickListener(null);
|
|
|
|
setOnLongClickListener(null);
|
|
|
|
setOnLongClickListener(null);
|
|
|
|
|
|
|
|
|
|
|
|
if (controller == null) return;
|
|
|
|
if (controller == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
setOnItemClickListener((p, v, pos, id) -> controller.onItemClick(pos));
|
|
|
|
// setOnItemClickListener((p, v, pos, id) -> controller.onItemClick(pos));
|
|
|
|
setOnItemLongClickListener((p, v, pos, id) -> {
|
|
|
|
// setOnItemLongClickListener((p, v, pos, id) -> {
|
|
|
|
controller.onItemLongClick(pos);
|
|
|
|
// controller.onItemLongClick(pos);
|
|
|
|
return true;
|
|
|
|
// return true;
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -127,32 +129,32 @@ public class HabitCardListView extends DragSortListView
|
|
|
|
|
|
|
|
|
|
|
|
public interface Controller extends CheckmarkButtonController.Listener,
|
|
|
|
public interface Controller extends CheckmarkButtonController.Listener,
|
|
|
|
HabitCardController.Listener,
|
|
|
|
HabitCardController.Listener,
|
|
|
|
DropListener,
|
|
|
|
DragSortListView.DropListener,
|
|
|
|
DragListener
|
|
|
|
DragSortListView.DragListener
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void onItemClick(int pos);
|
|
|
|
void onItemClick(int pos);
|
|
|
|
|
|
|
|
|
|
|
|
void onItemLongClick(int pos);
|
|
|
|
void onItemLongClick(int pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class ViewManager extends DragSortController
|
|
|
|
// private class ViewManager extends DragSortController
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
public ViewManager()
|
|
|
|
// public ViewManager()
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
super(HabitCardListView.this);
|
|
|
|
// super(HabitCardListView.this);
|
|
|
|
setRemoveEnabled(false);
|
|
|
|
// setRemoveEnabled(false);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
@Override
|
|
|
|
// @Override
|
|
|
|
public View onCreateFloatView(int position)
|
|
|
|
// public View onCreateFloatView(int position)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
if (adapter == null) return null;
|
|
|
|
// if (adapter == null) return null;
|
|
|
|
return adapter.getView(position, null, null);
|
|
|
|
// return adapter.getView(position, null, null);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
@Override
|
|
|
|
// @Override
|
|
|
|
public void onDestroyFloatView(View floatView)
|
|
|
|
// public void onDestroyFloatView(View floatView)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|