use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.
the class MainActivity method setupActivity.
private void setupActivity() {
initFolders();
checkActionBar();
appsListFragment = new AppsListFragment();
ArrayList<AppItem> apps = new ArrayList<>();
AppsListAdapter adapter = new AppsListAdapter(this, apps);
appsListFragment.setListAdapter(adapter);
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.container, appsListFragment).commitAllowingStateLoss();
initDb();
updateAppsList();
}
use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.
the class FileUtils method getApp.
public static AppItem getApp(File file) {
LinkedHashMap<String, String> params = FileUtils.loadManifest(new File(file.getAbsolutePath(), ConfigActivity.MIDLET_CONF_FILE));
String imagePath = params.get("MIDlet-Icon");
if (imagePath == null) {
imagePath = params.get("MIDlet-1").split(",")[1];
}
AppItem item = new AppItem(file.getName(), params.get("MIDlet-Name"), params.get("MIDlet-Vendor"), params.get("MIDlet-Version"));
item.setImagePathExt(imagePath);
return item;
}
use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.
the class FileUtils method getAppsList.
public static ArrayList<AppItem> getAppsList(Context context) {
ArrayList<AppItem> apps = new ArrayList<>();
String[] appFolders = new File(ConfigActivity.APP_DIR).list();
if (appFolders != null) {
for (String appFolder : appFolders) {
File temp = new File(ConfigActivity.APP_DIR, appFolder);
try {
if (temp.isDirectory() && temp.list().length > 0) {
AppItem item = getApp(temp);
apps.add(item);
} else {
temp.delete();
}
} catch (RuntimeException re) {
re.printStackTrace();
FileUtils.deleteDirectory(temp);
Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();
}
}
}
return apps;
}
use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.
the class AppUtils method updateDb.
public static void updateDb(AppRepository appRepository, List<AppItem> items) {
File tmp = new File(Config.getAppDir(), ".tmp");
if (tmp.exists()) {
// TODO: 30.07.2021 incomplete installation - maybe can continue?
FileUtils.deleteDirectory(tmp);
}
String[] appFolders = new File(Config.getAppDir()).list();
if (appFolders == null || appFolders.length == 0) {
// If db isn't empty
if (items.size() != 0) {
appRepository.deleteAll();
}
return;
}
List<String> appFoldersList = new ArrayList<>(Arrays.asList(appFolders));
// Delete invalid app items from db
ListIterator<AppItem> iterator = items.listIterator(items.size());
while (iterator.hasPrevious()) {
AppItem item = iterator.previous();
if (appFoldersList.remove(item.getPath())) {
iterator.remove();
}
}
if (items.size() > 0) {
appRepository.delete(items);
}
if (appFoldersList.size() > 0) {
appRepository.insert(getAppsList(appFoldersList));
}
}
use of ru.playsoftware.j2meloader.applist.AppItem in project J2ME-Loader by nikita36078.
the class MainActivity method updateAppsList.
private void updateAppsList() {
String appSort = sp.getString("pref_app_sort", "name");
List<AppItem> apps;
if (appSort.equals("name")) {
apps = appItemDao.getAllByName();
} else {
apps = appItemDao.getAllByDate();
}
AppsListAdapter adapter = (AppsListAdapter) appsListFragment.getListAdapter();
adapter.setItems(apps);
adapter.notifyDataSetChanged();
}
Aggregations