Search in sources :

Example 1 with WatchRecord

use of com.zhan_dui.model.WatchRecord in project AnimeTaste by daimajia.

the class LoadActivity method updateFromOldVersion.

/**
     * 从历史版本的数据库中迁移数据
     */
private void updateFromOldVersion() {
    if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("updated", false)) {
        return;
    }
    if (mContext.getDatabasePath(AnimeTasteDB.NAME).exists()) {
        AnimeTasteDB db = new AnimeTasteDB(mContext, AnimeTasteDB.NAME, null, AnimeTasteDB.VERSION);
        Cursor cursor = db.getReadableDatabase().query(true, "Video", null, "isFav=?", new String[] { String.valueOf(true) }, null, null, null, null);
        while (cursor.moveToNext()) {
            Animation animation = Animation.build(cursor);
            animation.save();
        }
        cursor.close();
        db.close();
        Cursor watchCursor = db.getReadableDatabase().query(true, "Watched", null, null, null, null, null, null, null);
        while (watchCursor.moveToNext()) {
            WatchRecord record = new WatchRecord(watchCursor.getInt(watchCursor.getColumnIndex("vid")), true);
            record.save();
        }
        cursor.close();
        db.close();
    }
    PreferenceManager.getDefaultSharedPreferences(mContext).edit().putBoolean("updated", true).commit();
}
Also used : AnimeTasteDB(com.zhan_dui.data.AnimeTasteDB) WatchRecord(com.zhan_dui.model.WatchRecord) Animation(com.zhan_dui.model.Animation) Cursor(android.database.Cursor)

Aggregations

Cursor (android.database.Cursor)1 AnimeTasteDB (com.zhan_dui.data.AnimeTasteDB)1 Animation (com.zhan_dui.model.Animation)1 WatchRecord (com.zhan_dui.model.WatchRecord)1