Commit 86cff479 authored by Alan McNatty's avatar Alan McNatty

Merge branch 'master' of https://code.google.com/p/maharadroid

parents f4db6242 26d1b788
......@@ -5,3 +5,4 @@ gen
local.properties
build
trunk
/.settings
......@@ -225,10 +225,6 @@ public class Artefact extends Object implements Parcelable {
time = System.currentTimeMillis();
}
public Artefact(Context mContext, Long id) {
// TODO Auto-generated constructor stub
load(mContext, id);
}
public void upload(Boolean auto, Context mContext) {
Intent i = new Intent(mContext, TransferService.class);
i.putExtra("artefact", (Parcelable) this);
......@@ -250,7 +246,6 @@ public class Artefact extends Object implements Parcelable {
mContext.startActivity(i);
}
public void save(Context mContext) {
// TODO Auto-generated method stub
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
if ( id != 0 ) { // update
Log.d("Artefact", "save: is_draft: " + is_draft);
......@@ -263,9 +258,8 @@ public class Artefact extends Object implements Parcelable {
artefactData.close();
}
public void load(Context mContext, Long id) {
// TODO Auto-generated method stub
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
artefactData.loadSavedArtefacts(id);
artefactData.loadSavedArtefact(id);
artefactData.close();
}
public String getFilePath(Context context) {
......
......@@ -102,65 +102,79 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
}
}
public void uploadAllSavedArtefacts(Boolean uploaded) {
SQLiteDatabase db = this.getReadableDatabase();
if ( uploaded == null ) {
uploaded = false;
}
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null,
null, null);
if ( VERBOSE ) Log.v(TAG, "uploadAllSavedArtefacts: returned " + cursor.getCount() + " records.");
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
a.upload(true, mContext);
public void uploadAllSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (VERBOSE) Log.v(TAG, "uploadAllSavedArtefacts: returned " + cursor.getCount() + " records.");
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
a.upload(true, mContext);
}
} finally {
cursor.close();
}
}
public Artefact loadSavedArtefacts(Long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, BaseColumns._ID + " = ?", new String[] { id.toString() },
null, null, null);
if ( cursor == null )
return null;
cursor.moveToFirst();
return createArtefactFromCursor(cursor);
public Artefact loadSavedArtefact(Long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, BaseColumns._ID + " = ?",
new String[] { id.toString() }, null, null, null);
try {
if (cursor == null)
return null;
cursor.moveToFirst();
return createArtefactFromCursor(cursor);
} finally {
cursor.close();
}
}
public Artefact[] loadSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
//startManagingCursor(cursor);
if ( cursor == null )
return new Artefact[] {};// TODO why different from above?
SQLiteDatabase db = this.getReadableDatabase();
//startManagingCursor(cursor);
Artefact[] a_array = new Artefact[cursor.getCount()];
int items = 0;
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
// Only include artefacts with either no attached file or valid files (may have been deleted in the background so we check)
if ( a.getFilename() == null ||
( a.getFilename() != null && a.getFilePath(mContext) != null ) ) {
a_array[items++] = a;
} else {
Log.i(TAG, "Artefact '" + a.getTitle() +
"' file [" + a.getFilename() +
"] no longer exists, deleting from saved artefacts");
this.deleteSavedArtefact(a.getId());
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (cursor == null)
return new Artefact[] {};// TODO why different from above?
Artefact[] a_array = new Artefact[cursor.getCount()];
int items = 0;
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
// Only include artefacts with either no attached file or valid
// files (may have been deleted in the background so we check)
if (a.getFilename() == null
|| (a.getFilename() != null && a.getFilePath(mContext) != null)) {
a_array[items++] = a;
} else {
Log.i(TAG, "Artefact '" + a.getTitle() + "' file [" + a.getFilename()
+ "] no longer exists, deleting from saved artefacts");
this.deleteSavedArtefact(a.getId());
}
}
return a_array;
} finally {
cursor.close();
}
return a_array;
}
private Artefact createArtefactFromCursor(Cursor cursor) {
if ( VERBOSE ) Log.v(TAG, "createArtefactFromCursor draft: " + cursor.getInt(8));
if ( VERBOSE ) Log.v(TAG, "createArtefactFromCursor allow comments: " + cursor.getInt(9));
......
......@@ -18,7 +18,6 @@ public class MaharaProvider extends ContentProvider {
private static final String DATABASE_NAME = "maharadroid_sync.db";
private static final int DATABASE_VERSION = 1;
private static final String TAG = "MyContentProvider";
private static class DatabaseHelper extends SQLiteOpenHelper {
......
......@@ -105,7 +105,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
if ( VERBOSE ) Log.v(TAG, "onPerformSync: canUpload so uploadAllSavedArtefacts");
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
artefactData.uploadAllSavedArtefacts(false);
artefactData.uploadAllSavedArtefacts();
artefactData.close();
}
} else {
......
......@@ -175,7 +175,7 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
loadSavedArtefacts();
break;
case R.id.option_upload:
artefactData.uploadAllSavedArtefacts(true);
artefactData.uploadAllSavedArtefacts();
loadSavedArtefacts();
break;
case R.id.about:
......
......@@ -54,7 +54,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
/*
/**
* The ArtifactSettings class is based on the PictureSettings class,
* it has been modified to only support upload components. The original was
* written by Russel Stewart (rnstewart@gmail.com) as part of the Flickr Free
......@@ -62,7 +62,6 @@ import android.widget.Toast;
*
* @author Alan McNatty (alan.mcnatty@catalyst.net.nz)
*/
public class ArtifactSettingsActivity extends Activity implements OnClickListener {
static final String TAG = LogConfig.getLogTag(ArtifactSettingsActivity.class);
......@@ -287,7 +286,6 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
boolean allow_comments = ((CheckBox) findViewById(R.id.txtArtefactAllowComments)).isChecked();
if ( id != null && id.length() > 0 ) {
a.load(mContext, Long.valueOf(id));
a.setTitle(title);
a.setDescription(description);
a.setTags(tags);
......@@ -489,7 +487,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
tgs.setText(TextUtils.join(",", new_tags));
}
public void onNothingSelected(AdapterView parent) {
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}
......@@ -503,7 +501,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
l.setVisibility( pos > 0 ? LinearLayout.VISIBLE : LinearLayout.GONE );
}
public void onNothingSelected(AdapterView parent) {
public void onNothingSelected(AdapterView<?> parent) {
LinearLayout l;
l = (LinearLayout) findViewById(R.id.ArtefactJournalExtrasLayout);
l.setVisibility( LinearLayout.GONE );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment