Compare commits

...

17 commits

Author SHA1 Message Date
ligi
40a0ff8888 Toast -> SnackBar 2016-01-05 00:14:04 +01:00
ligi
f098048c58 Remove unused Field 2016-01-05 00:14:04 +01:00
ligi
d23bfdd816 Slim down PassStore 2016-01-05 00:14:04 +01:00
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
29 changed files with 249 additions and 192 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

@ -5,8 +5,9 @@ import com.squareup.otto.Bus;
import org.ligi.passandroid.injections.FixedPassListPassStore;
import org.ligi.passandroid.model.BarCode;
import org.ligi.passandroid.model.Pass;
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;
@ -24,7 +25,7 @@ import static org.mockito.Mockito.when;
@Module
public class TestModule {
private final List<Pass> passList;
private final List<FiledPass> passList;
public TestModule() {
passList = new ArrayList<>();
@ -34,7 +35,7 @@ public class TestModule {
passList.add(object);
}
public TestModule(List<Pass> passList) {
public TestModule(List<FiledPass> passList) {
this.passList = passList;
}
@ -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

@ -4,7 +4,7 @@ import android.test.suitebuilder.annotation.MediumTest;
import com.squareup.spoon.Spoon;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.ui.PassListActivity;
import java.util.ArrayList;
@ -25,7 +25,7 @@ public class TheEmptyPassList extends BaseIntegration<PassListActivity> {
public void setUp() throws Exception {
super.setUp();
App.setComponent(DaggerTestComponent.builder().testModule(new TestModule(new ArrayList<Pass>())).build());
App.setComponent(DaggerTestComponent.builder().testModule(new TestModule(new ArrayList<FiledPass>())).build());
getActivity();
}

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,20 +1,26 @@
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 java.util.ArrayList;
import java.util.List;
public class FixedPassListPassStore implements PassStore {
private final List<Pass> passes;
private final List<FiledPass> passes;
private Pass actPass;
public FixedPassListPassStore(List<Pass> passes) {
public FixedPassListPassStore(List<FiledPass> passes) {
this.passes = passes;
}
@Override
public List<FiledPass> getPassList() {
return passes;
}
@Override
public void preCachePassesList() {
// no effect in this impl
@ -30,16 +36,6 @@ public class FixedPassListPassStore implements PassStore {
// no effect in this impl
}
@Override
public int passCount() {
return passes.size();
}
@Override
public Pass getPassbookAt(int pos) {
return passes.get(pos);
}
@Override
public Pass getPassbookForId(String id) {
for (Pass pass : passes) {
@ -51,12 +47,7 @@ public class FixedPassListPassStore implements PassStore {
}
@Override
public void sort(SortOrder order) {
}
@Override
public List<CountedType> getCountedTypes() {
return new ArrayList<>();
public void sort(PassSortOrder order) {
}
@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

@ -0,0 +1,35 @@
package org.ligi.passandroid.helper;
import org.ligi.passandroid.model.CountedType;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.model.Pass;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class PassTypeCounter {
public static Set<CountedType> count(final List<FiledPass> passList) {
final Map<String, Integer> tempMap = new HashMap<>();
for (Pass info : passList) {
if (tempMap.containsKey(info.getTypeNotNull())) {
final Integer i = tempMap.get(info.getTypeNotNull());
tempMap.put(info.getTypeNotNull(), i + 1);
} else {
tempMap.put(info.getTypeNotNull(), 1);
}
}
final Set<CountedType> result = new TreeSet<>();
for (String type : tempMap.keySet()) {
result.add(new CountedType(type, tempMap.get(type)));
}
return result;
}
}

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;
@ -15,20 +14,20 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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();
}
@ -41,6 +40,11 @@ public class AndroidFileSystemPassStore implements PassStore {
return new File(getPathForID(id) + "/base_cache.obj");
}
@Override
public List<FiledPass> getPassList() {
return passList;
}
@Override
public void preCachePassesList() {
for (String key : getPassIDArray()) {
@ -50,13 +54,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 +105,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();
@ -111,16 +114,6 @@ public class AndroidFileSystemPassStore implements PassStore {
return passes_dir;
}
@Override
public int passCount() {
return passList.size();
}
@Override
public Pass getPassbookAt(final int pos) {
return passList.get(pos);
}
@Override
public Pass getPassbookForId(final String id) {
for (Pass pass : passList) {
@ -133,7 +126,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());
@ -146,31 +139,6 @@ public class AndroidFileSystemPassStore implements PassStore {
}
@Override
public List<CountedType> getCountedTypes() {
// TODO - some sort of caching
final Map<String, Integer> tempMap = new HashMap<>();
for (Pass info : passList) {
if (tempMap.containsKey(info.getTypeNotNull())) {
final Integer i = tempMap.get(info.getTypeNotNull());
tempMap.put(info.getTypeNotNull(), i + 1);
} else {
tempMap.put(info.getTypeNotNull(), 1);
}
}
final List<CountedType> result = new ArrayList<>();
for (String type : tempMap.keySet()) {
result.add(new CountedType(type, tempMap.get(type)));
}
Collections.sort(result);
return result;
}
@Override
public Pass getCurrentPass() {
return actPass;

View file

@ -0,0 +1,29 @@
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;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof CountedType)) {
return false;
}
CountedType other = (CountedType) o;
return type.equals(other.type) && count.equals(other.count);
}
}

View file

@ -1,9 +1,12 @@
package org.ligi.passandroid.model;
import java.io.Serializable;
public interface FiledPass extends Pass,Serializable {
public interface FiledPass extends Pass, Serializable {
String getPath();
void setPath(String Path);
void save(PassStore store);
}

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,41 +1,12 @@
package org.ligi.passandroid.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
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;
}
}
List<FiledPass> getPassList();
void preCachePassesList();
@ -43,15 +14,9 @@ public interface PassStore {
void refreshPassesList();
int passCount();
Pass getPassbookAt(int pos);
Pass getPassbookForId(String id);
void sort(SortOrder order);
List<CountedType> getCountedTypes();
void sort(PassSortOrder order);
@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,22 @@ 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.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.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 +93,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,11 +139,11 @@ public class NavigationFragment extends Fragment {
}
private boolean shouldDisplayCategoryNav() {
return shouldDisplaySort() && settings.getSortOrder() == PassStore.SortOrder.TYPE;
return shouldDisplaySort() && settings.getSortOrder() == PassSortOrder.TYPE;
}
private boolean shouldDisplaySort() {
return passStore.getCountedTypes().size() >= 2;
return PassTypeCounter.count(passStore.getPassList()).size() >= 2;
}
private void setCategoryNavVisibilityByCurrentConditions() {
@ -149,13 +155,13 @@ public class NavigationFragment extends Fragment {
private void createCategoryJumpMarks(LayoutInflater inflater) {
final List<PassStore.CountedType> countedTypes = passStore.getCountedTypes();
final Set<CountedType> countedTypes = PassTypeCounter.count(passStore.getPassList());
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

@ -12,9 +12,12 @@ import android.view.ViewGroup;
import org.ligi.axt.AXT;
import org.ligi.passandroid.App;
import org.ligi.passandroid.R;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassStore;
import java.util.List;
import javax.inject.Inject;
public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
@ -40,7 +43,7 @@ public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
@Override
public void onBindViewHolder(PassViewHolder viewHolder, final int longClickedCardPosition) {
final Pass pass = passStore.getPassbookAt(longClickedCardPosition);
final Pass pass = passStore.getPassList().get(longClickedCardPosition);
viewHolder.apply(pass,passListActivity);
@ -59,7 +62,7 @@ public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
@Override
public boolean onLongClick(View v) {
final Pass pass = passStore.getPassbookAt(longClickedCardPosition);
final Pass pass = getList().get(longClickedCardPosition);
if (actionMode != null) {
final boolean clickedOnDifferentItem = actionMode.getTag() == null || !actionMode.getTag().equals(pass);
@ -85,7 +88,7 @@ public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
if (new PassMenuOptions(passListActivity, passStore.getPassbookAt(longClickedCardPosition)).process(menuItem)) {
if (new PassMenuOptions(passListActivity, getList().get(longClickedCardPosition)).process(menuItem)) {
actionMode.finish();
return true;
}
@ -100,7 +103,7 @@ public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
}
});
actionMode.setTag(passStore.getPassbookAt(longClickedCardPosition));
actionMode.setTag(getList().get(longClickedCardPosition));
root.setCardElevation(v.getContext().getResources().getDimension(R.dimen.card_longclick_elevation));
@ -116,9 +119,13 @@ public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
return position;
}
public List<FiledPass> getList() {
return passStore.getPassList();
}
@Override
public int getItemCount() {
return passStore.passCount();
return getList().size();
}
}

View file

@ -18,9 +18,6 @@ class PassExportTask extends AsyncTask<Void, Void, Void> {
private boolean share_after_export;
protected PassExporter passExporter;
@PassExporter.PassFormat
private final int passFormat;
public PassExportTask(final Activity activity,
final String inputPath,
final String zipPath,
@ -28,8 +25,7 @@ class PassExportTask extends AsyncTask<Void, Void, Void> {
final boolean share_after_export,
@PassExporter.PassFormat final int passFormat) {
this.activity = activity;
this.passFormat = passFormat;
passExporter = new PassExporter(this.passFormat, inputPath, zipPath + "/" + zipFileName);
passExporter = new PassExporter(passFormat, inputPath, zipPath + "/" + zipFileName);
this.share_after_export = share_after_export;
progress_dialog = new ProgressDialog(activity);
}

View file

@ -98,7 +98,7 @@ public class PassListActivity extends PassAndroidActivity {
intent.setType("*/*"); // tried with octet stream - no use
startActivityForResult(intent, OPEN_FILE_READ_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
Snackbar.make(floatingActionsMenu,"Unavailable",Snackbar.LENGTH_LONG).show();
Snackbar.make(floatingActionsMenu, "Unavailable", Snackbar.LENGTH_LONG).show();
}
}
@ -133,7 +133,7 @@ public class PassListActivity extends PassAndroidActivity {
passStore.refreshPassesList();
passStore.sort(settings.getSortOrder());
AXT.at(emptyView).setVisibility(passStore.passCount() == 0);
AXT.at(emptyView).setVisibility(passStore.getPassList().isEmpty());
passAdapter.notifyDataSetChanged();
@ -185,13 +185,14 @@ public class PassListActivity extends PassAndroidActivity {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
passAdapter = new PassAdapter(PassListActivity.this);
passAdapter = new PassAdapter(this);
recyclerView.setAdapter(passAdapter);
}
private void scrollToType(String type) {
for (int i = 0; i < passAdapter.getItemCount(); i++) {
if (passStore.getPassbookAt(i).getTypeNotNull().equals(type)) {
if (passStore.getPassList().get(i).getTypeNotNull().equals(type)) {
recyclerView.scrollToPosition(i);
return; // we are done
}
@ -208,8 +209,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

@ -3,19 +3,18 @@ package org.ligi.passandroid.ui;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
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();
}
@ -219,9 +218,8 @@ public class PassViewActivityBase extends PassAndroidActivity {
passStore.setCurrentPass(newPass);
optionalPass = passStore.getCurrentPass();
refresh();
Toast.makeText(PassViewActivityBase.this,
"Pass Updated",
Toast.LENGTH_LONG).show();
Snackbar.make(getWindow().getDecorView(), R.string.pass_updated,Snackbar.LENGTH_LONG).show();
}
});

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"/>

View file

@ -103,4 +103,5 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
<string name="unzip_pass_dialog_message">Please wait...</string>
<string name="action_update">update</string>
<string name="no_calendar_app_found">No Calendar-App found</string>
<string name="pass_updated">Pass Updated</string>
</resources>

View file

@ -0,0 +1,45 @@
package org.ligi.passandroid.unittest;
import org.json.JSONException;
import org.junit.Test;
import org.ligi.passandroid.helper.PassTypeCounter;
import org.ligi.passandroid.model.CountedType;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.model.PassImpl;
import java.util.ArrayList;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
public class ThePassTypeCounter {
@Test
public void shouldReturn0ForEmptyPassList() throws JSONException {
final Set<CountedType> count = PassTypeCounter.count(new ArrayList<FiledPass>());
assertThat(count.size()).isEqualTo(0);
}
@Test
public void shouldBeAbleToCount() throws JSONException {
final Set<CountedType> count = PassTypeCounter.count(new ArrayList<FiledPass>() {
{
add(getPassWithType("foo"));
add(getPassWithType("bar"));
add(getPassWithType("bar"));
}
});
assertThat(count).containsOnly(new CountedType("foo",1),new CountedType("bar",2));
}
private FiledPass getPassWithType(final String type) {
final PassImpl pass = new PassImpl();
pass.setType(type);
return pass;
}
}

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`