Simplify around sort order
This commit is contained in:
parent
2318afdc70
commit
8d52675560
9 changed files with 45 additions and 36 deletions
|
@ -7,9 +7,9 @@ import org.ligi.passandroid.injections.FixedPassListPassStore;
|
|||
import org.ligi.passandroid.model.BarCode;
|
||||
import org.ligi.passandroid.model.FiledPass;
|
||||
import org.ligi.passandroid.model.PassImpl;
|
||||
import org.ligi.passandroid.model.PassSortOrder;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.Settings;
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -2,8 +2,8 @@ package org.ligi.passandroid.injections;
|
|||
|
||||
import org.ligi.passandroid.model.FiledPass;
|
||||
import org.ligi.passandroid.model.Pass;
|
||||
import org.ligi.passandroid.model.PassSortOrder;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@ import android.content.Context;
|
|||
|
||||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.helper.DirectoryFileFilter;
|
||||
import org.ligi.passandroid.model.comparator.PassByTimeComparator;
|
||||
import org.ligi.passandroid.model.comparator.PassByTypeFirstAndTimeSecondComparator;
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
import org.ligi.passandroid.reader.AppleStylePassReader;
|
||||
import org.ligi.passandroid.reader.PassReader;
|
||||
import org.ligi.tracedroid.logging.Log;
|
||||
|
@ -127,16 +126,7 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
|
||||
@Override
|
||||
public void sort(final PassSortOrder order) {
|
||||
switch (order) {
|
||||
case TYPE:
|
||||
Collections.sort(passList, new PassByTypeFirstAndTimeSecondComparator());
|
||||
break;
|
||||
|
||||
case DATE:
|
||||
Collections.sort(passList, new PassByTimeComparator());
|
||||
break;
|
||||
}
|
||||
|
||||
Collections.sort(passList, order.toComparator());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package org.ligi.passandroid.model;
|
||||
|
||||
public enum PassSortOrder {
|
||||
DATE(0),
|
||||
TYPE(1);
|
||||
|
||||
private final int i;
|
||||
|
||||
PassSortOrder(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,17 @@ package org.ligi.passandroid.model;
|
|||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PassStore {
|
||||
|
||||
boolean deletePassWithId(String id);
|
||||
|
||||
String getPathForID(String id);
|
||||
|
||||
|
||||
List<FiledPass> getPassList();
|
||||
|
||||
void preCachePassesList();
|
||||
|
@ -16,6 +23,7 @@ public interface PassStore {
|
|||
|
||||
Pass getPassbookForId(String id);
|
||||
|
||||
|
||||
void sort(PassSortOrder order);
|
||||
|
||||
@Nullable
|
||||
|
@ -23,7 +31,4 @@ public interface PassStore {
|
|||
|
||||
void setCurrentPass(@Nullable Pass pass);
|
||||
|
||||
boolean deletePassWithId(String id);
|
||||
|
||||
String getPathForID(String id);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.content.SharedPreferences;
|
|||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
|
||||
public class Settings {
|
||||
public static final String ORDER_KEY = "order";
|
||||
public final Context context;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.ligi.passandroid.model.comparator;
|
||||
|
||||
import org.ligi.passandroid.model.AndroidFileSystemPassStore;
|
||||
import org.ligi.passandroid.model.Pass;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.ligi.passandroid.model.comparator;
|
||||
|
||||
import org.ligi.passandroid.model.Pass;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public enum PassSortOrder {
|
||||
DATE(0),
|
||||
TYPE(1);
|
||||
|
||||
private final int i;
|
||||
|
||||
PassSortOrder(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public Comparator<Pass> toComparator() {
|
||||
switch (this) {
|
||||
case TYPE:
|
||||
return new PassByTypeFirstAndTimeSecondComparator();
|
||||
default:
|
||||
case DATE:
|
||||
return new PassByTimeComparator();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,9 +25,9 @@ import org.ligi.passandroid.events.TypeFocusEvent;
|
|||
import org.ligi.passandroid.helper.CategoryHelper;
|
||||
import org.ligi.passandroid.helper.PassTypeCounter;
|
||||
import org.ligi.passandroid.model.CountedType;
|
||||
import org.ligi.passandroid.model.PassSortOrder;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.Settings;
|
||||
import org.ligi.passandroid.model.comparator.PassSortOrder;
|
||||
import org.ligi.passandroid.ui.views.CategoryIndicatorView;
|
||||
import org.ligi.tracedroid.logging.Log;
|
||||
|
||||
|
|
Loading…
Reference in a new issue