- adding possibility to create folder during upload

This commit is contained in:
tobiasKaminsky 2014-11-01 13:41:06 +01:00
parent 8de92ba3b0
commit ccdf0f1b96
3 changed files with 100 additions and 20 deletions

View file

@ -31,10 +31,29 @@
android:layout_height="fill_parent" android:divider="@drawable/uploader_list_separator"
android:dividerHeight="1dip"></ListView>
</FrameLayout>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_alignParentBottom="true" android:layout_height="wrap_content" android:orientation="vertical">
<Button android:layout_gravity="bottom" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/uploader_choose_folder"
android:text="@string/uploader_btn_upload_text"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/uploader_new_folder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:text="@string/uploader_btn_new_folder_text" />
<Button
android:id="@+id/uploader_choose_folder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:text="@string/uploader_btn_upload_text" />
</LinearLayout>
</RelativeLayout>

View file

@ -51,6 +51,7 @@
<string name="sync_string_files">Files</string>
<string name="setup_btn_connect">Connect</string>
<string name="uploader_btn_upload_text">Upload</string>
<string name="uploader_btn_new_folder_text">New folder</string>
<string name="uploader_top_message">Choose upload folder:</string>
<string name="uploader_wrn_no_account_title">No account found</string>
<string name="uploader_wrn_no_account_text">There are no %1$s accounts on your device. Please setup an account first.</string>

View file

@ -26,25 +26,17 @@ import java.util.List;
import java.util.Stack;
import java.util.Vector;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources.NotFoundException;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
@ -59,9 +51,29 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.MoveFileOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.utils.ErrorMessageAdapter;
/**
* This can be used to upload things to an ownCloud instance.
@ -69,7 +81,7 @@ import android.widget.Toast;
* @author Bartek Przybylski
*
*/
public class Uploader extends ListActivity implements OnItemClickListener, android.view.View.OnClickListener {
public class Uploader extends FileActivity implements OnItemClickListener, android.view.View.OnClickListener {
private static final String TAG = "ownCloudUploader";
private Account mAccount;
@ -80,7 +92,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
private String mUploadPath;
private FileDataStorageManager mStorageManager;
private OCFile mFile;
private final static int DIALOG_NO_ACCOUNT = 0;
private final static int DIALOG_WAITING = 1;
private final static int DIALOG_NO_STREAM = 2;
@ -258,6 +270,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
uploadFiles();
break;
case R.id.uploader_new_folder:
CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile);
dialog.show(getSupportFragmentManager(), "createdirdialog");
break;
default:
throw new IllegalArgumentException("Wrong element clicked");
}
@ -287,6 +306,8 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
private void populateDirectoryList() {
setContentView(R.layout.uploader_layout);
ListView mListView = (ListView) findViewById(android.R.id.list);
String full_path = "";
for (String a : mParents)
@ -310,10 +331,15 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
R.layout.uploader_list_item_layout,
new String[] {"dirname"},
new int[] {R.id.textView1});
setListAdapter(sa);
Button btn = (Button) findViewById(R.id.uploader_choose_folder);
btn.setOnClickListener(this);
getListView().setOnItemClickListener(this);
mListView.setAdapter(sa);
Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
btnChooseFolder.setOnClickListener(this);
Button btnNewFolder = (Button) findViewById(R.id.uploader_new_folder);
btnNewFolder.setOnClickListener(this);
mListView.setOnItemClickListener(this);
}
}
@ -416,5 +442,39 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
super.onRemoteOperationFinish(operation, result);
if (operation instanceof CreateFolderOperation) {
onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
}
}
/**
* Updates the view associated to the activity after the finish of an operation trying create a new folder
*
* @param operation Creation operation performed.
* @param result Result of the creation.
*/
private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
dismissLoadingDialog();
populateDirectoryList();
} else {
dismissLoadingDialog();
try {
Toast msg = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
msg.show();
} catch (NotFoundException e) {
Log_OC.e(TAG, "Error while trying to show fail message " , e);
}
}
}
}