Minor reformat and fix.

This commit is contained in:
Miku AuahDark
2024-01-26 23:18:54 +08:00
parent fc6053974f
commit a712164440
4 changed files with 117 additions and 116 deletions
@@ -20,11 +20,6 @@
package org.love2d.android; package org.love2d.android;
import androidx.annotation.Keep;
import androidx.core.app.ActivityCompat;
import org.libsdl.app.SDLActivity;
import android.Manifest; import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -43,6 +38,11 @@ import android.util.Log;
import android.view.DisplayCutout; import android.view.DisplayCutout;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.Keep;
import androidx.core.app.ActivityCompat;
import org.libsdl.app.SDLActivity;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -75,7 +75,7 @@ public class GameActivity extends SDLActivity {
@Override @Override
protected String[] getLibraries() { protected String[] getLibraries() {
return new String[] { return new String[]{
"c++_shared", "c++_shared",
"SDL2", "SDL2",
"oboe", "oboe",
@@ -193,15 +193,12 @@ public class GameActivity extends SDLActivity {
} }
} }
if (inputStream != null) { try {
try { inputStream.close();
inputStream.close(); } catch (IOException ignored) {
} catch (IOException e) {
// Ignored
}
} }
return inputStream != null; return true;
} }
@Keep @Keep
@@ -235,7 +232,7 @@ public class GameActivity extends SDLActivity {
HashMap<String, Boolean> map = buildFileTree(getAssets(), "", new HashMap<>()); HashMap<String, Boolean> map = buildFileTree(getAssets(), "", new HashMap<>());
ArrayList<String> result = new ArrayList<>(); ArrayList<String> result = new ArrayList<>();
for (Map.Entry<String, Boolean> data: map.entrySet()) { for (Map.Entry<String, Boolean> data : map.entrySet()) {
result.add((data.getValue() ? "d" : "f") + data.getKey()); result.add((data.getValue() ? "d" : "f") + data.getKey());
} }
@@ -418,13 +415,12 @@ public class GameActivity extends SDLActivity {
// Mark as file // Mark as file
map.put(dir, true); map.put(dir, true);
// This Object comparison is intentional. if (!strippedDir.equals(dir)) {
if (strippedDir != dir) {
map.put(strippedDir, true); map.put(strippedDir, true);
} }
if (list != null) { if (list != null) {
for (String path: list) { for (String path : list) {
buildFileTree(assetManager, dir + path + "/", map); buildFileTree(assetManager, dir + path + "/", map);
} }
} }
@@ -440,6 +436,10 @@ public class GameActivity extends SDLActivity {
try { try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r"); ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
throw new RuntimeException("pfd is null");
}
fd = pfd.dup().detachFd(); fd = pfd.dup().detachFd();
pfd.close(); pfd.close();
} catch (Exception e) { } catch (Exception e) {
@@ -453,12 +453,14 @@ public class GameActivity extends SDLActivity {
String scheme = game.getScheme(); String scheme = game.getScheme();
String path = game.getPath(); String path = game.getPath();
if (scheme.equals("content")) { if (scheme != null) {
// Convert the URI to file descriptor. if (scheme.equals("content")) {
args = new String[] {"/love2d://fd/" + convertToFileDescriptor(game)}; // Convert the URI to file descriptor.
} else if (scheme.equals("file")) { args = new String[]{"/love2d://fd/" + convertToFileDescriptor(game)};
// Regular file, pass as-is. } else if (scheme.equals("file")) {
args = new String[] {path}; // Regular file, pass as-is.
args = new String[]{path};
}
} }
} }
} }
@@ -20,14 +20,15 @@
package org.love2d.android; package org.love2d.android;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends AppCompatActivity {
@Override @Override
@@ -45,7 +46,11 @@ public class AboutActivity extends AppCompatActivity {
}); });
// Set version // Set version
TextView versionText = findViewById(R.id.textView4); try {
versionText.setText(getString(R.string.version_info, BuildConfig.VERSION_NAME)); String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
TextView versionText = findViewById(R.id.textView4);
versionText.setText(getString(R.string.version_info, version));
} catch (PackageManager.NameNotFoundException ignored) {
}
} }
} }
@@ -15,8 +15,8 @@
*/ */
/* /*
* Modified for use with LOVE by the LOVE Development Team * Modified for use with LOVE by the LOVE Development Team
* Copyright (C) 2023 LOVE Development Team * Copyright (C) 2023 LOVE Development Team
*/ */
package org.love2d.android; package org.love2d.android;
@@ -29,7 +29,6 @@ import android.database.MatrixCursor;
import android.graphics.Point; import android.graphics.Point;
import android.os.Build; import android.os.Build;
import android.os.CancellationSignal; import android.os.CancellationSignal;
import android.os.Handler;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root; import android.provider.DocumentsContract.Root;
@@ -42,15 +41,11 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects; import java.util.Objects;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.Set;
/** /**
* Manages documents and exposes them to the Android system for sharing. * Manages documents and exposes them to the Android system for sharing.
@@ -61,25 +56,25 @@ public class LoveDocumentsProvider extends DocumentsProvider {
// Use these as the default columns to return information about a root if no specific // Use these as the default columns to return information about a root if no specific
// columns are requested in a query. // columns are requested in a query.
private static final String[] DEFAULT_ROOT_PROJECTION = new String[]{ private static final String[] DEFAULT_ROOT_PROJECTION = new String[]{
Root.COLUMN_ROOT_ID, Root.COLUMN_ROOT_ID,
Root.COLUMN_MIME_TYPES, Root.COLUMN_MIME_TYPES,
Root.COLUMN_FLAGS, Root.COLUMN_FLAGS,
Root.COLUMN_ICON, Root.COLUMN_ICON,
Root.COLUMN_TITLE, Root.COLUMN_TITLE,
Root.COLUMN_SUMMARY, Root.COLUMN_SUMMARY,
Root.COLUMN_DOCUMENT_ID, Root.COLUMN_DOCUMENT_ID,
Root.COLUMN_AVAILABLE_BYTES Root.COLUMN_AVAILABLE_BYTES
}; };
// Use these as the default columns to return information about a document if no specific // Use these as the default columns to return information about a document if no specific
// columns are requested in a query. // columns are requested in a query.
private static final String[] DEFAULT_DOCUMENT_PROJECTION = new String[]{ private static final String[] DEFAULT_DOCUMENT_PROJECTION = new String[]{
Document.COLUMN_DOCUMENT_ID, Document.COLUMN_DOCUMENT_ID,
Document.COLUMN_MIME_TYPE, Document.COLUMN_MIME_TYPE,
Document.COLUMN_DISPLAY_NAME, Document.COLUMN_DISPLAY_NAME,
Document.COLUMN_LAST_MODIFIED, Document.COLUMN_LAST_MODIFIED,
Document.COLUMN_FLAGS, Document.COLUMN_FLAGS,
Document.COLUMN_SIZE Document.COLUMN_SIZE
}; };
// No official policy on how many to return, but make sure you do limit the number of recent // No official policy on how many to return, but make sure you do limit the number of recent
@@ -120,19 +115,13 @@ public class LoveDocumentsProvider extends DocumentsProvider {
// documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users // documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users
// to search all documents the application shares. FLAG_SUPPORTS_IS_CHILD allows // to search all documents the application shares. FLAG_SUPPORTS_IS_CHILD allows
// testing parent child relationships, available after SDK 21 (Lollipop). // testing parent child relationships, available after SDK 21 (Lollipop).
if (SDK_INT < Build.VERSION_CODES.LOLLIPOP) { row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE |
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_RECENTS |
Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_SEARCH |
Root.FLAG_SUPPORTS_SEARCH); Root.FLAG_SUPPORTS_IS_CHILD);
} else {
row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE |
Root.FLAG_SUPPORTS_RECENTS |
Root.FLAG_SUPPORTS_SEARCH |
Root.FLAG_SUPPORTS_IS_CHILD);
}
// COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider). // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider).
row.add(Root.COLUMN_TITLE, getContext().getApplicationInfo().loadLabel(getContext().getPackageManager()).toString()); row.add(Root.COLUMN_TITLE, Objects.requireNonNull(getContext()).getApplicationInfo().loadLabel(getContext().getPackageManager()).toString());
// This document id must be unique within this provider and consistent across time. The // This document id must be unique within this provider and consistent across time. The
// system picker UI may save it and refer to it later. // system picker UI may save it and refer to it later.
@@ -149,7 +138,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor queryRecentDocuments(String rootId, String[] projection) public Cursor queryRecentDocuments(String rootId, String[] projection)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "queryRecentDocuments"); Log.v(TAG, "queryRecentDocuments");
// This implementation walks a local file structure to find the most recently // This implementation walks a local file structure to find the most recently
@@ -181,7 +170,11 @@ public class LoveDocumentsProvider extends DocumentsProvider {
final File file = pending.removeFirst(); final File file = pending.removeFirst();
if (file.isDirectory()) { if (file.isDirectory()) {
// If it's a directory, add all its children to the unprocessed list // If it's a directory, add all its children to the unprocessed list
Collections.addAll(pending, file.listFiles()); File[] files = file.listFiles();
if (files != null) {
Collections.addAll(pending, files);
}
} else { } else {
// If it's a file, add it to the ordered queue. // If it's a file, add it to the ordered queue.
lastModifiedFiles.add(file); lastModifiedFiles.add(file);
@@ -200,7 +193,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) public Cursor querySearchDocuments(String rootId, String query, String[] projection)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "querySearchDocuments"); Log.v(TAG, "querySearchDocuments");
// Create a cursor with the requested projection, or the default projection. // Create a cursor with the requested projection, or the default projection.
@@ -225,7 +218,11 @@ public class LoveDocumentsProvider extends DocumentsProvider {
final File file = pending.removeFirst(); final File file = pending.removeFirst();
if (file.isDirectory()) { if (file.isDirectory()) {
// If it's a directory, add all its children to the unprocessed list // If it's a directory, add all its children to the unprocessed list
Collections.addAll(pending, file.listFiles()); File[] files = file.listFiles();
if (files != null) {
Collections.addAll(pending, files);
}
} else { } else {
// If it's a file and it matches, add it to the result cursor. // If it's a file and it matches, add it to the result cursor.
if (file.getName().toLowerCase().contains(query)) { if (file.getName().toLowerCase().contains(query)) {
@@ -239,18 +236,18 @@ public class LoveDocumentsProvider extends DocumentsProvider {
@Override @Override
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint, public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint,
CancellationSignal signal) CancellationSignal signal)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "openDocumentThumbnail"); Log.v(TAG, "openDocumentThumbnail");
final File file = getFileForDocId(documentId); final File file = getFileForDocId(documentId);
final ParcelFileDescriptor pfd = final ParcelFileDescriptor pfd =
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH); return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
} }
@Override @Override
public Cursor queryDocument(String documentId, String[] projection) public Cursor queryDocument(String documentId, String[] projection)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "queryDocument"); Log.v(TAG, "queryDocument");
// Create a cursor with the requested projection, or the default projection. // Create a cursor with the requested projection, or the default projection.
@@ -263,14 +260,18 @@ public class LoveDocumentsProvider extends DocumentsProvider {
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
String sortOrder) throws FileNotFoundException { String sortOrder) throws FileNotFoundException {
Log.v(TAG, "queryChildDocuments, parentDocumentId: " + Log.v(TAG, "queryChildDocuments, parentDocumentId: " +
parentDocumentId + parentDocumentId +
" sortOrder: " + " sortOrder: " +
sortOrder); sortOrder);
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
final File parent = getFileForDocId(parentDocumentId); final File parent = getFileForDocId(parentDocumentId);
for (File file : parent.listFiles()) { File[] files = parent.listFiles();
includeFile(result, null, file);
if (files != null) {
for (File file : files) {
includeFile(result, null, file);
}
} }
return result; return result;
} }
@@ -292,22 +293,18 @@ public class LoveDocumentsProvider extends DocumentsProvider {
@Override @Override
public boolean isChildDocument(String parentDocumentId, String documentId) { public boolean isChildDocument(String parentDocumentId, String documentId) {
Log.v(TAG, "isChildDocument"); Log.v(TAG, "isChildDocument");
if(documentId.startsWith(parentDocumentId)) { return documentId.startsWith(parentDocumentId);
return true;
} else {
return false;
}
} }
@Override @Override
public String createDocument(String documentId, String mimeType, String displayName) public String createDocument(String documentId, String mimeType, String displayName)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "createDocument"); Log.v(TAG, "createDocument");
File parent = getFileForDocId(documentId); File parent = getFileForDocId(documentId);
File file = new File(parent.getPath(), displayName); File file = new File(parent.getPath(), displayName);
int conflictId = 1; int conflictId = 1;
while(file.exists()) { while (file.exists()) {
file = new File(parent.getPath(), displayName + "(" + conflictId++ + ")"); file = new File(parent.getPath(), displayName + "(" + conflictId++ + ")");
} }
try { try {
@@ -321,18 +318,18 @@ public class LoveDocumentsProvider extends DocumentsProvider {
if (!wasNewFileCreated) { if (!wasNewFileCreated) {
throw new FileNotFoundException("Failed to create document with name " + throw new FileNotFoundException("Failed to create document with name " +
displayName + " and documentId " + documentId); displayName + " and documentId " + documentId);
} }
} catch (IOException e) { } catch (IOException e) {
throw new FileNotFoundException("Failed to create document with name " + throw new FileNotFoundException("Failed to create document with name " +
displayName + " and documentId " + documentId); displayName + " and documentId " + documentId);
} }
return getDocIdForFile(file); return getDocIdForFile(file);
} }
@Override @Override
public String renameDocument(String documentId, String displayName) public String renameDocument(String documentId, String displayName)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "renameDocument"); Log.v(TAG, "renameDocument");
if (displayName == null) { if (displayName == null) {
throw new FileNotFoundException("Failed to rename document, new name is null"); throw new FileNotFoundException("Failed to rename document, new name is null");
@@ -373,7 +370,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
@Override @Override
public void removeDocument(String documentId, String parentDocumentId) public void removeDocument(String documentId, String parentDocumentId)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "removeDocument"); Log.v(TAG, "removeDocument");
File parent = getFileForDocId(parentDocumentId); File parent = getFileForDocId(parentDocumentId);
File file = getFileForDocId(documentId); File file = getFileForDocId(documentId);
@@ -411,14 +408,14 @@ public class LoveDocumentsProvider extends DocumentsProvider {
Log.v(TAG, "copyDocument with document parent"); Log.v(TAG, "copyDocument with document parent");
if (!isChildDocument(sourceParentDocumentId, sourceDocumentId)) { if (!isChildDocument(sourceParentDocumentId, sourceDocumentId)) {
throw new FileNotFoundException("Failed to copy document with id " + throw new FileNotFoundException("Failed to copy document with id " +
sourceDocumentId + ". Parent is not: " + sourceParentDocumentId); sourceDocumentId + ". Parent is not: " + sourceParentDocumentId);
} }
return copyDocument(sourceDocumentId, targetParentDocumentId); return copyDocument(sourceDocumentId, targetParentDocumentId);
} }
@Override @Override
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) public String copyDocument(String sourceDocumentId, String targetParentDocumentId)
throws FileNotFoundException { throws FileNotFoundException {
Log.v(TAG, "copyDocument"); Log.v(TAG, "copyDocument");
File parent = getFileForDocId(targetParentDocumentId); File parent = getFileForDocId(targetParentDocumentId);
@@ -426,13 +423,13 @@ public class LoveDocumentsProvider extends DocumentsProvider {
File newFile = new File(parent.getPath(), oldFile.getName()); File newFile = new File(parent.getPath(), oldFile.getName());
try { try {
int conflictId = 1; int conflictId = 1;
while(newFile.exists()) { while (newFile.exists()) {
newFile = new File(parent.getPath(), oldFile.getName() + "(" + conflictId++ + ")"); newFile = new File(parent.getPath(), oldFile.getName() + "(" + conflictId++ + ")");
} }
// Create the new File to copy into // Create the new File to copy into
boolean wasNewFileCreated = false; boolean wasNewFileCreated = false;
boolean isDirectory = Document.MIME_TYPE_DIR.equals(getTypeForFile(oldFile)); boolean isDirectory = Document.MIME_TYPE_DIR.equals(getTypeForFile(oldFile));
if(isDirectory) { if (isDirectory) {
if (newFile.mkdir()) { if (newFile.mkdir()) {
if (newFile.setWritable(true) && newFile.setReadable(true)) { if (newFile.setWritable(true) && newFile.setReadable(true)) {
wasNewFileCreated = true; wasNewFileCreated = true;
@@ -448,13 +445,13 @@ public class LoveDocumentsProvider extends DocumentsProvider {
if (!wasNewFileCreated) { if (!wasNewFileCreated) {
throw new FileNotFoundException("Failed to copy document " + sourceDocumentId + throw new FileNotFoundException("Failed to copy document " + sourceDocumentId +
". Could not create new file."); ". Could not create new file.");
} }
if(!isDirectory) { if (!isDirectory) {
// Copy the bytes into the new file // Copy the bytes into the new file
try (InputStream inStream = new FileInputStream(oldFile)) { try (FileInputStream inStream = new FileInputStream(oldFile)) {
try (OutputStream outStream = new FileOutputStream(newFile)) { try (FileOutputStream outStream = new FileOutputStream(newFile)) {
// Transfer bytes from in to out // Transfer bytes from in to out
byte[] buf = new byte[16384]; // disk: 8-64k byte[] buf = new byte[16384]; // disk: 8-64k
int len; int len;
@@ -466,7 +463,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
} }
} catch (IOException e) { } catch (IOException e) {
throw new FileNotFoundException("Failed to copy document: " + sourceDocumentId + throw new FileNotFoundException("Failed to copy document: " + sourceDocumentId +
". " + e.getMessage()); ". " + e.getMessage());
} }
return getDocIdForFile(newFile); return getDocIdForFile(newFile);
} }
@@ -478,7 +475,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
try { try {
// Copy document, insisting that the parent is correct // Copy document, insisting that the parent is correct
String newDocumentId = copyDocument(sourceDocumentId, sourceParentDocumentId, String newDocumentId = copyDocument(sourceDocumentId, sourceParentDocumentId,
targetParentDocumentId); targetParentDocumentId);
// Remove old document // Remove old document
removeDocument(sourceDocumentId, sourceParentDocumentId); removeDocument(sourceDocumentId, sourceParentDocumentId);
return newDocumentId; return newDocumentId;
@@ -530,7 +527,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
final int lastDot = name.lastIndexOf('.'); final int lastDot = name.lastIndexOf('.');
if (lastDot >= 0) { if (lastDot >= 0) {
final String extension = name.substring(lastDot + 1); final String extension = name.substring(lastDot + 1);
if(extension == "love") { if (extension.equals("love")) {
return "application/x-love-game"; return "application/x-love-game";
} }
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
@@ -575,10 +572,9 @@ public class LoveDocumentsProvider extends DocumentsProvider {
* @param result the cursor to modify * @param result the cursor to modify
* @param docId the document ID representing the desired file (may be null if given file) * @param docId the document ID representing the desired file (may be null if given file)
* @param file the File object representing the desired file (may be null if given docID) * @param file the File object representing the desired file (may be null if given docID)
* @throws FileNotFoundException
*/ */
private void includeFile(MatrixCursor result, String docId, File file) private void includeFile(MatrixCursor result, String docId, File file)
throws FileNotFoundException { throws FileNotFoundException {
if (docId == null) { if (docId == null) {
docId = getDocIdForFile(file); docId = getDocIdForFile(file);
} else { } else {
@@ -597,11 +593,8 @@ public class LoveDocumentsProvider extends DocumentsProvider {
// FLAG_SUPPORTS_DELETE // FLAG_SUPPORTS_DELETE
flags |= Document.FLAG_SUPPORTS_WRITE; flags |= Document.FLAG_SUPPORTS_WRITE;
flags |= Document.FLAG_SUPPORTS_DELETE; flags |= Document.FLAG_SUPPORTS_DELETE;
flags |= Document.FLAG_SUPPORTS_RENAME;
// Add SDK specific flags if appropriate
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
flags |= Document.FLAG_SUPPORTS_RENAME;
}
if (SDK_INT >= Build.VERSION_CODES.N) { if (SDK_INT >= Build.VERSION_CODES.N) {
flags |= Document.FLAG_SUPPORTS_REMOVE; flags |= Document.FLAG_SUPPORTS_REMOVE;
flags |= Document.FLAG_SUPPORTS_MOVE; flags |= Document.FLAG_SUPPORTS_MOVE;
@@ -619,8 +612,8 @@ public class LoveDocumentsProvider extends DocumentsProvider {
final MatrixCursor.RowBuilder row = result.newRow(); final MatrixCursor.RowBuilder row = result.newRow();
row.add(Document.COLUMN_DOCUMENT_ID, docId); row.add(Document.COLUMN_DOCUMENT_ID, docId);
if(file.getAbsolutePath() == mBaseDir.getAbsolutePath()) { if (file.getAbsolutePath().equals(mBaseDir.getAbsolutePath())) {
row.add(Document.COLUMN_DISPLAY_NAME, getContext().getApplicationInfo().loadLabel(getContext().getPackageManager()).toString()); row.add(Document.COLUMN_DISPLAY_NAME, Objects.requireNonNull(getContext()).getApplicationInfo().loadLabel(getContext().getPackageManager()).toString());
} else { } else {
row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_DISPLAY_NAME, displayName);
} }
@@ -630,7 +623,7 @@ public class LoveDocumentsProvider extends DocumentsProvider {
row.add(Document.COLUMN_FLAGS, flags); row.add(Document.COLUMN_FLAGS, flags);
// Add a custom icon // Add a custom icon
if(mimeType == "application/x-love-game") { if (mimeType.equals("application/x-love-game")) {
row.add(Document.COLUMN_ICON, R.drawable.love); row.add(Document.COLUMN_ICON, R.drawable.love);
} else { } else {
row.add(Document.COLUMN_ICON, null); row.add(Document.COLUMN_ICON, null);
@@ -642,7 +635,6 @@ public class LoveDocumentsProvider extends DocumentsProvider {
* *
* @param docId the document ID representing the desired file * @param docId the document ID representing the desired file
* @return a File represented by the given document ID * @return a File represented by the given document ID
* @throws java.io.FileNotFoundException
*/ */
private File getFileForDocId(String docId) throws FileNotFoundException { private File getFileForDocId(String docId) throws FileNotFoundException {
File target = mBaseDir; File target = mBaseDir;
@@ -20,15 +20,6 @@
package org.love2d.android; package org.love2d.android;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@@ -40,6 +31,15 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -74,7 +74,7 @@ public class MainActivity extends AppCompatActivity {
GameListAdapter adapter = new GameListAdapter(); GameListAdapter adapter = new GameListAdapter();
// Set refresh listener // Set refresh listener
swipeLayout.setOnRefreshListener(() -> { swipeLayout.setOnRefreshListener(() -> {
scanGames(adapter, noGameText, swipeLayout); scanGames(adapter, noGameText, swipeLayout);
}); });
@@ -99,7 +99,7 @@ public class MainActivity extends AppCompatActivity {
// Handle item selection // Handle item selection
if (itemId == R.id.optionItem) { if (itemId == R.id.optionItem) {
openFileLauncher.launch(new String[] {"*/*"}); openFileLauncher.launch(new String[]{"*/*"});
return true; return true;
} else if (itemId == R.id.optionItem2) { } else if (itemId == R.id.optionItem2) {
Intent intent = new Intent(this, GameActivity.class); Intent intent = new Intent(this, GameActivity.class);
@@ -120,7 +120,8 @@ public class MainActivity extends AppCompatActivity {
private AlertDialog getGameFolderDialog() { private AlertDialog getGameFolderDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this) AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(getString(R.string.game_folder)) .setTitle(getString(R.string.game_folder))
.setPositiveButton(R.string.ok, (dialog1, which) -> { }); .setPositiveButton(R.string.ok, (dialog1, which) -> {
});
StringBuilder message = new StringBuilder() StringBuilder message = new StringBuilder()
.append(getString(R.string.game_folder_location, getPackageName())) .append(getString(R.string.game_folder_location, getPackageName()))
.append("\n\n"); .append("\n\n");
@@ -211,7 +212,8 @@ public class MainActivity extends AppCompatActivity {
ZipFile zip = new ZipFile(file, ZipFile.OPEN_READ); ZipFile zip = new ZipFile(file, ZipFile.OPEN_READ);
valid = zip.getEntry("main.lua") != null; valid = zip.getEntry("main.lua") != null;
zip.close(); zip.close();
} catch (IOException ignored) { } } catch (IOException ignored) {
}
return valid; return valid;
} }