Ability to sort by date Ascending and Descending
This commit is contained in:
parent
2484bd29b4
commit
b0bdeddfe2
7 changed files with 25 additions and 8 deletions
|
@ -56,7 +56,7 @@ public class TestModule {
|
|||
@Provides
|
||||
Settings provideSettings() {
|
||||
final Settings mock = mock(Settings.class);
|
||||
when(mock.getSortOrder()).thenReturn(PassSortOrder.DATE);
|
||||
when(mock.getSortOrder()).thenReturn(PassSortOrder.DATE_ASC);
|
||||
when(mock.doTraceDroidEmailSend()).thenReturn(false);
|
||||
return mock;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class AndroidSettings implements Settings {
|
|||
return order;
|
||||
}
|
||||
}
|
||||
return PassSortOrder.DATE;
|
||||
return PassSortOrder.DATE_ASC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,16 @@ import java.util.Comparator;
|
|||
|
||||
public class PassByTimeComparator implements Comparator<Pass> {
|
||||
|
||||
public final static int DIRECTION_DESC = 1;
|
||||
public final static int DIRECTION_ASC = -1;
|
||||
|
||||
private final int direction;
|
||||
|
||||
public PassByTimeComparator(int direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(Pass lhs, Pass rhs) {
|
||||
|
||||
|
@ -19,6 +29,6 @@ public class PassByTimeComparator implements Comparator<Pass> {
|
|||
if (rhs.getRelevantDate() == null) {
|
||||
return -1;
|
||||
}
|
||||
return rhs.getRelevantDate().compareTo(lhs.getRelevantDate());
|
||||
return rhs.getRelevantDate().compareTo(lhs.getRelevantDate()) * direction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import org.ligi.passandroid.model.Pass;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
import static org.ligi.passandroid.model.comparator.PassByTimeComparator.DIRECTION_ASC;
|
||||
|
||||
public class PassByTypeFirstAndTimeSecondComparator implements Comparator<Pass> {
|
||||
|
||||
private final PassByTimeComparator passByTimeComparator = new PassByTimeComparator();
|
||||
private final PassByTimeComparator passByTimeComparator = new PassByTimeComparator(DIRECTION_ASC);
|
||||
|
||||
@Override
|
||||
public int compare(Pass lhs, Pass rhs) {
|
||||
|
|
|
@ -5,7 +5,8 @@ import org.ligi.passandroid.model.Pass;
|
|||
import java.util.Comparator;
|
||||
|
||||
public enum PassSortOrder {
|
||||
DATE(0),
|
||||
DATE_DESC(-1),
|
||||
DATE_ASC(0),
|
||||
TYPE(1);
|
||||
|
||||
private final int i;
|
||||
|
@ -22,9 +23,11 @@ public enum PassSortOrder {
|
|||
switch (this) {
|
||||
case TYPE:
|
||||
return new PassByTypeFirstAndTimeSecondComparator();
|
||||
case DATE_DESC:
|
||||
return new PassByTimeComparator(-1);
|
||||
default:
|
||||
case DATE:
|
||||
return new PassByTimeComparator();
|
||||
case DATE_ASC:
|
||||
return new PassByTimeComparator(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="sort_order_keys" >
|
||||
<item>-1</item>
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
|
|
@ -118,7 +118,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
|
|||
<string name="found_pass">found: %s</string>
|
||||
<string name="found__pass">And %d more</string>
|
||||
<string-array name="sort_orders">
|
||||
<item>Date</item>
|
||||
<item>Date Ascending</item>
|
||||
<item>Date Descending</item>
|
||||
<item>Type</item>
|
||||
</string-array>
|
||||
</resources>
|
Loading…
Reference in a new issue