Search in sources :

Example 11 with RowDataRequest

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

the class RequestHandler method addTableDataAndGetResponse.

private String addTableDataAndGetResponse(String route) {
    UpdateRowResponse response;
    try {
        Uri uri = Uri.parse(URLDecoder.decode(route, "UTF-8"));
        String tableName = uri.getQueryParameter("tableName");
        String updatedData = uri.getQueryParameter("addData");
        List<RowDataRequest> rowDataRequests = mGson.fromJson(updatedData, new TypeToken<List<RowDataRequest>>() {
        }.getType());
        if (Constants.APP_SHARED_PREFERENCES.equals(mSelectedDatabase)) {
            response = PrefHelper.addOrUpdateRow(mContext, tableName, rowDataRequests);
        } else {
            response = DatabaseHelper.addRow(sqLiteDB, tableName, rowDataRequests);
        }
        return mGson.toJson(response);
    } catch (Exception e) {
        e.printStackTrace();
        response = new UpdateRowResponse();
        response.isSuccessful = false;
        return mGson.toJson(response);
    }
}
Also used : UpdateRowResponse(com.amitshekhar.model.UpdateRowResponse) RowDataRequest(com.amitshekhar.model.RowDataRequest) TypeToken(com.google.gson.reflect.TypeToken) Uri(android.net.Uri) IOException(java.io.IOException)

Aggregations

RowDataRequest (com.amitshekhar.model.RowDataRequest)11 UpdateRowResponse (com.amitshekhar.model.UpdateRowResponse)11 ArrayList (java.util.ArrayList)4 ContentValues (android.content.ContentValues)3 SharedPreferences (android.content.SharedPreferences)3 Uri (android.net.Uri)3 TypeToken (com.google.gson.reflect.TypeToken)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)2 JSONArray (org.json.JSONArray)2