diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersInfos.java b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersInfos.java index 8ca74bc..719c288 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersInfos.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersInfos.java @@ -58,12 +58,31 @@ public class GetUsersInfos { } + /** + * Get and return informations about a user + * + * @param id The ID of the user to get the informations + * @param callback What to do once we got the response + */ + public void get(int id, getUserInfosCallback callback){ + + //Check if the user is already present in the database or not + if(!udbHelper.exists(id)) + //Perform a request on the server + getOnServer(id, callback); + + //Else we can retrieve user informations from the local database + callback.callback(udbHelper.get(id)); + + } + /** * Get and return the informations about a user on the server * * @param id The ID of the user to get informations from + * @param callback What to do once the request is done */ - public void get(final int id, final getUserInfosCallback callback){ + private void getOnServer(final int id, final getUserInfosCallback callback){ //Perform a request on the API server //Setup the request @@ -89,7 +108,7 @@ public class GetUsersInfos { userInfos = parse_user_json(userObject); } - //Save user in the local database in case of success + //Save user information in the local database in case of success if(userInfos != null) udbHelper.insertOrUpdate(userInfos); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/UsersInfosDbHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/UsersInfosDbHelper.java index 195e647..20ec2a2 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/UsersInfosDbHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/UsersInfosDbHelper.java @@ -16,7 +16,7 @@ import org.communiquons.android.comunic.client.data.DatabaseHelper; * Created by pierre on 11/2/17. */ -public class UsersInfosDbHelper { +class UsersInfosDbHelper { /** * Database helper @@ -28,7 +28,7 @@ public class UsersInfosDbHelper { * * @param dbHelper Database helper object */ - public UsersInfosDbHelper(DatabaseHelper dbHelper){ + UsersInfosDbHelper(DatabaseHelper dbHelper){ this.dbHelper = dbHelper; } @@ -56,7 +56,7 @@ public class UsersInfosDbHelper { * @param userID The user to research on the database * @return boolean True if the user exists / false else */ - public boolean exists(int userID){ + boolean exists(int userID){ //Get the database SQLiteDatabase db = dbHelper.getReadableDatabase();