Android: Fix filenames for SAF paths showing incorrectly
This commit is contained in:
parent
c3f914565f
commit
f9fb4c2d16
|
@ -1003,9 +1003,9 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|||
(s_EmulationActivity_method_setInputDeviceVibration =
|
||||
env->GetMethodID(s_EmulationActivity_class, "setInputDeviceVibration", "(IFF)V")) == nullptr ||
|
||||
(s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr ||
|
||||
(s_GameListEntry_constructor = env->GetMethodID(
|
||||
s_GameListEntry_class, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/"
|
||||
(s_GameListEntry_constructor =
|
||||
env->GetMethodID(s_GameListEntry_class, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/"
|
||||
"String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) == nullptr ||
|
||||
(s_SaveStateInfo_constructor = env->GetMethodID(
|
||||
s_SaveStateInfo_class, "<init>",
|
||||
|
@ -1345,13 +1345,11 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
|||
{
|
||||
const Timestamp modified_ts(
|
||||
Timestamp::FromUnixTimestamp(static_cast<Timestamp::UnixTimestampValue>(entry.last_modified_time)));
|
||||
const std::string file_title_str(FileSystem::GetFileTitleFromPath(entry.path));
|
||||
const std::string cover_path_str(hi->GetGameList()->GetCoverImagePathForEntry(&entry));
|
||||
|
||||
jstring path = env->NewStringUTF(entry.path.c_str());
|
||||
jstring code = env->NewStringUTF(entry.code.c_str());
|
||||
jstring title = env->NewStringUTF(entry.title.c_str());
|
||||
jstring file_title = env->NewStringUTF(file_title_str.c_str());
|
||||
jstring region = env->NewStringUTF(DiscRegionToString(entry.region));
|
||||
jstring type = env->NewStringUTF(GameList::EntryTypeToString(entry.type));
|
||||
jstring compatibility_rating =
|
||||
|
@ -1360,8 +1358,7 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
|||
jstring modified_time = env->NewStringUTF(modified_ts.ToString("%Y/%m/%d, %H:%M:%S"));
|
||||
jlong size = entry.total_size;
|
||||
|
||||
jobject entry_jobject =
|
||||
env->NewObject(s_GameListEntry_class, s_GameListEntry_constructor, path, code, title, file_title, size,
|
||||
jobject entry_jobject = env->NewObject(s_GameListEntry_class, s_GameListEntry_constructor, path, code, title, size,
|
||||
modified_time, region, type, compatibility_rating, cover_path);
|
||||
|
||||
env->DeleteLocalRef(modified_time);
|
||||
|
@ -1370,7 +1367,6 @@ static jobject CreateGameListEntry(JNIEnv* env, AndroidHostInterface* hi, const
|
|||
env->DeleteLocalRef(compatibility_rating);
|
||||
env->DeleteLocalRef(type);
|
||||
env->DeleteLocalRef(region);
|
||||
env->DeleteLocalRef(file_title);
|
||||
env->DeleteLocalRef(title);
|
||||
env->DeleteLocalRef(code);
|
||||
env->DeleteLocalRef(path);
|
||||
|
|
|
@ -712,7 +712,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
|||
|
||||
CharSequence[] items = new CharSequence[numPaths + 1];
|
||||
for (int i = 0; i < numPaths; i++)
|
||||
items[i] = GameListEntry.getFileNameForPath(paths[i]);
|
||||
items[i] = FileHelper.getFileNameForPath(paths[i]);
|
||||
items[numPaths] = getString(R.string.emulation_activity_change_disc_select_new_file);
|
||||
|
||||
builder.setSingleChoiceItems(items, (currentPath < numPaths) ? currentPath : -1, (dialogInterface, i) -> {
|
||||
|
|
|
@ -242,6 +242,29 @@ public class FileHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file name component of a path or URI.
|
||||
* @param path Path/URI to examine.
|
||||
* @return File name component of path/URI.
|
||||
*/
|
||||
public static String getFileNameForPath(String path) {
|
||||
if (path.startsWith("content:/") || path.startsWith("file:/")) {
|
||||
try {
|
||||
final Uri uri = Uri.parse(path);
|
||||
final String lastPathSegment = uri.getLastPathSegment();
|
||||
if (lastPathSegment != null)
|
||||
path = lastPathSegment;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
int lastSlash = path.lastIndexOf('/');
|
||||
if (lastSlash > 0 && lastSlash < path.length() - 1)
|
||||
return path.substring(lastSlash + 1);
|
||||
else
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a file descriptor for a content URI string. Called by native code.
|
||||
*
|
||||
|
|
|
@ -27,7 +27,6 @@ public class GameListEntry {
|
|||
private String mPath;
|
||||
private String mCode;
|
||||
private String mTitle;
|
||||
private String mFileTitle;
|
||||
private long mSize;
|
||||
private String mModifiedTime;
|
||||
private DiscRegion mRegion;
|
||||
|
@ -35,12 +34,11 @@ public class GameListEntry {
|
|||
private CompatibilityRating mCompatibilityRating;
|
||||
private String mCoverPath;
|
||||
|
||||
public GameListEntry(String path, String code, String title, String fileTitle, long size, String modifiedTime, String region,
|
||||
public GameListEntry(String path, String code, String title, long size, String modifiedTime, String region,
|
||||
String type, String compatibilityRating, String coverPath) {
|
||||
mPath = path;
|
||||
mCode = code;
|
||||
mTitle = title;
|
||||
mFileTitle = fileTitle;
|
||||
mSize = size;
|
||||
mModifiedTime = modifiedTime;
|
||||
mCoverPath = coverPath;
|
||||
|
@ -76,10 +74,6 @@ public class GameListEntry {
|
|||
return mTitle;
|
||||
}
|
||||
|
||||
public String getFileTitle() {
|
||||
return mFileTitle;
|
||||
}
|
||||
|
||||
public long getSize() { return mSize; }
|
||||
|
||||
public String getModifiedTime() {
|
||||
|
@ -102,11 +96,4 @@ public class GameListEntry {
|
|||
|
||||
public void setCoverPath(String coverPath) { mCoverPath = coverPath; }
|
||||
|
||||
public static String getFileNameForPath(String path) {
|
||||
int lastSlash = path.lastIndexOf('/');
|
||||
if (lastSlash > 0 && lastSlash < path.length() - 1)
|
||||
return path.substring(lastSlash + 1);
|
||||
else
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,10 @@ package com.github.stenzek.duckstation;
|
|||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -74,7 +70,7 @@ public class GameListFragment extends Fragment implements GameList.OnRefreshList
|
|||
}
|
||||
|
||||
private String getSubTitle() {
|
||||
String fileName = GameListEntry.getFileNameForPath(mEntry.getPath());
|
||||
String fileName = FileHelper.getFileNameForPath(mEntry.getPath());
|
||||
String sizeString = String.format("%.2f MB", (double) mEntry.getSize() / 1048576.0);
|
||||
return String.format("%s (%s)", fileName, sizeString);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ public class GamePropertiesActivity extends AppCompatActivity {
|
|||
|
||||
mPropertiesListAdapter = new PropertyListAdapter(this);
|
||||
mPropertiesListAdapter.addItem("title", "Title", mGameListEntry.getTitle());
|
||||
mPropertiesListAdapter.addItem("filetitle", "File Title", mGameListEntry.getFileTitle());
|
||||
mPropertiesListAdapter.addItem("serial", "Serial", mGameListEntry.getCode());
|
||||
mPropertiesListAdapter.addItem("type", "Type", mGameListEntry.getType().toString());
|
||||
mPropertiesListAdapter.addItem("path", "Path", mGameListEntry.getPath());
|
||||
|
|
Loading…
Reference in New Issue