Search in sources :

Example 6 with TableDataResponse

use of com.amitshekhar.model.TableDataResponse in project Android-Debug-Database by amitshekhariitbhu.

the class PrefHelper method getAllPrefData.

public static TableDataResponse getAllPrefData(Context context, String tag) {
    TableDataResponse response = new TableDataResponse();
    response.isEditable = true;
    response.isSuccessful = true;
    response.isSelectQuery = true;
    TableDataResponse.TableInfo keyInfo = new TableDataResponse.TableInfo();
    keyInfo.isPrimary = true;
    keyInfo.title = "Key";
    TableDataResponse.TableInfo valueInfo = new TableDataResponse.TableInfo();
    valueInfo.isPrimary = false;
    valueInfo.title = "Value";
    response.tableInfos = new ArrayList<>();
    response.tableInfos.add(keyInfo);
    response.tableInfos.add(valueInfo);
    response.rows = new ArrayList<>();
    SharedPreferences preferences = context.getSharedPreferences(tag, Context.MODE_PRIVATE);
    Map<String, ?> allEntries = preferences.getAll();
    for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
        List<TableDataResponse.ColumnData> row = new ArrayList<>();
        TableDataResponse.ColumnData keyColumnData = new TableDataResponse.ColumnData();
        keyColumnData.dataType = DataType.TEXT;
        keyColumnData.value = entry.getKey();
        row.add(keyColumnData);
        TableDataResponse.ColumnData valueColumnData = new TableDataResponse.ColumnData();
        valueColumnData.value = entry.getValue().toString();
        if (entry.getValue() != null) {
            if (entry.getValue() instanceof String) {
                valueColumnData.dataType = DataType.TEXT;
            } else if (entry.getValue() instanceof Integer) {
                valueColumnData.dataType = DataType.INTEGER;
            } else if (entry.getValue() instanceof Long) {
                valueColumnData.dataType = DataType.LONG;
            } else if (entry.getValue() instanceof Float) {
                valueColumnData.dataType = DataType.FLOAT;
            } else if (entry.getValue() instanceof Boolean) {
                valueColumnData.dataType = DataType.BOOLEAN;
            } else if (entry.getValue() instanceof Set) {
                valueColumnData.dataType = DataType.STRING_SET;
            }
        } else {
            valueColumnData.dataType = DataType.TEXT;
        }
        row.add(valueColumnData);
        response.rows.add(row);
    }
    return response;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) TableDataResponse(com.amitshekhar.model.TableDataResponse) Map(java.util.Map)

Example 7 with TableDataResponse

use of com.amitshekhar.model.TableDataResponse in project Android-Debug-Database by amitshekhariitbhu.

the class RequestHandler method getAllDataFromTheTableResponse.

private String getAllDataFromTheTableResponse(String route) {
    String tableName = null;
    if (route.contains("?tableName=")) {
        tableName = route.substring(route.indexOf("=") + 1, route.length());
    }
    TableDataResponse response;
    if (isDbOpened) {
        String sql = "SELECT * FROM " + tableName;
        response = DatabaseHelper.getTableData(sqLiteDB, sql, tableName);
    } else {
        response = PrefHelper.getAllPrefData(mContext, tableName);
    }
    return mGson.toJson(response);
}
Also used : TableDataResponse(com.amitshekhar.model.TableDataResponse)

Aggregations

TableDataResponse (com.amitshekhar.model.TableDataResponse)7 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 SharedPreferences (android.content.SharedPreferences)1 Response (com.amitshekhar.model.Response)1 UpdateRowResponse (com.amitshekhar.model.UpdateRowResponse)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1