mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
[Android] InstalledCoresFragment is now functional. Complete with alphabetic sorting and the ability to uninstall cores.
This commit is contained in:
parent
8453002ee0
commit
490f35a6c3
@ -2,7 +2,5 @@
|
||||
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
|
||||
</ListView>
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" />
|
@ -26,6 +26,10 @@
|
||||
|
||||
<!-- Core Manager -->
|
||||
<string name="installed_cores">Installed Cores</string>
|
||||
<string name="uninstall_core">Uninstall Core</string>
|
||||
<string name="uninstall_core_message">Would you like to uninstall %1$s?</string>
|
||||
<string name="uninstall_failure">Failed to uninstall core: %1$s.</string>
|
||||
<string name="uninstall_success">Successfully uninstalled core: %1$s.</string>
|
||||
<string name="downloadable_cores">Downloadable Cores</string>
|
||||
|
||||
<!-- Display Refresh Rate Test Class -->
|
||||
@ -214,8 +218,10 @@
|
||||
<!-- Miscellaneous -->
|
||||
<string name="ok">OK</string>
|
||||
<string name="close">Close</string>
|
||||
<string name="general">General</string>
|
||||
<string name="enable">Enable</string>
|
||||
<string name="general">General</string>
|
||||
<string name="no">No</string>
|
||||
<string name="yes">Yes</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
@ -44,7 +44,7 @@ public final class CoreSelection extends ListActivity {
|
||||
setTitle(R.string.select_libretro_core);
|
||||
|
||||
// Populate the list
|
||||
final File[] libs = new File(getApplicationInfo().dataDir, "cores").listFiles();
|
||||
final File[] libs = new File(getApplicationInfo().dataDir, "/cores").listFiles();
|
||||
for (final File lib : libs) {
|
||||
String libName = lib.getName();
|
||||
|
||||
|
@ -5,7 +5,7 @@ import java.io.File;
|
||||
/**
|
||||
* Represents a list item within the CoreManager fragments.
|
||||
*/
|
||||
public final class CoreManagerListItem
|
||||
public final class CoreManagerListItem implements Comparable<CoreManagerListItem>
|
||||
{
|
||||
private final String name;
|
||||
private final String subtitle;
|
||||
@ -66,4 +66,13 @@ public final class CoreManagerListItem
|
||||
{
|
||||
return underlyingFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CoreManagerListItem other)
|
||||
{
|
||||
if(name != null)
|
||||
return name.toLowerCase().compareTo(other.getName().toLowerCase());
|
||||
else
|
||||
throw new NullPointerException("The name of this CoreManagerListItem is null");
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,123 @@
|
||||
package com.retroarch.browser.coremanager.fragments;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.coremanager.CoreManagerListItem;
|
||||
import com.retroarch.browser.preferences.util.ConfigFile;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* {@link ListFragment} that displays all of the currently installed cores
|
||||
*/
|
||||
public final class InstalledCoresFragment extends ListFragment
|
||||
{
|
||||
// Adapter backing this ListFragment.
|
||||
private InstalledCoresAdapter adapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// List which will contain all of the items for the list.
|
||||
List<CoreManagerListItem> items = new ArrayList<CoreManagerListItem>();
|
||||
// The list of items that will be added to the adapter backing this ListFragment.
|
||||
final List<CoreManagerListItem> items = new ArrayList<CoreManagerListItem>();
|
||||
|
||||
// TODO: Populate list adapter.
|
||||
// Initialize the core config for retrieving core names.
|
||||
ConfigFile coreConfig = new ConfigFile();
|
||||
try
|
||||
{
|
||||
coreConfig.append(getActivity().getAssets().open("libretro_cores.cfg"));
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
Log.e("InstalledCoresFragment", "Failed to load libretro_cores.cfg from assets.");
|
||||
}
|
||||
|
||||
// Set the list adapter.
|
||||
final InstalledCoresAdapter adapter = new InstalledCoresAdapter(getActivity(), R.layout.coremanager_list_item, items);
|
||||
// Check if the device supports NEON.
|
||||
final String cpuInfo = UserPreferences.readCPUInfo();
|
||||
final boolean supportsNeon = cpuInfo.contains("neon");
|
||||
|
||||
// Populate the list
|
||||
final File[] libs = new File(getActivity().getApplicationInfo().dataDir, "/cores").listFiles();
|
||||
for (File lib : libs)
|
||||
{
|
||||
String libName = lib.getName();
|
||||
|
||||
// Never append a NEON lib if we don't have NEON.
|
||||
if (libName.contains("neon") && !supportsNeon)
|
||||
continue;
|
||||
|
||||
// If we have a NEON version with NEON capable CPU,
|
||||
// never append a non-NEON version.
|
||||
if (supportsNeon && !libName.contains("neon"))
|
||||
{
|
||||
boolean hasNeonVersion = false;
|
||||
for (File lib_ : libs)
|
||||
{
|
||||
String otherName = lib_.getName();
|
||||
String baseName = libName.replace(".so", "");
|
||||
|
||||
if (otherName.contains("neon") && otherName.startsWith(baseName))
|
||||
{
|
||||
hasNeonVersion = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNeonVersion)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Attempt to get the core name.
|
||||
String coreName;
|
||||
String strippedName = libName.replace(".so", "");
|
||||
if (coreConfig.keyExists(strippedName))
|
||||
coreName = coreConfig.getString(strippedName);
|
||||
else
|
||||
coreName = strippedName;
|
||||
|
||||
// Attempt to get the core subtitle.
|
||||
String subtitle = strippedName + "_system";
|
||||
if (coreConfig.keyExists(subtitle))
|
||||
subtitle = coreConfig.getString(subtitle);
|
||||
else
|
||||
subtitle = "";
|
||||
|
||||
Log.d("InstalledCoresFragment", "Core Name: " + coreName);
|
||||
Log.d("InstalledCoresFragment", "Core Subtitle: " + subtitle);
|
||||
|
||||
// Add it to the list.
|
||||
items.add(new CoreManagerListItem(coreName, subtitle, lib.getPath()));
|
||||
}
|
||||
|
||||
// Sort the list alphabetically
|
||||
Collections.sort(items);
|
||||
|
||||
// Initialize and set the backing adapter for this ListFragment.
|
||||
adapter = new InstalledCoresAdapter(getActivity(), R.layout.coremanager_list_item, items);
|
||||
setListAdapter(adapter);
|
||||
}
|
||||
|
||||
@ -41,11 +125,51 @@ public final class InstalledCoresFragment extends ListFragment
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
// Inflate the layout for this ListFragment.
|
||||
View parentView = inflater.inflate(R.layout.coremanager_listview_layout, container, false);
|
||||
View parentView = inflater.inflate(R.layout.coremanager_listview, container, false);
|
||||
|
||||
return parentView.findViewById(android.R.id.list);
|
||||
// Set the long click listener.
|
||||
ListView mainList = (ListView) parentView.findViewById(android.R.id.list);
|
||||
mainList.setOnItemLongClickListener(itemLongClickListener);
|
||||
|
||||
return mainList;
|
||||
}
|
||||
|
||||
// This will be the handler for long clicks on individual list items in this ListFragment.
|
||||
private final OnItemLongClickListener itemLongClickListener = new OnItemLongClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
// Begin building the AlertDialog
|
||||
final CoreManagerListItem item = adapter.getItem(position);
|
||||
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setTitle(R.string.uninstall_core);
|
||||
alert.setMessage(String.format(getString(R.string.uninstall_core_message), item.getName()));
|
||||
alert.setNegativeButton(R.string.no, null);
|
||||
alert.setPositiveButton(R.string.yes, new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// Attempt to uninstall the core item.
|
||||
if (item.getUnderlyingFile().delete())
|
||||
{
|
||||
Toast.makeText(getActivity(), String.format(getString(R.string.uninstall_success), item.getName()), Toast.LENGTH_LONG).show();
|
||||
adapter.remove(item);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
else // Failed to uninstall.
|
||||
{
|
||||
Toast.makeText(getActivity(), String.format(getString(R.string.uninstall_failure), item.getName()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The {@link ArrayAdapter} that backs this InstalledCoresFragment.
|
||||
*/
|
||||
@ -60,7 +184,7 @@ public final class InstalledCoresFragment extends ListFragment
|
||||
*
|
||||
* @param context The current {@link Context}.
|
||||
* @param resourceId The resource ID for a layout file containing a layout to use when instantiating views.
|
||||
* @param objects The items to represent in the {@link ListView}.
|
||||
* @param items The list of items to represent in this adapter.
|
||||
*/
|
||||
public InstalledCoresAdapter(Context context, int resourceId, List<CoreManagerListItem> items)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user