package com.sharedhere;

import java.io.File;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.sharedhere.model.SHArrayAdapter;
import com.sharedhere.model.SHClientServer;
import com.sharedhere.model.SHLocation;

public class UploadActivity extends ListActivity {
	private File currentDirectory = null;
	private File parentDirectory = null;
	private SHLocation currentLocation = null;
	private String serverAddress = null;
	static final String ROOT_DIRECTORY = "/mnt/sdcard";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set current and parent directories to root (initially)
		currentDirectory = new File(ROOT_DIRECTORY);
		parentDirectory = currentDirectory;
		// Set current location
		currentLocation = (SHLocation) getIntent().getSerializableExtra(
				"SHLocation");
		// Process the root directory
		processDirectory();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		File file = (File) getListAdapter().getItem(position);
		if (file.isDirectory()) {
			currentDirectory = file;
			parentDirectory = file.getParentFile() == null ? new File(
					ROOT_DIRECTORY) : file.getParentFile();
			processDirectory();
		} else {
			serverAddress = getString(R.string.server_address);
			SHClientServer shConnection = new SHClientServer(serverAddress);
			// TODO CleintServer.download should return/throw boolean/exception
			// and
			// the return should be checked and the toast below be set
			// accordingly
			shConnection.upload(file.getAbsolutePath(), currentLocation,
					"Is it a game, or is it real?");
			Toast.makeText(this, "File uploaded", Toast.LENGTH_LONG).show();
		}
	}

	/**
	 * Processes the current directory Assigns the content of current directory
	 * to the upload array adapter
	 */
	private void processDirectory() {
		File[] files = currentDirectory.listFiles();
		SHArrayAdapter adapter = new SHArrayAdapter(this, files);
		setListAdapter(adapter);
	}
}

@@ -1675,16 +1675,39 @@
 ngly%0A%09%09%09
+boolean uploadStatus = 
 shConnec
@@ -1741,17 +1741,22 @@
 ePath(),
- 
+%0A%09%09%09%09%09
 currentL
@@ -1763,22 +1763,17 @@
 ocation,
-%0A%09%09%09%09%09
+ 
 %22Is it a
@@ -1797,16 +1797,38 @@
 eal?%22);%0A
+%09%09%09if (uploadStatus)%0A%09
 %09%09%09Toast
@@ -1887,16 +1887,93 @@
 show();%0A
+%09%09%09else%0A%09%09%09%09Toast.makeText(this, %22Upload failed%22, Toast.LENGTH_LONG).show();%0A
 %09%09%7D%0A%09%7D%0A%0A

Improve Upload Activity * Display a toast message if upload fails