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

Commit

Permalink
Correctly block going above root-folder
Browse files Browse the repository at this point in the history
And update to newer support library versions and android targets
  • Loading branch information
spacecowboy committed May 30, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0152b15 commit 8f02d21
Showing 12 changed files with 77 additions and 77 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Project-wide Gradle settings.

VERSION_NAME=2.0.5
VERSION_CODE=15
VERSION_NAME=2.1
VERSION_CODE=16
GROUP=com.nononsenseapps

PROJECT_NAME=com.nononsenseapps:filepicker
@@ -20,6 +20,6 @@ [email protected]

POM_URL_ISSUES=https://github.com/spacecowboy/NoNonsense-FilePicker/issues

ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_BUILD_SDK_VERSION=21
#ANDROID_BUILD_TARGET_SDK_VERSION=22
#ANDROID_BUILD_TOOLS_VERSION=22.0.1
#ANDROID_BUILD_SDK_VERSION=22
17 changes: 5 additions & 12 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -4,28 +4,21 @@ apply plugin: 'com.android.library'
apply plugin: 'bintray-release'

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
targetSdkVersion 22
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
}
buildTypes {
release {
//minifyEnabled true
//shrinkResources true
//proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:recyclerview-v7:22.1.1'
}

3 changes: 0 additions & 3 deletions library/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ public abstract class AbstractFilePickerActivity<T> extends AppCompatActivity
protected boolean allowMultiple = false;

@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@@ -149,7 +150,7 @@ public void onFilesPicked(final List<Uri> files) {
}
i.setClipData(clip);
} else {
ArrayList<String> paths = new ArrayList<String>();
ArrayList<String> paths = new ArrayList<>();
for (Uri file : files) {
paths.add(file.toString());
}
Original file line number Diff line number Diff line change
@@ -78,9 +78,6 @@ public abstract class AbstractFilePickerFragment<T> extends Fragment
private OnFilePickedListener listener;
private FileItemAdapter<T> mAdapter = null;
private TextView currentDirView;
private Toolbar mToolbar;
private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager;
private SortedList<T> mFiles = null;

protected FileItemAdapter<T> getAdapter() {
@@ -107,10 +104,10 @@ public AbstractFilePickerFragment() {
/**
* Set before making the fragment visible.
*
* @param startPath
* @param mode
* @param allowMultiple
* @param allowDirCreate
* @param startPath path to directory the picker will show upon start
* @param mode what is allowed to be selected (dirs, files, both)
* @param allowMultiple selecting a single item or several?
* @param allowDirCreate can new directories be created?
*/
public void setArgs(final String startPath, final int mode,
final boolean allowMultiple, final boolean allowDirCreate) {
@@ -129,19 +126,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_filepicker, container, false);

mToolbar = (Toolbar) view.findViewById(R.id.picker_toolbar);
Toolbar mToolbar = (Toolbar) view.findViewById(R.id.picker_toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);


mRecyclerView = (RecyclerView) view.findViewById(android.R.id.list);
RecyclerView mRecyclerView = (RecyclerView) view.findViewById(android.R.id.list);
// improve performance if you know that changes in content
// do not change the size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// I want some dividers
//mRecyclerView.addItemDecoration(new DividerColor
// (getActivity(), DividerColor.VERTICAL_LIST, 0, 1));
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(getActivity());
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
// Set adapter
mAdapter = new FileItemAdapter<>(this);
@@ -207,7 +201,7 @@ public T getFirstCheckedItem() {
}

protected List<Uri> toUri(Iterable<T> files) {
ArrayList<Uri> uris = new ArrayList<Uri>();
ArrayList<Uri> uris = new ArrayList<>();
for (T file : files) {
uris.add(toUri(file));
}
@@ -390,16 +384,16 @@ public void onLoaderReset(final Loader<SortedList<T>> loader) {
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFilePickedListener {
public void onFilePicked(Uri file);
void onFilePicked(Uri file);

public void onFilesPicked(List<Uri> files);
void onFilesPicked(List<Uri> files);

public void onCancelled();
void onCancelled();
}

/**
* @param position 0 - n, where the header has been subtracted
* @param data
* @param data the actual file or directory
* @return an integer greater than 0
*/
@Override
@@ -417,8 +411,8 @@ public void onBindHeaderViewHolder(HeaderViewHolder viewHolder) {
}

/**
* @param parent
* @param viewType
* @param parent Containing view
* @param viewType which the ViewHolder will contain
* @return a view holder for a file or directory
*/
@Override
@@ -444,7 +438,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
/**
* @param vh to bind data from either a file or directory
* @param position 0 - n, where the header has been subtracted
* @param data
* @param data the file or directory which this item represents
*/
@Override
public void onBindViewHolder(DirViewHolder vh, int position, T data) {
@@ -457,6 +451,7 @@ public void onBindViewHolder(DirViewHolder vh, int position, T data) {
checkedVisibleViewHolders.add((CheckableViewHolder) vh);
((CheckableViewHolder) vh).checkbox.setChecked(true);
} else {
//noinspection SuspiciousMethodCalls
checkedVisibleViewHolders.remove(vh);
((CheckableViewHolder) vh).checkbox.setChecked(false);
}
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
}

@Override
@SuppressWarnings("unchecked")
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int headerPosition) {
if (headerPosition == 0) {
mLogic.onBindHeaderViewHolder((AbstractFilePickerFragment<T>.HeaderViewHolder) viewHolder);
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
package com.nononsenseapps.filepicker;

import android.annotation.SuppressLint;
import android.os.Environment;

import java.io.File;

@@ -33,7 +34,9 @@ protected AbstractFilePickerFragment<File> getFragment(
final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new FilePickerFragment();
fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir);
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir);
return fragment;
}
}
Original file line number Diff line number Diff line change
@@ -40,15 +40,16 @@ public FilePickerFragment() {
/**
* Return true if the path is a directory and not a file.
*
* @param path
* @param path either a file or directory
* @return true if path is a directory, false if file
*/
@Override
public boolean isDir(final File path) {
return path.isDirectory();
}

/**
* @param path
* @param path either a file or directory
* @return filename of path
*/
@Override
@@ -60,11 +61,15 @@ public String getName(File path) {
* Return the path to the parent directory. Should return the root if
* from is root.
*
* @param from
* @param from either a file or directory
* @return the parent directory
*/
@Override
public File getParent(final File from) {
if (from.getParentFile() != null) {
if (from.getPath().equals(getRoot().getPath())) {
// Already at root, we can't go higher
return from;
} else if (from.getParentFile() != null) {
if (from.isFile()) {
return getParent(from.getParentFile());
} else {
@@ -78,15 +83,16 @@ public File getParent(final File from) {
/**
* Convert the path to the type used.
*
* @param path
* @param path either a file or directory
* @return File representation of the string path
*/
@Override
public File getPath(final String path) {
return new File(path);
}

/**
* @param path
* @param path either a file or directory
* @return the full path to the file
*/
@Override
@@ -95,17 +101,19 @@ public String getFullPath(final File path) {
}

/**
* Get the root path (lowest allowed).
* Get the root path.
*
* @return the highest allowed path, which is "/" by default
*/
@Override
public File getRoot() {
return Environment.getExternalStorageDirectory();
return new File("/");
}

/**
* Convert the path to a URI for the return intent
*
* @param file
* @param file either a file or directory
* @return a Uri
*/
@Override
Original file line number Diff line number Diff line change
@@ -28,69 +28,69 @@
*/
public interface LogicHandler<T> {

int VIEWTYPE_HEADER = 0;
int VIEWTYPE_DIR = 1;
int VIEWTYPE_CHECKABLE = 2;

/**
* Return true if the path is a directory and not a file.
*
* @param path
*/
public boolean isDir(final T path);
boolean isDir(final T path);

/**
*
* @param path
* @return filename of path
*/
public String getName(final T path);
String getName(final T path);

/**
* Convert the path to a URI for the return intent
*
* @param path
* @return a Uri
*/
public Uri toUri(final T path);
Uri toUri(final T path);

/**
* Return the path to the parent directory. Should return the root if
* from is root.
*
* @param from
*/
public T getParent(final T from);
T getParent(final T from);

/**
* @param path
* @return the full path to the file
*/
public String getFullPath(final T path);
String getFullPath(final T path);

/**
* Convert the path to the type used.
*
* @param path
*/
public T getPath(final String path);
T getPath(final String path);

/**
* Get the root path (lowest allowed).
*/
public T getRoot();
T getRoot();

/**
* Get a loader that lists the files in the current path,
* and monitors changes.
*/
public Loader<SortedList<T>> getLoader();

public final static int VIEWTYPE_HEADER = 0;
public final static int VIEWTYPE_DIR = 1;
public final static int VIEWTYPE_CHECKABLE = 2;
Loader<SortedList<T>> getLoader();

/**
* Bind the header ".." which goes to parent folder.
*
* @param viewHolder
*/
public void onBindHeaderViewHolder(AbstractFilePickerFragment<T>.HeaderViewHolder viewHolder);
void onBindHeaderViewHolder(AbstractFilePickerFragment<T>.HeaderViewHolder viewHolder);

/**
* Header is subtracted from the position
@@ -99,21 +99,19 @@ public interface LogicHandler<T> {
* @param viewType
* @return a view holder for a file or directory
*/
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType);
RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType);

/**
*
* @param viewHolder to bind data from either a file or directory
* @param position 0 - n, where the header has been subtracted
* @param position 0 - n, where the header has been subtracted
* @param data
*/
public void onBindViewHolder(AbstractFilePickerFragment<T>.DirViewHolder viewHolder, int position, T data);
void onBindViewHolder(AbstractFilePickerFragment<T>.DirViewHolder viewHolder, int position, T data);

/**
*
* @param position 0 - n, where the header has been subtracted
* @param data
* @return an integer greater than 0
*/
public int getItemViewType(int position, T data);
int getItemViewType(int position, T data);
}
Loading

0 comments on commit 8f02d21

Please sign in to comment.