mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-17 21:29:39 -04:00
Parse extras
This commit is contained in:
@@ -5,9 +5,12 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.Normalizer;
|
||||
|
||||
/**
|
||||
* Class for importing a database from CSV (Comma Separate Values)
|
||||
@@ -146,6 +149,17 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
headerTextColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR, record, true);
|
||||
}
|
||||
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
JSONObject extras;
|
||||
|
||||
try
|
||||
{
|
||||
extras = new JSONObject(extractString(DBHelper.LoyaltyCardDbIds.EXTRAS, record, ""));
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
throw new FormatException("Invalid JSON in extras field: " + ex);
|
||||
}
|
||||
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper
|
||||
{
|
||||
public static final String DATABASE_NAME = "LoyaltyCards.db";
|
||||
public static final int ORIGINAL_DATABASE_VERSION = 1;
|
||||
public static final int DATABASE_VERSION = 3;
|
||||
public static final int DATABASE_VERSION = 4;
|
||||
|
||||
static class LoyaltyCardDbIds
|
||||
{
|
||||
@@ -23,6 +25,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
public static final String HEADER_TEXT_COLOR = "headertextcolor";
|
||||
public static final String CARD_ID = "cardid";
|
||||
public static final String BARCODE_TYPE = "barcodetype";
|
||||
public static final String EXTRAS = "extras";
|
||||
}
|
||||
|
||||
public DBHelper(Context context)
|
||||
@@ -41,7 +44,8 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
LoyaltyCardDbIds.HEADER_COLOR + " INTEGER," +
|
||||
LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER," +
|
||||
LoyaltyCardDbIds.CARD_ID + " TEXT not null," +
|
||||
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null)");
|
||||
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null," +
|
||||
LoyaltyCardDbIds.EXTRAS + " TEXT)");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,11 +66,18 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
|
||||
+ " ADD COLUMN " + LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER");
|
||||
}
|
||||
|
||||
// Upgrade from version 3 to version 4
|
||||
if(oldVersion < 4 && newVersion >= 4)
|
||||
{
|
||||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
|
||||
+ " ADD COLUMN " + LoyaltyCardDbIds.EXTRAS + " TEXT");
|
||||
}
|
||||
}
|
||||
|
||||
public long insertLoyaltyCard(final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor)
|
||||
final Integer headerTextColor, final JSONObject extras)
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -76,6 +87,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return newId;
|
||||
}
|
||||
@@ -83,7 +95,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
|
||||
final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor)
|
||||
final Integer headerTextColor, final JSONObject extras)
|
||||
{
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(LoyaltyCardDbIds.ID, id);
|
||||
@@ -93,6 +105,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return (newId != -1);
|
||||
}
|
||||
@@ -100,7 +113,8 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
|
||||
public boolean updateLoyaltyCard(final int id, final String store, final String note,
|
||||
final String cardId, final String barcodeType,
|
||||
final Integer headerColor, final Integer headerTextColor)
|
||||
final Integer headerColor, final Integer headerTextColor,
|
||||
final JSONObject extras)
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -110,6 +124,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues,
|
||||
LoyaltyCardDbIds.ID + "=?",
|
||||
new String[]{Integer.toString(id)});
|
||||
|
||||
@@ -3,6 +3,10 @@ package protect.card_locker;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
|
||||
public class ImportURIHelper {
|
||||
@@ -12,6 +16,7 @@ public class ImportURIHelper {
|
||||
private static final String BARCODE_TYPE = DBHelper.LoyaltyCardDbIds.BARCODE_TYPE;
|
||||
private static final String HEADER_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_COLOR;
|
||||
private static final String HEADER_TEXT_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR;
|
||||
private static final String EXTRAS = DBHelper.LoyaltyCardDbIds.EXTRAS;
|
||||
|
||||
private final Context context;
|
||||
private final String host;
|
||||
@@ -41,8 +46,14 @@ public class ImportURIHelper {
|
||||
String barcodeType = uri.getQueryParameter(BARCODE_TYPE);
|
||||
Integer headerColor = Integer.parseInt(uri.getQueryParameter(HEADER_COLOR));
|
||||
Integer headerTextColor = Integer.parseInt(uri.getQueryParameter(HEADER_TEXT_COLOR));
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
} catch (NullPointerException | NumberFormatException ex) {
|
||||
// Extras was added in a later version, so don't crash if it doesn't exist
|
||||
JSONObject extras = new JSONObject();
|
||||
if(uri.getQueryParameter(EXTRAS) != null)
|
||||
{
|
||||
extras = new JSONObject(uri.getQueryParameter(EXTRAS));
|
||||
}
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
} catch (NullPointerException | NumberFormatException | JSONException ex) {
|
||||
throw new InvalidObjectException("Not a valid import URI");
|
||||
}
|
||||
}
|
||||
@@ -59,6 +70,7 @@ public class ImportURIHelper {
|
||||
uriBuilder.appendQueryParameter(BARCODE_TYPE, loyaltyCard.barcodeType);
|
||||
uriBuilder.appendQueryParameter(HEADER_COLOR, loyaltyCard.headerColor.toString());
|
||||
uriBuilder.appendQueryParameter(HEADER_TEXT_COLOR, loyaltyCard.headerTextColor.toString());
|
||||
uriBuilder.appendQueryParameter(EXTRAS, loyaltyCard.extras.toString());
|
||||
|
||||
return uriBuilder.build();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@ package protect.card_locker;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LoyaltyCard
|
||||
{
|
||||
public final int id;
|
||||
@@ -17,8 +22,12 @@ public class LoyaltyCard
|
||||
@Nullable
|
||||
public final Integer headerTextColor;
|
||||
|
||||
@Nullable
|
||||
public final JSONObject extras;
|
||||
|
||||
public LoyaltyCard(final int id, final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor, final Integer headerTextColor)
|
||||
final String barcodeType, final Integer headerColor, final Integer headerTextColor,
|
||||
final JSONObject extras)
|
||||
{
|
||||
this.id = id;
|
||||
this.store = store;
|
||||
@@ -27,6 +36,7 @@ public class LoyaltyCard
|
||||
this.barcodeType = barcodeType;
|
||||
this.headerColor = headerColor;
|
||||
this.headerTextColor = headerTextColor;
|
||||
this.extras = extras;
|
||||
}
|
||||
|
||||
public static LoyaltyCard toLoyaltyCard(Cursor cursor)
|
||||
@@ -53,6 +63,23 @@ public class LoyaltyCard
|
||||
headerTextColor = cursor.getInt(headerTextColorColumn);
|
||||
}
|
||||
|
||||
return new LoyaltyCard(id, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
int extrasColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.EXTRAS);
|
||||
JSONObject extras = new JSONObject();
|
||||
|
||||
if(cursor.isNull(extrasColumn) == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
extras = new JSONObject(cursor.getString(extrasColumn));
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
// That this is actually JSON is an implementation detail
|
||||
// The important part is that the DB is in a bad state
|
||||
throw new IllegalArgumentException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return new LoyaltyCard(id, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialog;
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
@@ -64,6 +65,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
String importLoyaltyCardType = null;
|
||||
Integer headingColorValue = null;
|
||||
Integer headingStoreTextColorValue = null;
|
||||
JSONObject extras = new JSONObject();
|
||||
|
||||
DBHelper db;
|
||||
ImportURIHelper importUriHelper;
|
||||
@@ -219,6 +221,8 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
extras = loyaltyCard.extras;
|
||||
|
||||
setTitle(R.string.editCardTitle);
|
||||
}
|
||||
else if(importLoyaltyCardUri != null)
|
||||
@@ -239,6 +243,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
barcodeTypeField.setText(importCard.barcodeType);
|
||||
headingColorValue = importCard.headerColor;
|
||||
headingStoreTextColorValue = importCard.headerTextColor;
|
||||
extras = importCard.extras;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -416,12 +421,12 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
|
||||
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue, extras);
|
||||
Log.i(TAG, "Updated " + loyaltyCardId + " to " + cardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
|
||||
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue, extras);
|
||||
}
|
||||
|
||||
finish();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package protect.card_locker;
|
||||
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
@@ -8,6 +9,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.TextViewCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
@@ -24,6 +26,14 @@ import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
|
||||
@@ -210,6 +220,12 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
if(loyaltyCard.extras.length() > 0)
|
||||
{
|
||||
MenuItem item = menu.findItem(R.id.action_view_extras);
|
||||
item.setVisible(true);
|
||||
}
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@@ -249,6 +265,18 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
}
|
||||
rotationEnabled = !rotationEnabled;
|
||||
return true;
|
||||
|
||||
case R.id.action_view_extras:
|
||||
try
|
||||
{
|
||||
displayExtrasDialog();
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
Toast.makeText(this, R.string.failedShowingExtras, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
@@ -269,4 +297,29 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayExtrasDialog() throws JSONException
|
||||
{
|
||||
StringBuilder items = new StringBuilder();
|
||||
|
||||
Iterator<String> iter = loyaltyCard.extras.keys();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
String key = iter.next();
|
||||
String value = loyaltyCard.extras.getString(key);
|
||||
items.append(key + ": " + value + "\n");
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(items.toString())
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
@@ -13,6 +14,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -26,6 +28,31 @@ public class PkpassImporter {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private JSONObject appendFieldDictionaryValues(JSONObject original, JSONObject pkpassJSON, String styleKey, String arrayName) throws JSONException
|
||||
{
|
||||
// https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1
|
||||
// TODO: Do something with label
|
||||
|
||||
JSONArray fields;
|
||||
// These are all optional, so don't throw an exception if they don't exist
|
||||
try
|
||||
{
|
||||
fields = pkpassJSON.getJSONObject(styleKey).getJSONArray(arrayName);
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
return original;
|
||||
}
|
||||
|
||||
for(int i = 0; i < fields.length(); i++)
|
||||
{
|
||||
JSONObject fieldObject = fields.getJSONObject(i);
|
||||
original.put(fieldObject.getString("key"), fieldObject.getString("value"));
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
public boolean isPkpass(String type) {
|
||||
return Arrays.asList("application/octet-stream", "application/zip", "application/vnd.apple.pkpass", "application/pkpass", "application/vndapplepkpass", "application/vnd-com.apple.pkpass").contains(type);
|
||||
}
|
||||
@@ -148,6 +175,40 @@ public class PkpassImporter {
|
||||
catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
// https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html#//apple_ref/doc/uid/TP40012026-CH2-SW6
|
||||
// There needs to be exactly one style key
|
||||
|
||||
String styleKey = null;
|
||||
ImmutableList<String> possibleStyleKeys = ImmutableList.<String>builder()
|
||||
.add("boardingPass")
|
||||
.add("coupon")
|
||||
.add("eventTicket")
|
||||
.add("generic")
|
||||
.add("storeCard")
|
||||
.build();
|
||||
for(int i = 0; i < possibleStyleKeys.size(); i++)
|
||||
{
|
||||
String possibleStyleKey = possibleStyleKeys.get(i);
|
||||
if(json.has(possibleStyleKey))
|
||||
{
|
||||
styleKey = possibleStyleKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(styleKey == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/LowerLevel.html#//apple_ref/doc/uid/TP40012026-CH3-SW14
|
||||
JSONObject extras = new JSONObject();
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "headerFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "primaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "secondaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "auxiliaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "backFields");
|
||||
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_info_outline_white.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_info_outline_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 582 B |
BIN
app/src/main/res/drawable-mdpi/ic_info_outline_white.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_info_outline_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 371 B |
BIN
app/src/main/res/drawable-xhdpi/ic_info_outline_white.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_info_outline_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 742 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_info_outline_white.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_info_outline_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -17,4 +17,10 @@
|
||||
android:icon="@drawable/ic_mode_edit_white_24dp"
|
||||
android:title="@string/edit"
|
||||
app:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/action_view_extras"
|
||||
android:icon="@drawable/ic_info_outline_white"
|
||||
android:title="More info"
|
||||
app:showAsAction="always"
|
||||
android:visible="false"/>
|
||||
</menu>
|
||||
@@ -44,6 +44,7 @@
|
||||
<string name="noCardIdError">No Card ID entered</string>
|
||||
<string name="noCardExistsError">Could not lookup loyalty card</string>
|
||||
<string name="failedParsingImportUriError">Could not parse the import Uri</string>
|
||||
<string name="failedShowingExtras">Could not show extra information: data not correctly formatted</string>
|
||||
|
||||
<string name="cardIdFormat">%1$s: %2$s</string>
|
||||
<string name="storeNameAndNoteFormat" translatable="false">%1$s - %2$s</string>
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.graphics.Color;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,7 +41,7 @@ public class DatabaseTest
|
||||
public void addRemoveOneGiftCard()
|
||||
{
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, new JSONObject());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -61,12 +62,12 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void updateGiftCard()
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, new JSONObject());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1", BarcodeFormat.AZTEC.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1", BarcodeFormat.AZTEC.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, new JSONObject());
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -84,7 +85,7 @@ public class DatabaseTest
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
boolean result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1",
|
||||
BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, new JSONObject());
|
||||
assertEquals(false, result);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
}
|
||||
@@ -92,7 +93,7 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void emptyGiftCardValues()
|
||||
{
|
||||
long id = db.insertLoyaltyCard("", "", "", "", null, null);
|
||||
long id = db.insertLoyaltyCard("", "", "", "", null, null, new JSONObject());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -115,7 +116,7 @@ public class DatabaseTest
|
||||
for(int index = CARDS_TO_ADD-1; index >= 0; index--)
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
|
||||
BarcodeFormat.UPC_A.toString(), index, index*2);
|
||||
BarcodeFormat.UPC_A.toString(), index, index*2, new JSONObject());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.os.Environment;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.apache.tools.ant.filters.StringInputStream;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -68,7 +69,7 @@ public class ImportExportTest
|
||||
{
|
||||
String storeName = String.format("store, \"%4d", index);
|
||||
String note = String.format("note, \"%4d", index);
|
||||
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE, index, index*2);
|
||||
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE, index, index*2, new JSONObject());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,7 +35,7 @@ public class ImportURITest {
|
||||
public void ensureNoDataLoss() throws InvalidObjectException
|
||||
{
|
||||
// Generate card
|
||||
db.insertLoyaltyCard("store", "note", BarcodeFormat.UPC_A.toString(), LoyaltyCardDbIds.BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BarcodeFormat.UPC_A.toString(), LoyaltyCardDbIds.BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
// Get card
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -83,7 +84,7 @@ public class LoyaltyCardCursorAdapterTest
|
||||
@Test
|
||||
public void TestCursorAdapterEmptyNote()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -97,7 +98,7 @@ public class LoyaltyCardCursorAdapterTest
|
||||
@Test
|
||||
public void TestCursorAdapterWithNote()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -111,7 +112,7 @@ public class LoyaltyCardCursorAdapterTest
|
||||
@Test
|
||||
public void TestCursorAdapterFontSizes()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.widget.TextView;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -362,7 +363,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -378,7 +379,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -394,7 +395,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -415,7 +416,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -441,7 +442,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -485,7 +486,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -503,7 +504,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -521,7 +522,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new JSONObject());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -538,7 +539,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
final int STORE_FONT_SIZE = 50;
|
||||
final int CARD_FONT_SIZE = 40;
|
||||
@@ -580,7 +581,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
settings.edit()
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -109,7 +110,7 @@ public class MainActivityTest
|
||||
assertEquals(0, list.getCount());
|
||||
|
||||
DBHelper db = new DBHelper(mainActivity);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
assertEquals(View.VISIBLE, helpText.getVisibility());
|
||||
assertEquals(View.GONE, noMatchingCardsText.getVisibility());
|
||||
@@ -141,8 +142,8 @@ public class MainActivityTest
|
||||
ListView list = mainActivity.findViewById(R.id.list);
|
||||
|
||||
DBHelper db = new DBHelper(mainActivity);
|
||||
db.insertLoyaltyCard("The First Store", "Initial note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("The Second Store", "Secondary note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
db.insertLoyaltyCard("The First Store", "Initial note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("The Second Store", "Secondary note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
|
||||
activityController.pause();
|
||||
activityController.resume();
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -50,6 +51,41 @@ public class PkpassTest {
|
||||
assertEquals("Passbook Example Company", card.store);
|
||||
assertEquals(String.valueOf(Color.rgb(90, 90, 90)), card.headerColor.toString());
|
||||
assertEquals(String.valueOf(Color.rgb(255, 255, 255)), card.headerTextColor.toString());
|
||||
|
||||
// Check if all the extras got parsed correctly
|
||||
JSONObject extras = card.extras;
|
||||
assertEquals(7, extras.length());
|
||||
|
||||
// Check all 7 values
|
||||
Iterator<String> extrasKeys = extras.keys();
|
||||
|
||||
// 1
|
||||
assertEquals("staffNumber", extrasKeys.next());
|
||||
assertEquals("001", extras.get("staffNumber"));
|
||||
|
||||
// 2
|
||||
assertEquals("staffName", extrasKeys.next());
|
||||
assertEquals("Peter Brooke", extras.get("staffName"));
|
||||
|
||||
// 3
|
||||
assertEquals("telephoneExt", extrasKeys.next());
|
||||
assertEquals("9779", extras.get("telephoneExt"));
|
||||
|
||||
// 4
|
||||
assertEquals("jobTitle", extrasKeys.next());
|
||||
assertEquals("Chief Pass Creator", extras.get("jobTitle"));
|
||||
|
||||
// 5
|
||||
assertEquals("expiryDate", extrasKeys.next());
|
||||
assertEquals("2013-12-31T00:00-23:59", extras.get("expiryDate"));
|
||||
|
||||
// 6
|
||||
assertEquals("managersName", extrasKeys.next());
|
||||
assertEquals("Paul Bailey", extras.get("managersName"));
|
||||
|
||||
// 7
|
||||
assertEquals("managersExt", extrasKeys.next());
|
||||
assertEquals("9673", extras.get("managersExt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,5 +105,84 @@ public class PkpassTest {
|
||||
// Violates the spec, but we want to support it anyway...
|
||||
assertEquals(String.valueOf(Color.parseColor("#FFFFFF")), card.headerColor.toString());
|
||||
assertEquals(String.valueOf(Color.parseColor("#AA0061")), card.headerTextColor.toString());
|
||||
|
||||
// Check if all the extras got parsed correctly
|
||||
JSONObject extras = card.extras;
|
||||
assertEquals(18, extras.length());
|
||||
|
||||
// Check all 18 values
|
||||
Iterator<String> extrasKeys = extras.keys();
|
||||
|
||||
// 1
|
||||
assertEquals("gate", extrasKeys.next());
|
||||
assertEquals("B61", extras.get("gate"));
|
||||
|
||||
// 2
|
||||
assertEquals("seat", extrasKeys.next());
|
||||
assertEquals("16E", extras.get("seat"));
|
||||
|
||||
// 3
|
||||
assertEquals("origin", extrasKeys.next());
|
||||
assertEquals("CGN", extras.get("origin"));
|
||||
|
||||
// 4
|
||||
assertEquals("destination", extrasKeys.next());
|
||||
assertEquals("DBV", extras.get("destination"));
|
||||
|
||||
// 5
|
||||
assertEquals("name", extrasKeys.next());
|
||||
assertEquals("John Doe", extras.get("name"));
|
||||
|
||||
// 6
|
||||
assertEquals("status", extrasKeys.next());
|
||||
assertEquals("-", extras.get("status"));
|
||||
|
||||
// 7
|
||||
assertEquals("boardinggroup", extrasKeys.next());
|
||||
assertEquals("GROUP 1", extras.get("boardinggroup"));
|
||||
|
||||
// 8
|
||||
assertEquals("tarif", extrasKeys.next());
|
||||
assertEquals("SMART", extras.get("tarif"));
|
||||
|
||||
// 9
|
||||
assertEquals("flightNumber", extrasKeys.next());
|
||||
assertEquals("EW 954", extras.get("flightNumber"));
|
||||
|
||||
// 10
|
||||
assertEquals("departureDate", extrasKeys.next());
|
||||
assertEquals("08/09/2019", extras.get("departureDate"));
|
||||
|
||||
// 11
|
||||
assertEquals("boarding", extrasKeys.next());
|
||||
assertEquals("05:00", extras.get("boarding"));
|
||||
|
||||
// 12
|
||||
assertEquals("closure", extrasKeys.next());
|
||||
assertEquals("05:15", extras.get("closure"));
|
||||
|
||||
// 13
|
||||
assertEquals("info", extrasKeys.next());
|
||||
assertEquals("info_content_str", extras.get("info"));
|
||||
|
||||
// 14
|
||||
assertEquals("recordlocator", extrasKeys.next());
|
||||
assertEquals("JBZPPP", extras.get("recordlocator"));
|
||||
|
||||
// 15
|
||||
assertEquals("sequence", extrasKeys.next());
|
||||
assertEquals("73", extras.get("sequence"));
|
||||
|
||||
// 16
|
||||
assertEquals("notice", extrasKeys.next());
|
||||
assertEquals("notice_content_str", extras.get("notice"));
|
||||
|
||||
// 17
|
||||
assertEquals("baggage", extrasKeys.next());
|
||||
assertEquals("baggage_content_str", extras.get("baggage"));
|
||||
|
||||
// 18
|
||||
assertEquals("contact", extrasKeys.next());
|
||||
assertEquals("contact_content_str", extras.get("contact"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user