private static void migrateGalleryWidgetsInternal(Context context) { GalleryApp galleryApp = (GalleryApp) context.getApplicationContext(); DataManager manager = galleryApp.getDataManager(); WidgetDatabaseHelper dbHelper = new WidgetDatabaseHelper(context); // only need to migrate local-album entries of type TYPE_ALBUM List<Entry> entries = dbHelper.getEntries(WidgetDatabaseHelper.TYPE_ALBUM); if (entries != null) { HashMap<Integer, Entry> localEntries = new HashMap<Integer, Entry>(entries.size()); for (Entry entry : entries) { Path path = Path.fromString(entry.albumPath); MediaSet mediaSet = (MediaSet) manager.getMediaObject(path); if (mediaSet instanceof LocalAlbum) { int bucketId = Integer.parseInt(path.getSuffix()); localEntries.put(bucketId, entry); } } if (!localEntries.isEmpty()) migrateLocalEntries(localEntries, dbHelper); } }
private static void updatePath( File root, HashMap<Integer, Entry> entries, WidgetDatabaseHelper dbHelper) { File[] files = root.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && !entries.isEmpty()) { String path = file.getAbsolutePath(); String oldPath = OLD_EXT_PATH + path.substring(RELATIVE_PATH_START); int oldBucketId = GalleryUtils.getBucketId(oldPath); Entry entry = entries.remove(oldBucketId); if (entry != null) { int newBucketId = GalleryUtils.getBucketId(path); String newAlbumPath = Path.fromString(entry.albumPath).getParent().getChild(newBucketId).toString(); Log.d(TAG, "migrate from " + entry.albumPath + " to " + newAlbumPath); entry.albumPath = newAlbumPath; dbHelper.updateEntry(entry); } updatePath(file, entries, dbHelper); // recursion } } } }