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.Nullable;
import androidx.appcompat.widget.*;
import android.view.*;
import androidx.recyclerview.widget.RecyclerView;
@ -83,8 +83,8 @@ public class HabitCardListAdapter
cache.setListener(this);
cache.setCheckmarkCount(
ListHabitsRootViewKt.MAX_CHECKMARK_COUNT);
cache.setPreviousOrder(preferences.getDefaultPreviousOrder());
cache.setOrder(preferences.getDefaultOrder());
cache.setSecondaryOrder(preferences.getDefaultSecondaryOrder());
cache.setPrimaryOrder(preferences.getDefaultPrimaryOrder());
setHasStableIds(true);
}
@ -161,7 +161,7 @@ public class HabitCardListAdapter
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
public void setOrder(HabitList.Order order)
public void setPrimaryOrder(HabitList.Order order)
{
cache.setOrder(order);
preferences.setDefaultOrder(order);
cache.setPrimaryOrder(order);
preferences.setDefaultPrimaryOrder(order);
}
@Override
public void setPreviousOrder(HabitList.Order order) {
cache.setPreviousOrder(order);
preferences.setDefaultPreviousOrder(order);
public void setSecondaryOrder(HabitList.Order order) {
cache.setSecondaryOrder(order);
preferences.setDefaultSecondaryOrder(order);
}
@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;
}
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.
*
* @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.
*
* @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

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

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

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

@ -116,14 +116,14 @@ public class HabitCardListCache implements CommandRunner.Listener
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)
@ -201,18 +201,18 @@ public class HabitCardListCache implements CommandRunner.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();
allHabits.setOrder(order);
filteredHabits.setOrder(order);
allHabits.setPrimaryOrder(order);
filteredHabits.setPrimaryOrder(order);
refreshAllHabits();
}
public synchronized void setPreviousOrder(@NonNull HabitList.Order order)
public synchronized void setSecondaryOrder(@NonNull HabitList.Order order)
{
allHabits.setPreviousOrder(order);
filteredHabits.setPreviousOrder(order);
allHabits.setSecondaryOrder(order);
filteredHabits.setSecondaryOrder(order);
refreshAllHabits();
}

@ -97,7 +97,7 @@ public class ListHabitsMenuBehavior
public void onSortByManually()
{
adapter.setOrder(HabitList.Order.BY_POSITION);
adapter.setPrimaryOrder(HabitList.Order.BY_POSITION);
}
public void onSortByColor()
@ -123,13 +123,13 @@ public class ListHabitsMenuBehavior
private void onSortToggleBy(HabitList.Order defaultOrder, HabitList.Order reversedOrder)
{
if (adapter.getOrder() != defaultOrder) {
if (adapter.getOrder() != reversedOrder) {
adapter.setPreviousOrder(adapter.getOrder());
if (adapter.getPrimaryOrder() != defaultOrder) {
if (adapter.getPrimaryOrder() != reversedOrder) {
adapter.setSecondaryOrder(adapter.getPrimaryOrder());
}
adapter.setOrder(defaultOrder);
adapter.setPrimaryOrder(defaultOrder);
} else {
adapter.setOrder(reversedOrder);
adapter.setPrimaryOrder(reversedOrder);
}
}
@ -155,11 +155,11 @@ public class ListHabitsMenuBehavior
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

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

@ -75,13 +75,13 @@ public class PreferencesTest extends BaseUnitTest
@Test
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);
assertThat(prefs.getDefaultOrder(), equalTo(HabitList.Order.BY_SCORE_DESC));
prefs.setDefaultPrimaryOrder(HabitList.Order.BY_SCORE_DESC);
assertThat(prefs.getDefaultPrimaryOrder(), equalTo(HabitList.Order.BY_SCORE_DESC));
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"));
}

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

Loading…
Cancel
Save