mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Fixed bug: depecrated showdialog should not be used anymore, DialogFragment used instead
This commit is contained in:
parent
15512f8d63
commit
8aa0060f4a
4 changed files with 235 additions and 98 deletions
|
@ -61,7 +61,6 @@ import com.owncloud.android.operations.SynchronizeFolderOperation;
|
|||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.services.OperationsService;
|
||||
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
|
||||
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.LoadingDialog;
|
||||
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
|
||||
import com.owncloud.android.utils.ErrorMessageAdapter;
|
||||
|
@ -176,41 +175,49 @@ public class FileActivity extends SherlockFragmentActivity
|
|||
*/
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
Log_OC.v(TAG, "onRestart() start");
|
||||
super.onRestart();
|
||||
boolean validAccount = (mAccount != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name));
|
||||
boolean validAccount =
|
||||
(mAccount != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name));
|
||||
if (!validAccount) {
|
||||
swapToDefaultAccount();
|
||||
}
|
||||
Log_OC.v(TAG, "onRestart() end");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
Log_OC.v(TAG, "onStart() start");
|
||||
super.onStart();
|
||||
|
||||
if (mAccountWasSet) {
|
||||
onAccountSet(mAccountWasRestored);
|
||||
}
|
||||
Log_OC.v(TAG, "onStart() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log_OC.v(TAG, "onResume() start");
|
||||
super.onResume();
|
||||
|
||||
if (mOperationsServiceBinder != null) {
|
||||
doOnResumeAndBound();
|
||||
}
|
||||
|
||||
Log_OC.v(TAG, "onResume() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
|
||||
Log_OC.v(TAG, "onPause() start");
|
||||
|
||||
if (mOperationsServiceBinder != null) {
|
||||
mOperationsServiceBinder.removeOperationListener(this);
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
Log_OC.v(TAG, "onPause() end");
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,7 +252,8 @@ public class FileActivity extends SherlockFragmentActivity
|
|||
*/
|
||||
protected void setAccount(Account account, boolean savedAccount) {
|
||||
Account oldAccount = mAccount;
|
||||
boolean validAccount = (account != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account.name));
|
||||
boolean validAccount =
|
||||
(account != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account.name));
|
||||
if (validAccount) {
|
||||
mAccount = account;
|
||||
mAccountWasSet = true;
|
||||
|
@ -546,7 +554,9 @@ public class FileActivity extends SherlockFragmentActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) {
|
||||
private void onSynchronizeFolderOperationFinish(
|
||||
SynchronizeFolderOperation operation, RemoteOperationResult result
|
||||
) {
|
||||
if (!result.isSuccess() && result.getCode() != ResultCode.CANCELLED){
|
||||
Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
||||
Toast.LENGTH_LONG);
|
||||
|
|
|
@ -56,7 +56,6 @@ import android.provider.OpenableColumns;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
@ -100,6 +99,7 @@ import com.owncloud.android.syncadapter.FileSyncAdapter;
|
|||
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
|
||||
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
|
||||
import com.owncloud.android.ui.dialog.UploadSourceDialogFragment;
|
||||
import com.owncloud.android.ui.fragment.FileDetailFragment;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
import com.owncloud.android.ui.fragment.OCFileListFragment;
|
||||
|
@ -142,8 +142,8 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
|
||||
public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
|
||||
|
||||
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
|
||||
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
|
||||
public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
|
||||
public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
|
||||
public static final int ACTION_MOVE_FILES = 3;
|
||||
|
||||
private static final String TAG = FileDisplayActivity.class.getSimpleName();
|
||||
|
@ -214,8 +214,10 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
Log_OC.d(TAG, "onStart() start");
|
||||
super.onStart();
|
||||
getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
|
||||
Log_OC.d(TAG, "onStart() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -478,9 +480,8 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
boolean retval = true;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_create_dir: {
|
||||
CreateFolderDialogFragment dialog =
|
||||
CreateFolderDialogFragment.newInstance(getCurrentDir());
|
||||
dialog.show(getSupportFragmentManager(), "createdirdialog");
|
||||
CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(getCurrentDir());
|
||||
dialog.show(getSupportFragmentManager(), "createDirDialog");
|
||||
break;
|
||||
}
|
||||
case R.id.action_sync_account: {
|
||||
|
@ -488,7 +489,10 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
break;
|
||||
}
|
||||
case R.id.action_upload: {
|
||||
showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);
|
||||
//showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE);
|
||||
UploadSourceDialogFragment dialog = UploadSourceDialogFragment.newInstance(getAccount());
|
||||
dialog.show(getSupportFragmentManager(), "uploadSourceDialog");
|
||||
|
||||
break;
|
||||
}
|
||||
case R.id.action_settings: {
|
||||
|
@ -608,8 +612,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
*
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Log_OC.e(TAG, "ON ACTIVITIRESULT IN FILE_DISPLAY_ACTIVITY");
|
||||
|
||||
if (requestCode == ACTION_SELECT_CONTENT_FROM_APPS && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
|
||||
//getClipData is only supported on api level 16+, Jelly Bean
|
||||
|
@ -638,7 +643,11 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
},
|
||||
DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
|
||||
);
|
||||
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void requestMultipleUpload(Intent data, int resultCode) {
|
||||
|
@ -723,7 +732,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
if (cursor != null && cursor.moveToFirst()) {
|
||||
String displayName = cursor.getString(
|
||||
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
Log.i(TAG, "Display Name: " + displayName + "; mimeType: " + mimeType);
|
||||
Log_OC.i(TAG, "Display Name: " + displayName + "; mimeType: " + mimeType);
|
||||
|
||||
displayName.replace(File.separatorChar, '_');
|
||||
displayName.replace(File.pathSeparatorChar, '_');
|
||||
|
@ -798,9 +807,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log_OC.d(TAG, "onResume() start");
|
||||
|
||||
super.onResume();
|
||||
|
||||
// refresh list of files
|
||||
refreshListOfFilesFragment();
|
||||
|
||||
|
@ -847,8 +856,8 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
}
|
||||
|
||||
|
||||
Log_OC.d(TAG, "onPause() end");
|
||||
super.onPause();
|
||||
Log_OC.d(TAG, "onPause() end");
|
||||
}
|
||||
|
||||
|
||||
|
@ -866,6 +875,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
dialog = working_dialog;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case DIALOG_CHOOSE_UPLOAD_SOURCE: {
|
||||
|
||||
|
||||
|
@ -887,7 +897,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
// }
|
||||
} else if (item == 1) {
|
||||
Intent action = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
|
||||
action = action.setType("*-/*").addCategory(Intent.CATEGORY_OPENABLE);
|
||||
//Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
||||
|
@ -899,7 +909,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
});
|
||||
dialog = builder.create();
|
||||
break;
|
||||
}
|
||||
} */
|
||||
case DIALOG_CERT_NOT_SAVED: {
|
||||
builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
|
||||
|
@ -920,77 +930,6 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a content URI of an content to a physical path on the disk
|
||||
*
|
||||
* @param uri The URI to resolve
|
||||
* @return The path to the content or null if it could not be found
|
||||
*/
|
||||
public String getPath(Uri uri) {
|
||||
final boolean isKitKatOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
// DocumentProvider
|
||||
if (isKitKatOrLater && DocumentsContract.isDocumentUri(getApplicationContext(), uri)) {
|
||||
// ExternalStorageProvider
|
||||
if (UriUtils.isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||
}
|
||||
}
|
||||
// DownloadsProvider
|
||||
else if (UriUtils.isDownloadsDocument(uri)) {
|
||||
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
|
||||
Long.valueOf(id));
|
||||
|
||||
return UriUtils.getDataColumn(getApplicationContext(), contentUri, null, null);
|
||||
}
|
||||
// MediaProvider
|
||||
else if (UriUtils.isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[] { split[1] };
|
||||
|
||||
return UriUtils.getDataColumn(getApplicationContext(), contentUri, selection, selectionArgs);
|
||||
}
|
||||
// Documents providers returned as content://...
|
||||
else if (UriUtils.isContentDocument(uri)) {
|
||||
return uri.toString();
|
||||
}
|
||||
}
|
||||
// MediaStore (and general)
|
||||
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
||||
// Return the remote address
|
||||
if (UriUtils.isGooglePhotosUri(uri))
|
||||
return uri.getLastPathSegment();
|
||||
|
||||
return UriUtils.getDataColumn(getApplicationContext(), uri, null, null);
|
||||
}
|
||||
// File
|
||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a directory to the drop down list
|
||||
* @param directory to push
|
||||
|
@ -1932,4 +1871,81 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
|||
private void sortByName(boolean ascending){
|
||||
getListOfFilesFragment().sortByName(ascending);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Translates a content URI of a content to a physical path on the disk
|
||||
*
|
||||
* @param uri The URI to resolve
|
||||
* @return The path to the content or null if it could not be found
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public String getPath(Uri uri) {
|
||||
final boolean isKitKatOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
// DocumentProvider
|
||||
if (isKitKatOrLater && DocumentsContract.isDocumentUri(this, uri)) {
|
||||
// ExternalStorageProvider
|
||||
if (UriUtils.isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||
}
|
||||
}
|
||||
// DownloadsProvider
|
||||
else if (UriUtils.isDownloadsDocument(uri)) {
|
||||
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
|
||||
Long.valueOf(id));
|
||||
|
||||
return UriUtils.getDataColumn(this, contentUri, null, null);
|
||||
}
|
||||
// MediaProvider
|
||||
else if (UriUtils.isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[] { split[1] };
|
||||
|
||||
return UriUtils.getDataColumn(this, contentUri, selection, selectionArgs);
|
||||
}
|
||||
// Documents providers returned as content://...
|
||||
else if (UriUtils.isContentDocument(uri)) {
|
||||
return uri.toString();
|
||||
}
|
||||
}
|
||||
// MediaStore (and general)
|
||||
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
||||
// Return the remote address
|
||||
if (UriUtils.isGooglePhotosUri(uri))
|
||||
return uri.getLastPathSegment();
|
||||
|
||||
return UriUtils.getDataColumn(this, uri, null, null);
|
||||
}
|
||||
// File
|
||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -64,11 +64,13 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
private Account mAccountOnCreation;
|
||||
private DialogFragment mCurrentDialog;
|
||||
|
||||
public static final String EXTRA_CHOSEN_FILES = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
|
||||
public static final String EXTRA_CHOSEN_FILES =
|
||||
UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
|
||||
|
||||
public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
|
||||
|
||||
private static final String KEY_DIRECTORY_PATH = UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
|
||||
private static final String KEY_DIRECTORY_PATH =
|
||||
UploadFilesActivity.class.getCanonicalName() + ".KEY_DIRECTORY_PATH";
|
||||
private static final String TAG = "UploadFilesActivity";
|
||||
private static final String WAIT_DIALOG_TAG = "WAIT";
|
||||
private static final String QUERY_TO_MOVE_DIALOG_TAG = "QUERY_TO_MOVE";
|
||||
|
@ -180,7 +182,8 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
// responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
|
||||
// responsibility of restore is preferred in onCreate() before than in
|
||||
// onRestoreInstanceState when there are Fragments involved
|
||||
Log_OC.d(TAG, "onSaveInstanceState() start");
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(UploadFilesActivity.KEY_DIRECTORY_PATH, mCurrentDir.getAbsolutePath());
|
||||
|
@ -317,7 +320,7 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
File localFile = new File(localPath);
|
||||
total += localFile.length();
|
||||
}
|
||||
return (FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total);
|
||||
return (new Boolean(FileStorageUtils.getUsableSpace(mAccountOnCreation.name) >= total));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -341,9 +344,12 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
finish();
|
||||
|
||||
} else {
|
||||
// show a dialog to query the user if wants to move the selected files to the ownCloud folder instead of copying
|
||||
// show a dialog to query the user if wants to move the selected files
|
||||
// to the ownCloud folder instead of copying
|
||||
String[] args = {getString(R.string.app_name)};
|
||||
ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no);
|
||||
ConfirmationDialogFragment dialog = ConfirmationDialogFragment.newInstance(
|
||||
R.string.upload_query_move_foreign_files, args, R.string.common_yes, -1, R.string.common_no
|
||||
);
|
||||
dialog.setOnConfirmationListener(UploadFilesActivity.this);
|
||||
dialog.show(getSupportFragmentManager(), QUERY_TO_MOVE_DIALOG_TAG);
|
||||
}
|
||||
|
@ -354,7 +360,8 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
public void onConfirmation(String callerTag) {
|
||||
Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
|
||||
if (callerTag.equals(QUERY_TO_MOVE_DIALOG_TAG)) {
|
||||
// return the list of selected files to the caller activity (success), signaling that they should be moved to the ownCloud folder, instead of copied
|
||||
// return the list of selected files to the caller activity (success),
|
||||
// signaling that they should be moved to the ownCloud folder, instead of copied
|
||||
Intent data = new Intent();
|
||||
data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
|
||||
setResult(RESULT_OK_AND_MOVE, data);
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.ui.dialog;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockDialogFragment;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.UploadFilesActivity;
|
||||
|
||||
|
||||
/**
|
||||
* Dialog showing two options to allow the user upload files from the filesystem or from other apps.
|
||||
*
|
||||
* Assumes that its parent activity extends {@link FileActivity}
|
||||
*/
|
||||
public class UploadSourceDialogFragment extends SherlockDialogFragment {
|
||||
|
||||
private final static String TAG = UploadSourceDialogFragment.class.getSimpleName();
|
||||
private final static String ARG_ACCOUNT = UploadSourceDialogFragment.class.getSimpleName() + ".ARG_ACCOUNT";
|
||||
|
||||
public static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
|
||||
public static final int ACTION_SELECT_MULTIPLE_FILES = 2;
|
||||
|
||||
public static UploadSourceDialogFragment newInstance(Account account) {
|
||||
UploadSourceDialogFragment f = new UploadSourceDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_ACCOUNT, account);
|
||||
f.setArguments(args);
|
||||
return f;
|
||||
}
|
||||
|
||||
public UploadSourceDialogFragment() {
|
||||
super();
|
||||
Log_OC.v(TAG, "constructor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
String[] allTheItems = {
|
||||
getString(R.string.actionbar_upload_files),
|
||||
getString(R.string.actionbar_upload_from_apps)
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
|
||||
builder.setTitle(R.string.actionbar_upload);
|
||||
builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
if (item == 0) {
|
||||
Intent action = new Intent(getSherlockActivity(), UploadFilesActivity.class);
|
||||
action.putExtra(
|
||||
UploadFilesActivity.EXTRA_ACCOUNT,
|
||||
((FileActivity)getSherlockActivity()).getAccount()
|
||||
);
|
||||
//startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES); // this flow seems broken;
|
||||
// Actionbarsherlock, maybe?
|
||||
getSherlockActivity().startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
|
||||
|
||||
} else if (item == 1) {
|
||||
Intent action = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
|
||||
//Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
||||
}
|
||||
//startActivityForResult( // this flow seems broken;
|
||||
// Actionbarsherlock, maybe?
|
||||
getSherlockActivity().startActivityForResult(
|
||||
Intent.createChooser(action, getString(R.string.upload_chooser_title)),
|
||||
ACTION_SELECT_CONTENT_FROM_APPS
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue