Search in sources :

Example 1 with AppItem

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();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) AppsListAdapter(ru.playsoftware.j2meloader.applist.AppsListAdapter) AppsListFragment(ru.playsoftware.j2meloader.applist.AppsListFragment) AppItem(ru.playsoftware.j2meloader.applist.AppItem) ArrayList(java.util.ArrayList)

Example 2 with AppItem

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;
}
Also used : AppItem(ru.playsoftware.j2meloader.applist.AppItem) File(java.io.File)

Example 3 with AppItem

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;
}
Also used : AppItem(ru.playsoftware.j2meloader.applist.AppItem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with AppItem

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));
    }
}
Also used : AppItem(ru.playsoftware.j2meloader.applist.AppItem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with AppItem

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();
}
Also used : AppsListAdapter(ru.playsoftware.j2meloader.applist.AppsListAdapter) AppItem(ru.playsoftware.j2meloader.applist.AppItem)

Aggregations

AppItem (ru.playsoftware.j2meloader.applist.AppItem)8 File (java.io.File)6 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)2 AppsListAdapter (ru.playsoftware.j2meloader.applist.AppsListAdapter)2 FragmentManager (android.support.v4.app.FragmentManager)1 JarFile (java.util.jar.JarFile)1 ZipFile (net.lingala.zip4j.ZipFile)1 AppsListFragment (ru.playsoftware.j2meloader.applist.AppsListFragment)1 ConverterException (ru.playsoftware.j2meloader.util.ConverterException)1 Descriptor (ru.woesss.j2me.jar.Descriptor)1