Commit 7ae9ef3e authored by Alan McNatty's avatar Alan McNatty
Browse files

1. Reworked the main UI (artefacts) to switch out if no artefacts remain.

   - Help text to be included.
2. Fixed a NPE bug in the httpclient if a space or similar exists in the post URI
3. Adjusted the onActivityResult method to support attaching multiple files
parent 4b4602dc
...@@ -3,63 +3,113 @@ ...@@ -3,63 +3,113 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="right" > android:gravity="right" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/body_heading" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/introduction"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="2dip"
style="@style/headerBackground" style="@style/headerBackground"
> android:visibility="visible"
<ImageView >
android:id="@+id/saved"
<ImageView
android:id="@+id/banner"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/saved" android:layout_margin="5dp"
android:layout_gravity="left" android:src="@drawable/banner"
android:layout_marginLeft="10dp"
/>
<TextView android:id="@+id/saved_artefacts_header"
android:text="@string/options_menu_viewsaved"
android:layout_width="fill_parent"
android:singleLine="true"
android:layout_height="wrap_content"
style="@style/headerText"
android:layout_marginLeft="10dp"
android:gravity="left|bottom"
android:layout_toRightOf="@id/saved"
android:layout_centerInParent="true"
/> />
<TextView android:id="@+id/artefacts_banner_text"
android:text="@string/artefacts_banner_text"
android:layout_width="wrap_content"
android:singleLine="false"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_margin="5dp"
style="@android:style/TextAppearance.Large"
android:layout_below="@+id/banner"
/>
<TextView android:id="@+id/artefacts_banner_text2"
android:text="@string/artefacts_banner_text2"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:singleLine="false"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Small"
android:layout_below="@+id/artefacts_banner_text"
/>
<TextView android:text="@string/artefacts_help"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:singleLine="false"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Small"
android:layout_below="@+id/artefacts_banner_text2"
/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/body" android:id="@+id/artefacts"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/body_heading" android:padding="2dip"
android:layout_margin="5dp" style="@style/headerBackground"
> android:visibility="visible"
<ExpandableListView android:id="@+id/listView" android:layout_below="@+id/introduction"
android:scrollbars="none" >
android:choiceMode="multipleChoice"
android:fastScrollEnabled="true" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="@+id/saved_artefacts_header" android:id="@+id/body_heading"
android:layout_weight="1" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="fill_parent" style="@style/headerBackground"
android:visibility="gone" >
android:headerDividersEnabled="true" <ImageView
android:footerDividersEnabled="true" android:id="@+id/saved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/saved"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
/> />
<!-- android:groupIndicator="@drawable/expander_group" -->
<TextView android:id="@+id/no_saved_artefacts" <TextView android:id="@+id/saved_artefacts_header"
android:text="@string/artefacts_no_saved_artefacts" android:text="@string/options_menu_viewsaved"
android:layout_margin="0dp" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:singleLine="true"
android:singleLine="true" android:layout_height="wrap_content"
android:layout_height="wrap_content" style="@style/headerText"
style="@android:style/TextAppearance.Small" android:layout_marginLeft="10dp"
android:layout_below="@+id/listView" android:gravity="left|bottom"
android:visibility="gone" android:layout_toRightOf="@id/saved"
/> android:layout_centerInParent="true"
/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/body_heading"
android:layout_margin="5dp"
>
<ExpandableListView android:id="@+id/listView"
android:scrollbars="none"
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"
android:footerDividersEnabled="true"
/>
<!-- android:groupIndicator="@drawable/expander_group" -->
</RelativeLayout>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
>
<ImageView
android:id="@+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:src="@drawable/banner"
/>
<TextView android:text="Open source eportfolios"
android:layout_width="wrap_content"
android:singleLine="false"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_margin="5dp"
style="@android:style/TextAppearance.Large"
/>
<TextView android:text="[mah-har-rah;verb]: to think, thinking, thought"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:singleLine="false"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Small"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/context_upload"
android:icon="@android:drawable/ic_menu_upload"
android:title="@string/context_menu_upload" />
<item android:id="@+id/context_view"
android:icon="@android:drawable/ic_menu_view"
android:title="@string/context_menu_view" />
<item android:id="@+id/context_delete"
android:icon="@android:drawable/ic_delete"
android:title="@string/context_menu_delete" />
</menu>
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<string name="artefacts_banner_text">Open source ePortfolios</string> <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_banner_text2">[mah-har-rah;verb]: to think, thinking, thought</string>
<string name="artefacts_help">
</string>
<string name="artefacts_no_saved_artefacts">Nothing saved.</string> <string name="artefacts_no_saved_artefacts">Nothing saved.</string>
<string name="options_menu_prefs">Preferences</string> <string name="options_menu_prefs">Preferences</string>
......
...@@ -29,6 +29,7 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -29,6 +29,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
/** Helper to the database, manages versions and creation */ /** Helper to the database, manages versions and creation */
public class ArtefactDataSQLHelper extends SQLiteOpenHelper { public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
...@@ -137,6 +138,21 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper { ...@@ -137,6 +138,21 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
cursor.close(); cursor.close();
} }
} }
public int countSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
int count = 0;
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (cursor == null)
return count;
return cursor.getCount();
} finally {
cursor.close();
}
}
public Artefact[] loadSavedArtefacts() { public Artefact[] loadSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
...@@ -161,8 +177,8 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper { ...@@ -161,8 +177,8 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
|| (a.getFilename() != null && a.getFilePath(mContext) != null)) { || (a.getFilename() != null && a.getFilePath(mContext) != null)) {
a_array[items++] = a; a_array[items++] = a;
} else { } else {
Log.i(TAG, "Artefact '" + a.getTitle() + "' file [" + a.getFilename() Log.w(TAG, "File '" + a.getTitle() + "' does not exist on the device, deleting from saved artefacts");
+ "] no longer exists, deleting from saved artefacts"); Toast.makeText(mContext, "File '" + a.getTitle() + "' does not exist on the device, deleting from saved artefacts", Toast.LENGTH_LONG);
this.deleteSavedArtefact(a.getId()); this.deleteSavedArtefact(a.getId());
} }
} }
......
...@@ -40,28 +40,24 @@ import android.os.Bundle; ...@@ -40,28 +40,24 @@ import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener; import android.view.Window;
import android.widget.BaseExpandableListAdapter; import android.widget.BaseExpandableListAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class ArtefactExpandableListAdapterActivity extends Activity implements OnCreateContextMenuListener { public class ArtefactExpandableListAdapterActivity extends Activity {
static final String TAG = LogConfig.getLogTag(ArtefactExpandableListAdapterActivity.class); static final String TAG = LogConfig.getLogTag(ArtefactExpandableListAdapterActivity.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly // whether DEBUG level logging is enabled (whether globally, or explicitly
// for this log tag) // for this log tag)
...@@ -74,44 +70,42 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -74,44 +70,42 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
private ArtefactDataSQLHelper artefactData; private ArtefactDataSQLHelper artefactData;
//private ArrayList<Artefact> items = new ArrayList<Artefact>(); //private ArrayList<Artefact> items = new ArrayList<Artefact>();
private ArtefactExpandableListAdapter adapter;
private ExpandableListAdapter adapter;
private ExpandableListView listview; private ExpandableListView listview;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.artefacts);
mContext = this; mContext = this;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.artefacts);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windowtitle); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.windowtitle);
((TextView) findViewById(R.id.windowtitle_text)).setText(getString(R.string.app_name)); adapter = new ArtefactExpandableListAdapter(this, new ArrayList<String>(),
// ((ImageView) findViewById(R.id.windowtitle_icon)).setVisibility(View.GONE); new ArrayList<ArrayList<Artefact>>());
listview = (ExpandableListView) findViewById(R.id.listView); listview = (ExpandableListView) findViewById(R.id.listView);
// listview.setOnChildClickListener(this); listview.setAdapter(adapter);
registerForContextMenu(listview);
// if ( DEBUG ) Log.d(TAG, "onCreate() calls loadSavedArtefacts");
// loadSavedArtefacts(); // A content view has now be set so lets set the title.
((TextView) findViewById(R.id.windowtitle_text)).setText(getString(R.string.app_name));
if ( VERBOSE ) Log.v(TAG, "onCreate() called");
} }
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if ( DEBUG ) Log.d(TAG, "onResume() calls loadSavedArtefacts"); if ( VERBOSE ) Log.v(TAG, "onResume() calls loadSavedArtefacts");
//TODO remove this db access stuff with wrapper class or move to Arefact
loadSavedArtefacts(); updateView();
} }
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// if ( DEBUG ) Log.d(TAG, "onStart() calls loadSavedArtefacts"); if ( VERBOSE ) Log.v(TAG, "onStart() called");
//
// loadSavedArtefacts();
} }
@Override @Override
...@@ -127,39 +121,39 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -127,39 +121,39 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
super.onDestroy(); super.onDestroy();
} }
private Integer loadSavedArtefacts() { private void updateView() {
adapter = new ExpandableListAdapter(this, new ArrayList<String>(), // First lets get our DB object
new ArrayList<ArrayList<Artefact>>());
//TODO remove this db access stuff with wrapper class or move to Arefact
if ( artefactData == null ) if ( artefactData == null )
artefactData = new ArtefactDataSQLHelper(this); artefactData = new ArtefactDataSQLHelper(this);
// Lets see how many saved artefacts we have
Artefact[] a_array = artefactData.loadSavedArtefacts(); Artefact[] a_array = artefactData.loadSavedArtefacts();
if ( DEBUG ) Log.d(TAG, "returned " + a_array.length + " items"); if ( DEBUG ) Log.d(TAG, "returned " + a_array.length + " items");
for ( int i = 0; i < a_array.length && a_array[i] != null; i++ ) { // If none then we show introduction screen
if ( DEBUG ) Log.d(TAG, "adding item " + a_array[i].getFilename() + " [" + i + "]"); if ( a_array == null || a_array.length <= 0 ) {
adapter.addItem(a_array[i]); // Show the introduction screen
} ((RelativeLayout) findViewById(R.id.introduction)).setVisibility(View.VISIBLE);
((RelativeLayout) findViewById(R.id.artefacts)).setVisibility(View.GONE);
if ( a_array.length > 0 ) {
listview.setVisibility(View.VISIBLE); // Else we have some artefacts to show lets load them up in our ExpandableListAdapter
((TextView) findViewById(R.id.no_saved_artefacts)).setVisibility(View.GONE); } else {
} else { // Hide the introduction bits
listview.setVisibility(View.GONE); ((RelativeLayout) findViewById(R.id.introduction)).setVisibility(View.GONE);
((TextView) findViewById(R.id.no_saved_artefacts)).setVisibility(View.VISIBLE); ((RelativeLayout) findViewById(R.id.artefacts)).setVisibility(View.VISIBLE);
}
for ( int i = 0; i < a_array.length && a_array[i] != null; i++ ) {
// Set this blank adapter to the list view if ( DEBUG ) Log.d(TAG, "adding item " + a_array[i].getFilename() + " [" + i + "]");
listview.setAdapter(adapter); adapter.addItem(a_array[i]);
// notifiyDataSetChanged triggers the re-draw }
adapter.notifyDataSetChanged();
// notifiyDataSetChanged triggers the re-draw
//TODO remove this db access stuff with wrapper class or move to Artefact // Set this blank adapter to the list view
artefactData.close(); adapter.notifyDataSetChanged();
listview.invalidate();
return a_array.length; }
} }
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu); boolean result = super.onCreateOptionsMenu(menu);
...@@ -174,11 +168,11 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -174,11 +168,11 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.option_delete: case R.id.option_delete:
artefactData.deleteAllSavedArtefacts(); artefactData.deleteAllSavedArtefacts();
loadSavedArtefacts(); updateView();
break; break;
case R.id.option_upload: case R.id.option_upload:
artefactData.uploadAllSavedArtefacts(); artefactData.uploadAllSavedArtefacts();
loadSavedArtefacts(); updateView();
break; break;
case R.id.about: case R.id.about:
startActivity(new Intent(this, AboutActivity.class)); startActivity(new Intent(this, AboutActivity.class));
...@@ -232,31 +226,29 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -232,31 +226,29 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
} }
} }
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
adapter.onCreateContextMenu(menu, v, menuInfo); // adapter.onCreateContextMenu(menu, v, menuInfo);
} // }
public boolean onContextItemSelected(MenuItem item) { // public boolean onContextItemSelected(MenuItem item) {
adapter.onContextItemSelected(item); // adapter.onContextItemSelected(item);
return false; // return false;
} // }
public class ArtefactExpandableListAdapter extends BaseExpandableListAdapter implements OnClickListener {
public class ExpandableListAdapter extends BaseExpandableListAdapter implements OnClickListener, OnCreateContextMenuListener {
@Override @Override
public boolean areAllItemsEnabled() public boolean areAllItemsEnabled()
{ {
return true; return true;
} }
private Context eContext; private Context mContext;
private ArrayList<String> groups; private ArrayList<String> groups;
private ArrayList<ArrayList<Artefact>> children; private ArrayList<ArrayList<Artefact>> children;
public ExpandableListAdapter(Context context, ArrayList<String> groups, public ArtefactExpandableListAdapter(Context context, ArrayList<String> groups,
ArrayList<ArrayList<Artefact>> children) { ArrayList<ArrayList<Artefact>> children) {
this.eContext = context; this.mContext = context;
this.groups = groups; this.groups = groups;
this.children = children; this.children = children;
} }
...@@ -264,6 +256,7 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -264,6 +256,7 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
public void addItem(Artefact art) { public void addItem(Artefact art) {
if (!groups.contains(art.getGroup())) { if (!groups.contains(art.getGroup())) {
groups.add(art.getGroup()); groups.add(art.getGroup());
if ( VERBOSE ) Log.v(TAG, "adding item '" + art.getGroup() + "'");
} }
int index = groups.indexOf(art.getGroup()); int index = groups.indexOf(art.getGroup());
if (children.size() < index + 1) { if (children.size() < index + 1) {
...@@ -289,16 +282,16 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -289,16 +282,16 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
View convertView, ViewGroup parent) { View convertView, ViewGroup parent) {
Artefact art = (Artefact) getChild(groupPosition, childPosition); Artefact art = (Artefact) getChild(groupPosition, childPosition);
if (convertView == null) { if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) eContext LayoutInflater infalInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.artefact_row_child, null); convertView = infalInflater.inflate(R.layout