package com.xplora.xpsettings.Data;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import java.util.ArrayList;
import java.util.List;


public class DatabaseHelper {
    @SuppressLint("Range")
    public static List querySetting(Context context) {
        List dataList = new ArrayList<>();
        ContentResolver resolver = context.getContentResolver();
        Cursor cursor = resolver.query(MetaData.TABLE_URI_SETTING, null, null, null, null);
        if (cursor == null)
            return new ArrayList();
        if (cursor.moveToNext()) {
            int app_name = cursor.getInt(cursor.getColumnIndex(MetaData.KEY_APPNAME));
            String photo_resolution = cursor.getString(cursor.getColumnIndex(MetaData.KEY_RESOLUTION_PHOTO));
            String video_resolution = cursor.getString(cursor.getColumnIndex(MetaData.KEY_RESOLUTION_VIDEO));
            dataList.add(app_name);
            dataList.add(photo_resolution);
            dataList.add(video_resolution);
        }
        cursor.close();
        return dataList;
    }

    public static void update(Context context, String key, String value) {
        ContentResolver resolver = context.getContentResolver();
        ContentValues cv = new ContentValues();
        cv.put(key, value);
        resolver.update(MetaData.TABLE_URI_SETTING, cv, null, null);
    }
}
