Compare commits

...

14 commits

Author SHA1 Message Date
ligi
3d2083be87 Remove flakyness from test 2016-01-04 16:11:17 +01:00
ligi
667addef93 Bump gradle to 2.10 2016-01-04 13:59:34 +01:00
ligi
df5af83d9d Use mockito 2.0.26 2016-01-04 13:51:28 +01:00
ligi
f483b6453f Use okhttp 2.7.1 2016-01-04 13:50:49 +01:00
ligi
04e7cd269d Use spoon 1.3.0 2016-01-04 13:49:03 +01:00
ligi
8ed1e4da7f Cleanup 2016-01-04 13:46:53 +01:00
ligi
632d1587fa Use spacing better fitting material design 2016-01-04 03:38:37 +01:00
ligi
fd239c5a6f Use AXT here 2016-01-04 03:35:28 +01:00
ligi
31c845c3f4 Simplify 2016-01-04 03:34:17 +01:00
ligi
560c09ca3d Remove unused layout 2016-01-04 02:11:22 +01:00
ligi
42d3f9ddc3 Extract CountedType and PassSortOrder 2016-01-02 22:21:40 +01:00
ligi
c441fe19e3 Use a TreeSet here to Sort while inserting 2016-01-02 22:21:33 +01:00
ligi
c906ea934c Pass -> FiledPass 2016-01-02 22:20:59 +01:00
ligi
89be3573e2 Move paths to settings-module 2016-01-02 22:14:11 +01:00
22 changed files with 123 additions and 117 deletions

View file

@ -111,14 +111,12 @@ dependencies {
exclude module: 'recyclerview-v7'
}
androidTestCompile 'com.squareup.spoon:spoon-client:1.2.1'
androidTestCompile 'com.squareup.spoon:spoon-client:1.3.0'
androidTestCompile 'com.squareup.assertj:assertj-android:1.1.1'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
// The Apache Softwjsrare License, Version 2.0
compile 'net.lingala.zip4j:zip4j:1.3.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'net.danlew:android.joda:2.9.1'
@ -136,7 +134,7 @@ dependencies {
compile 'org.ligi:AXT:0.35'
compile 'org.ligi:tracedroid:1.4'
compile 'org.ligi:snackengage:0.4'
compile 'com.squareup.okhttp:okhttp:2.7.0'
compile 'com.squareup.okhttp:okhttp:2.7.1'
compile 'com.larswerkman:HoloColorPicker:1.5'
compile 'com.google.code.findbugs:jsr305:3.0.1'
@ -150,7 +148,7 @@ dependencies {
testCompile 'com.squareup.assertj:assertj-android:1.1.1'
testCompile 'com.android.support:support-annotations:23.1.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.31-beta'
testCompile 'org.mockito:mockito-core:2.0.36-beta'
// cannot use this new version: https://github.com/zxing/zxing/issues/165
// WARNING: might work on some devices or the emulator - but fails on others

View file

@ -7,6 +7,7 @@ import org.ligi.passandroid.injections.FixedPassListPassStore;
import org.ligi.passandroid.model.BarCode;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassImpl;
import org.ligi.passandroid.model.PassSortOrder;
import org.ligi.passandroid.model.PassStore;
import org.ligi.passandroid.model.Settings;
@ -53,7 +54,7 @@ public class TestModule {
@Provides
Settings provideSettings() {
final Settings mock = mock(Settings.class);
when(mock.getSortOrder()).thenReturn(PassStore.SortOrder.DATE);
when(mock.getSortOrder()).thenReturn(PassSortOrder.DATE);
when(mock.doTraceDroidEmailSend()).thenReturn(false);
return mock;
}

View file

@ -16,6 +16,8 @@ public class ThePastLocationsStore extends BaseIntegration<Activity> {
@Inject
Tracker tracker;
private SharedPreferences sharedPreferences;
public ThePastLocationsStore() {
super(Activity.class);
}
@ -23,22 +25,20 @@ public class ThePastLocationsStore extends BaseIntegration<Activity> {
@Override
public void setUp() throws Exception {
super.setUp();
App.setComponent(DaggerTestComponent.builder().testModule(new TestModule()).build());
sharedPreferences = getInstrumentation().getContext().getSharedPreferences("" + (System.currentTimeMillis() / 100000), Context.MODE_PRIVATE);
((TestComponent) App.component()).inject(this);
}
@Override
protected void tearDown() throws Exception {
sharedPreferences.edit().clear().apply();
super.tearDown();
getSharedPrefs().edit().clear();
}
private SharedPreferences getSharedPrefs() {
return getInstrumentation().getContext().getSharedPreferences("" + (System.currentTimeMillis() / 100000), Context.MODE_PRIVATE);
}
@SmallTest
public void testPastLocationsStoreShouldNeverContainMoreThanMaxElements() {
PastLocationsStore tested = new PastLocationsStore(getSharedPrefs(), tracker);
PastLocationsStore tested = new PastLocationsStore(sharedPreferences, tracker);
for (int i = 0; i < PastLocationsStore.MAX_ELEMENTS * 2; i++) {
tested.putLocation("" + i);
@ -50,7 +50,7 @@ public class ThePastLocationsStore extends BaseIntegration<Activity> {
@SmallTest
public void testPastLocationsStoreShouldStoreOnlyOneOfAKind() {
PastLocationsStore tested = new PastLocationsStore(getSharedPrefs(), tracker);
PastLocationsStore tested = new PastLocationsStore(sharedPreferences, tracker);
for (int i = 0; i < 3; i++) {
tested.putLocation("foo");

View file

@ -1,10 +1,13 @@
package org.ligi.passandroid.injections;
import org.ligi.passandroid.model.CountedType;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassSortOrder;
import org.ligi.passandroid.model.PassStore;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class FixedPassListPassStore implements PassStore {
@ -51,12 +54,12 @@ public class FixedPassListPassStore implements PassStore {
}
@Override
public void sort(SortOrder order) {
public void sort(PassSortOrder order) {
}
@Override
public List<CountedType> getCountedTypes() {
return new ArrayList<>();
public Set<CountedType> getCountedTypes() {
return new TreeSet<>();
}
@Override

View file

@ -1,8 +1,6 @@
package org.ligi.passandroid;
import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.support.annotation.VisibleForTesting;
import com.squareup.leakcanary.LeakCanary;
@ -35,14 +33,6 @@ public class App extends Application {
Log.setTAG("PassAndroid");
}
public static String getPassesDir(final Context ctx) {
return ctx.getFilesDir().getAbsolutePath() + "/passes";
}
public static String getShareDir() {
return Environment.getExternalStorageDirectory() + "/tmp/passbook_share_tmp/";
}
public static AppComponent component() {
return component;
}

View file

@ -1,6 +1,7 @@
package org.ligi.passandroid;
import org.ligi.passandroid.model.PassStore;
import org.ligi.passandroid.model.Settings;
import org.ligi.passandroid.ui.NavigationFragment;
import org.ligi.passandroid.ui.PassAdapter;
import org.ligi.passandroid.ui.PassAndroidActivity;
@ -56,4 +57,5 @@ public interface AppComponent {
Tracker tracker();
Settings settings();
}

View file

@ -26,8 +26,8 @@ public class AppModule {
@Singleton
@Provides
PassStore providePassStore() {
return new AndroidFileSystemPassStore(app);
PassStore providePassStore(Settings settings) {
return new AndroidFileSystemPassStore(app, settings);
}
@Singleton

View file

@ -3,7 +3,6 @@ package org.ligi.passandroid.model;
import android.content.Context;
import org.ligi.axt.AXT;
import org.ligi.passandroid.App;
import org.ligi.passandroid.helper.DirectoryFileFilter;
import org.ligi.passandroid.model.comparator.PassByTimeComparator;
import org.ligi.passandroid.model.comparator.PassByTypeFirstAndTimeSecondComparator;
@ -18,17 +17,21 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class AndroidFileSystemPassStore implements PassStore {
private final Context context;
private String path;
private final String path;
private List<FiledPass> passList = new ArrayList<>();
private Pass actPass;
public AndroidFileSystemPassStore(Context context) {
public AndroidFileSystemPassStore(final Context context,final Settings settings) {
this.context = context;
path = settings.getPassesDir();
refreshPassesList();
}
@ -50,13 +53,12 @@ public class AndroidFileSystemPassStore implements PassStore {
@Override
public void refreshPassesList() {
path = App.getPassesDir(context);
final List<String> newIds = Arrays.asList(getPassIDArray());
final List<String> oldIds = new ArrayList<>();
final List<Pass> toRemove = new ArrayList<>();
final List<FiledPass> toRemove = new ArrayList<>();
for (Pass pass : passList) {
for (FiledPass pass : passList) {
oldIds.add(pass.getId());
if (!newIds.contains(pass.getId())) {
toRemove.add(pass);
@ -102,7 +104,7 @@ public class AndroidFileSystemPassStore implements PassStore {
}
private File getPassesDirSafely() {
final File passes_dir = new File(App.getPassesDir(context));
final File passes_dir = new File(path);
if (!passes_dir.exists()) {
passes_dir.mkdirs();
@ -133,7 +135,7 @@ public class AndroidFileSystemPassStore implements PassStore {
}
@Override
public void sort(final SortOrder order) {
public void sort(final PassSortOrder order) {
switch (order) {
case TYPE:
Collections.sort(passList, new PassByTypeFirstAndTimeSecondComparator());
@ -147,7 +149,7 @@ public class AndroidFileSystemPassStore implements PassStore {
}
@Override
public List<CountedType> getCountedTypes() {
public Set<CountedType> getCountedTypes() {
// TODO - some sort of caching
final Map<String, Integer> tempMap = new HashMap<>();
@ -160,14 +162,12 @@ public class AndroidFileSystemPassStore implements PassStore {
}
}
final List<CountedType> result = new ArrayList<>();
final Set<CountedType> result = new TreeSet<>();
for (String type : tempMap.keySet()) {
result.add(new CountedType(type, tempMap.get(type)));
}
Collections.sort(result);
return result;
}

View file

@ -0,0 +1,18 @@
package org.ligi.passandroid.model;
import android.support.annotation.NonNull;
public class CountedType implements Comparable<CountedType> {
public final String type;
public final Integer count;
public CountedType(String type, Integer count) {
this.type = type;
this.count = count;
}
@Override
public int compareTo(@NonNull CountedType another) {
return another.count - count;
}
}

View file

@ -0,0 +1,17 @@
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;
}
}

View file

@ -1,42 +1,11 @@
package org.ligi.passandroid.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
import java.util.Set;
public interface PassStore {
enum SortOrder {
DATE(0),
TYPE(1);
private final int i;
SortOrder(int i) {
this.i = i;
}
public int getInt() {
return i;
}
}
class CountedType implements Comparable<CountedType> {
public final String type;
public final Integer count;
public CountedType(String type, Integer count) {
this.type = type;
this.count = count;
}
@Override
public int compareTo(@NonNull CountedType another) {
return another.count - count;
}
}
void preCachePassesList();
void deleteCacheForId(String id);
@ -49,9 +18,9 @@ public interface PassStore {
Pass getPassbookForId(String id);
void sort(SortOrder order);
void sort(PassSortOrder order);
List<CountedType> getCountedTypes();
Set<CountedType> getCountedTypes();
@Nullable
Pass getCurrentPass();

View file

@ -2,6 +2,7 @@ package org.ligi.passandroid.model;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.preference.PreferenceManager;
public class Settings {
@ -15,22 +16,31 @@ public class Settings {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
public void setSortOrder(PassStore.SortOrder order) {
public void setSortOrder(PassSortOrder order) {
sharedPreferences.edit().putInt(ORDER_KEY, order.getInt()).apply();
}
public PassStore.SortOrder getSortOrder() {
public PassSortOrder getSortOrder() {
int id = sharedPreferences.getInt(ORDER_KEY, 0);
for (PassStore.SortOrder order : PassStore.SortOrder.values()) {
for (PassSortOrder order : PassSortOrder.values()) {
if (order.getInt() == id) {
return order;
}
}
return PassStore.SortOrder.DATE;
return PassSortOrder.DATE;
}
public boolean doTraceDroidEmailSend() {
// will be overridden in test-module
return true;
}
public String getPassesDir() {
return context.getFilesDir().getAbsolutePath() + "/passes";
}
public String getShareDir() {
return Environment.getExternalStorageDirectory() + "/tmp/passbook_share_tmp/";
}
}

View file

@ -11,13 +11,10 @@ import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import java.util.List;
import org.ligi.axt.AXT;
import org.ligi.axt.listeners.RepeatedOnClicksListener;
import org.ligi.passandroid.App;
@ -26,13 +23,21 @@ import org.ligi.passandroid.events.NavigationOpenedEvent;
import org.ligi.passandroid.events.SortOrderChangeEvent;
import org.ligi.passandroid.events.TypeFocusEvent;
import org.ligi.passandroid.helper.CategoryHelper;
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.ui.views.CategoryIndicatorView;
import org.ligi.tracedroid.logging.Log;
import java.util.Set;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
@ -87,9 +92,9 @@ public class NavigationFragment extends Fragment {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (dateRadioButton.isChecked()) {
settings.setSortOrder(PassStore.SortOrder.DATE);
settings.setSortOrder(PassSortOrder.DATE);
} else if (categoryRadioButton.isChecked()) {
settings.setSortOrder(PassStore.SortOrder.TYPE);
settings.setSortOrder(PassSortOrder.TYPE);
}
setCategoryNavVisibilityByCurrentConditions();
bus.post(new SortOrderChangeEvent());
@ -133,7 +138,7 @@ public class NavigationFragment extends Fragment {
}
private boolean shouldDisplayCategoryNav() {
return shouldDisplaySort() && settings.getSortOrder() == PassStore.SortOrder.TYPE;
return shouldDisplaySort() && settings.getSortOrder() == PassSortOrder.TYPE;
}
private boolean shouldDisplaySort() {
@ -149,13 +154,13 @@ public class NavigationFragment extends Fragment {
private void createCategoryJumpMarks(LayoutInflater inflater) {
final List<PassStore.CountedType> countedTypes = passStore.getCountedTypes();
final Set<CountedType> countedTypes = passStore.getCountedTypes();
setCategoryNavVisibilityByCurrentConditions();
categoriesContainer.removeAllViews();
for (PassStore.CountedType countedType : countedTypes) {
for (CountedType countedType : countedTypes) {
final String type = countedType.type;
final View item = inflater.inflate(R.layout.item_nav_pass_category, categoriesContainer, false);

View file

@ -185,7 +185,7 @@ public class PassListActivity extends PassAndroidActivity {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
passAdapter = new PassAdapter(PassListActivity.this);
passAdapter = new PassAdapter(this);
recyclerView.setAdapter(passAdapter);
}
@ -208,8 +208,7 @@ public class PassListActivity extends PassAndroidActivity {
switch (item.getItemId()) {
case R.id.menu_help:
Intent intent = new Intent(this, HelpActivity.class);
startActivity(intent);
AXT.at(this).startCommonIntent().activityFromClass(HelpActivity.class);
return true;
}

View file

@ -15,6 +15,7 @@ import org.ligi.passandroid.Tracker;
import org.ligi.passandroid.maps.PassbookMapsFacade;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassStore;
import org.ligi.passandroid.model.Settings;
import java.io.File;
@ -28,6 +29,9 @@ public class PassMenuOptions {
@Inject
Tracker tracker;
@Inject
Settings settings;
public final Activity activity;
public final Pass pass;
@ -85,12 +89,12 @@ public class PassMenuOptions {
case R.id.menu_share:
tracker.trackEvent("ui_action", "share", "shared", null);
new AlertDialog.Builder(activity).setItems(new CharSequence[]{"OpenPass ( no Apple support yet)", "Passbook"},
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
exportInFormat(which);
}
}).show();
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
exportInFormat(which);
}
}).show();
return true;
@ -105,7 +109,7 @@ public class PassMenuOptions {
private void exportInFormat(final int which) {
final int passFormat = getPassFormat(which);
new PassExportTask(activity, pass.getPath(), App.getShareDir(), "share", true, passFormat).execute();
new PassExportTask(activity, pass.getPath(), settings.getShareDir(), "share", true, passFormat).execute();
}
@PassExporter.PassFormat

View file

@ -15,7 +15,6 @@ import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import org.ligi.passandroid.App;
import org.ligi.passandroid.R;
import org.ligi.passandroid.helper.PassUtil;
import org.ligi.passandroid.model.InputStreamWithSource;
@ -111,7 +110,7 @@ public class PassViewActivityBase extends PassAndroidActivity {
public void onClick(DialogInterface dialog, int which) {
new ExportProblemPassToLigiAndFinishTask(PassViewActivityBase.this,
pass.getId(),
App.getShareDir(),
settings.getShareDir(),
"share",
reason).execute();
}

View file

@ -115,7 +115,7 @@ public class UnzipPassController {
}
public UnzipControllerSpec(Context context, SuccessCallback onSuccessCallback, FailCallback failCallback) {
this(App.getPassesDir(context), context, onSuccessCallback, failCallback);
this(App.component().settings().getPassesDir(), context, onSuccessCallback, failCallback);
}

View file

@ -7,5 +7,5 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/help_tv"
android:padding="7dp" />
android:padding="16dp" />
</ScrollView>

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>

Binary file not shown.

View file

@ -1,6 +1,6 @@
#Thu Nov 27 18:33:47 CET 2014
#Mon Jan 04 13:57:01 CET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip

10
gradlew vendored
View file

@ -42,11 +42,6 @@ case "`uname`" in
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`