Commit f58a9c63 authored by Alan McNatty's avatar Alan McNatty
Browse files

ve the contentprovider / Manifest set-up working finally .. curors responding...

ve the contentprovider / Manifest set-up working finally .. curors responding with data and loading (beta) into ListPreferences .. enabling users to choose a default from sync'ed data.

Next will be showing sync'ed data on the upload form (mainly a journal spinner). Then we can focus back on extending the Mahara upload api to support journals.
parent bba1a4f3
......@@ -98,10 +98,12 @@
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
<provider android:name=".provider.MaharaProvider"
android:authorities="nz.net.catalyst" android:enabled="true">
</provider>
<provider android:name="nz.net.catalyst.MaharaDroid.provider.MaharaProvider"
android:authorities="nz.net.catalyst.MaharaDroid"
android:label="MaharaDroid"
android:syncable="true"
android:enabled="true">
</provider>
</application>
<!-- API Level 4 aka 1.6 required for multi-send support -->
<!-- API Level 5 aka 2.0 required for Account & Sync support -->
......
......@@ -4,12 +4,12 @@
<string name="artefacts_banner_text">Open source ePortfolios</string>
<string name="artefacts_banner_text2">[mah-har-rah;verb]: to think, thinking, thought</string>
<string name="artefacts_no_saved_artefacts">No saved artefacts</string>
<string name="artefacts_no_saved_artefacts">Nothing saved.</string>
<string name="options_menu_prefs">Preferences</string>
<string name="options_menu_deleteall">Delete All</string>
<string name="options_menu_uploadall">Upload All</string>
<string name="options_menu_viewsaved">Saved Files</string>
<string name="options_menu_viewsaved">Saved</string>
<string name="context_menu_upload">Upload</string>
<string name="context_menu_view">View</string>
......@@ -37,36 +37,15 @@
<string name="pref_upload_journal_key">upload.journal</string>
<string name="pref_upload_journal_title">Journal</string>
<string name="pref_upload_journal_summary">Enter the Journal to post to</string>
<string name="pref_upload_journal_default">My Mobile Journal</string>
<string-array name="pref_upload_journal_entry">
<item>My Mobile Journal</item>
</string-array>
<string-array name="pref_upload_journal_entryValues">
<item>My Mobile Journal</item>
</string-array>
<string name="pref_upload_journal_summary">Select the default journal to post to</string>
<string name="pref_upload_folder_key">upload.folder</string>
<string name="pref_upload_folder_title">Upload Folder</string>
<string name="pref_upload_folder_summary">Enter the (base) folder to upload your artefacts into</string>
<string name="pref_upload_folder_default">MobileUploads</string>
<string-array name="pref_upload_folder_entry">
<item>MobileUploads</item>
</string-array>
<string-array name="pref_upload_folder_entryValues">
<item>MobileUploads</item>
</string-array>
<string name="pref_upload_folder_summary">Select the default folder to upload your files into</string>
<string name="pref_upload_tags_key">upload.tags</string>
<string name="pref_upload_tags_title">Artefact Tags</string>
<string name="pref_upload_tags_summary">Enter the tags (space separated) to add to all uploaded artefacts</string>
<string name="pref_upload_tags_default">Android</string>
<string-array name="pref_upload_tags_entry">
<item>Android</item>
</string-array>
<string-array name="pref_upload_tags_entryValues">
<item>Android</item>
</string-array>
<string name="pref_upload_tags_title">Tags</string>
<string name="pref_upload_tags_summary">Select the default tag to add to all uploaded files/journals</string>
<string name="pref_upload_connection_key">upload.connection</string>
<string name="pref_upload_connection_title">Connection Type</string>
......@@ -96,15 +75,15 @@
<string name="lbluploadoptions">Upload Settings</string>
<string name="artifact_retrieve_error">Error Retrieving File Details</string>
<string name="artifact_retrieve_error">Error Retrieving Details</string>
<string name="artifactsettings">Settings</string>
<string name="transferprogress">File Transfer Progress</string>
<string name="transferprogress">Upload progress</string>
<string name="uploadstarting">Your Upload is Starting</string>
<string name="uploadfinished">Your Upload is Finished</string>
<string name="uploadfailed">Upload failed</string>
<string name="savefailed">Save failed</string>
<string name="uploadsaved">Upload saved</string>
<string name="uploadnotavailable">Sorry you can only uploaded files as artefacts.</string>
<string name="uploadnotavailable">Sorry you can only uploaded files.</string>
<string name="uploadingartifact">Uploading ...</string>
<string name="uploading">Uploading</string>
<string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string>
......
......@@ -28,27 +28,18 @@
android:key="@string/pref_upload_journal_key"
android:title="@string/pref_upload_journal_title"
android:summary="@string/pref_upload_journal_summary"
android:defaultValue="@string/pref_upload_journal_default"
android:entries="@array/pref_upload_journal_entry"
android:entryValues="@array/pref_upload_journal_entryValues"
android:dialogTitle="@string/pref_upload_journal_title" />
<ListPreference
android:key="@string/pref_upload_folder_key"
android:title="@string/pref_upload_folder_title"
android:summary="@string/pref_upload_folder_summary"
android:defaultValue="@string/pref_upload_folder_default"
android:entries="@array/pref_upload_folder_entry"
android:entryValues="@array/pref_upload_folder_entryValues"
android:dialogTitle="@string/pref_upload_folder_title" />
<ListPreference
android:key="@string/pref_upload_tags_key"
android:title="@string/pref_upload_tags_title"
android:summary="@string/pref_upload_tags_summary"
android:defaultValue="@string/pref_upload_tags_default"
android:entries="@array/pref_upload_tags_entry"
android:entryValues="@array/pref_upload_tags_entryValues"
android:dialogTitle="@string/pref_upload_tags_title" />
<ListPreference
......
<!-- API Version 7 requires the accountType attribute to be hard-coded as a string -->
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="nz.net.catalyst"
android:contentAuthority="nz.net.catalyst.MaharaDroid"
android:accountType="nz.net.catalyst.MaharaDroid.account"/>
\ No newline at end of file
......@@ -50,8 +50,8 @@ public class GlobalResources {
public static final String ACCOUNT_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String AUTHTOKEN_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String CONTENT_URL = "nz.net.catalyst.MaharaDroid.provider";
public static final String SYNC_AUTHORITY = "nz.net.catalyst";
public static final String CONTENT_URL = "nz.net.catalyst.MaharaDroid";
public static final String SYNC_AUTHORITY = "nz.net.catalyst.MaharaDroid";
public static final int REGISTRATION_TIMEOUT = 30 * 1000; // ms
}
\ No newline at end of file
......@@ -241,7 +241,7 @@ public class Utils {
int items = jsonArray.length();
ContentValues[] cv = new ContentValues[items];
Uri uri = Uri.parse(GlobalResources.CONTENT_URL + "/" + fieldName);
Uri uri = Uri.parse("content://" + GlobalResources.CONTENT_URL + "/" + fieldName);
Log.i(TAG, jsonArray.toString());
......@@ -249,9 +249,11 @@ public class Utils {
String value = jsonArray.getJSONObject(i).getString(fieldName);
String id = jsonArray.getJSONObject(i).getString("id");
Log.i(TAG, "id: " + id + ", value: " + value);
Log.v(TAG, "saving " + fieldName + " [ id: " + id + ", value: " + value + "]");
//if ( myProvider.query(uri, null, null, null, null) != null ) {
// test provider query
myProvider.query(uri, null, null, null, null);
if ( cv[i] == null )
cv[i] = new ContentValues();
......
......@@ -91,8 +91,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
if (mRequestNewAccount) {
mAccountManager.addAccountExplicitly(account, null, null);
// Set contacts sync for this account.
ContentResolver.setSyncAutomatically(account, MaharaProvider.AUTHORITY, true);
ContentResolver.setIsSyncable(account, MaharaProvider.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, GlobalResources.SYNC_AUTHORITY, true);
ContentResolver.setIsSyncable(account, GlobalResources.SYNC_AUTHORITY, 1);
}
final Intent intent = new Intent();
......
package nz.net.catalyst.MaharaDroid.provider;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import android.content.ContentProvider;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
......@@ -14,8 +12,6 @@ import android.net.Uri;
public class MaharaProvider extends ContentProvider {
public static final String AUTHORITY = GlobalResources.SYNC_AUTHORITY;
private SQLiteDatabase sqlDB;
private DatabaseHelper dbHelper;
......
......@@ -44,6 +44,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
......@@ -57,19 +58,24 @@ import org.xml.sax.helpers.DefaultHandler;
import com.google.zxing.integration.android.IntentIntegrator;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
......@@ -93,6 +99,49 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
loadPreferenceLists(getResources().getString(R.string.pref_upload_journal_key), "blog");
loadPreferenceLists(getResources().getString(R.string.pref_upload_tags_key), "tag");
loadPreferenceLists(getResources().getString(R.string.pref_upload_folder_key), "folder");
}
private void loadPreferenceLists(String pref_key, String pref_table) {
ContentResolver cr = this.getContentResolver();
Uri uri = Uri.parse("content://" + GlobalResources.CONTENT_URL + "/" + pref_table);
Cursor cursor = cr.query(uri, new String[] { "ID", "VALUE" }, null, null, null);
ListPreference lp = (ListPreference) findPreference(pref_key);
if (lp != null && cursor != null) {
//if ( DEBUG ) Log.d(TAG, "cursor query succeeded [" + cursor.getCount() + " rows, " + cursor.getColumnCount() + " columns]");
try {
cursor.moveToFirst();
CharSequence entries[] = new String[cursor.getCount()];
CharSequence entryValues[] = new String[cursor.getCount()];
int i = 0;
while(!cursor.isAfterLast()) {
//if ( DEBUG ) Log.d(TAG, "row [" + i + "]");
entryValues[i] = cursor.getString(0);
entries[i] = cursor.getString(1);
i++;
cursor.moveToNext();
}
cursor.close();
lp.setEntries(entries);
lp.setEntryValues(entryValues);
} catch ( android.database.CursorIndexOutOfBoundsException e ) {
if ( DEBUG ) Log.d(TAG, "couldn't get file_path from cursor");
return;
}
} else {
if ( DEBUG ) Log.d(TAG, "cursor query failed");
return;
}
}
@Override
......
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