mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'feature/recyclerview' into dev
This commit is contained in:
@@ -69,8 +69,6 @@ dependencies {
|
|||||||
androidTestApt 'com.google.dagger:dagger-compiler:2.2'
|
androidTestApt 'com.google.dagger:dagger-compiler:2.2'
|
||||||
provided 'javax.annotation:jsr250-api:1.0'
|
provided 'javax.annotation:jsr250-api:1.0'
|
||||||
|
|
||||||
compile project(':libs:drag-sort-listview:library')
|
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile 'org.hamcrest:hamcrest-library:1.3'
|
testCompile 'org.hamcrest:hamcrest-library:1.3'
|
||||||
testCompile 'org.mockito:mockito-core:1.10.19'
|
testCompile 'org.mockito:mockito-core:1.10.19'
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.models.sqlite;
|
|||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import com.activeandroid.query.*;
|
import com.activeandroid.query.*;
|
||||||
|
import com.activeandroid.util.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.*;
|
import org.apache.commons.lang3.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
@@ -181,8 +182,16 @@ public class SQLiteHabitList extends HabitList
|
|||||||
{
|
{
|
||||||
if (from == to) return;
|
if (from == to) return;
|
||||||
|
|
||||||
Integer toPos = indexOf(to);
|
HabitRecord fromRecord = HabitRecord.get(from.getId());
|
||||||
Integer fromPos = indexOf(from);
|
HabitRecord toRecord = HabitRecord.get(to.getId());
|
||||||
|
|
||||||
|
if (fromRecord == null) throw new RuntimeException("habit not in database");
|
||||||
|
if (toRecord == null) throw new RuntimeException("habit not in database");
|
||||||
|
|
||||||
|
Integer fromPos = fromRecord.position;
|
||||||
|
Integer toPos = toRecord.position;
|
||||||
|
|
||||||
|
Log.d("SQLiteHabitList", String.format("reorder: %d %d", fromPos, toPos));
|
||||||
|
|
||||||
if (toPos < fromPos)
|
if (toPos < fromPos)
|
||||||
{
|
{
|
||||||
@@ -199,10 +208,8 @@ public class SQLiteHabitList extends HabitList
|
|||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
HabitRecord record = HabitRecord.get(from.getId());
|
fromRecord.position = toPos;
|
||||||
if (record == null) throw new RuntimeException("habit not in database");
|
fromRecord.save();
|
||||||
record.position = toPos;
|
|
||||||
record.save();
|
|
||||||
|
|
||||||
update(from);
|
update(from);
|
||||||
|
|
||||||
@@ -212,10 +219,6 @@ public class SQLiteHabitList extends HabitList
|
|||||||
@Override
|
@Override
|
||||||
public int size()
|
public int size()
|
||||||
{
|
{
|
||||||
// SQLiteDatabase db = Cache.openDatabase();
|
|
||||||
// SQLiteStatement st = db.compileStatement(buildCountQuery());
|
|
||||||
// return (int) st.simpleQueryForLong();
|
|
||||||
|
|
||||||
return toList().size();
|
return toList().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,11 +254,6 @@ public class SQLiteHabitList extends HabitList
|
|||||||
return habits;
|
return habits;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendCount(StringBuilder query)
|
|
||||||
{
|
|
||||||
query.append("select count (*) from habits ");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendOrderBy(StringBuilder query)
|
private void appendOrderBy(StringBuilder query)
|
||||||
{
|
{
|
||||||
query.append("order by position ");
|
query.append("order by position ");
|
||||||
@@ -278,14 +276,6 @@ public class SQLiteHabitList extends HabitList
|
|||||||
query.append(" ");
|
query.append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildCountQuery()
|
|
||||||
{
|
|
||||||
StringBuilder query = new StringBuilder();
|
|
||||||
appendCount(query);
|
|
||||||
appendWhere(query);
|
|
||||||
return query.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String buildSelectQuery()
|
private String buildSelectQuery()
|
||||||
{
|
{
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class ListHabitsController
|
|||||||
@Override
|
@Override
|
||||||
public void onHabitReorder(@NonNull Habit from, @NonNull Habit to)
|
public void onHabitReorder(@NonNull Habit from, @NonNull Habit to)
|
||||||
{
|
{
|
||||||
habitList.reorder(from, to);
|
new SimpleTask(() -> habitList.reorder(from, to)).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onImportData(@NonNull File file)
|
public void onImportData(@NonNull File file)
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class ListHabitsRootView extends BaseRootView
|
|||||||
@NonNull ListHabitsSelectionMenu menu)
|
@NonNull ListHabitsSelectionMenu menu)
|
||||||
{
|
{
|
||||||
HabitCardListController listController =
|
HabitCardListController listController =
|
||||||
new HabitCardListController(listAdapter, listView);
|
new HabitCardListController(listAdapter);
|
||||||
|
|
||||||
listController.setHabitListener(controller);
|
listController.setHabitListener(controller);
|
||||||
listController.setSelectionListener(menu);
|
listController.setSelectionListener(menu);
|
||||||
@@ -141,6 +141,6 @@ public class ListHabitsRootView extends BaseRootView
|
|||||||
private void updateEmptyView()
|
private void updateEmptyView()
|
||||||
{
|
{
|
||||||
llEmpty.setVisibility(
|
llEmpty.setVisibility(
|
||||||
listAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
|
listAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ package org.isoron.uhabits.ui.habits.list.controllers;
|
|||||||
|
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import com.mobeta.android.dslv.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||||
@@ -32,9 +30,7 @@ import org.isoron.uhabits.ui.habits.list.views.*;
|
|||||||
* HabitListView. These include selecting and reordering items, toggling
|
* HabitListView. These include selecting and reordering items, toggling
|
||||||
* checkmarks and clicking habits.
|
* checkmarks and clicking habits.
|
||||||
*/
|
*/
|
||||||
public class HabitCardListController implements DragSortListView.DropListener,
|
public class HabitCardListController implements HabitCardListView.Controller
|
||||||
DragSortListView.DragListener,
|
|
||||||
HabitCardListView.Controller
|
|
||||||
{
|
{
|
||||||
private final Mode NORMAL_MODE = new NormalMode();
|
private final Mode NORMAL_MODE = new NormalMode();
|
||||||
|
|
||||||
@@ -43,9 +39,6 @@ public class HabitCardListController implements DragSortListView.DropListener,
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final HabitCardListAdapter adapter;
|
private final HabitCardListAdapter adapter;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final HabitCardListView view;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private HabitListener habitListener;
|
private HabitListener habitListener;
|
||||||
|
|
||||||
@@ -55,11 +48,9 @@ public class HabitCardListController implements DragSortListView.DropListener,
|
|||||||
@NonNull
|
@NonNull
|
||||||
private Mode activeMode;
|
private Mode activeMode;
|
||||||
|
|
||||||
public HabitCardListController(@NonNull HabitCardListAdapter adapter,
|
public HabitCardListController(@NonNull HabitCardListAdapter adapter)
|
||||||
@NonNull HabitCardListView view)
|
|
||||||
{
|
{
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
this.view = view;
|
|
||||||
this.activeMode = new NormalMode();
|
this.activeMode = new NormalMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +181,6 @@ public class HabitCardListController implements DragSortListView.DropListener,
|
|||||||
private void cancelSelection()
|
private void cancelSelection()
|
||||||
{
|
{
|
||||||
adapter.clearSelection();
|
adapter.clearSelection();
|
||||||
view.setDragEnabled(true);
|
|
||||||
activeMode = new NormalMode();
|
activeMode = new NormalMode();
|
||||||
|
|
||||||
if (selectionListener != null) selectionListener.onSelectionFinish();
|
if (selectionListener != null) selectionListener.onSelectionFinish();
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
package org.isoron.uhabits.ui.habits.list.model;
|
package org.isoron.uhabits.ui.habits.list.model;
|
||||||
|
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
import android.support.v7.widget.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
@@ -35,7 +35,8 @@ import java.util.*;
|
|||||||
* The data if fetched and cached by a {@link HabitCardListCache}. This adapter
|
* The data if fetched and cached by a {@link HabitCardListCache}. This adapter
|
||||||
* also holds a list of items that have been selected.
|
* also holds a list of items that have been selected.
|
||||||
*/
|
*/
|
||||||
public class HabitCardListAdapter extends BaseAdapter
|
public class HabitCardListAdapter
|
||||||
|
extends RecyclerView.Adapter<HabitCardViewHolder>
|
||||||
implements HabitCardListCache.Listener
|
implements HabitCardListCache.Listener
|
||||||
{
|
{
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -61,6 +62,8 @@ public class HabitCardListAdapter extends BaseAdapter
|
|||||||
cache = new HabitCardListCache(allHabits);
|
cache = new HabitCardListCache(allHabits);
|
||||||
cache.setListener(this);
|
cache.setListener(this);
|
||||||
cache.setCheckmarkCount(checkmarkCount);
|
cache.setCheckmarkCount(checkmarkCount);
|
||||||
|
|
||||||
|
setHasStableIds(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelRefresh()
|
public void cancelRefresh()
|
||||||
@@ -78,7 +81,7 @@ public class HabitCardListAdapter extends BaseAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount()
|
public int getItemCount()
|
||||||
{
|
{
|
||||||
return cache.getHabitCount();
|
return cache.getHabitCount();
|
||||||
}
|
}
|
||||||
@@ -90,13 +93,38 @@ public class HabitCardListAdapter extends BaseAdapter
|
|||||||
* @return the item at given position
|
* @return the item at given position
|
||||||
* @throws IndexOutOfBoundsException if position is not valid
|
* @throws IndexOutOfBoundsException if position is not valid
|
||||||
*/
|
*/
|
||||||
@Override
|
@Deprecated
|
||||||
@NonNull
|
@NonNull
|
||||||
public Habit getItem(int position)
|
public Habit getItem(int position)
|
||||||
{
|
{
|
||||||
return cache.getHabitByPosition(position);
|
return cache.getHabitByPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HabitCardViewHolder onCreateViewHolder(ViewGroup parent,
|
||||||
|
int viewType)
|
||||||
|
{
|
||||||
|
if(listView == null) return null;
|
||||||
|
View view = listView.createCardView();
|
||||||
|
return new HabitCardViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@Nullable HabitCardViewHolder holder, int position)
|
||||||
|
{
|
||||||
|
if(holder == null) return;
|
||||||
|
if(listView == null) return;
|
||||||
|
|
||||||
|
Habit habit = cache.getHabitByPosition(position);
|
||||||
|
int score = cache.getScore(habit.getId());
|
||||||
|
int checkmarks[] = cache.getCheckmarks(habit.getId());
|
||||||
|
boolean selected = this.selected.contains(habit);
|
||||||
|
|
||||||
|
HabitCardView cardView = (HabitCardView) holder.itemView;
|
||||||
|
listView.bindCardView(cardView, habit, score, checkmarks, selected,
|
||||||
|
position);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position)
|
public long getItemId(int position)
|
||||||
{
|
{
|
||||||
@@ -115,21 +143,21 @@ public class HabitCardListAdapter extends BaseAdapter
|
|||||||
return new LinkedList<>(selected);
|
return new LinkedList<>(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public View getView(int position,
|
// public View getView(int position,
|
||||||
@Nullable View view,
|
// @Nullable View view,
|
||||||
@Nullable ViewGroup parent)
|
// @Nullable ViewGroup parent)
|
||||||
{
|
// {
|
||||||
if (listView == null) return null;
|
// if (listView == null) return null;
|
||||||
|
//
|
||||||
Habit habit = cache.getHabitByPosition(position);
|
// Habit habit = cache.getHabitByPosition(position);
|
||||||
int score = cache.getScore(habit.getId());
|
// int score = cache.getScore(habit.getId());
|
||||||
int checkmarks[] = cache.getCheckmarks(habit.getId());
|
// int checkmarks[] = cache.getCheckmarks(habit.getId());
|
||||||
boolean selected = this.selected.contains(habit);
|
// boolean selected = this.selected.contains(habit);
|
||||||
|
//
|
||||||
return listView.buildCardView((HabitCardView) view, habit, score,
|
// return listView.buildCardView((HabitCardView) view, habit, score,
|
||||||
checkmarks, selected);
|
// checkmarks, selected);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether list of selected items is empty.
|
* Returns whether list of selected items is empty.
|
||||||
@@ -203,12 +231,6 @@ public class HabitCardListAdapter extends BaseAdapter
|
|||||||
this.listView = listView;
|
this.listView = listView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowArchived(boolean showArchived)
|
|
||||||
{
|
|
||||||
cache.setIncludeArchived(showArchived);
|
|
||||||
cache.refreshAllHabits(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects or deselects the item at a given position.
|
* Selects or deselects the item at a given position.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -102,16 +102,6 @@ public class HabitCardListCache implements CommandRunner.Listener
|
|||||||
return data.habits.size();
|
return data.habits.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIncludeArchived()
|
|
||||||
{
|
|
||||||
return includeArchived;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIncludeArchived(boolean includeArchived)
|
|
||||||
{
|
|
||||||
this.includeArchived = includeArchived;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Long getLastLoadTimestamp()
|
public Long getLastLoadTimestamp()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.habits.list.model;
|
||||||
|
|
||||||
|
import android.support.v7.widget.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
public class HabitCardViewHolder extends RecyclerView.ViewHolder
|
||||||
|
{
|
||||||
|
public HabitCardViewHolder(View itemView)
|
||||||
|
{
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,22 +19,18 @@
|
|||||||
|
|
||||||
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.support.v7.widget.helper.*;
|
||||||
import android.view.View;
|
import android.util.*;
|
||||||
import android.widget.ListAdapter;
|
import android.view.*;
|
||||||
|
|
||||||
import com.mobeta.android.dslv.DragSortController;
|
import org.isoron.uhabits.models.*;
|
||||||
import com.mobeta.android.dslv.DragSortListView;
|
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.models.Habit;
|
public class HabitCardListView extends RecyclerView
|
||||||
import org.isoron.uhabits.ui.habits.list.controllers.CheckmarkButtonController;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.controllers.HabitCardController;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListAdapter;
|
|
||||||
|
|
||||||
public class HabitCardListView extends DragSortListView
|
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
private HabitCardListAdapter adapter;
|
private HabitCardListAdapter adapter;
|
||||||
@@ -45,9 +41,12 @@ 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());
|
|
||||||
setDragEnabled(true);
|
|
||||||
setLongClickable(true);
|
setLongClickable(true);
|
||||||
|
setHasFixedSize(true);
|
||||||
|
setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
||||||
|
TouchHelperCallback callback = new TouchHelperCallback();
|
||||||
|
new ItemTouchHelper(callback).attachToRecyclerView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,16 +60,16 @@ public class HabitCardListView extends DragSortListView
|
|||||||
* @param checkmarks the list of checkmark values to be included in the
|
* @param checkmarks the list of checkmark values to be included in the
|
||||||
* card
|
* card
|
||||||
* @param selected true if the card is selected, false otherwise
|
* @param selected true if the card is selected, false otherwise
|
||||||
|
* @param position
|
||||||
* @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,
|
||||||
|
int position)
|
||||||
{
|
{
|
||||||
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);
|
||||||
@@ -82,13 +81,24 @@ public class HabitCardListView extends DragSortListView
|
|||||||
cardController.setListener(controller);
|
cardController.setListener(controller);
|
||||||
cardView.setController(cardController);
|
cardView.setController(cardController);
|
||||||
cardController.setView(cardView);
|
cardController.setView(cardView);
|
||||||
|
|
||||||
|
cardView.setOnClickListener(v -> controller.onItemClick(position));
|
||||||
|
cardView.setOnLongClickListener(v -> {
|
||||||
|
controller.onItemLongClick(position);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +107,6 @@ 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);
|
|
||||||
setDragListener(controller);
|
|
||||||
setOnItemClickListener(null);
|
|
||||||
setOnLongClickListener(null);
|
|
||||||
|
|
||||||
if (controller == null) return;
|
|
||||||
|
|
||||||
setOnItemClickListener((p, v, pos, id) -> controller.onItemClick(pos));
|
|
||||||
setOnItemLongClickListener((p, v, pos, id) -> {
|
|
||||||
controller.onItemLongClick(pos);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -126,33 +124,56 @@ public class HabitCardListView extends DragSortListView
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface Controller extends CheckmarkButtonController.Listener,
|
public interface Controller extends CheckmarkButtonController.Listener,
|
||||||
HabitCardController.Listener,
|
HabitCardController.Listener
|
||||||
DropListener,
|
|
||||||
DragListener
|
|
||||||
{
|
{
|
||||||
|
void drag(int from, int to);
|
||||||
|
|
||||||
|
void drop(int from, int to);
|
||||||
|
|
||||||
void onItemClick(int pos);
|
void onItemClick(int pos);
|
||||||
|
|
||||||
void onItemLongClick(int pos);
|
void onItemLongClick(int pos);
|
||||||
|
|
||||||
|
void startDrag(int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewManager extends DragSortController
|
class TouchHelperCallback extends ItemTouchHelper.Callback
|
||||||
{
|
{
|
||||||
public ViewManager()
|
@Override
|
||||||
|
public int getMovementFlags(RecyclerView recyclerView,
|
||||||
|
ViewHolder viewHolder)
|
||||||
{
|
{
|
||||||
super(HabitCardListView.this);
|
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
||||||
setRemoveEnabled(false);
|
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
||||||
|
return makeMovementFlags(dragFlags, swipeFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateFloatView(int position)
|
public boolean isLongPressDragEnabled()
|
||||||
{
|
{
|
||||||
if (adapter == null) return null;
|
return true;
|
||||||
return adapter.getView(position, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyFloatView(View floatView)
|
public boolean isItemViewSwipeEnabled()
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMove(RecyclerView recyclerView,
|
||||||
|
ViewHolder from,
|
||||||
|
ViewHolder to)
|
||||||
|
{
|
||||||
|
if (controller == null) return false;
|
||||||
|
controller.drop(from.getAdapterPosition(), to.getAdapterPosition());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwiped(ViewHolder viewHolder, int direction)
|
||||||
|
{
|
||||||
|
// NOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ public class HabitCardView extends FrameLayout
|
|||||||
checkmarkPanel.setController(null);
|
checkmarkPanel.setController(null);
|
||||||
if (controller == null) return;
|
if (controller == null) return;
|
||||||
|
|
||||||
|
setOnClickListener(v -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
checkmarkPanel.setController(controller);
|
checkmarkPanel.setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,6 @@
|
|||||||
android:divider="?windowBackgroundColor"
|
android:divider="?windowBackgroundColor"
|
||||||
android:dividerHeight="1dp"
|
android:dividerHeight="1dp"
|
||||||
android:listSelector="@android:color/transparent"
|
android:listSelector="@android:color/transparent"
|
||||||
app:drag_start_mode="onLongPress"
|
|
||||||
app:sort_enabled="true"
|
|
||||||
app:track_drag_sort="false"
|
|
||||||
android:layout_below="@id/header"/>
|
android:layout_below="@id/header"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class HabitCardListControllerTest extends BaseUnitTest
|
|||||||
|
|
||||||
resetMocks();
|
resetMocks();
|
||||||
|
|
||||||
this.controller = new HabitCardListController(adapter, view);
|
this.controller = new HabitCardListController(adapter);
|
||||||
controller.setHabitListener(habitListener);
|
controller.setHabitListener(habitListener);
|
||||||
controller.setSelectionListener(selectionListener);
|
controller.setSelectionListener(selectionListener);
|
||||||
view.setController(controller);
|
view.setController(controller);
|
||||||
|
|||||||
Submodule libs/drag-sort-listview deleted from 54ca667d4c
@@ -1,2 +1 @@
|
|||||||
include ':app'
|
include ':app'
|
||||||
include ':libs:drag-sort-listview:library'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user