implement correct local/remote folder picking in preference dialog

This commit is contained in:
AndyScherzinger 2017-05-28 00:12:15 +02:00
parent a3985e7227
commit e93cd2723f
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
7 changed files with 85 additions and 19 deletions

View file

@ -456,8 +456,12 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
mSyncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
} else {
} if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
String localPath = data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
mSyncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
}

View file

@ -75,6 +75,7 @@ public class UploadFilesActivity extends FileActivity implements
private ArrayAdapter<String> mDirectories;
private File mCurrentDir = null;
private boolean mSelectAll = false;
private boolean mLocalFolderPickerMode = false;
private LocalFileListFragment mFileListFragment;
private Button mCancelBtn;
protected Button mUploadBtn;
@ -88,6 +89,10 @@ public class UploadFilesActivity extends FileActivity implements
public static final String EXTRA_CHOSEN_FILES =
UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
public static final String EXTRA_ACTION = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_ACTION";
public final static String KEY_LOCAL_FOLDER_PICKER_MODE = UploadFilesActivity.class.getCanonicalName()
+ ".LOCAL_FOLDER_PICKER_MODE";
public static final int RESULT_OK_AND_MOVE = RESULT_FIRST_USER;
public static final int RESULT_OK_AND_DO_NOTHING = 2;
public static final int RESULT_OK_AND_DELETE = 3;
@ -106,6 +111,11 @@ public class UploadFilesActivity extends FileActivity implements
Log_OC.d(TAG, "onCreate() start");
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
mLocalFolderPickerMode = extras.getBoolean(KEY_LOCAL_FOLDER_PICKER_MODE, false);
}
if(savedInstanceState != null) {
mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH, Environment
.getExternalStorageDirectory().getAbsolutePath()));
@ -130,9 +140,14 @@ public class UploadFilesActivity extends FileActivity implements
// Inflate and set the layout view
setContentView(R.layout.upload_files_layout);
if (mLocalFolderPickerMode) {
findViewById(R.id.upload_options).setVisibility(View.GONE);
((AppCompatButton) findViewById(R.id.upload_files_btn_upload))
.setText(R.string.uploader_btn_alternative_text);
}
mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list);
// Set input controllers
mCancelBtn = (Button) findViewById(R.id.upload_files_btn_cancel);
mCancelBtn.setOnClickListener(this);
@ -432,7 +447,17 @@ public class UploadFilesActivity extends FileActivity implements
finish();
} else if (v.getId() == R.id.upload_files_btn_upload) {
new CheckAvailableSpaceTask().execute(mBehaviourSpinner.getSelectedItemPosition()==0);
if(mLocalFolderPickerMode) {
Intent data = new Intent();
if(mCurrentDir != null) {
data.putExtra(EXTRA_CHOSEN_FILES, mCurrentDir.getAbsolutePath());
}
setResult(RESULT_OK, data);
finish();
} else {
new CheckAvailableSpaceTask().execute(mBehaviourSpinner.getSelectedItemPosition() == 0);
}
}
}

View file

@ -41,6 +41,7 @@ import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -58,10 +59,12 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
private Context mContext;
private File[] mFiles = null;
private Vector<File> mFilesAll = new Vector<File>();
private Vector<File> mFilesAll = new Vector<>();
private boolean mLocalFolderPicker;
public LocalFileListAdapter(File directory, Context context) {
public LocalFileListAdapter(boolean localFolderPickerMode, File directory, Context context) {
mContext = context;
mLocalFolderPicker = localFolderPickerMode;
// Read sorting order, default to sort by name ascending
FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(context);
@ -272,7 +275,11 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
* @param directory New file to adapt. Can be NULL, meaning "no content to adapt".
*/
public void swapDirectory(final File directory) {
mFiles = (directory != null ? directory.listFiles() : null);
if(mLocalFolderPicker) {
mFiles = (directory != null ? getFolders(directory) : null);
} else {
mFiles = (directory != null ? directory.listFiles() : null);
}
if (mFiles != null) {
Arrays.sort(mFiles, new Comparator<File>() {
@Override
@ -288,7 +295,6 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
private int compareNames(File lhs, File rhs) {
return lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase());
}
});
mFiles = FileStorageUtils.sortLocalFolder(mFiles);
@ -317,6 +323,15 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
notifyDataSetChanged();
}
private File[] getFolders(final File directory) {
return directory.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
}
});
}
public void filter(String text){
if(text.isEmpty()){
mFiles = mFilesAll.toArray(new File[1]);

View file

@ -45,6 +45,7 @@ import com.owncloud.android.datamodel.MediaFolder;
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FolderPickerActivity;
import com.owncloud.android.ui.activity.UploadFilesActivity;
import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ThemeUtils;
@ -218,6 +219,18 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
mRemoteFolderSummary.setText(path);
}
/**
* set (new) local path on activity result of the folder picker activity. The result gets originally propagated
* to the underlying activity since the picker is an activity and the result can't get passed to the dialog
* fragment directly.
*
* @param path the remote path to be set
*/
public void setLocalFolderSummary(String path) {
mSyncedFolder.setLocalPath(path);
mLocalFolderSummary.setText(path);
}
/**
* setup all listeners.
*
@ -258,8 +271,6 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
@Override
public void onClick(View v) {
Intent action = new Intent(getActivity(), FolderPickerActivity.class);
action.putExtra(
FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.choose_remote_folder));
getActivity().startActivityForResult(action, REQUEST_CODE__SELECT_REMOTE_FOLDER);
}
});
@ -267,9 +278,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
view.findViewById(R.id.local_folder_container).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent action = new Intent(getActivity(), FolderPickerActivity.class);
action.putExtra(
FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.choose_remote_folder));
Intent action = new Intent(getActivity(), UploadFilesActivity.class);
action.putExtra(UploadFilesActivity.KEY_LOCAL_FOLDER_PICKER_MODE, true);
getActivity().startActivityForResult(action, REQUEST_CODE__SELECT_LOCAL_FOLDER);
}
});

View file

@ -49,6 +49,11 @@ import java.util.ArrayList;
*/
public class LocalFileListFragment extends ExtendedListFragment {
private static final String TAG = LocalFileListFragment.class.getSimpleName();
private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ?
OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
public final static String ARG_LOCAL_FOLDER_PICKER_MODE = MY_PACKAGE + ".LOCAL_FOLDER_PICKER_MODE";
/** Reference to the Activity which this fragment is attached to. For callbacks */
private LocalFileListFragment.ContainerActivity mContainerActivity;
@ -59,6 +64,8 @@ public class LocalFileListFragment extends ExtendedListFragment {
/** Adapter to connect the data from the directory with the View object */
private LocalFileListAdapter mAdapter = null;
private boolean mLocalFolderPicker;
private static final String SCREEN_NAME = "Local file browser";
@Override
@ -97,7 +104,9 @@ public class LocalFileListFragment extends ExtendedListFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.i(TAG, "onCreateView() start");
View v = super.onCreateView(inflater, container, savedInstanceState);
setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
if(!mLocalFolderPicker) {
setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
setSwipeEnabled(false); // Disable pull-to-refresh
setFabEnabled(false); // Disable FAB
setMessageForEmptyList(R.string.file_list_empty_headline, R.string.local_file_list_empty,
@ -115,7 +124,10 @@ public class LocalFileListFragment extends ExtendedListFragment {
Log_OC.i(TAG, "onActivityCreated() start");
super.onActivityCreated(savedInstanceState);
mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
Bundle args = getArguments();
mLocalFolderPicker = (args != null) && args.getBoolean(ARG_LOCAL_FOLDER_PICKER_MODE, false);
mAdapter = new LocalFileListAdapter(mLocalFolderPicker, mContainerActivity.getInitialDirectory(), getActivity());
setListAdapter(mAdapter);
Log_OC.i(TAG, "onActivityCreated() stop");

View file

@ -45,11 +45,12 @@
</LinearLayout>
<LinearLayout
android:id="@+id/upload_options"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/standard_half_padding"
android:paddingBottom="@dimen/standard_padding"
android:paddingBottom="0dp"
android:paddingLeft="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding">
@ -73,9 +74,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="@dimen/standard_padding"
android:paddingRight="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_padding">
android:padding="@dimen/standard_padding">
<android.support.v7.widget.AppCompatButton
android:id="@+id/upload_files_btn_cancel"

View file

@ -80,6 +80,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_alternative_text">Choose</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 set up an account first.</string>