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

Some small changes to 2.1 to ensure the saved items do not upload...

Some small changes to 2.1 to ensure the saved items do not upload automatically and also have a toggle to hide/show them
parent 02a9360c
......@@ -140,27 +140,6 @@
</ImageView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView android:text="@string/upload_time_label"
android:layout_width="60dp"
android:singleLine="false"
android:layout_height="wrap_content"
android:textStyle="bold"
style="@android:style/TextAppearance.Small">
</TextView>
<TextView android:id="@+id/txtArtefactTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Small">
</TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtefactSettingsButtonLayout"
......
......@@ -77,10 +77,9 @@
android:layout_gravity="left"
android:layout_marginLeft="10dp"
/>
<TextView android:id="@+id/saved_artefacts_header"
android:text="@string/options_menu_viewsaved"
android:layout_width="fill_parent"
android:text="@string/saved"
android:layout_width="wrap_content"
android:singleLine="true"
android:layout_height="wrap_content"
style="@style/headerText"
......@@ -89,7 +88,13 @@
android:layout_toRightOf="@id/saved"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<CheckBox android:id="@+id/show_upload_ready"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/body"
android:layout_width="fill_parent"
......@@ -102,7 +107,6 @@
android:choiceMode="multipleChoice"
android:fastScrollEnabled="true"
android:layout_below="@+id/saved_artefacts_header"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:headerDividersEnabled="true"
......
......@@ -11,10 +11,12 @@
Back in MaharaDroid touch your back button, and an authentication attempt will be made.
&lt;/p&gt;
&lt;p&gt;
Once authenticated check the Menu for options on writing Journal posts and uploading files.
Once authenticated check the Menu for options on writing Journal posts.
Alternatively when taking photos, videos or recording audio look for options to \'share\' these files with MaharaDroid.
&lt;/p&gt;
</string>
<string name="saved">Saved</string>
<string name="savedanduploadready">Saved &amp; Ready for Upload</string>
<string name="artefacts_no_saved_artefacts">Nothing saved at present.</string>
<string name="options_menu_prefs">Preferences</string>
......@@ -25,8 +27,7 @@
<string name="options_menu_compose">Write</string>
<string name="options_menu_deleteall">Delete All</string>
<string name="options_menu_uploadall">Upload All</string>
<string name="options_menu_viewsaved">Saved for upload</string>
<string name="context_menu_upload">Upload</string>
<string name="context_menu_view">View</string>
<string name="context_menu_delete">Delete</string>
......
......@@ -27,6 +27,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.ui.ArtefactExpandableListAdapterActivity;
import android.app.Notification;
import android.app.NotificationManager;
......@@ -316,4 +317,31 @@ public class Utils {
return bm;
}
public static String getUploadFolderPref(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
String[][] folderItems = SyncUtils.getFolders(null, context);
if ( mPrefs.getBoolean(context.getResources().getString(R.string.pref_upload_folder_default_key), false) ) {
String folder_key = mPrefs.getString(context.getResources().getString(R.string.pref_upload_folder_key), "");
for (int i=0; i<folderItems[0].length; i++) {
if ( folder_key.equals(folderItems[0][i]) ) {
return folderItems[1][i];
}
}
}
return "";
}
public static String getUploadAuthTokenPref(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
return mPrefs.getString(context.getResources().getString(R.string.pref_auth_token_key), "");
}
public static String getUploadUsernamePref(Context context) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
return mPrefs.getString(context.getResources().getString(R.string.pref_auth_username_key), "");
}
}
......@@ -84,13 +84,13 @@ public class Artefact extends Object implements Parcelable {
public String getJournalPostId() {
return journal_post_id;
}
public boolean getIsDraft() {
public boolean isDraft() {
return is_draft;
}
public boolean getAllowComments() {
public boolean allowComments() {
return allow_comments;
}
public boolean getUploadReady() {
public boolean isUploadReady() {
return upload_ready;
}
public void setId(Long i) {
......@@ -310,9 +310,9 @@ public class Artefact extends Object implements Parcelable {
tags = ta.getTags();
journal_id = ta.getJournalId();
journal_post_id = ta.getJournalPostId();
is_draft = ta.getIsDraft();
allow_comments = ta.getAllowComments();
upload_ready = ta.getUploadReady();
is_draft = ta.isDraft();
allow_comments = ta.allowComments();
upload_ready = ta.isUploadReady();
}
public String getFilePath(Context context) {
if ( filename == null )
......
......@@ -69,21 +69,39 @@ public class ArtefactUtils {
// artefactContentProvider.release();
return a;
}
public static Artefact loadSavedArtefact(Context context, Long id) {
Artefact[] a = getArtefactsFromSelection(context, BaseColumns._ID + " = ?", new String[] { id.toString() });
if ( a != null && a.length > 0 )
return a[0];
return null;
}
public static long countArtefactsFromSelection(Context context, String selection, String[] selectionArgs) {
long items = 0;
ContentProviderClient artefactContentProvider = context.getContentResolver().acquireContentProviderClient(URI);
Cursor cursor = null;
try {
cursor = artefactContentProvider.query(URI, null, selection, selectionArgs, null);
} catch (RemoteException e) {
// TODO Auto-generated catch block
Log.e(TAG, "Failed to aquire content provider for query.");
e.printStackTrace();
}
if ( cursor == null )
return items;
items = cursor.getCount();
cursor.close();
return items;
}
public static int countSavedArtefacts(Context context) {
Artefact[] a = getArtefactsFromSelection(context, null, null);
if ( a != null )
return a.length;
return 0;
}
public static int uploadAllSavedArtefacts(Context context) {
Artefact[] a = getArtefactsFromSelection(context, null, null);
Artefact[] a = getArtefactsFromSelection(context, ArtefactContentProvider.UPLOAD_READY + " = 1 ", null);
if ( a == null )
return 0;
......@@ -94,8 +112,14 @@ public class ArtefactUtils {
return a.length;
}
public static Artefact[] loadSavedArtefacts(Context context) {
Artefact[] a = getArtefactsFromSelection(context, null, null);
public static Artefact[] loadSavedArtefacts(Context context, boolean include_ready_for_upload) {
Artefact[] a;
if ( include_ready_for_upload )
a = getArtefactsFromSelection(context, null, null );
else
a = getArtefactsFromSelection(context, ArtefactContentProvider.UPLOAD_READY + " = 0 ", null);
// while (cursor.moveToNext()) {
// Artefact a = createArtefactFromCursor(cursor);
......
......@@ -36,6 +36,7 @@ import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
......@@ -57,8 +58,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;
public class ArtefactExpandableListAdapterActivity extends Activity {
public class ArtefactExpandableListAdapterActivity extends Activity implements OnClickListener {
static final String TAG = LogConfig.getLogTag(ArtefactExpandableListAdapterActivity.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly
// for this log tag)
......@@ -73,6 +75,8 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
private ExpandableListView listview;
private CheckBox toggleContents;
ArtefactContentObserver acObserver = new ArtefactContentObserver(new Handler());
private class ArtefactContentObserver extends ContentObserver {
......@@ -105,6 +109,9 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windowtitle);
this.getContentResolver().registerContentObserver(ArtefactUtils.URI, true, acObserver);
toggleContents = (CheckBox) findViewById(R.id.show_upload_ready);
toggleContents.setOnClickListener(this);
// Load artefacts on the UI
updateView();
......@@ -127,14 +134,9 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
this.getContentResolver().unregisterContentObserver(acObserver);
}
private void updateView() {
// First lets get our DB object
// Lets see how many saved artefacts we have
Artefact[] a_array = ArtefactUtils.loadSavedArtefacts(mContext);
if ( DEBUG ) Log.d(TAG, "returned " + a_array.length + " items");
// If none then we show introduction screen
if ( a_array == null || a_array.length <= 0 ) {
if ( ArtefactUtils.countSavedArtefacts(mContext) <= 0 ) {
// Show the introduction screen
((RelativeLayout) findViewById(R.id.introduction)).setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.artefacts_help)).setText(Html.fromHtml(getString(R.string.artefacts_help)));
......@@ -142,6 +144,10 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
// Else we have some artefacts to show lets load them up in our ExpandableListAdapter
} else {
Artefact[] a_array = ArtefactUtils.loadSavedArtefacts(mContext, toggleContents.isChecked());
if ( DEBUG ) Log.d(TAG, "returned " + a_array.length + " items");
adapter = new ArtefactExpandableListAdapter(this, new ArrayList<String>(),
new ArrayList<ArrayList<Artefact>>());
listview = (ExpandableListView) findViewById(R.id.listView);
......@@ -300,8 +306,8 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
break;
}
}
((CheckBox) convertView.findViewById(R.id.txtArtefactIsDraft)).setChecked(art.getIsDraft());
((CheckBox) convertView.findViewById(R.id.txtArtefactAllowComments)).setChecked(art.getAllowComments());
((CheckBox) convertView.findViewById(R.id.txtArtefactIsDraft)).setChecked(art.isDraft());
((CheckBox) convertView.findViewById(R.id.txtArtefactAllowComments)).setChecked(art.allowComments());
}
// TDODO hide layout
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalLayout);
......@@ -386,6 +392,9 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
// Default to image - change if journal
for ( int i = 0 ; i < children.get(groupPosition).size(); i++ ) {
Artefact a = children.get(groupPosition).get(i);
if ( a.isUploadReady() ) {
tv.setTextColor(Color.GRAY);
}
if ( a.isJournal() ) {
ImageView iv = (ImageView) convertView.findViewById(R.id.artefact_icon);
iv.setImageResource(R.drawable.ic_menu_compose);
......@@ -429,4 +438,11 @@ public class ArtefactExpandableListAdapterActivity extends Activity {
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
updateView();
((TextView) findViewById(R.id.saved_artefacts_header)).setText( toggleContents.isChecked() ? R.string.savedanduploadready : R.string.saved );
}
}
\ No newline at end of file
......@@ -146,8 +146,8 @@ public class JournalSettingsActivity extends Activity implements OnClickListener
((EditText)findViewById(R.id.txtArtefactDescription)).setText(a.getDescription());
((EditText)findViewById(R.id.txtArtefactTags)).setText(a.getTags());
((EditText)findViewById(R.id.txtArtefactId)).setText(a.getId().toString());
((CheckBox)findViewById(R.id.txtArtefactIsDraft)).setChecked(a.getIsDraft());
((CheckBox)findViewById(R.id.txtArtefactAllowComments)).setChecked(a.getAllowComments());
((CheckBox)findViewById(R.id.txtArtefactIsDraft)).setChecked(a.isDraft());
((CheckBox)findViewById(R.id.txtArtefactAllowComments)).setChecked(a.allowComments());
setDefaultJournal();
......@@ -190,8 +190,8 @@ public class JournalSettingsActivity extends Activity implements OnClickListener
if ( DEBUG ) Log.d(TAG, "setting default journal to '" + journal_id + "'");
if ( a != null ) {
((CheckBox)findViewById(R.id.txtArtefactIsDraft)).setChecked(a.getIsDraft());
((CheckBox)findViewById(R.id.txtArtefactAllowComments)).setChecked(a.getAllowComments());
((CheckBox)findViewById(R.id.txtArtefactIsDraft)).setChecked(a.isDraft());
((CheckBox)findViewById(R.id.txtArtefactAllowComments)).setChecked(a.allowComments());
}
if ( i > 0 ) {
TextView tv;
......
......@@ -80,11 +80,11 @@ public class TransferService extends IntentService {
JSONObject result = RestClient.UploadArtifact(
Utils.getUploadURLPref(mContext),
getUploadAuthTokenPref(),
getUploadUsernamePref(),
Utils.getUploadAuthTokenPref(mContext),
Utils.getUploadUsernamePref(mContext),
a.getJournalId(), a.getJournalPostId(),
a.getIsDraft(), a.getAllowComments(),
getUploadFolderPref(),
a.isDraft(), a.allowComments(),
Utils.getUploadFolderPref(mContext),
a.getTags(),
a.getFilePath(mContext),
a.getTitle(),
......@@ -158,10 +158,10 @@ public class TransferService extends IntentService {
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(mContext, title, description, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
// notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// notification.flags |= Notification.DEFAULT_SOUND;
// notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// Send the notification.
mNM.notify(id, notification);
......@@ -174,31 +174,5 @@ public class TransferService extends IntentService {
}
private String getUploadFolderPref() {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String[][] folderItems = SyncUtils.getFolders(null, mContext);
if ( mPrefs.getBoolean(mContext.getResources().getString(R.string.pref_upload_folder_default_key), false) ) {
String folder_key = mPrefs.getString(mContext.getResources().getString(R.string.pref_upload_folder_key), "");
for (int i=0; i<folderItems[0].length; i++) {
if ( folder_key.equals(folderItems[0][i]) ) {
return folderItems[1][i];
}
}
}
return "";
}
private String getUploadAuthTokenPref() {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
return mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_token_key), "");
}
private String getUploadUsernamePref() {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
return mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_username_key), "");
}
}
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