Ticket -> Pass

This commit is contained in:
ligi 2014-07-17 12:58:32 +02:00
parent c26e06d4b6
commit 1a3f58ff10
27 changed files with 105 additions and 107 deletions

View file

@ -6,20 +6,19 @@ import com.squareup.spoon.Spoon;
import org.ligi.passandroid.injections.FixedPassListPassStore;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.ui.TicketListActivity;
import org.ligi.passandroid.ui.PassListActivity;
import java.util.ArrayList;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
public class TheEmptyTicketList extends BaseIntegration<TicketListActivity> {
public class TheEmptyPassList extends BaseIntegration<PassListActivity> {
public TheEmptyTicketList() {
super(TicketListActivity.class);
public TheEmptyPassList() {
super(PassListActivity.class);
}
@Override

View file

@ -8,7 +8,7 @@ import com.squareup.spoon.Spoon;
import org.ligi.passandroid.injections.FixedPassListPassStore;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassImpl;
import org.ligi.passandroid.ui.TicketListActivity;
import org.ligi.passandroid.ui.PassListActivity;
import java.util.ArrayList;
@ -20,10 +20,10 @@ import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMat
import static org.hamcrest.CoreMatchers.not;
@TargetApi(14)
public class TheTicketListActivity extends BaseIntegration<TicketListActivity> {
public class ThePassListActivity extends BaseIntegration<PassListActivity> {
public TheTicketListActivity() {
super(TicketListActivity.class);
public ThePassListActivity() {
super(PassListActivity.class);
}
@Override

View file

@ -9,7 +9,7 @@ import org.joda.time.DateTime;
import org.ligi.passandroid.injections.FixedPassListPassStore;
import org.ligi.passandroid.model.Pass;
import org.ligi.passandroid.model.PassImpl;
import org.ligi.passandroid.ui.TicketViewActivity;
import org.ligi.passandroid.ui.PasViewActivity;
import java.util.ArrayList;
@ -22,12 +22,12 @@ import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMat
import static org.hamcrest.CoreMatchers.not;
@TargetApi(14)
public class TheTicketViewActivity extends BaseIntegration<TicketViewActivity> {
public class ThePassViewActivity extends BaseIntegration<PasViewActivity> {
private PassImpl act_pass;
public TheTicketViewActivity() {
super(TicketViewActivity.class);
public ThePassViewActivity() {
super(PasViewActivity.class);
}
@Override

View file

@ -27,7 +27,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".ui.TicketListActivity"
android:name=".ui.PassListActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -37,7 +37,7 @@
<activity android:name=".ui.HelpActivity" />
<activity
android:name=".ui.TicketImportActivity"
android:name=".ui.PassImportActivity"
tools:ignore="ExportedActivity">
<intent-filter>
@ -130,12 +130,12 @@
</activity>
<activity
android:name=".ui.TicketViewActivity"
android:name=".ui.PasViewActivity"
android:label="@string/app_name"
android:parentActivityName=".ui.TicketListActivity">
android:parentActivityName=".ui.PassListActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.TicketListActivity" />
android:value=".ui.PassListActivity" />
</activity>
<activity

View file

@ -32,7 +32,7 @@ public class App extends Application {
private void initTraceDroid() {
TraceDroid.init(this);
Log.setTAG("TicketViewer");
Log.setTAG("PassAndroid");
}
public static boolean isDeveloperMode() {

View file

@ -36,7 +36,7 @@ public class AppleStylePassReader {
pass.setId(path.substring(path.lastIndexOf('/') + 1));
JSONObject pass_json = null, ticketJSONObject = null;
JSONObject pass_json = null, type_json = null;
final File file = new File(path + "/pass.json");
@ -179,18 +179,18 @@ public class AppleStylePassReader {
e.printStackTrace();
}
} else try {
ticketJSONObject = pass_json.getJSONObject(pass.getType());
type_json = pass_json.getJSONObject(pass.getType());
} catch (JSONException e) {
}
}
if (ticketJSONObject != null) {
pass.setPrimaryFields(new PassFieldList(ticketJSONObject, "primaryFields"));
pass.setSecondaryFields(new PassFieldList(ticketJSONObject, "secondaryFields"));
pass.setAuxiliaryFields(new PassFieldList(ticketJSONObject, "auxiliaryFields"));
pass.setBackFields(new PassFieldList(ticketJSONObject, "backFields"));
pass.setHeaderFields(new PassFieldList(ticketJSONObject, "headerFields"));
if (type_json != null) {
pass.setPrimaryFields(new PassFieldList(type_json, "primaryFields"));
pass.setSecondaryFields(new PassFieldList(type_json, "secondaryFields"));
pass.setAuxiliaryFields(new PassFieldList(type_json, "auxiliaryFields"));
pass.setBackFields(new PassFieldList(type_json, "backFields"));
pass.setHeaderFields(new PassFieldList(type_json, "headerFields"));
}
try {

View file

@ -14,9 +14,9 @@ public class PassFieldList extends ArrayList<PassField> {
public PassFieldList() {
}
public PassFieldList(JSONObject ticketJSONObject, String fieldsName) {
public PassFieldList(JSONObject passJSON, String fieldsName) {
try {
final JSONArray jsonArray = ticketJSONObject.getJSONArray(fieldsName);
final JSONArray jsonArray = passJSON.getJSONArray(fieldsName);
for (int i = 0; i < jsonArray.length(); i++) {
try {
final PassField field = new PassField(jsonArray.getJSONObject(i));

View file

@ -14,7 +14,7 @@ import org.ligi.passandroid.R;
import static butterknife.ButterKnife.findById;
public class FullscreenBarcodeActivity extends TicketViewActivityBase {
public class FullscreenBarcodeActivity extends PassViewActivityBase {
@Override
protected void onCreate(Bundle savedInstanceState) {

View file

@ -10,10 +10,10 @@ import org.ligi.passandroid.model.InputStreamWithSource;
class ImportAsyncTask extends AsyncTask<Void, Void, InputStreamWithSource> {
private final Uri uri;
protected final Activity ticketImportActivity;
protected final Activity passImportActivity;
public ImportAsyncTask(Activity ticketImportActivity, Uri uri) {
this.ticketImportActivity = ticketImportActivity;
public ImportAsyncTask(Activity passImportActivity, Uri uri) {
this.passImportActivity = passImportActivity;
this.uri = uri;
}
@ -24,7 +24,7 @@ class ImportAsyncTask extends AsyncTask<Void, Void, InputStreamWithSource> {
switch (uri.getScheme()) {
case "content":
return InputStreamProvider.fromContent(ticketImportActivity, uri);
return InputStreamProvider.fromContent(passImportActivity, uri);
case "http":
case "https":

View file

@ -50,7 +50,7 @@ public class InputStreamProvider {
try {
return new InputStreamWithSource(uri.toString(), ctx.getContentResolver().openInputStream(uri));
} catch (FileNotFoundException e) {
Tracker.get().trackException("FileNotFoundException in ticketImportActivity/ImportAsyncTask", e, false);
Tracker.get().trackException("FileNotFoundException in passImportActivity/ImportAsyncTask", e, false);
return null;
}
@ -61,7 +61,7 @@ public class InputStreamProvider {
try {
return new InputStreamWithSource(uri.toString(), new BufferedInputStream(new URL(uri.toString()).openStream(), 4096));
} catch (IOException e) {
Tracker.get().trackException("IOException in ticketImportActivity/ImportAsyncTask", e, false);
Tracker.get().trackException("IOException in passImportActivity/ImportAsyncTask", e, false);
return null;
}
}

View file

@ -28,7 +28,7 @@ import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
public class TicketViewActivity extends TicketViewActivityBase {
public class PasViewActivity extends PassViewActivityBase {
@OnClick(R.id.barcode_img)
@ -73,14 +73,14 @@ public class TicketViewActivity extends TicketViewActivityBase {
.setNeutralButton(getString(R.string.send), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new ExportProblemPassToLigiAndFinishTask(TicketViewActivity.this, pass.getId(), App.getShareDir(), "share.pkpass").execute();
new ExportProblemPassToLigiAndFinishTask(PasViewActivity.this, pass.getId(), App.getShareDir(), "share.pkpass").execute();
}
})
.show();
return;
}
final View contentView = getLayoutInflater().inflate(R.layout.activity_ticket_view, null);
final View contentView = getLayoutInflater().inflate(R.layout.activity_pass_view, null);
setContentView(contentView);
ButterKnife.inject(this);

View file

@ -10,10 +10,10 @@ import org.ligi.passandroid.helper.PassVisualizer;
class PassAdapter extends BaseAdapter {
private final TicketListActivity ticketListActivity;
private final PassListActivity passListActivity;
public PassAdapter(TicketListActivity ticketListActivity) {
this.ticketListActivity = ticketListActivity;
public PassAdapter(PassListActivity passListActivity) {
this.passListActivity = passListActivity;
}
@Override
@ -34,9 +34,9 @@ class PassAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View res = ticketListActivity.getLayoutInflater().inflate(R.layout.pass_list_item, null);
View res = passListActivity.getLayoutInflater().inflate(R.layout.pass_list_item, null);
PassVisualizer.visualize(ticketListActivity, App.getPassStore().getPassbookAt(position), res);
PassVisualizer.visualize(passListActivity, App.getPassStore().getPassbookAt(position), res);
return res;
}

View file

@ -12,7 +12,7 @@ import org.ligi.passandroid.R;
import org.ligi.passandroid.model.InputStreamWithSource;
import org.ligi.passandroid.model.PassStore;
public class TicketImportActivity extends ActionBarActivity {
public class PassImportActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -22,15 +22,15 @@ public class TicketImportActivity extends ActionBarActivity {
class ImportAndShowAsyncTask extends ImportAsyncTask {
public ImportAndShowAsyncTask(final Activity ticketImportActivity, final Uri intent_uri) {
super(ticketImportActivity, intent_uri);
public ImportAndShowAsyncTask(final Activity passImportActivity, final Uri intent_uri) {
super(passImportActivity, intent_uri);
}
@Override
protected void onPostExecute(InputStreamWithSource result) {
if (result != null) {
UnzipPassDialog.show(result, ticketImportActivity, new UnzipPassDialog.FinishCallback() {
UnzipPassDialog.show(result, passImportActivity, new UnzipPassDialog.FinishCallback() {
@Override
public Void call(String path) {
@ -40,7 +40,7 @@ public class TicketImportActivity extends ActionBarActivity {
final PassStore store = App.getPassStore();
store.setCurrentPass(store.getPassbookForId(id));
AXT.at(TicketImportActivity.this).startCommonIntent().activityFromClass(TicketViewActivity.class);
AXT.at(PassImportActivity.this).startCommonIntent().activityFromClass(PasViewActivity.class);
return null;
}
@ -53,7 +53,7 @@ public class TicketImportActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_ticket_view, menu);
getMenuInflater().inflate(R.menu.activity_pass_view, menu);
return true;
}

View file

@ -54,7 +54,7 @@ import static org.ligi.passandroid.ui.UnzipPassController.SilentFail;
import static org.ligi.passandroid.ui.UnzipPassController.SilentWin;
import static org.ligi.passandroid.ui.UnzipPassController.processInputStream;
public class TicketListActivity extends ActionBarActivity {
public class PassListActivity extends ActionBarActivity {
private PassAdapter passAdapter;
private boolean scanning = false;
@ -94,7 +94,7 @@ public class TicketListActivity extends ActionBarActivity {
void listItemClick(int position) {
final Pass newSelectedPass = App.getPassStore().getPassbookAt(position);
App.getPassStore().setCurrentPass(Optional.of(newSelectedPass));
AXT.at(this).startCommonIntent().activityFromClass(TicketViewActivity.class);
AXT.at(this).startCommonIntent().activityFromClass(PasViewActivity.class);
}
public void refreshPasses() {
@ -103,7 +103,7 @@ public class TicketListActivity extends ActionBarActivity {
passAdapter.notifyDataSetChanged();
}
public TicketListActivity() {
public PassListActivity() {
super();
}
@ -111,7 +111,7 @@ public class TicketListActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.ticket_list);
setContentView(R.layout.pass_list);
ButterKnife.inject(this);
passAdapter = new PassAdapter(this);
@ -161,7 +161,7 @@ public class TicketListActivity extends ActionBarActivity {
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
getMenuInflater().inflate(R.menu.activity_ticket_view, menu);
getMenuInflater().inflate(R.menu.activity_pass_view, menu);
return true;
}
@ -172,7 +172,7 @@ public class TicketListActivity extends ActionBarActivity {
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
if (new PassMenuOptions(TicketListActivity.this, App.getPassStore().getPassbookAt(position)).process(menuItem)) {
if (new PassMenuOptions(PassListActivity.this, App.getPassStore().getPassbookAt(position)).process(menuItem)) {
actionMode.finish();
return true;
}
@ -268,7 +268,7 @@ public class TicketListActivity extends ActionBarActivity {
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
if (!scanning) {
getMenuInflater().inflate(R.menu.activity_ticket_list_view, menu);
getMenuInflater().inflate(R.menu.activity_pass_list_view, menu);
}
return true;
}
@ -320,15 +320,15 @@ public class TicketListActivity extends ActionBarActivity {
class ImportAndRefreshListAsync extends ImportAsyncTask {
public ImportAndRefreshListAsync(final Activity ticketImportActivity, final String path) {
super(ticketImportActivity, Uri.parse("file://" + path));
new PastLocationsStore(ticketImportActivity).putLocation(path);
public ImportAndRefreshListAsync(final Activity passImportActivity, final String path) {
super(passImportActivity, Uri.parse("file://" + path));
new PastLocationsStore(passImportActivity).putLocation(path);
}
@Override
protected InputStreamWithSource doInBackground(Void... params) {
final InputStreamWithSource ins = super.doInBackground(params);
final InputStreamUnzipControllerSpec spec = new InputStreamUnzipControllerSpec(ins, ticketImportActivity, new SilentWin(), new SilentFail());
final InputStreamUnzipControllerSpec spec = new InputStreamUnzipControllerSpec(ins, passImportActivity, new SilentWin(), new SilentFail());
processInputStream(spec);
return ins;
}
@ -390,7 +390,7 @@ public class TicketListActivity extends ActionBarActivity {
} else if (file.getName().endsWith(".pkpass")) {
Log.i("found" + file.getAbsolutePath());
new ImportAndRefreshListAsync(TicketListActivity.this, file.getAbsolutePath()).execute();
new ImportAndRefreshListAsync(PassListActivity.this, file.getAbsolutePath()).execute();
}
}
@ -425,7 +425,7 @@ public class TicketListActivity extends ActionBarActivity {
@Override
protected Void doInBackground(Void... params) {
for (String path : new PastLocationsStore(TicketListActivity.this).getLocations()) {
for (String path : new PastLocationsStore(PassListActivity.this).getLocations()) {
search_in(new File(path), false);
}

View file

@ -49,11 +49,11 @@ public class PassMenuOptions {
new File(pass.getSource().get().replace("file://", "")).delete();
}
App.getPassStore().deletePassWithId(pass.getId());
if (activity instanceof TicketViewActivityBase) {
final Intent ticketListIntent = new Intent(activity, TicketListActivity.class);
NavUtils.navigateUpTo(activity, ticketListIntent);
} else if (activity instanceof TicketListActivity) {
((TicketListActivity) activity).refreshPasses();
if (activity instanceof PassViewActivityBase) {
final Intent passListIntent = new Intent(activity, PassListActivity.class);
NavUtils.navigateUpTo(activity, passListIntent);
} else if (activity instanceof PassListActivity) {
((PassListActivity) activity).refreshPasses();
}
}

View file

@ -3,7 +3,6 @@ package org.ligi.passandroid.ui;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@ -15,7 +14,7 @@ import org.ligi.passandroid.R;
import org.ligi.passandroid.Tracker;
import org.ligi.passandroid.model.Pass;
public class TicketViewActivityBase extends ActionBarActivity {
public class PassViewActivityBase extends ActionBarActivity {
protected Bitmap icon_bitmap;
public Optional<Pass> optionalPass;
@ -30,7 +29,7 @@ public class TicketViewActivityBase extends ActionBarActivity {
optionalPass = App.getPassStore().getCurrentPass();
if (!optionalPass.isPresent()) {
Tracker.get().trackException("pass not present in TicketViewActivityBase", false);
Tracker.get().trackException("pass not present in " + this, false);
finish();
return;
}
@ -51,7 +50,7 @@ public class TicketViewActivityBase extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_ticket_view, menu);
getMenuInflater().inflate(R.menu.activity_pass_view, menu);
return true;
}

View file

@ -0,0 +1,18 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<include
layout="@layout/activity_pass_view_base"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/map_container"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent" />
</LinearLayout>

View file

@ -1,18 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<include layout="@layout/activity_ticket_view_base"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"
/>
<LinearLayout
android:id="@+id/map_container"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="match_parent"/>
</LinearLayout>

View file

@ -0,0 +1,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/activity_pass_view_base" />
</LinearLayout>

View file

@ -1,9 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/activity_ticket_view_base"/>
</LinearLayout>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ligi.ticketviewer">
package="org.ligi.passandroid">
<application>

View file

@ -6,9 +6,9 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import org.ligi.passandroid.ui.NavigateToLocationsDialog;
import org.ligi.passandroid.ui.TicketViewActivityBase;
import org.ligi.passandroid.ui.PassViewActivityBase;
public class FullscreenMapActivity extends TicketViewActivityBase {
public class FullscreenMapActivity extends PassViewActivityBase {
@Override
protected void onCreate(Bundle savedInstanceState) {

View file

@ -19,12 +19,12 @@ import com.google.android.gms.maps.model.MarkerOptions;
import org.ligi.axt.AXT;
import org.ligi.passandroid.model.PassLocation;
import org.ligi.passandroid.ui.TicketViewActivityBase;
import org.ligi.passandroid.ui.PassViewActivityBase;
import java.util.List;
public class LocationsMapFragment extends SupportMapFragment {
private TicketViewActivityBase base_activity;
private PassViewActivityBase base_activity;
public boolean click_to_fullscreen = false;
private Handler handler;
@ -32,10 +32,10 @@ public class LocationsMapFragment extends SupportMapFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
base_activity = (TicketViewActivityBase) getActivity();
base_activity = (PassViewActivityBase) getActivity();
if (!(getActivity() instanceof TicketViewActivityBase)) {
throw new IllegalArgumentException("LocationsMapFragment must be used inside a TicketViewActivityBase");
if (!(getActivity() instanceof PassViewActivityBase)) {
throw new IllegalArgumentException("LocationsMapFragment must be used inside a PassViewActivityBase");
}
final MapInitRunnable mapInitRunnable = new MapInitRunnable();