Restructured data folder

This commit is contained in:
Pierre 2018-04-10 18:56:59 +02:00
parent a910beca51
commit 5c018aa936
16 changed files with 69 additions and 74 deletions

View File

@ -2,9 +2,9 @@ package org.communiquons.android.comunic.client.data.asynctasks;
import android.os.AsyncTask;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
/**
* Perform an API request on the server
@ -33,7 +33,7 @@ public abstract class APIRequestTask extends AsyncTask<APIRequestParameters, Voi
try {
//Perform the API request
APIRequest req = new APIRequest();
APIRequestHelper req = new APIRequestHelper();
return req.exec(params[0]);
} catch (Exception e) {
e.printStackTrace();

View File

@ -1,4 +1,4 @@
package org.communiquons.android.comunic.client.api;
package org.communiquons.android.comunic.client.data.helpers;
import android.content.Context;
import android.net.ConnectivityManager;
@ -6,6 +6,8 @@ import android.net.NetworkInfo;
import org.communiquons.android.comunic.client.BuildConfig;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
@ -28,12 +30,12 @@ import java.util.ArrayList;
* Created by pierre on 11/12/17.
*/
public class APIRequest {
public class APIRequestHelper {
/**
* Public constructor
*/
public APIRequest(){
public APIRequestHelper(){
}

View File

@ -4,9 +4,8 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.Comment;
import org.json.JSONArray;
import org.json.JSONException;
@ -59,7 +58,7 @@ public class CommentsHelper {
try {
//Try to perform the request
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Check and return success
return response.getJSONObject().getInt("commentID");
@ -87,7 +86,7 @@ public class CommentsHelper {
try {
//Perform the request
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Process result (if any)
if(response.getResponse_code() != 200)
@ -119,7 +118,7 @@ public class CommentsHelper {
//Try to perform the request on the server
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;
} catch (Exception e) {
e.printStackTrace();
@ -143,7 +142,7 @@ public class CommentsHelper {
//Try to perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;

View File

@ -4,9 +4,8 @@ import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.ConversationMessage;
import org.json.JSONArray;
import org.json.JSONException;
@ -99,7 +98,7 @@ public class ConversationMessagesHelper {
params.addString("image", "data:image/png;base64," + image);
try {
new APIRequest().exec(params);
new APIRequestHelper().exec(params);
return true;
} catch (Exception e){
e.printStackTrace();
@ -163,7 +162,7 @@ public class ConversationMessagesHelper {
try {
//Perform the request
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Get the list of new messages
JSONArray messages = response.getJSONArray();

View File

@ -6,9 +6,8 @@ import android.support.annotation.Nullable;
import android.util.ArrayMap;
import android.util.Log;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.communiquons.android.comunic.client.data.models.ConversationsInfo;
@ -121,7 +120,7 @@ public class ConversationsListHelper {
//Try to perform request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
JSONObject object = response.getJSONObject();
//Check for conversations ID
@ -217,7 +216,7 @@ public class ConversationsListHelper {
params.addString("conversationID", ""+convID);
try {
new APIRequest().exec(params);
new APIRequestHelper().exec(params);
} catch (Exception e){
return false;
}
@ -251,7 +250,7 @@ public class ConversationsListHelper {
//Perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Get conversation ID
JSONObject obj = response.getJSONObject();
@ -306,7 +305,7 @@ public class ConversationsListHelper {
try {
//Try to perform the request
new APIRequest().exec(params);
new APIRequestHelper().exec(params);
//Delete the conversation from the local database to force it to be refreshed
//on next load
@ -334,7 +333,7 @@ public class ConversationsListHelper {
//Prepare the request on the server
APIRequestParameters params = new APIRequestParameters(mContext, "conversations/getList");
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Check if an error occurred
JSONArray friends = response.getJSONArray();
@ -373,7 +372,7 @@ public class ConversationsListHelper {
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
JSONObject object = response.getJSONObject();

View File

@ -4,9 +4,8 @@ import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.Friend;
import org.json.JSONArray;
import org.json.JSONObject;
@ -78,7 +77,7 @@ public class FriendsListHelper {
try {
//Perform the request and retrieve the response
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
JSONArray friendsList = response.getJSONArray();
if(friendsList == null)
@ -123,7 +122,7 @@ public class FriendsListHelper {
//Remove the friend online
APIRequestParameters delparams = new APIRequestParameters(mContext, "friends/remove");
delparams.addString("friendID", ""+friend.getId());
new APIRequest().exec(delparams);
new APIRequestHelper().exec(delparams);
//Remove the friend from the local database
fdbHelper.delete_friend(friend);
@ -148,7 +147,7 @@ public class FriendsListHelper {
"friends/respondRequest");
reqParams.addInt("friendID", friend.getId());
reqParams.addString("accept", accept ? "true" : "false");
new APIRequest().exec(reqParams);
new APIRequestHelper().exec(reqParams);
//Update the friend in the local database
if(accept) {

View File

@ -6,9 +6,8 @@ import android.support.annotation.Nullable;
import android.util.ArrayMap;
import android.util.Log;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.AdvancedUserInfo;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.json.JSONArray;
@ -134,7 +133,7 @@ public class GetUsersHelper {
//Perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Parse user informations
return parse_advanced_user_json(response.getJSONObject());
@ -253,7 +252,7 @@ public class GetUsersHelper {
try {
//Get and extract the response
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
JSONArray array = response.getJSONArray();
//Make response
@ -297,7 +296,7 @@ public class GetUsersHelper {
try {
//Perform the request
APIResponse result = new APIRequest().exec(requestParameters);
APIResponse result = new APIRequestHelper().exec(requestParameters);
if(result != null) {

View File

@ -2,9 +2,8 @@ package org.communiquons.android.comunic.client.data.helpers;
import android.content.Context;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.enums.LikesType;
/**
@ -64,7 +63,7 @@ public class LikesHelper {
//Intend to perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;

View File

@ -3,9 +3,8 @@ package org.communiquons.android.comunic.client.data.helpers;
import android.content.Context;
import android.support.annotation.Nullable;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.Notif;
import org.communiquons.android.comunic.client.data.enums.NotifElemType;
import org.communiquons.android.comunic.client.data.enums.NotificationTypes;
@ -57,7 +56,7 @@ public class NotificationsHelper {
//Try to perform the request and parse results
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Try to parse results
JSONObject object = response.getJSONObject();
@ -85,7 +84,7 @@ public class NotificationsHelper {
//Try to perform the request on the server
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;
} catch (Exception e) {
e.printStackTrace();
@ -109,7 +108,7 @@ public class NotificationsHelper {
try {
//Try to perform the request on the server
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Check for errors
if(response.getResponse_code() != 200)

View File

@ -3,9 +3,8 @@ package org.communiquons.android.comunic.client.data.helpers;
import android.content.Context;
import android.support.annotation.Nullable;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.models.CreatePost;
import org.communiquons.android.comunic.client.data.enums.PageType;
import org.communiquons.android.comunic.client.data.models.Post;
@ -63,7 +62,7 @@ public class PostsHelper {
try {
//Send the request to the server
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Check for errors
if(response.getResponse_code() != 200)
@ -95,7 +94,7 @@ public class PostsHelper {
try {
//Make the request on the API
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Get the list of posts and process it
JSONArray posts = response.getJSONArray();
@ -128,7 +127,7 @@ public class PostsHelper {
//Intend to perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;
@ -200,7 +199,7 @@ public class PostsHelper {
try {
//Perform the request
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
//Check for errors
if(response.getResponse_code() != 200)
@ -231,7 +230,7 @@ public class PostsHelper {
//Try to perform the request
try {
APIResponse response = new APIRequest().exec(params);
APIResponse response = new APIRequestHelper().exec(params);
return response.getResponse_code() == 200;
} catch (Exception e) {
e.printStackTrace();

View File

@ -1,4 +1,4 @@
package org.communiquons.android.comunic.client.api;
package org.communiquons.android.comunic.client.data.models;
import java.net.URLEncoder;

View File

@ -1,4 +1,4 @@
package org.communiquons.android.comunic.client.api;
package org.communiquons.android.comunic.client.data.models;
import android.content.Context;
@ -81,7 +81,7 @@ public class APIRequestParameters {
*
* @return The request URI
*/
String getRequest_uri() {
public String getRequest_uri() {
return request_uri;
}
@ -91,7 +91,7 @@ public class APIRequestParameters {
*
* @return A string
*/
String get_parameters_encoded(){
public String get_parameters_encoded(){
//Return string
String result = "";

View File

@ -1,4 +1,4 @@
package org.communiquons.android.comunic.client.api;
package org.communiquons.android.comunic.client.data.models;
import org.json.JSONArray;
import org.json.JSONException;
@ -26,14 +26,14 @@ public class APIResponse {
/**
* Constructor of the API response
*/
APIResponse(){}
public APIResponse(){}
/**
* Set response string
*
* @param response The request response
*/
void setResponse(String response) {
public void setResponse(String response) {
this.response = response;
}
@ -42,7 +42,7 @@ public class APIResponse {
*
* @param response_code The response code
*/
void setResponse_code(int response_code) {
public void setResponse_code(int response_code) {
this.response_code = response_code;
}

View File

@ -2,9 +2,9 @@ package org.communiquons.android.comunic.client.data.utils;
import android.content.Context;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.asynctasks.APIRequestTask;
import org.communiquons.android.comunic.client.api.APIResponse;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.json.JSONObject;
/**

View File

@ -12,7 +12,10 @@ import android.widget.Toast;
import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.asynctasks.APIRequestTask;
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.models.APIRequestParameters;
import org.communiquons.android.comunic.client.data.models.APIResponse;
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
import org.communiquons.android.comunic.client.data.utils.Utilities;
import org.json.JSONException;
@ -20,8 +23,6 @@ import org.json.JSONObject;
import java.util.ArrayList;
import org.communiquons.android.comunic.client.api.*;
/**
* Login activity of the application
*
@ -52,7 +53,7 @@ public class LoginActivity extends AppCompatActivity {
aUtils = new AccountUtils(this);
//Check for connectivity
if(!APIRequest.isAPIavailable(this)){
if(!APIRequestHelper.isAPIavailable(this)){
Toast.makeText(this, R.string.err_no_internet_connection, Toast.LENGTH_SHORT).show();
}
@ -95,7 +96,7 @@ public class LoginActivity extends AppCompatActivity {
}
//Check internet connection
if(!APIRequest.isAPIavailable(this)){
if(!APIRequestHelper.isAPIavailable(this)){
show_form_error(getString(R.string.err_no_internet_connection));
stop = 1;
}

View File

@ -16,7 +16,7 @@ import android.view.MenuItem;
import android.widget.Toast;
import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
@ -101,7 +101,7 @@ public class MainActivity extends AppCompatActivity
init_bottom_menu();
//Check for connectivity
if(!APIRequest.isAPIavailable(this)){
if(!APIRequestHelper.isAPIavailable(this)){
Toast.makeText(this, R.string.err_no_internet_connection, Toast.LENGTH_SHORT).show();
}