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

Commit

Permalink
Merge pull request #108 from spacecowboy/fix-fastscroll
Browse files Browse the repository at this point in the history
Fix some of the samples
  • Loading branch information
spacecowboy authored Sep 3, 2016
2 parents 370097f + 9918ed5 commit e4167c3
Show file tree
Hide file tree
Showing 8 changed files with 661 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public abstract class AbstractFilePickerFragment<T> extends Fragment
protected Toast mToast = null;
// Keep track if we are currently loading a directory, in case it takes a long time
protected boolean isLoading = false;
private View mNewFileButtonContainer = null;
private View mRegularButtonContainer = null;
protected View mNewFileButtonContainer = null;
protected View mRegularButtonContainer = null;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
Expand Down Expand Up @@ -162,7 +162,7 @@ public void setArgs(@Nullable final String startPath, final int mode,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.nnf_fragment_filepicker, container, false);
final View view = inflateRootView(inflater, container);

Toolbar toolbar = (Toolbar) view.findViewById(R.id.nnf_picker_toolbar);
if (toolbar != null) {
Expand Down Expand Up @@ -235,6 +235,10 @@ public void afterTextChanged(Editable s) {
return view;
}

protected View inflateRootView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate( R.layout.nnf_fragment_filepicker, container, false);
}

/**
* Checks if a divider drawable has been defined in the current theme. If it has, will apply
* an item decoration with the divider. If no divider has been specified, then does nothing.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.nononsenseapps.filepicker.sample;


import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.action.ViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.nononsenseapps.filepicker.sample.PermissionGranter.allowPermissionsIfNeeded;
import static org.hamcrest.Matchers.allOf;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class FtpPicker {

@Rule
public ActivityTestRule<NoNonsenseFilePickerTest> mActivityTestRule =
new ActivityTestRule<>(NoNonsenseFilePickerTest.class);

@Before
public void allowPermissions() {
allowPermissionsIfNeeded(mActivityTestRule.getActivity());
}

@Test
public void selectDir() throws IOException {
ViewInteraction radioButton = onView(
allOf(withId(R.id.radioDir), withText("Select directory"),
withParent(withId(R.id.radioGroup)),
isDisplayed()));
radioButton.perform(click());

onView(withId(R.id.button_ftp)).perform(ViewActions.scrollTo());

ViewInteraction button = onView(
allOf(withId(R.id.button_ftp), isDisplayed()));
button.perform(click());

ViewInteraction recyclerView = onView(
allOf(withId(android.R.id.list), isDisplayed()));

// press pub
recyclerView.perform(actionOnItemAtPosition(1, click()));

ViewInteraction okButton = onView(
allOf(withId(R.id.nnf_button_ok),
withParent(allOf(withId(R.id.nnf_button_container),
withParent(withId(R.id.nnf_buttons_container)))),
isDisplayed()));
// Click ok
okButton.perform(click());

ViewInteraction textView = onView(withId(R.id.text));
textView.check(matches(withText("ftp://anonymous:anonymous@debian.simnet.is:21/pub")));
}
}
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
@@ -1,70 +1,15 @@
package com.nononsenseapps.filepicker.sample.fastscroller;

import android.os.Bundle;
import android.support.v4.content.Loader;
import android.support.v7.util.SortedList;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nononsenseapps.filepicker.FilePickerFragment;
import com.nononsenseapps.filepicker.sample.R;
import com.nononsenseapps.filepicker.sample.fastscroller.FastScrollerFileItemAdapter;
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;

import java.io.File;

public class FastScrollerFilePickerFragment extends FilePickerFragment {

private FastScrollRecyclerView recyclerView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fastscrollerfilepicker, container, false);

Toolbar toolbar = (Toolbar) view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_picker_toolbar);
if (toolbar != null) {
setupToolbar(toolbar);
}

recyclerView = (FastScrollRecyclerView) 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 FastScrollerFileItemAdapter(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;
protected View inflateRootView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate(R.layout.fragment_fastscrollerfilepicker, container, false);
}
}
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
Loading

0 comments on commit e4167c3

Please sign in to comment.