rename order to primaryOrder and previousOrder to secondaryOrder

pull/660/head
Quentin Hibon 5 years ago
parent 0197fb86d3
commit 35f43534bc

@ -21,7 +21,7 @@ package org.isoron.uhabits.activities.habits.list.views;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.*;
import android.view.*; import android.view.*;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -83,8 +83,8 @@ public class HabitCardListAdapter
cache.setListener(this); cache.setListener(this);
cache.setCheckmarkCount( cache.setCheckmarkCount(
ListHabitsRootViewKt.MAX_CHECKMARK_COUNT); ListHabitsRootViewKt.MAX_CHECKMARK_COUNT);
cache.setPreviousOrder(preferences.getDefaultPreviousOrder()); cache.setSecondaryOrder(preferences.getDefaultSecondaryOrder());
cache.setOrder(preferences.getDefaultOrder()); cache.setPrimaryOrder(preferences.getDefaultPrimaryOrder());
setHasStableIds(true); setHasStableIds(true);
} }
@ -161,7 +161,7 @@ public class HabitCardListAdapter
public boolean isSortable() public boolean isSortable()
{ {
return cache.getOrder() == HabitList.Order.BY_POSITION; return cache.getPrimaryOrder() == HabitList.Order.BY_POSITION;
} }
/** /**
@ -314,22 +314,22 @@ public class HabitCardListAdapter
} }
@Override @Override
public void setOrder(HabitList.Order order) public void setPrimaryOrder(HabitList.Order order)
{ {
cache.setOrder(order); cache.setPrimaryOrder(order);
preferences.setDefaultOrder(order); preferences.setDefaultPrimaryOrder(order);
} }
@Override @Override
public void setPreviousOrder(HabitList.Order order) { public void setSecondaryOrder(HabitList.Order order) {
cache.setPreviousOrder(order); cache.setSecondaryOrder(order);
preferences.setDefaultPreviousOrder(order); preferences.setDefaultSecondaryOrder(order);
} }
@Override @Override
public HabitList.Order getOrder() public HabitList.Order getPrimaryOrder()
{ {
return cache.getOrder(); return cache.getPrimaryOrder();
} }
/** /**

@ -107,23 +107,23 @@ public abstract class HabitList implements Iterable<Habit>
return observable; return observable;
} }
public abstract Order getOrder(); public abstract Order getPrimaryOrder();
public abstract Order getPreviousOrder(); public abstract Order getSecondaryOrder();
/** /**
* Changes the order of the elements on the list. * Changes the order of the elements on the list.
* *
* @param order the new order criterion * @param order the new order criterion
*/ */
public abstract void setOrder(@NonNull Order order); public abstract void setPrimaryOrder(@NonNull Order order);
/** /**
* Changes the previous order of the elements on the list. * Changes the previous order of the elements on the list.
* *
* @param order the new order criterion * @param order the new order criterion
*/ */
public abstract void setPreviousOrder(@NonNull Order order); public abstract void setSecondaryOrder(@NonNull Order order);
/** /**
* Returns the index of the given habit in the list, or -1 if the list does * Returns the index of the given habit in the list, or -1 if the list does

@ -36,12 +36,12 @@ public class MemoryHabitList extends HabitList
private LinkedList<Habit> list = new LinkedList<>(); private LinkedList<Habit> list = new LinkedList<>();
@NonNull @NonNull
private Order order = Order.BY_POSITION; private Order primaryOrder = Order.BY_POSITION;
@NonNull @NonNull
private Order previousOrder = Order.BY_NAME_ASC; private Order secondaryOrder = Order.BY_NAME_ASC;
private Comparator<Habit> comparator = getComposedComparatorByOrder(order, previousOrder); private Comparator<Habit> comparator = getComposedComparatorByOrder(primaryOrder, secondaryOrder);
@Nullable @Nullable
private MemoryHabitList parent = null; private MemoryHabitList parent = null;
@ -58,8 +58,8 @@ public class MemoryHabitList extends HabitList
super(matcher); super(matcher);
this.parent = parent; this.parent = parent;
this.comparator = comparator; this.comparator = comparator;
this.order = parent.order; this.primaryOrder = parent.primaryOrder;
this.previousOrder = parent.previousOrder; this.secondaryOrder = parent.secondaryOrder;
parent.getObservable().addListener(this::loadFromParent); parent.getObservable().addListener(this::loadFromParent);
loadFromParent(); loadFromParent();
} }
@ -109,31 +109,31 @@ public class MemoryHabitList extends HabitList
} }
@Override @Override
public synchronized Order getOrder() public synchronized Order getPrimaryOrder()
{ {
return order; return primaryOrder;
} }
@Override @Override
public synchronized Order getPreviousOrder() public synchronized Order getSecondaryOrder()
{ {
return previousOrder; return secondaryOrder;
} }
@Override @Override
public synchronized void setOrder(@NonNull Order order) public synchronized void setPrimaryOrder(@NonNull Order order)
{ {
this.order = order; this.primaryOrder = order;
this.comparator = getComposedComparatorByOrder(this.order, this.previousOrder); this.comparator = getComposedComparatorByOrder(this.primaryOrder, this.secondaryOrder);
resort(); resort();
getObservable().notifyListeners(); getObservable().notifyListeners();
} }
@Override @Override
public void setPreviousOrder(@NonNull Order order) public void setSecondaryOrder(@NonNull Order order)
{ {
this.previousOrder = order; this.secondaryOrder = order;
this.comparator = getComposedComparatorByOrder(this.order, this.previousOrder); this.comparator = getComposedComparatorByOrder(this.primaryOrder, this.secondaryOrder);
resort(); resort();
getObservable().notifyListeners(); getObservable().notifyListeners();
} }
@ -228,7 +228,7 @@ public class MemoryHabitList extends HabitList
public synchronized void reorder(@NonNull Habit from, @NonNull Habit to) public synchronized void reorder(@NonNull Habit from, @NonNull Habit to)
{ {
throwIfHasParent(); throwIfHasParent();
if (order != BY_POSITION) throw new IllegalStateException( if (primaryOrder != BY_POSITION) throw new IllegalStateException(
"cannot reorder automatically sorted list"); "cannot reorder automatically sorted list");
if (indexOf(from) < 0) throw new IllegalArgumentException( if (indexOf(from) < 0) throw new IllegalArgumentException(

@ -116,28 +116,28 @@ public class SQLiteHabitList extends HabitList
@Override @Override
@NonNull @NonNull
public Order getOrder() public Order getPrimaryOrder()
{ {
return list.getOrder(); return list.getPrimaryOrder();
} }
@Override @Override
public Order getPreviousOrder() public Order getSecondaryOrder()
{ {
return list.getPreviousOrder(); return list.getSecondaryOrder();
} }
@Override @Override
public synchronized void setOrder(@NonNull Order order) public synchronized void setPrimaryOrder(@NonNull Order order)
{ {
list.setOrder(order); list.setPrimaryOrder(order);
getObservable().notifyListeners(); getObservable().notifyListeners();
} }
@Override @Override
public synchronized void setPreviousOrder(@NonNull Order order) public synchronized void setSecondaryOrder(@NonNull Order order)
{ {
list.setPreviousOrder(order); list.setSecondaryOrder(order);
getObservable().notifyListeners(); getObservable().notifyListeners();
} }

@ -60,7 +60,7 @@ public class Preferences
fallbackColor); fallbackColor);
} }
public HabitList.Order getDefaultOrder() public HabitList.Order getDefaultPrimaryOrder()
{ {
String name = storage.getString("pref_default_order", "BY_POSITION"); String name = storage.getString("pref_default_order", "BY_POSITION");
@ -70,13 +70,13 @@ public class Preferences
} }
catch (IllegalArgumentException e) catch (IllegalArgumentException e)
{ {
setDefaultOrder(HabitList.Order.BY_POSITION); setDefaultPrimaryOrder(HabitList.Order.BY_POSITION);
return HabitList.Order.BY_POSITION; return HabitList.Order.BY_POSITION;
} }
} }
public HabitList.Order getDefaultPreviousOrder() { public HabitList.Order getDefaultSecondaryOrder() {
String name = storage.getString("pref_default_previous_order", "BY_NAME_ASC"); String name = storage.getString("pref_default_secondary_order", "BY_NAME_ASC");
try try
{ {
@ -84,19 +84,19 @@ public class Preferences
} }
catch (IllegalArgumentException e) catch (IllegalArgumentException e)
{ {
setDefaultPreviousOrder(HabitList.Order.BY_NAME_ASC); setDefaultSecondaryOrder(HabitList.Order.BY_NAME_ASC);
return HabitList.Order.BY_POSITION; return HabitList.Order.BY_POSITION;
} }
} }
public void setDefaultOrder(HabitList.Order order) public void setDefaultPrimaryOrder(HabitList.Order order)
{ {
storage.putString("pref_default_order", order.name()); storage.putString("pref_default_order", order.name());
} }
public void setDefaultPreviousOrder(HabitList.Order order) public void setDefaultSecondaryOrder(HabitList.Order order)
{ {
storage.putString("pref_default_previous_order", order.name()); storage.putString("pref_default_secondary_order", order.name());
} }
public int getDefaultScoreSpinnerPosition() public int getDefaultScoreSpinnerPosition()

@ -116,14 +116,14 @@ public class HabitCardListCache implements CommandRunner.Listener
return data.habits.size(); return data.habits.size();
} }
public synchronized HabitList.Order getOrder() public synchronized HabitList.Order getPrimaryOrder()
{ {
return filteredHabits.getOrder(); return filteredHabits.getPrimaryOrder();
} }
public synchronized HabitList.Order getPreviousOrder() public synchronized HabitList.Order getSecondaryOrder()
{ {
return filteredHabits.getPreviousOrder(); return filteredHabits.getSecondaryOrder();
} }
public synchronized double getScore(long habitId) public synchronized double getScore(long habitId)
@ -201,18 +201,18 @@ public class HabitCardListCache implements CommandRunner.Listener
this.listener = listener; this.listener = listener;
} }
public synchronized void setOrder(@NonNull HabitList.Order order) public synchronized void setPrimaryOrder(@NonNull HabitList.Order order)
{ {
if (order == null) throw new NullPointerException(); if (order == null) throw new NullPointerException();
allHabits.setOrder(order); allHabits.setPrimaryOrder(order);
filteredHabits.setOrder(order); filteredHabits.setPrimaryOrder(order);
refreshAllHabits(); refreshAllHabits();
} }
public synchronized void setPreviousOrder(@NonNull HabitList.Order order) public synchronized void setSecondaryOrder(@NonNull HabitList.Order order)
{ {
allHabits.setPreviousOrder(order); allHabits.setSecondaryOrder(order);
filteredHabits.setPreviousOrder(order); filteredHabits.setSecondaryOrder(order);
refreshAllHabits(); refreshAllHabits();
} }

@ -97,7 +97,7 @@ public class ListHabitsMenuBehavior
public void onSortByManually() public void onSortByManually()
{ {
adapter.setOrder(HabitList.Order.BY_POSITION); adapter.setPrimaryOrder(HabitList.Order.BY_POSITION);
} }
public void onSortByColor() public void onSortByColor()
@ -123,13 +123,13 @@ public class ListHabitsMenuBehavior
private void onSortToggleBy(HabitList.Order defaultOrder, HabitList.Order reversedOrder) private void onSortToggleBy(HabitList.Order defaultOrder, HabitList.Order reversedOrder)
{ {
if (adapter.getOrder() != defaultOrder) { if (adapter.getPrimaryOrder() != defaultOrder) {
if (adapter.getOrder() != reversedOrder) { if (adapter.getPrimaryOrder() != reversedOrder) {
adapter.setPreviousOrder(adapter.getOrder()); adapter.setSecondaryOrder(adapter.getPrimaryOrder());
} }
adapter.setOrder(defaultOrder); adapter.setPrimaryOrder(defaultOrder);
} else { } else {
adapter.setOrder(reversedOrder); adapter.setPrimaryOrder(reversedOrder);
} }
} }
@ -155,11 +155,11 @@ public class ListHabitsMenuBehavior
void setFilter(HabitMatcher build); void setFilter(HabitMatcher build);
void setOrder(HabitList.Order order); void setPrimaryOrder(HabitList.Order order);
void setPreviousOrder(HabitList.Order order); void setSecondaryOrder(HabitList.Order order);
HabitList.Order getOrder(); HabitList.Order getPrimaryOrder();
} }
public interface Screen public interface Screen

@ -133,50 +133,50 @@ public class HabitListTest extends BaseUnitTest
HabitList list; HabitList list;
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_POSITION); list.setPrimaryOrder(BY_POSITION);
assertThat(list.getByPosition(0), equalTo(h3)); assertThat(list.getByPosition(0), equalTo(h3));
assertThat(list.getByPosition(1), equalTo(h1)); assertThat(list.getByPosition(1), equalTo(h1));
assertThat(list.getByPosition(2), equalTo(h4)); assertThat(list.getByPosition(2), equalTo(h4));
assertThat(list.getByPosition(3), equalTo(h2)); assertThat(list.getByPosition(3), equalTo(h2));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_NAME_DESC); list.setPrimaryOrder(BY_NAME_DESC);
assertThat(list.getByPosition(0), equalTo(h4)); assertThat(list.getByPosition(0), equalTo(h4));
assertThat(list.getByPosition(1), equalTo(h3)); assertThat(list.getByPosition(1), equalTo(h3));
assertThat(list.getByPosition(2), equalTo(h2)); assertThat(list.getByPosition(2), equalTo(h2));
assertThat(list.getByPosition(3), equalTo(h1)); assertThat(list.getByPosition(3), equalTo(h1));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_NAME_ASC); list.setPrimaryOrder(BY_NAME_ASC);
assertThat(list.getByPosition(0), equalTo(h1)); assertThat(list.getByPosition(0), equalTo(h1));
assertThat(list.getByPosition(1), equalTo(h2)); assertThat(list.getByPosition(1), equalTo(h2));
assertThat(list.getByPosition(2), equalTo(h3)); assertThat(list.getByPosition(2), equalTo(h3));
assertThat(list.getByPosition(3), equalTo(h4)); assertThat(list.getByPosition(3), equalTo(h4));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_NAME_ASC); list.setPrimaryOrder(BY_NAME_ASC);
list.remove(h1); list.remove(h1);
list.add(h1); list.add(h1);
assertThat(list.getByPosition(0), equalTo(h1)); assertThat(list.getByPosition(0), equalTo(h1));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_COLOR_ASC); list.setPrimaryOrder(BY_COLOR_ASC);
list.setPreviousOrder(BY_NAME_ASC); list.setSecondaryOrder(BY_NAME_ASC);
assertThat(list.getByPosition(0), equalTo(h3)); assertThat(list.getByPosition(0), equalTo(h3));
assertThat(list.getByPosition(1), equalTo(h4)); assertThat(list.getByPosition(1), equalTo(h4));
assertThat(list.getByPosition(2), equalTo(h1)); assertThat(list.getByPosition(2), equalTo(h1));
assertThat(list.getByPosition(3), equalTo(h2)); assertThat(list.getByPosition(3), equalTo(h2));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_COLOR_DESC); list.setPrimaryOrder(BY_COLOR_DESC);
list.setPreviousOrder(BY_NAME_ASC); list.setSecondaryOrder(BY_NAME_ASC);
assertThat(list.getByPosition(0), equalTo(h1)); assertThat(list.getByPosition(0), equalTo(h1));
assertThat(list.getByPosition(1), equalTo(h2)); assertThat(list.getByPosition(1), equalTo(h2));
assertThat(list.getByPosition(2), equalTo(h4)); assertThat(list.getByPosition(2), equalTo(h4));
assertThat(list.getByPosition(3), equalTo(h3)); assertThat(list.getByPosition(3), equalTo(h3));
list = testOrderingSetup(h1, h2, h3, h4); list = testOrderingSetup(h1, h2, h3, h4);
list.setOrder(BY_POSITION); list.setPrimaryOrder(BY_POSITION);
assertThat(list.getByPosition(0), equalTo(h3)); assertThat(list.getByPosition(0), equalTo(h3));
assertThat(list.getByPosition(1), equalTo(h1)); assertThat(list.getByPosition(1), equalTo(h1));
assertThat(list.getByPosition(2), equalTo(h4)); assertThat(list.getByPosition(2), equalTo(h4));
@ -241,12 +241,12 @@ public class HabitListTest extends BaseUnitTest
@Test @Test
public void testOrder_inherit() public void testOrder_inherit()
{ {
habitList.setOrder(BY_COLOR_ASC); habitList.setPrimaryOrder(BY_COLOR_ASC);
HabitList filteredList = habitList.getFiltered(new HabitMatcherBuilder() HabitList filteredList = habitList.getFiltered(new HabitMatcherBuilder()
.setArchivedAllowed(false) .setArchivedAllowed(false)
.setCompletedAllowed(false) .setCompletedAllowed(false)
.build()); .build());
assertEquals(filteredList.getOrder(), BY_COLOR_ASC); assertEquals(filteredList.getPrimaryOrder(), BY_COLOR_ASC);
} }
@Test @Test
@ -322,7 +322,7 @@ public class HabitListTest extends BaseUnitTest
@Test @Test
public void testReorder_onSortedList() throws Exception public void testReorder_onSortedList() throws Exception
{ {
habitList.setOrder(BY_SCORE_DESC); habitList.setPrimaryOrder(BY_SCORE_DESC);
Habit h1 = habitsArray.get(1); Habit h1 = habitsArray.get(1);
Habit h2 = habitsArray.get(2); Habit h2 = habitsArray.get(2);
thrown.expect(IllegalStateException.class); thrown.expect(IllegalStateException.class);

@ -75,13 +75,13 @@ public class PreferencesTest extends BaseUnitTest
@Test @Test
public void testDefaultOrder() throws Exception public void testDefaultOrder() throws Exception
{ {
assertThat(prefs.getDefaultOrder(), equalTo(HabitList.Order.BY_POSITION)); assertThat(prefs.getDefaultPrimaryOrder(), equalTo(HabitList.Order.BY_POSITION));
prefs.setDefaultOrder(HabitList.Order.BY_SCORE_DESC); prefs.setDefaultPrimaryOrder(HabitList.Order.BY_SCORE_DESC);
assertThat(prefs.getDefaultOrder(), equalTo(HabitList.Order.BY_SCORE_DESC)); assertThat(prefs.getDefaultPrimaryOrder(), equalTo(HabitList.Order.BY_SCORE_DESC));
storage.putString("pref_default_order", "BOGUS"); storage.putString("pref_default_order", "BOGUS");
assertThat(prefs.getDefaultOrder(), equalTo(HabitList.Order.BY_POSITION)); assertThat(prefs.getDefaultPrimaryOrder(), equalTo(HabitList.Order.BY_POSITION));
assertThat(storage.getString("pref_default_order", ""), equalTo("BY_POSITION")); assertThat(storage.getString("pref_default_order", ""), equalTo("BY_POSITION"));
} }

@ -103,7 +103,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
public void testOnSortByColor() public void testOnSortByColor()
{ {
behavior.onSortByColor(); behavior.onSortByColor();
verify(adapter).setOrder(orderCaptor.capture()); verify(adapter).setPrimaryOrder(orderCaptor.capture());
assertThat(orderCaptor.getValue(), equalTo(BY_COLOR_ASC)); assertThat(orderCaptor.getValue(), equalTo(BY_COLOR_ASC));
} }
@ -111,7 +111,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
public void testOnSortManually() public void testOnSortManually()
{ {
behavior.onSortByManually(); behavior.onSortByManually();
verify(adapter).setOrder(orderCaptor.capture()); verify(adapter).setPrimaryOrder(orderCaptor.capture());
assertThat(orderCaptor.getValue(), equalTo(BY_POSITION)); assertThat(orderCaptor.getValue(), equalTo(BY_POSITION));
} }
@ -119,7 +119,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
public void testOnSortScore() public void testOnSortScore()
{ {
behavior.onSortByScore(); behavior.onSortByScore();
verify(adapter).setOrder(orderCaptor.capture()); verify(adapter).setPrimaryOrder(orderCaptor.capture());
assertThat(orderCaptor.getValue(), equalTo(BY_SCORE_DESC)); assertThat(orderCaptor.getValue(), equalTo(BY_SCORE_DESC));
} }
@ -127,7 +127,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
public void testOnSortName() public void testOnSortName()
{ {
behavior.onSortByName(); behavior.onSortByName();
verify(adapter).setOrder(orderCaptor.capture()); verify(adapter).setPrimaryOrder(orderCaptor.capture());
assertThat(orderCaptor.getValue(), equalTo(BY_NAME_ASC)); assertThat(orderCaptor.getValue(), equalTo(BY_NAME_ASC));
} }
@ -135,7 +135,7 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
public void testOnSortStatus() public void testOnSortStatus()
{ {
behavior.onSortByStatus(); behavior.onSortByStatus();
verify(adapter).setOrder(orderCaptor.capture()); verify(adapter).setPrimaryOrder(orderCaptor.capture());
assertThat(orderCaptor.getValue(), equalTo(BY_STATUS_ASC)); assertThat(orderCaptor.getValue(), equalTo(BY_STATUS_ASC));
} }

Loading…
Cancel
Save