mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 16:47:14 -04:00
Implement file/folder opening along with link opening
This commit is contained in:
parent
33d7d854ae
commit
db7881792f
@ -20,6 +20,7 @@ import android.os.*;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.*;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -508,12 +509,37 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
|
||||
b.show();
|
||||
}
|
||||
|
||||
private static void setUri(Context context, String input, Intent intent) {
|
||||
if(input.startsWith("file:")) {
|
||||
int truncLength = 5;
|
||||
if(input.startsWith("file://")) truncLength = 7;
|
||||
input = input.substring(truncLength);
|
||||
Log.i("MainActivity", input);
|
||||
boolean isDirectory = new File(input).isDirectory();
|
||||
if(isDirectory) {
|
||||
intent.setType(DocumentsContract.Document.MIME_TYPE_DIR);
|
||||
}else{
|
||||
String type = null;
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(input);
|
||||
if(extension != null) type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
if(type == null) type = "*/*";
|
||||
intent.setType(type);
|
||||
}
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
intent.setData(DocumentsContract.buildDocumentUri(
|
||||
context.getString(R.string.storageProviderAuthorities), input
|
||||
));
|
||||
return;
|
||||
}
|
||||
intent.setDataAndType(Uri.parse(input), "*/*");
|
||||
}
|
||||
|
||||
public static void openLink(String link) {
|
||||
Context ctx = touchpad.getContext(); // no more better way to obtain a context statically
|
||||
((Activity)ctx).runOnUiThread(() -> {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.parse(link.replace("file://", "content://")), "*/*");
|
||||
setUri(ctx, link, intent);
|
||||
ctx.startActivity(intent);
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(ctx, th);
|
||||
|
@ -1,16 +1,21 @@
|
||||
package net.kdt.pojavlaunch.scoped;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.Point;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.provider.DocumentsContract.Root;
|
||||
import android.provider.DocumentsProvider;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
|
||||
@ -19,8 +24,10 @@ import org.apache.commons.io.FileUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A document provider for the Storage Access Framework which exposes the files in the
|
||||
@ -183,6 +190,7 @@ public class FolderProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public String getDocumentType(String documentId) throws FileNotFoundException {
|
||||
Log.i("FolderPRovider", "getDocumentType("+documentId+")");
|
||||
File file = getFileForDocId(documentId);
|
||||
return getMimeType(file);
|
||||
}
|
||||
@ -300,4 +308,11 @@ public class FolderProvider extends DocumentsProvider {
|
||||
row.add(Document.COLUMN_ICON, R.mipmap.ic_launcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(26)
|
||||
public DocumentsContract.Path findDocumentPath(@Nullable String parentDocumentId, String childDocumentId) throws FileNotFoundException {
|
||||
File source = BASE_DIR;
|
||||
if(parentDocumentId != null) source = getFileForDocId(parentDocumentId);
|
||||
return new DocumentsContract.Path(getDocIdForFile(source), Collections.singletonList(childDocumentId));
|
||||
}
|
||||
}
|
@ -93,7 +93,8 @@ public class AsyncMinecraftDownloader {
|
||||
}
|
||||
|
||||
try {
|
||||
assets = downloadIndex(verInfo, new File(Tools.ASSETS_PATH, "indexes/" + verInfo.assets + ".json"));
|
||||
if(verInfo.assets != null)
|
||||
assets = downloadIndex(verInfo, new File(Tools.ASSETS_PATH, "indexes/" + verInfo.assets + ".json"));
|
||||
} catch (IOException e) {
|
||||
Log.e("AsyncMcDownloader", e.toString(), e);
|
||||
throw new DownloaderException(e);
|
||||
@ -199,7 +200,8 @@ public class AsyncMinecraftDownloader {
|
||||
|
||||
|
||||
try {
|
||||
downloadAssets(assets, verInfo.assets, assets.mapToResources ? new File(Tools.OBSOLETE_RESOURCES_PATH) : new File(Tools.ASSETS_PATH));
|
||||
if(assets != null)
|
||||
downloadAssets(assets, verInfo.assets, assets.mapToResources ? new File(Tools.OBSOLETE_RESOURCES_PATH) : new File(Tools.ASSETS_PATH));
|
||||
} catch (Exception e) {
|
||||
Log.e("AsyncMcDownloader", e.toString(), e);
|
||||
ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user