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;
}
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);
}
Aggregations