// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/helpers/Utils.java
// public class Utils {
// 
//     public static Bitmap generateCode(String data, BarcodeFormat format, Map<EncodeHintType, Object> hints, Map<ResultMetadataType,Object> metadata) {
//         if(hints == null) {
//             hints = new EnumMap<>(EncodeHintType.class);
//         }
// 
//         if(!hints.containsKey(ERROR_CORRECTION) && metadata != null && metadata.containsKey(ERROR_CORRECTION_LEVEL)) {
//             Object ec = metadata.get(ERROR_CORRECTION_LEVEL);
//             if(ec != null) {
//                 hints.put(ERROR_CORRECTION, ec);
//             }
//         }
//         if(!hints.containsKey(ERROR_CORRECTION) && format!=BarcodeFormat.AZTEC) {
//             hints.put(ERROR_CORRECTION, ErrorCorrectionLevel.L.name());
//         }
// 
//         return generateCode(data, getFormat(format), hints); // only reshow as QR Codes
//     }
// 
//     private static BarcodeFormat getFormat(BarcodeFormat format) {
//         switch (format) {
//             case EAN_8:
//             case UPC_E:
//             case EAN_13:
//             case UPC_A:
//             case QR_CODE:
//             case CODE_39:
//             case CODE_93:
//             case CODE_128:
//             case ITF:
//             case PDF_417:
//             case CODABAR:
//             case DATA_MATRIX:
//             case AZTEC:
//                 return format;
//             default:
//                 return BarcodeFormat.QR_CODE;
//         }
//     }
// 
//     public static Bitmap generateCode(String data, BarcodeFormat format, Map<EncodeHintType,?> hints) {
//         try {
//             MultiFormatWriter writer = new MultiFormatWriter();
//             BitMatrix result = writer.encode(data, format, 100, 100, hints);
//             int width = result.getWidth();
//             int height = result.getHeight();
//             int[] pixels = new int[width * height];
//             // All are 0, or black, by default
//             for (int y = 0; y < height; y++) {
//                 int offset = y * width;
//                 for (int x = 0; x < width; x++) {
//                     pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
//                 }
//             }
//             Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//             bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
// 
//             return bitmap;
//         } catch (WriterException e) {
//             return null;
//         }
//     }
// }


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import com.google.zxing.BarcodeFormat;
import com.secuso.privacyfriendlycodescanner.qrscanner.helpers.Utils;
import java.util.GregorianCalendar;
    public abstract HistoryDao historyDao();

    private static AppDatabase INSTANCE;

    public static final Migration MIGRATION_1_2 = new Migration(1,2) {
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE `Histories` (" +
                    "`_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
                    "`text` TEXT NOT NULL," +
                    "`image` TEXT," +
                    "`rawBytes` BLOB," +
                    "`numBits` INTEGER NOT NULL DEFAULT 0," +
                    "`timestamp` INTEGER NOT NULL DEFAULT 0," +
                    "`format` TEXT," +
                    "`resultPoints` TEXT)");
            database.execSQL("INSERT INTO Histories(text) SELECT content FROM contents");
            database.execSQL("DROP TABLE contents;");

            HistoryItem[] items = null;
            Cursor c = database.query("SELECT * FROM Histories");
            if(c != null) {
                if(c.moveToFirst()) {
                    items = new HistoryItem[c.getCount()];
                    int i = 0;

                    while (!c.isAfterLast()) {
                        items[i] = new HistoryItem();
                        items[i].set_id(c.getInt(c.getColumnIndex("_id")));
                        items[i].setText(c.getString(c.getColumnIndex("text")));
// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/helpers/Utils.java
// public class Utils {
// 
//     public static Bitmap generateCode(String data, BarcodeFormat format, Map<EncodeHintType, Object> hints, Map<ResultMetadataType,Object> metadata) {
//         if(hints == null) {
//             hints = new EnumMap<>(EncodeHintType.class);
//         }
// 
//         if(!hints.containsKey(ERROR_CORRECTION) && metadata != null && metadata.containsKey(ERROR_CORRECTION_LEVEL)) {
//             Object ec = metadata.get(ERROR_CORRECTION_LEVEL);
//             if(ec != null) {
//                 hints.put(ERROR_CORRECTION, ec);
//             }
//         }
//         if(!hints.containsKey(ERROR_CORRECTION) && format!=BarcodeFormat.AZTEC) {
//             hints.put(ERROR_CORRECTION, ErrorCorrectionLevel.L.name());
//         }
// 
//         return generateCode(data, getFormat(format), hints); // only reshow as QR Codes
//     }
// 
//     private static BarcodeFormat getFormat(BarcodeFormat format) {
//         switch (format) {
//             case EAN_8:
//             case UPC_E:
//             case EAN_13:
//             case UPC_A:
//             case QR_CODE:
//             case CODE_39:
//             case CODE_93:
//             case CODE_128:
//             case ITF:
//             case PDF_417:
//             case CODABAR:
//             case DATA_MATRIX:
//             case AZTEC:
//                 return format;
//             default:
//                 return BarcodeFormat.QR_CODE;
//         }
//     }
// 
//     public static Bitmap generateCode(String data, BarcodeFormat format, Map<EncodeHintType,?> hints) {
//         try {
//             MultiFormatWriter writer = new MultiFormatWriter();
//             BitMatrix result = writer.encode(data, format, 100, 100, hints);
//             int width = result.getWidth();
//             int height = result.getHeight();
//             int[] pixels = new int[width * height];
//             // All are 0, or black, by default
//             for (int y = 0; y < height; y++) {
//                 int offset = y * width;
//                 for (int x = 0; x < width; x++) {
//                     pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
//                 }
//             }
//             Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//             bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
// 
//             return bitmap;
//         } catch (WriterException e) {
//             return null;
//         }
//     }
// }


// Path: app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/database/AppDatabase.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import com.google.zxing.BarcodeFormat;
import com.secuso.privacyfriendlycodescanner.qrscanner.helpers.Utils;
import java.util.GregorianCalendar;

    public abstract HistoryDao historyDao();

    private static AppDatabase INSTANCE;

    public static final Migration MIGRATION_1_2 = new Migration(1,2) {
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE `Histories` (" +
                    "`_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
                    "`text` TEXT NOT NULL," +
                    "`image` TEXT," +
                    "`rawBytes` BLOB," +
                    "`numBits` INTEGER NOT NULL DEFAULT 0," +
                    "`timestamp` INTEGER NOT NULL DEFAULT 0," +
                    "`format` TEXT," +
                    "`resultPoints` TEXT)");
            database.execSQL("INSERT INTO Histories(text) SELECT content FROM contents");
            database.execSQL("DROP TABLE contents;");

            HistoryItem[] items = null;
            Cursor c = database.query("SELECT * FROM Histories");
            if(c != null) {
                if(c.moveToFirst()) {
                    items = new HistoryItem[c.getCount()];
                    int i = 0;

                    while (!c.isAfterLast()) {
                        items[i] = new HistoryItem();
                        items[i].set_id(c.getInt(c.getColumnIndex("_id")));
                        items[i].setText(c.getString(c.getColumnIndex("text")));
                        items[i].setImage(Utils.generateCode(items[i].getText(), BarcodeFormat.QR_CODE, null));