From 9918ed541d7101895cb0b55679349721e34833ee Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Sat, 3 Sep 2016 14:43:50 +0200 Subject: [PATCH] Fix dropbox and ftp pickers --- .../dropbox/DropboxFilePickerFragment.java | 47 +---------- .../sample/ftp/FtpPickerFragment.java | 43 ++++++++++ .../layout/fragment_loading_filepicker.xml | 79 +++++++++++++------ 3 files changed, 100 insertions(+), 69 deletions(-) diff --git a/sample/src/main/java/com/nononsenseapps/filepicker/sample/dropbox/DropboxFilePickerFragment.java b/sample/src/main/java/com/nononsenseapps/filepicker/sample/dropbox/DropboxFilePickerFragment.java index 0a88f800..de473a7a 100644 --- a/sample/src/main/java/com/nononsenseapps/filepicker/sample/dropbox/DropboxFilePickerFragment.java +++ b/sample/src/main/java/com/nononsenseapps/filepicker/sample/dropbox/DropboxFilePickerFragment.java @@ -56,58 +56,13 @@ public DropboxFilePickerFragment(final DropboxAPI api) { this.dbApi = api; } - /** - * Copy paste of normal onCreateView, except we load a different layout, and bind the progress - * bar which was added to it. - */ @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + protected View inflateRootView(LayoutInflater inflater, ViewGroup container) { // Load the specific layout we created for dropbox/ftp View view = inflater.inflate(R.layout.fragment_loading_filepicker, container, false); - // And bind the progress bar progressBar = (ProgressBar) view.findViewById(R.id.progressBar); - Toolbar toolbar = - (Toolbar) view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_picker_toolbar); - if (toolbar != null) { - setupToolbar(toolbar); - } - - recyclerView = (RecyclerView) view.findViewById(android.R.id.list); - // improve performance if you know that changes in content - // do not change the size of the RecyclerView - recyclerView.setHasFixedSize(true); - // use a linear layout manager - LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); - recyclerView.setLayoutManager(layoutManager); - // Set adapter - mAdapter = new FileItemAdapter<>(this); - recyclerView.setAdapter(mAdapter); - - view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_button_cancel) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - onClickCancel(v); - } - }); - - view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_button_ok) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - onClickOk(v); - } - }); - - mCurrentDirView = (TextView) view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_current_dir); - // Restore state - if (mCurrentPath != null && mCurrentDirView != null) { - mCurrentDirView.setText(getFullPath(mCurrentPath)); - } - return view; } diff --git a/sample/src/main/java/com/nononsenseapps/filepicker/sample/ftp/FtpPickerFragment.java b/sample/src/main/java/com/nononsenseapps/filepicker/sample/ftp/FtpPickerFragment.java index 95827ff7..cbe72899 100644 --- a/sample/src/main/java/com/nononsenseapps/filepicker/sample/ftp/FtpPickerFragment.java +++ b/sample/src/main/java/com/nononsenseapps/filepicker/sample/ftp/FtpPickerFragment.java @@ -15,6 +15,10 @@ import android.support.v7.util.SortedList; import android.support.v7.widget.util.SortedListAdapterCallback; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; import android.widget.Toast; import com.nononsenseapps.filepicker.AbstractFilePickerFragment; @@ -44,6 +48,7 @@ public class FtpPickerFragment extends AbstractFilePickerFragment { private String password; private boolean loggedIn = false; private String rootDir = "/"; + private ProgressBar progressBar; public FtpPickerFragment() { super(); @@ -89,6 +94,16 @@ public void onCreate(Bundle b) { this.rootDir = args.getString(KEY_FTP_ROOTDIR) != null ? args.getString(KEY_FTP_ROOTDIR) : "/"; } + @Override + protected View inflateRootView(LayoutInflater inflater, ViewGroup container) { + // Load the specific layout we created for dropbox/ftp + View view = inflater.inflate(R.layout.fragment_loading_filepicker, container, false); + // And bind the progress bar + progressBar = (ProgressBar) view.findViewById(R.id.progressBar); + + return view; + } + /** * Return true if the path is a directory and not a file. */ @@ -328,6 +343,34 @@ protected void onPostExecute(FtpFile folder) { task.execute(name); } + /** + * If we are loading, then hide the list and show the progress bar instead. + * + * @param nextPath path to list files for + */ + @Override + protected void refresh(@NonNull FtpFile nextPath) { + super.refresh(nextPath); + if (isLoading) { + progressBar.setVisibility(View.VISIBLE); + recyclerView.setVisibility(View.INVISIBLE); + } + } + + @Override + public void onLoadFinished(Loader> loader, SortedList data) { + progressBar.setVisibility(View.INVISIBLE); + recyclerView.setVisibility(View.VISIBLE); + super.onLoadFinished(loader, data); + } + + @Override + public void onLoaderReset(Loader> loader) { + progressBar.setVisibility(View.INVISIBLE); + recyclerView.setVisibility(View.VISIBLE); + super.onLoaderReset(loader); + } + /** * @param name The name of the folder the user wishes to create. */ diff --git a/sample/src/main/res/layout/fragment_loading_filepicker.xml b/sample/src/main/res/layout/fragment_loading_filepicker.xml index 1fb616da..c5d60a16 100644 --- a/sample/src/main/res/layout/fragment_loading_filepicker.xml +++ b/sample/src/main/res/layout/fragment_loading_filepicker.xml @@ -36,7 +36,7 @@ android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@+id/nnf_button_container" + android:layout_above="@+id/nnf_buttons_container" android:layout_below="@+id/nnf_picker_toolbar" android:descendantFocusability="afterDescendants" android:focusable="true" @@ -51,30 +51,63 @@ android:layout_centerVertical="true" android:visibility="invisible"/> - - -