diff --git a/gradle.properties b/gradle.properties index f63ef9de..d4950a80 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 @@ POM_DEVELOPER_EMAIL=jonas@kalderstam.se 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 diff --git a/library/build.gradle b/library/build.gradle index d1377850..bc33f4b9 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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' } diff --git a/library/gradle.properties b/library/gradle.properties deleted file mode 100644 index e2baad53..00000000 --- a/library/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=NoNonsense FilePicker library -POM_ARTIFACT_ID=filepicker -POM_PACKAGING=aar diff --git a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerActivity.java b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerActivity.java index 9f26029f..7df36e68 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerActivity.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerActivity.java @@ -81,6 +81,7 @@ public abstract class AbstractFilePickerActivity 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 files) { } i.setClipData(clip); } else { - ArrayList paths = new ArrayList(); + ArrayList paths = new ArrayList<>(); for (Uri file : files) { paths.add(file.toString()); } diff --git a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java index b2b3d213..9cad5744 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java @@ -78,9 +78,6 @@ public abstract class AbstractFilePickerFragment extends Fragment private OnFilePickedListener listener; private FileItemAdapter mAdapter = null; private TextView currentDirView; - private Toolbar mToolbar; - private RecyclerView mRecyclerView; - private LinearLayoutManager mLayoutManager; private SortedList mFiles = null; protected FileItemAdapter 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 toUri(Iterable files) { - ArrayList uris = new ArrayList(); + ArrayList uris = new ArrayList<>(); for (T file : files) { uris.add(toUri(file)); } @@ -390,16 +384,16 @@ public void onLoaderReset(final Loader> loader) { * >Communicating with Other Fragments for more information. */ public interface OnFilePickedListener { - public void onFilePicked(Uri file); + void onFilePicked(Uri file); - public void onFilesPicked(List files); + void onFilesPicked(List 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); } diff --git a/library/src/main/java/com/nononsenseapps/filepicker/FileItemAdapter.java b/library/src/main/java/com/nononsenseapps/filepicker/FileItemAdapter.java index 4584382c..9afe5bb1 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/FileItemAdapter.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/FileItemAdapter.java @@ -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.HeaderViewHolder) viewHolder); diff --git a/library/src/main/java/com/nononsenseapps/filepicker/FilePickerActivity.java b/library/src/main/java/com/nononsenseapps/filepicker/FilePickerActivity.java index 4359a54d..2cc47076 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/FilePickerActivity.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/FilePickerActivity.java @@ -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 getFragment( final String startPath, final int mode, final boolean allowMultiple, final boolean allowCreateDir) { AbstractFilePickerFragment 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; } } diff --git a/library/src/main/java/com/nononsenseapps/filepicker/FilePickerFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/FilePickerFragment.java index 6fe891d2..e5af96ff 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/FilePickerFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/FilePickerFragment.java @@ -40,7 +40,8 @@ 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) { @@ -48,7 +49,7 @@ public boolean isDir(final File path) { } /** - * @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,7 +83,8 @@ 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) { @@ -86,7 +92,7 @@ public File getPath(final String 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 diff --git a/library/src/main/java/com/nononsenseapps/filepicker/LogicHandler.java b/library/src/main/java/com/nononsenseapps/filepicker/LogicHandler.java index 6b66b920..f37d889c 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/LogicHandler.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/LogicHandler.java @@ -28,19 +28,22 @@ */ public interface LogicHandler { + 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 @@ -48,7 +51,7 @@ public interface LogicHandler { * @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 @@ -56,41 +59,38 @@ public interface LogicHandler { * * @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> getLoader(); - - public final static int VIEWTYPE_HEADER = 0; - public final static int VIEWTYPE_DIR = 1; - public final static int VIEWTYPE_CHECKABLE = 2; + Loader> getLoader(); /** * Bind the header ".." which goes to parent folder. + * * @param viewHolder */ - public void onBindHeaderViewHolder(AbstractFilePickerFragment.HeaderViewHolder viewHolder); + void onBindHeaderViewHolder(AbstractFilePickerFragment.HeaderViewHolder viewHolder); /** * Header is subtracted from the position @@ -99,21 +99,19 @@ public interface LogicHandler { * @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.DirViewHolder viewHolder, int position, T data); + void onBindViewHolder(AbstractFilePickerFragment.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); } diff --git a/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java index 73da81e4..d28a01ab 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java @@ -125,6 +125,6 @@ public interface OnNewFolderListener { * * @param name The name of the folder the user wishes to create. */ - public void onNewFolder(final String name); + void onNewFolder(final String name); } } diff --git a/sample/build.gradle b/sample/build.gradle index 15088533..8215468b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' 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 } diff --git a/sample/src/main/java/com/nononsenseapps/filepicker/sample/ImagePickerActivity.java b/sample/src/main/java/com/nononsenseapps/filepicker/sample/ImagePickerActivity.java index 3c0048f0..48895a3d 100644 --- a/sample/src/main/java/com/nononsenseapps/filepicker/sample/ImagePickerActivity.java +++ b/sample/src/main/java/com/nononsenseapps/filepicker/sample/ImagePickerActivity.java @@ -17,6 +17,8 @@ package com.nononsenseapps.filepicker.sample; +import android.os.Environment; + import com.nononsenseapps.filepicker.AbstractFilePickerActivity; import com.nononsenseapps.filepicker.AbstractFilePickerFragment; @@ -36,7 +38,9 @@ protected AbstractFilePickerFragment getFragment( final String startPath, final int mode, final boolean allowMultiple, final boolean allowCreateDir) { AbstractFilePickerFragment fragment = new ImagePickerFragment(); - 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; } }