mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2025-12-24 15:47:53 -05:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eeb87578f | ||
|
|
badba551d0 | ||
|
|
49abf8a918 | ||
|
|
5fba338223 | ||
|
|
388a0723dc | ||
|
|
e14da63d06 | ||
|
|
1673c0229a | ||
|
|
22afeddcbc | ||
|
|
7758c61079 | ||
|
|
47b30ca9fb | ||
|
|
7b4d587b13 | ||
|
|
685ee018c6 | ||
|
|
e0915578ba | ||
|
|
c733a6c3b9 | ||
|
|
ec17255a43 | ||
|
|
1fc7baa5a0 | ||
|
|
0df411ee96 | ||
|
|
23178d9694 | ||
|
|
94accc951d | ||
|
|
0207e12aed | ||
|
|
c760465b3e | ||
|
|
f480bd0c7e | ||
|
|
5599560258 | ||
|
|
7b4c119d7d | ||
|
|
6144353079 | ||
|
|
03a5334961 | ||
|
|
04e0a5716e | ||
|
|
91e3f9f785 | ||
|
|
2ebc862e27 | ||
|
|
5d122affce | ||
|
|
9e09b9052a | ||
|
|
2753b8826f | ||
|
|
4e02252b75 | ||
|
|
647ce00e72 | ||
|
|
86a5f2fb50 | ||
|
|
dca5129031 | ||
|
|
e30eb00bf7 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
## v0.16 (2017-11-29)
|
||||
|
||||
Changes:
|
||||
- Add support for adding loyalty card shortcuts from the launcher/homescreen. (https://github.com/brarcher/loyalty-card-locker/pull/161)
|
||||
- Remove support for adding loyalty card shortcuts from the app itself. This removes the need for the shortcut permission. (https://github.com/brarcher/loyalty-card-locker/pull/163)
|
||||
|
||||
## v0.15 (2017-11-25)
|
||||
|
||||
Changes:
|
||||
- Add support for adding shortcuts to home screen when adding or editing a card. (https://github.com/brarcher/loyalty-card-locker/pull/155)
|
||||
- Remove widget, as it was a poor substitute for shortcuts. (https://github.com/brarcher/loyalty-card-locker/pull/155)
|
||||
- Fix exporting backups on Android 7+. (https://github.com/brarcher/loyalty-card-locker/pull/153)
|
||||
- Report more accurate mime type when exporting backup data. (https://github.com/brarcher/loyalty-card-locker/pull/156)
|
||||
- Fix bug where a card could not be edited. (https://github.com/brarcher/loyalty-card-locker/pull/155)
|
||||
|
||||
## v0.14 (2017-10-26)
|
||||
|
||||
Changes:
|
||||
|
||||
@@ -14,8 +14,8 @@ android {
|
||||
applicationId "protect.card_locker"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 15
|
||||
versionName "0.14"
|
||||
versionCode 17
|
||||
versionName "0.16"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
||||
7
app/proguard-rules.pro
vendored
7
app/proguard-rules.pro
vendored
@@ -15,3 +15,10 @@
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# This keep the class and method names the same, for debugging stack traces
|
||||
-dontobfuscate
|
||||
@@ -36,7 +36,8 @@
|
||||
android:name=".LoyaltyCardViewActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:windowSoftInputMode="stateHidden"/>
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:exported="true"/>
|
||||
<activity
|
||||
android:name=".BarcodeSelectorActivity"
|
||||
android:label="@string/selectBarcodeTitle"
|
||||
@@ -53,20 +54,25 @@
|
||||
android:label=""
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:theme="@style/AppTheme.NoActionBar"/>
|
||||
|
||||
<receiver android:name=".appwidget.CardAppWidgetProvider">
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/appwidget_provider" />
|
||||
<activity
|
||||
android:name=".CardShortcutConfigure"
|
||||
android:label="@string/cardShortcut"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".appwidget.CardAppWidgetConfigure">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false"
|
||||
android:authorities="${applicationId}">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_provider_paths"/>
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* The configuration screen for creating a shortcut.
|
||||
*/
|
||||
public class CardShortcutConfigure extends AppCompatActivity
|
||||
{
|
||||
static final String TAG = "LoyaltyCardLocker";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle)
|
||||
{
|
||||
super.onCreate(bundle);
|
||||
|
||||
// Set the result to CANCELED. This will cause nothing to happen if the
|
||||
// aback button is pressed.
|
||||
setResult(RESULT_CANCELED);
|
||||
|
||||
setContentView(R.layout.main_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setVisibility(View.GONE);
|
||||
|
||||
final DBHelper db = new DBHelper(this);
|
||||
|
||||
// If there are no cards, bail
|
||||
if(db.getLoyaltyCardCount() == 0)
|
||||
{
|
||||
Toast.makeText(this, R.string.noCardsMessage, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
final ListView cardList = (ListView) findViewById(R.id.list);
|
||||
cardList.setVisibility(View.VISIBLE);
|
||||
|
||||
Cursor cardCursor = db.getLoyaltyCardCursor();
|
||||
|
||||
final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, cardCursor);
|
||||
cardList.setAdapter(adapter);
|
||||
|
||||
cardList.setOnItemClickListener(new AdapterView.OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
Cursor selected = (Cursor) parent.getItemAtPosition(position);
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected);
|
||||
|
||||
Log.d(TAG, "Creating shortcut for card " + loyaltyCard.store + "," + loyaltyCard.id);
|
||||
|
||||
Intent shortcutIntent = new Intent(CardShortcutConfigure.this, LoyaltyCardViewActivity.class);
|
||||
shortcutIntent.setAction(Intent.ACTION_MAIN);
|
||||
// Prevent instances of the view activity from piling up; if one exists let this
|
||||
// one replace it.
|
||||
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("id", loyaltyCard.id);
|
||||
bundle.putBoolean("view", true);
|
||||
shortcutIntent.putExtras(bundle);
|
||||
|
||||
Parcelable icon = Intent.ShortcutIconResource.fromContext(CardShortcutConfigure.this, R.mipmap.ic_launcher);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, loyaltyCard.store);
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
}
|
||||
}
|
||||
|
||||
public boolean insertLoyaltyCard(final String store, final String note, final String cardId,
|
||||
public long insertLoyaltyCard(final String store, final String note, final String cardId,
|
||||
final String barcodeType)
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
@@ -61,7 +61,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return (newId != -1);
|
||||
return newId;
|
||||
}
|
||||
|
||||
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
|
||||
|
||||
@@ -7,12 +7,15 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
@@ -24,6 +27,9 @@ import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class ImportExportActivity extends AppCompatActivity
|
||||
@@ -132,24 +138,34 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
startImport(exportFile);
|
||||
Uri uri = Uri.fromFile(exportFile);
|
||||
try
|
||||
{
|
||||
FileInputStream stream = new FileInputStream(exportFile);
|
||||
startImport(stream, uri);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
Log.e(TAG, "Could not import file " + exportFile.getAbsolutePath(), e);
|
||||
onImportComplete(false, uri);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startImport(File target)
|
||||
private void startImport(final InputStream target, final Uri targetUri)
|
||||
{
|
||||
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onTaskComplete(boolean success, File file)
|
||||
public void onTaskComplete(boolean success)
|
||||
{
|
||||
onImportComplete(success, file);
|
||||
onImportComplete(success, targetUri);
|
||||
}
|
||||
};
|
||||
|
||||
importExporter = new ImportExportTask(ImportExportActivity.this,
|
||||
true, DataFormat.CSV, target, listener);
|
||||
DataFormat.CSV, target, listener);
|
||||
importExporter.execute();
|
||||
}
|
||||
|
||||
@@ -158,14 +174,14 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onTaskComplete(boolean success, File file)
|
||||
public void onTaskComplete(boolean success)
|
||||
{
|
||||
onExportComplete(success, file);
|
||||
onExportComplete(success, exportFile);
|
||||
}
|
||||
};
|
||||
|
||||
importExporter = new ImportExportTask(ImportExportActivity.this,
|
||||
false, DataFormat.CSV, exportFile, listener);
|
||||
DataFormat.CSV, exportFile, listener);
|
||||
importExporter.execute();
|
||||
}
|
||||
|
||||
@@ -220,7 +236,34 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void onImportComplete(boolean success, File path)
|
||||
private String fileNameFromUri(Uri uri)
|
||||
{
|
||||
if("file".equals(uri.getScheme()))
|
||||
{
|
||||
return uri.getPath();
|
||||
}
|
||||
|
||||
Cursor returnCursor =
|
||||
getContentResolver().query(uri, null, null, null, null);
|
||||
if(returnCursor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if(returnCursor.moveToFirst() == false)
|
||||
{
|
||||
returnCursor.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = returnCursor.getString(nameIndex);
|
||||
returnCursor.close();
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private void onImportComplete(boolean success, Uri path)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
||||
@@ -236,7 +279,15 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
int messageId = success ? R.string.importedFrom : R.string.importFailed;
|
||||
|
||||
final String template = getResources().getString(messageId);
|
||||
final String message = String.format(template, path.getAbsolutePath());
|
||||
|
||||
// Get the filename of the file being imported
|
||||
String filename = fileNameFromUri(path);
|
||||
if(filename == null)
|
||||
{
|
||||
filename = "(unknown)";
|
||||
}
|
||||
|
||||
final String message = String.format(template, filename);
|
||||
builder.setMessage(message);
|
||||
builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@@ -286,10 +337,13 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
Uri outputUri = Uri.fromFile(path);
|
||||
Uri outputUri = FileProvider.getUriForFile(ImportExportActivity.this, BuildConfig.APPLICATION_ID, path);
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, outputUri);
|
||||
sendIntent.setType("text/plain");
|
||||
sendIntent.setType("text/csv");
|
||||
|
||||
// set flag to give temporary permission to external app to use the FileProvider
|
||||
sendIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
ImportExportActivity.this.startActivity(Intent.createChooser(sendIntent,
|
||||
sendLabel));
|
||||
@@ -344,34 +398,28 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode == RESULT_OK && requestCode == CHOOSE_EXPORT_FILE)
|
||||
{
|
||||
String path = null;
|
||||
|
||||
Uri uri = data.getData();
|
||||
if(uri != null && uri.toString().startsWith("/"))
|
||||
{
|
||||
uri = Uri.parse("file://" + uri.toString());
|
||||
}
|
||||
|
||||
if(uri != null)
|
||||
{
|
||||
path = uri.getPath();
|
||||
}
|
||||
|
||||
if(path != null)
|
||||
{
|
||||
Log.e(TAG, "Starting file import with: " + uri.toString());
|
||||
startImport(new File(path));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e(TAG, "Fail to make sense of URI returned from activity: " + (uri != null ? uri.toString() : "null"));
|
||||
}
|
||||
}
|
||||
else
|
||||
if (resultCode != RESULT_OK || requestCode != CHOOSE_EXPORT_FILE)
|
||||
{
|
||||
Log.w(TAG, "Failed onActivityResult(), result=" + resultCode);
|
||||
return;
|
||||
}
|
||||
|
||||
Uri uri = data.getData();
|
||||
if(uri == null)
|
||||
{
|
||||
Log.e(TAG, "Activity returned a NULL URI");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
InputStream reader = getContentResolver().openInputStream(uri);
|
||||
Log.e(TAG, "Starting file import with: " + uri.toString());
|
||||
startImport(reader, uri);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
Log.e(TAG, "Failed to import file: " + uri.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -24,29 +25,46 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
|
||||
private boolean doImport;
|
||||
private DataFormat format;
|
||||
private File target;
|
||||
private InputStream inputStream;
|
||||
private TaskCompleteListener listener;
|
||||
|
||||
private ProgressDialog progress;
|
||||
|
||||
public ImportExportTask(Activity activity, boolean doImport, DataFormat format, File target,
|
||||
/**
|
||||
* Constructor which will setup a task for exporting to the given file
|
||||
*/
|
||||
ImportExportTask(Activity activity, DataFormat format, File target,
|
||||
TaskCompleteListener listener)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.doImport = doImport;
|
||||
this.doImport = false;
|
||||
this.format = format;
|
||||
this.target = target;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private boolean performImport(File importFile, DBHelper db)
|
||||
/**
|
||||
* Constructor which will setup a task for importing from the given InputStream.
|
||||
*/
|
||||
ImportExportTask(Activity activity, DataFormat format, InputStream input,
|
||||
TaskCompleteListener listener)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.doImport = true;
|
||||
this.format = format;
|
||||
this.inputStream = input;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private boolean performImport(InputStream stream, DBHelper db)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
try
|
||||
{
|
||||
FileInputStream fileReader = new FileInputStream(importFile);
|
||||
InputStreamReader reader = new InputStreamReader(fileReader, Charset.forName("UTF-8"));
|
||||
InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8"));
|
||||
result = MultiFormatImporter.importData(db, reader, format);
|
||||
reader.close();
|
||||
}
|
||||
@@ -55,7 +73,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
|
||||
Log.e(TAG, "Unable to import file", e);
|
||||
}
|
||||
|
||||
Log.i(TAG, "Import of '" + importFile.getAbsolutePath() + "' result: " + result);
|
||||
Log.i(TAG, "Import result: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -105,7 +123,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
|
||||
|
||||
if(doImport)
|
||||
{
|
||||
result = performImport(target, db);
|
||||
result = performImport(inputStream, db);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,7 +135,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
|
||||
|
||||
protected void onPostExecute(Boolean result)
|
||||
{
|
||||
listener.onTaskComplete(result, target);
|
||||
listener.onTaskComplete(result);
|
||||
|
||||
progress.dismiss();
|
||||
Log.i(TAG, (doImport ? "Import" : "Export") + " Complete");
|
||||
@@ -130,7 +148,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
|
||||
}
|
||||
interface TaskCompleteListener
|
||||
{
|
||||
void onTaskComplete(boolean success, File file);
|
||||
void onTaskComplete(boolean success);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
{
|
||||
public LoyaltyCardCursorAdapter(Context context, Cursor cursor)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -61,6 +62,18 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
|
||||
DBHelper db;
|
||||
|
||||
private void extractIntentFields(Intent intent)
|
||||
{
|
||||
final Bundle b = intent.getExtras();
|
||||
loyaltyCardId = b != null ? b.getInt("id") : 0;
|
||||
updateLoyaltyCard = b != null && b.getBoolean("update", false);
|
||||
viewLoyaltyCard = b != null && b.getBoolean("view", false);
|
||||
|
||||
Log.d(TAG, "View activity: id=" + loyaltyCardId
|
||||
+ ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard)
|
||||
+ ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -75,16 +88,37 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
final Bundle b = getIntent().getExtras();
|
||||
loyaltyCardId = b != null ? b.getInt("id") : 0;
|
||||
updateLoyaltyCard = b != null && b.getBoolean("update", false);
|
||||
viewLoyaltyCard = b != null && b.getBoolean("view", false);
|
||||
|
||||
Log.d(TAG, "View activity: id=" + loyaltyCardId
|
||||
+ ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard)
|
||||
+ ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard));
|
||||
extractIntentFields(getIntent());
|
||||
|
||||
db = new DBHelper(this);
|
||||
|
||||
storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit);
|
||||
storeFieldView = (TextView) findViewById(R.id.storeNameView);
|
||||
noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
|
||||
noteFieldView = (TextView) findViewById(R.id.noteView);
|
||||
cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
|
||||
cardIdDivider = findViewById(R.id.cardIdDivider);
|
||||
cardIdTableRow = findViewById(R.id.cardIdTableRow);
|
||||
barcodeTypeField = (TextView) findViewById(R.id.barcodeType);
|
||||
barcodeImage = (ImageView) findViewById(R.id.barcode);
|
||||
barcodeImageLayout = findViewById(R.id.barcodeLayout);
|
||||
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
|
||||
|
||||
captureButton = (Button) findViewById(R.id.captureButton);
|
||||
enterButton = (Button) findViewById(R.id.enterButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent)
|
||||
{
|
||||
Log.i(TAG, "Received new intent");
|
||||
extractIntentFields(intent);
|
||||
|
||||
// Reset these fields, so they are re-populated in onResume().
|
||||
storeFieldEdit.setText("");
|
||||
noteFieldEdit.setText("");
|
||||
cardIdFieldView.setText("");
|
||||
barcodeTypeField.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,21 +142,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit);
|
||||
storeFieldView = (TextView) findViewById(R.id.storeNameView);
|
||||
noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
|
||||
noteFieldView = (TextView) findViewById(R.id.noteView);
|
||||
cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
|
||||
cardIdDivider = findViewById(R.id.cardIdDivider);
|
||||
cardIdTableRow = findViewById(R.id.cardIdTableRow);
|
||||
barcodeTypeField = (TextView) findViewById(R.id.barcodeType);
|
||||
barcodeImage = (ImageView) findViewById(R.id.barcode);
|
||||
barcodeImageLayout = findViewById(R.id.barcodeLayout);
|
||||
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
|
||||
|
||||
captureButton = (Button) findViewById(R.id.captureButton);
|
||||
enterButton = (Button) findViewById(R.id.enterButton);
|
||||
|
||||
if(updateLoyaltyCard || viewLoyaltyCard)
|
||||
{
|
||||
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
|
||||
@@ -296,7 +315,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
}
|
||||
else
|
||||
{
|
||||
db.insertLoyaltyCard(store, note, cardId, barcodeType);
|
||||
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType);
|
||||
}
|
||||
|
||||
finish();
|
||||
@@ -305,10 +324,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
final Bundle b = getIntent().getExtras();
|
||||
final boolean updateLoyaltyCard = b != null && b.getBoolean("update", false);
|
||||
final boolean viewLoyaltyCard = b != null && b.getBoolean("view", false);
|
||||
|
||||
if(viewLoyaltyCard)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_view_menu, menu);
|
||||
@@ -332,9 +347,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
{
|
||||
int id = item.getItemId();
|
||||
|
||||
final Bundle b = getIntent().getExtras();
|
||||
final int loyaltyCardId = b != null ? b.getInt("id") : 0;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case android.R.id.home:
|
||||
|
||||
@@ -7,10 +7,7 @@ import android.content.ClipboardManager;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
@@ -30,7 +27,6 @@ import android.widget.Toast;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import protect.card_locker.intro.IntroActivity;
|
||||
|
||||
@@ -103,10 +103,16 @@ class ShortcutHelper
|
||||
{
|
||||
ShortcutInfo prevShortcut = list.get(index);
|
||||
|
||||
Intent shortcutIntent = prevShortcut.getIntent();
|
||||
|
||||
// Prevent instances of the view activity from piling up; if one exists let this
|
||||
// one replace it.
|
||||
shortcutIntent.setFlags(shortcutIntent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
ShortcutInfo updatedShortcut = new ShortcutInfo.Builder(context, prevShortcut.getId())
|
||||
.setShortLabel(prevShortcut.getShortLabel())
|
||||
.setLongLabel(prevShortcut.getLongLabel())
|
||||
.setIntent(prevShortcut.getIntent())
|
||||
.setIntent(shortcutIntent)
|
||||
.setIcon(Icon.createWithResource(context, R.drawable.circle))
|
||||
.setRank(index)
|
||||
.build();
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package protect.card_locker.appwidget;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import protect.card_locker.DBHelper;
|
||||
import protect.card_locker.LoyaltyCard;
|
||||
import protect.card_locker.LoyaltyCardCursorAdapter;
|
||||
import protect.card_locker.R;
|
||||
|
||||
/**
|
||||
* The configuration screen for the CardAppWidgetProvider widget.
|
||||
*/
|
||||
public class CardAppWidgetConfigure extends AppCompatActivity
|
||||
{
|
||||
static final String TAG = "LoyaltyCardLocker";
|
||||
|
||||
private static final String PREFS_NAME
|
||||
= "protect.card_locker.appwidget.CardAppWidgetProvider";
|
||||
private static final String PREF_PREFIX_KEY = "prefix_";
|
||||
|
||||
int appWidgetId_ = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle)
|
||||
{
|
||||
super.onCreate(bundle);
|
||||
|
||||
// Set the result to CANCELED. This will cause the widget host to cancel
|
||||
// out of the widget placement if they press the back button.
|
||||
setResult(RESULT_CANCELED);
|
||||
|
||||
setContentView(R.layout.main_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setVisibility(View.GONE);
|
||||
|
||||
setTitle(R.string.selectCardTitle);
|
||||
|
||||
// Find the widget id from the intent.
|
||||
Intent intent = getIntent();
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras != null)
|
||||
{
|
||||
appWidgetId_ = extras.getInt(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
}
|
||||
|
||||
// If they gave us an intent without the widget id, just bail.
|
||||
if (appWidgetId_ == AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
final DBHelper db = new DBHelper(this);
|
||||
|
||||
// If there are no cards, bail
|
||||
if(db.getLoyaltyCardCount() == 0)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
final ListView cardList = (ListView) findViewById(R.id.list);
|
||||
cardList.setVisibility(View.VISIBLE);
|
||||
|
||||
Cursor cardCursor = db.getLoyaltyCardCursor();
|
||||
|
||||
final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, cardCursor);
|
||||
cardList.setAdapter(adapter);
|
||||
|
||||
cardList.setOnItemClickListener(new AdapterView.OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
Context context = CardAppWidgetConfigure.this;
|
||||
Cursor selected = (Cursor) parent.getItemAtPosition(position);
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected);
|
||||
|
||||
Log.d(TAG, "Saving card " + loyaltyCard.store + "," + loyaltyCard.id + " at " + appWidgetId_);
|
||||
|
||||
// Save the association of the card to the widget
|
||||
saveIdPref(context, appWidgetId_, loyaltyCard.id);
|
||||
|
||||
// Push widget update to surface with newly set association
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
CardAppWidgetProvider.updateAppWidget(context, appWidgetManager, appWidgetId_);
|
||||
|
||||
// Make sure we pass back the original appWidgetId
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId_);
|
||||
setResult(RESULT_OK, resultValue);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Write the prefix to the SharedPreferences object for this widget
|
||||
static void saveIdPref(Context context, int appWidgetId, int id)
|
||||
{
|
||||
SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
|
||||
prefs.putInt(PREF_PREFIX_KEY + appWidgetId, id);
|
||||
prefs.commit();
|
||||
}
|
||||
|
||||
// Read the prefix from the SharedPreferences object for this widget.
|
||||
// If there is no preference saved, get the default from a resource
|
||||
static Integer loadIdPref(Context context, int appWidgetId)
|
||||
{
|
||||
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
|
||||
int id = prefs.getInt(PREF_PREFIX_KEY + appWidgetId, -1);
|
||||
if(id >= 0)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package protect.card_locker.appwidget;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import protect.card_locker.DBHelper;
|
||||
import protect.card_locker.LoyaltyCard;
|
||||
import protect.card_locker.LoyaltyCardViewActivity;
|
||||
import protect.card_locker.R;
|
||||
|
||||
public class CardAppWidgetProvider extends AppWidgetProvider
|
||||
{
|
||||
private static final String TAG = "LoyaltyCardLocker";
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
|
||||
{
|
||||
Log.d(TAG, "CardAppWidgetProvider onUpdate");
|
||||
// For each widget that needs an update, get the text that we should display:
|
||||
// - Create a RemoteViews object for it
|
||||
// - Set the text in the RemoteViews object
|
||||
// - Tell the AppWidgetManager to show that views object for the widget.
|
||||
for (int appWidgetId : appWidgetIds)
|
||||
{
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||
}
|
||||
}
|
||||
|
||||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
|
||||
{
|
||||
Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId);
|
||||
|
||||
LoyaltyCard card = null;
|
||||
DBHelper db = new DBHelper(context);
|
||||
|
||||
Integer id = CardAppWidgetConfigure.loadIdPref(context, appWidgetId);
|
||||
if(id != null)
|
||||
{
|
||||
Log.d(TAG, "updateAppWidget Retrieved id " + id);
|
||||
card = db.getLoyaltyCard(id);
|
||||
}
|
||||
|
||||
if(card != null)
|
||||
{
|
||||
Log.d(TAG, "updateAppWidget Updating widget " + appWidgetId + " to load " + card.store);
|
||||
|
||||
// Construct the RemoteViews object. It takes the package name (in our case, it's our
|
||||
// package, but it needs this because on the other side it's the widget host inflating
|
||||
// the layout from our package).
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
|
||||
views.setTextViewText(R.id.title, card.store);
|
||||
|
||||
// Launch the view activity when clicked
|
||||
Intent intent = new Intent(context, LoyaltyCardViewActivity.class);
|
||||
Bundle extras = new Bundle();
|
||||
extras.putInt("id", id);
|
||||
extras.putBoolean("view", true);
|
||||
intent.putExtras(extras);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
|
||||
|
||||
// Tell the widget manager
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "updateAppWidget, no card ID associated with widget " + appWidgetId
|
||||
+ ", ignoring update");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
package protect.card_locker.intro;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.github.paolorotolo.appintro.AppIntro;
|
||||
|
||||
import protect.card_locker.R;
|
||||
|
||||
|
||||
public class IntroActivity extends AppIntro
|
||||
{
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget"
|
||||
android:layout_width="60.0dip"
|
||||
android:layout_height="70.0dip">
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_gravity="start"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_width="55.0dip"
|
||||
android:layout_height="55.0dip"
|
||||
android:gravity="center_horizontal"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/icon"
|
||||
android:gravity="center_horizontal"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
|
||||
</RelativeLayout>
|
||||
@@ -65,6 +65,7 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/storeNameEdit"
|
||||
android:inputType="textCapWords"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="@dimen/inputPadding"
|
||||
@@ -121,6 +122,7 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/noteEdit"
|
||||
android:inputType="textCapSentences"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="@dimen/inputPadding"
|
||||
|
||||
@@ -26,12 +26,14 @@
|
||||
<string name="ok">OK</string>
|
||||
<string name="copy_to_clipboard">Copy ID to clipboard</string>
|
||||
<string name="sendLabel">Send…</string>
|
||||
<string name="addedShortcut">Added to Home Screen</string>
|
||||
|
||||
<string name="editCardTitle">Edit Loyalty Card</string>
|
||||
<string name="addCardTitle">Add Loyalty Card</string>
|
||||
<string name="viewCardTitle">View Loyalty Card</string>
|
||||
<string name="scanCardBarcode">Scan Card\'s Barcode</string>
|
||||
<string name="selectCardTitle">Select Card</string>
|
||||
<string name="cardShortcut">Card Shortcut</string>
|
||||
<string name="noCardsMessage">There are no cards, add one first</string>
|
||||
|
||||
<string name="barcodeImageDescription">Image of card\'s barcode</string>
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="60dp"
|
||||
android:minHeight="30dp"
|
||||
android:initialLayout="@layout/appwidget_provider"
|
||||
android:configure="protect.card_locker.appwidget.CardAppWidgetConfigure"
|
||||
android:resizeMode="horizontal"
|
||||
>
|
||||
</appwidget-provider>
|
||||
3
app/src/main/res/xml/file_provider_paths.xml
Normal file
3
app/src/main/res/xml/file_provider_paths.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<paths>
|
||||
<external-path name="exportPath" path="/" />
|
||||
</paths>
|
||||
@@ -36,7 +36,8 @@ public class DatabaseTest
|
||||
public void addRemoveOneGiftCard()
|
||||
{
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
boolean result = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -56,7 +57,8 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void updateGiftCard()
|
||||
{
|
||||
boolean result = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -86,7 +88,8 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void emptyGiftCardValues()
|
||||
{
|
||||
boolean result = db.insertLoyaltyCard("", "", "", "");
|
||||
long id = db.insertLoyaltyCard("", "", "", "");
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -107,8 +110,9 @@ public class DatabaseTest
|
||||
// that they are sorted
|
||||
for(int index = CARDS_TO_ADD-1; index >= 0; index--)
|
||||
{
|
||||
boolean result = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
|
||||
long id = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
|
||||
BarcodeFormat.UPC_A.toString());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.robolectric.annotation.Config;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
@@ -63,7 +65,8 @@ public class ImportExportTest
|
||||
{
|
||||
String storeName = String.format("store, \"%4d", index);
|
||||
String note = String.format("note, \"%4d", index);
|
||||
boolean result = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE);
|
||||
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@@ -211,17 +214,15 @@ public class ImportExportTest
|
||||
class TestTaskCompleteListener implements ImportExportTask.TaskCompleteListener
|
||||
{
|
||||
Boolean success;
|
||||
File file;
|
||||
|
||||
public void onTaskComplete(boolean success, File file)
|
||||
public void onTaskComplete(boolean success)
|
||||
{
|
||||
this.success = success;
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useImportExportTask()
|
||||
public void useImportExportTask() throws FileNotFoundException
|
||||
{
|
||||
final int NUM_CARDS = 10;
|
||||
|
||||
@@ -235,7 +236,7 @@ public class ImportExportTest
|
||||
TestTaskCompleteListener listener = new TestTaskCompleteListener();
|
||||
|
||||
// Export to the file
|
||||
ImportExportTask task = new ImportExportTask(activity, false, format, exportFile, listener);
|
||||
ImportExportTask task = new ImportExportTask(activity, format, exportFile, listener);
|
||||
task.execute();
|
||||
|
||||
// Actually run the task to completion
|
||||
@@ -244,8 +245,6 @@ public class ImportExportTest
|
||||
// Check that the listener was executed
|
||||
assertNotNull(listener.success);
|
||||
assertEquals(true, listener.success);
|
||||
assertNotNull(listener.file);
|
||||
assertEquals(exportFile, listener.file);
|
||||
|
||||
clearDatabase();
|
||||
|
||||
@@ -253,7 +252,9 @@ public class ImportExportTest
|
||||
|
||||
listener = new TestTaskCompleteListener();
|
||||
|
||||
task = new ImportExportTask(activity, true, format, exportFile, listener);
|
||||
FileInputStream fileStream = new FileInputStream(exportFile);
|
||||
|
||||
task = new ImportExportTask(activity, format, fileStream, listener);
|
||||
task.execute();
|
||||
|
||||
// Actually run the task to completion
|
||||
@@ -262,8 +263,6 @@ public class ImportExportTest
|
||||
// Check that the listener was executed
|
||||
assertNotNull(listener.success);
|
||||
assertEquals(true, listener.success);
|
||||
assertNotNull(listener.file);
|
||||
assertEquals(exportFile, listener.file);
|
||||
|
||||
assertEquals(NUM_CARDS, db.getLoyaltyCardCount());
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -29,6 +30,7 @@ import org.robolectric.android.controller.ActivityController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
Reference in New Issue
Block a user