Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Fix dropbox and ftp pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Sep 3, 2016
1 parent ac6e15c commit 9918ed5
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,58 +56,13 @@ public DropboxFilePickerFragment(final DropboxAPI<AndroidAuthSession> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +48,7 @@ public class FtpPickerFragment extends AbstractFilePickerFragment<FtpFile> {
private String password;
private boolean loggedIn = false;
private String rootDir = "/";
private ProgressBar progressBar;

public FtpPickerFragment() {
super();
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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<SortedList<FtpFile>> loader, SortedList<FtpFile> data) {
progressBar.setVisibility(View.INVISIBLE);
recyclerView.setVisibility(View.VISIBLE);
super.onLoadFinished(loader, data);
}

@Override
public void onLoaderReset(Loader<SortedList<FtpFile>> loader) {
progressBar.setVisibility(View.INVISIBLE);
recyclerView.setVisibility(View.VISIBLE);
super.onLoaderReset(loader);
}

/**
* @param name The name of the folder the user wishes to create.
*/
Expand Down
79 changes: 56 additions & 23 deletions sample/src/main/res/layout/fragment_loading_filepicker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -51,30 +51,63 @@
android:layout_centerVertical="true"
android:visibility="invisible"/>

<LinearLayout
android:id="@+id/nnf_button_container"
<FrameLayout
android:id="@+id/nnf_buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">

<Button
android:id="@+id/nnf_button_cancel"
style="?attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:text="@android:string/cancel"/>

<Button
android:id="@+id/nnf_button_ok"
style="?attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:text="@android:string/ok"/>

</LinearLayout>
android:layout_alignParentBottom="true">

<LinearLayout
android:id="@+id/nnf_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/nnf_button_cancel"
style="?attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:text="@android:string/cancel"/>

<Button
android:id="@+id/nnf_button_ok"
style="?attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:text="@android:string/ok"/>

</LinearLayout>

<LinearLayout
android:id="@+id/nnf_newfile_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:id="@+id/nnf_text_filename"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:hint="@string/nnf_filename"
android:maxLines="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"/>

<ImageButton
android:id="@+id/nnf_button_ok_newfile"
style="?attr/borderlessButtonStyle"
android:layout_width="48dp"
android:layout_height="48dp"
android:hint="@android:string/ok"
android:src="@drawable/nnf_ic_save_black_24dp"

This comment has been minimized.

Copy link
@sevar83

sevar83 Sep 12, 2016

Crashes here. Must be srcCompat cause it's vector drawable.

android:tint="?attr/nnf_save_icon_color"/>

</LinearLayout>
</FrameLayout>

<FrameLayout
android:id="@+id/divider"
Expand Down

0 comments on commit 9918ed5

Please sign in to comment.