mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
User informations can be successfully cached locally.
This commit is contained in:
parent
7d8816912f
commit
dca9924fc9
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user