Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed May 5, 2024
2 parents 75cccbd + 3a04e7d commit c3452ad
Show file tree
Hide file tree
Showing 48 changed files with 885 additions and 413 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
with:
java-version: '17'
distribution: temurin
- uses: actions/cache@v4
with:
path: gh-cache/
key: "prefix-${{ hashFiles('buildscripts/**.sh') }}"
restore-keys: "prefix-"
enableCrossOsArchive: true

- name: Build the release artifacts
run: |
Expand All @@ -32,5 +38,8 @@ jobs:
./download.sh > /dev/null
./buildall.sh --arch ${{ matrix.architecture }} mpv
./buildall.sh -n
env:
GRADLE_OPTS: -Xmx4G
- uses: actions/upload-artifact@v4
with:
name: aniyomi-mpv-lib-${{ matrix.architecture }}
path: app/build/outputs/aar/app-default-release.aar
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
versionCode 33
versionCode 35
versionName "1.14.n"
vectorDrawables.useSupportLibrary = true
}
Expand Down
428 changes: 323 additions & 105 deletions app/src/main/assets/cacert.pem

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void onLoadFinished(@NonNull final Loader<List<T>> loader,
mFiles = data;
mAdapter.setList(data);
onChangePath(mCurrentPath);
String key = mCurrentPath.toString();
String key = pathToString(mCurrentPath);
if (mPositionMap.containsKey(key))
layoutManager.scrollToPositionWithOffset(mPositionMap.get(key), 0);
else
Expand Down Expand Up @@ -314,14 +314,21 @@ public void onClickHeader(@NonNull View view, @NonNull HeaderViewHolder viewHold
goUp();
}

/**
* Returns the directory currently being viewed.
*/
public T getCurrentDir() {
return mCurrentPath;
}

/**
* Browses to the parent directory from the current directory. For example, if the current
* directory is /foo/bar/, then goUp() will change the current directory to /foo/. It is up to
* the caller to not call this in vain, e.g. if you are already at the root.
* <p/>
*/
public void goUp() {
String key = mCurrentPath.toString();
String key = pathToString(mCurrentPath);
mPositionMap.remove(key);
goToDir(getParent(mCurrentPath), false);
}
Expand All @@ -334,7 +341,7 @@ public void goUp() {
*/
public void onClickDir(@NonNull View view, @NonNull DirViewHolder viewHolder) {
if (isDir(viewHolder.file)) {
String key = mCurrentPath.toString();
String key = pathToString(mCurrentPath);
mPositionMap.put(key, layoutManager.findFirstVisibleItemPosition());
goToDir(viewHolder.file, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Basic ItemDecoration which loads a drawable as a divider.
*/
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
class DividerItemDecoration extends RecyclerView.ItemDecoration {
private final Drawable mDivider;

public DividerItemDecoration(Drawable divider) {
Expand Down
59 changes: 30 additions & 29 deletions app/src/main/java/is/xyz/filepicker/DocumentPickerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.loader.content.AsyncTaskLoader;
Expand All @@ -18,7 +19,7 @@

/**
* An implementation of the picker that operates on a document tree.
*
* <br>
* See also:
* - https://developer.android.com/training/data-storage/shared/documents-files
* - https://developer.android.com/reference/android/provider/DocumentsContract.Document#MIME_TYPE_DIR
Expand All @@ -31,10 +32,13 @@ public class DocumentPickerFragment extends AbstractFilePickerFragment<Uri> {
// grab additional info for free afterwards. This is not the case with the documents API so we
// have to work around it.
final HashMap<Uri, Document> mLastRead;
// maps document ID of directories to parent path
final HashMap<String, Uri> mParents;

public DocumentPickerFragment(@NonNull Uri root) {
mRoot = root;
mLastRead = new HashMap<>();
mParents = new HashMap<>();
}

/**
Expand Down Expand Up @@ -106,32 +110,26 @@ public String getName(@NonNull Uri path) {
return ret;
}

@NonNull
@Override
public Uri toUri(@NonNull Uri path) {
return path;
}

@NonNull
@Override
public Uri getParent(@NonNull Uri from) {
Document doc = mLastRead.get(from);
if (doc != null) {
return doc.parent;
}
// This is not supposed to happen
String docId = DocumentsContract.getDocumentId(from);
Uri parent = mParents.get(docId);
if (parent != null)
return parent;
Log.e(TAG, "getParent() has not seen this document before");
return getRoot();
}

@NonNull
@Override
public String getFullPath(@NonNull Uri path) {
public String pathToString(@NonNull Uri path) {
return path.toString();
}

@NonNull
@Override
public Uri getPath(@NonNull String path) {
public Uri pathFromString(@NonNull String path) {
return Uri.parse(path);
}

Expand All @@ -148,7 +146,7 @@ public Loader<List<Uri>> getLoader() {
final Uri currentPath = mCurrentPath;

// totally makes sense!
final String docId = mCurrentPath.equals(root) ? DocumentsContract.getTreeDocumentId(currentPath) :
final String docId = currentPath.equals(root) ? DocumentsContract.getTreeDocumentId(currentPath) :
DocumentsContract.getDocumentId(currentPath);
final Uri childUri = DocumentsContract.buildChildDocumentsUriUsingTree(root, docId);

Expand All @@ -157,7 +155,7 @@ public Loader<List<Uri>> getLoader() {
DocumentsContract.Document.COLUMN_MIME_TYPE,
DocumentsContract.Document.COLUMN_DISPLAY_NAME,
};
return new AsyncTaskLoader<List<Uri>>(requireContext()) {
return new AsyncTaskLoader<>(requireContext()) {
@Override
public List<Uri> loadInBackground() {
final ContentResolver contentResolver = getContext().getContentResolver();
Expand All @@ -170,12 +168,19 @@ public List<Uri> loadInBackground() {
final int i1 = c.getColumnIndex(cols[0]), i2 = c.getColumnIndex(cols[1]), i3 = c.getColumnIndex(cols[2]);
while (c.moveToNext()) {
// TODO later: support FileFilter equivalent here
final String docId = c.getString(i1);
final boolean isDir = c.getString(i2).equals(DocumentsContract.Document.MIME_TYPE_DIR);
files.add(new Document(
DocumentsContract.buildDocumentUriUsingTree(root, c.getString(i1)),
currentPath,
c.getString(i2).equals(DocumentsContract.Document.MIME_TYPE_DIR),
DocumentsContract.buildDocumentUriUsingTree(root, docId),
isDir,
c.getString(i3)
));
// There is no generic way to get a parent directory for another directory and this
// can't be solved via mLastRead either, since by the time someone asks getParent()
// we're already inside the new directory. Not to mention that this would be insufficient
// when going back multiple times.
if (isDir)
mParents.put(docId, currentPath);
}
c.close();

Expand Down Expand Up @@ -206,13 +211,11 @@ protected void onStartLoading() {
*/
private static class Document implements Comparable<Document> {
private final @NonNull Uri uri;
private final @NonNull Uri parent;
private final boolean isDir;
private final @NonNull String displayName;

private Document(@NonNull Uri uri, @NonNull Uri parent, boolean dir, @NonNull String name) {
private Document(@NonNull Uri uri, boolean dir, @NonNull String name) {
this.uri = uri;
this.parent = parent;
isDir = dir;
displayName = name;
}
Expand All @@ -228,13 +231,11 @@ public boolean equals(Object o) {
// Sort directories before files, alphabetically otherwise
@Override
public int compareTo(Document other) {
if (isDir && !other.isDir) {
return -1;
} else if (other.isDir && !isDir) {
return 1;
} else {
return displayName.compareToIgnoreCase(other.displayName);
}
if (isDir != other.isDir)
return other.isDir ? 1 : -1;
return displayName.compareToIgnoreCase(other.displayName);
}
}

private static final String TAG = "mpv";
}
2 changes: 1 addition & 1 deletion app/src/main/java/is/xyz/filepicker/FileItemAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* A simple adapter which also inserts a header item ".." to handle going up to the parent folder.
* @param <T> the type which is used, for example a normal java File object.
*/
public class FileItemAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
class FileItemAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

protected final LogicHandler<T> mLogic;
protected List<T> mList = null;
Expand Down
38 changes: 8 additions & 30 deletions app/src/main/java/is/xyz/filepicker/FilePickerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public File getParent(@NonNull final File from) {
*/
@NonNull
@Override
public File getPath(@NonNull final String path) {
public File pathFromString(@NonNull final String path) {
return new File(path);
}

Expand All @@ -224,7 +224,7 @@ public File getPath(@NonNull final String path) {
*/
@NonNull
@Override
public String getFullPath(@NonNull final File path) {
public String pathToString(@NonNull final File path) {
return path.getPath();
}

Expand All @@ -239,27 +239,14 @@ public File getRoot() {
return new File("/");
}

/**
* Convert the path to a URI for the return intent
*
* @param file either a file or directory
* @return a Uri
*/
@NonNull
@Override
public Uri toUri(@NonNull final File file) {
return Uri.fromFile(file);
}

/**
* Get a loader that lists the Files in the current path,
* and monitors changes.
*/
@NonNull
@Override
public Loader<List<File>> getLoader() {
return new AsyncTaskLoader<List<File>>(getActivity()) {

return new AsyncTaskLoader<>(requireContext()) {
FileObserver fileObserver;

@Override
Expand All @@ -271,7 +258,6 @@ public List<File> loadInBackground() {
}

ArrayList<File> files = new ArrayList<>(listFiles.length);

for (File f : listFiles) {
if (f.isHidden() && !areHiddenItemsShown())
continue;
Expand All @@ -280,12 +266,7 @@ public List<File> loadInBackground() {
files.add(f);
}

Collections.sort(files, new Comparator<File>() {
@Override
public int compare(File lhs, File rhs) {
return compareFiles(lhs, rhs);
}
});
Collections.sort(files, (lhs, rhs) -> compareFiles(lhs, rhs));

return files;
}
Expand Down Expand Up @@ -349,13 +330,10 @@ protected void onReset() {
* and 1 if rhs should be placed before lhs
*/
protected int compareFiles(@NonNull File lhs, @NonNull File rhs) {
if (lhs.isDirectory() && !rhs.isDirectory()) {
return -1;
} else if (rhs.isDirectory() && !lhs.isDirectory()) {
return 1;
} else {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
final boolean ldir = lhs.isDirectory(), rdir = rhs.isDirectory();
if (ldir != rdir)
return rdir ? 1 : -1;
return lhs.getName().compareToIgnoreCase(rhs.getName());
}

private static final String TAG = "mpv";
Expand Down
23 changes: 5 additions & 18 deletions app/src/main/java/is/xyz/filepicker/LogicHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package is.xyz.filepicker;

import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -37,38 +36,26 @@ public interface LogicHandler<T> {
@NonNull
String getName(@NonNull final T path);

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

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

/**
* @param path
* @return the full path to the file
* Convert path to a string representation.
*/
@NonNull
String getFullPath(@NonNull final T path);
String pathToString(@NonNull final T path);

/**
* Convert the path to the type used.
*
* @param path
* Convert string representation back to a path.
*/
@NonNull
T getPath(@NonNull final String path);
T pathFromString(@NonNull final String path);

/**
* Get the root path (lowest allowed).
Expand Down
Loading

0 comments on commit c3452ad

Please sign in to comment.