Simplied GetUserHelper constructors

This commit is contained in:
Pierre HUBERT 2019-03-02 09:57:57 +01:00
parent 039f6d994c
commit 8a309dd508
9 changed files with 24 additions and 43 deletions

View File

@ -23,17 +23,12 @@ import java.util.ArrayList;
* Created by pierre on 12/10/17. * Created by pierre on 12/10/17.
*/ */
public class GetUsersHelper { public class GetUsersHelper extends BaseHelper {
/** /**
* Debug tag * Debug tag
*/ */
private final String TAG = "GetUsersHelper"; private final String TAG = GetUsersHelper.class.getSimpleName();
/**
* The context of the application
*/
private Context mContext;
/** /**
* User information database helper * User information database helper
@ -46,30 +41,11 @@ public class GetUsersHelper {
* @param context The context of the application * @param context The context of the application
*/ */
public GetUsersHelper(@NonNull Context context){ public GetUsersHelper(@NonNull Context context){
this(context, DatabaseHelper.getInstance(context)); super(context);
this.udbHelper = new UsersInfoDbHelper(context);
} }
/**
* Public constructor of the class
*
* @param context The context of execution of the application
* @param udbHelper User database helper
*/
public GetUsersHelper(@NonNull Context context, @NonNull UsersInfoDbHelper udbHelper){
mContext = context.getApplicationContext();
this.udbHelper = udbHelper;
}
/**
* Public constructor of the class
*
* @param context The context of execution of the application
* @param dbHelper DatabaseHelper
*/
public GetUsersHelper(@NonNull Context context, @NonNull DatabaseHelper dbHelper){
mContext = context;
this.udbHelper = new UsersInfoDbHelper(dbHelper);
}
/** /**
* Get information about a single user from the server * Get information about a single user from the server
@ -127,7 +103,7 @@ public class GetUsersHelper {
public AdvancedUserInfo get_advanced_infos(int userID){ public AdvancedUserInfo get_advanced_infos(int userID){
//Perform an API request //Perform an API request
APIRequest params = new APIRequest(mContext, APIRequest params = new APIRequest(getContext(),
"user/getAdvancedUserInfos"); "user/getAdvancedUserInfos");
params.setTryContinueOnError(true); params.setTryContinueOnError(true);
params.addInt("userID", userID); params.addInt("userID", userID);
@ -263,7 +239,7 @@ public class GetUsersHelper {
private ArrayList<Integer> search_users_online(String query, int limit){ private ArrayList<Integer> search_users_online(String query, int limit){
//Make an API request //Make an API request
APIRequest params = new APIRequest(mContext, "search/user"); APIRequest params = new APIRequest(getContext(), "search/user");
params.addString("query", query); params.addString("query", query);
params.addString("searchLimit", ""+limit); params.addString("searchLimit", ""+limit);
@ -299,7 +275,7 @@ public class GetUsersHelper {
//Perform a request on the API server //Perform a request on the API server
//Setup the request //Setup the request
APIRequest requestParameters = new APIRequest(mContext, APIRequest requestParameters = new APIRequest(getContext(),
"user/getInfosMultiple"); "user/getInfosMultiple");

View File

@ -1,6 +1,7 @@
package org.communiquons.android.comunic.client.data.helpers; package org.communiquons.android.comunic.client.data.helpers;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
@ -35,10 +36,13 @@ class UsersInfoDbHelper {
/** /**
* Class constructor * Class constructor
* *
* @param dbHelper Database helper object * @param context Application context
*/ */
UsersInfoDbHelper(DatabaseHelper dbHelper){ UsersInfoDbHelper(Context context){
this.dbHelper = dbHelper; this.dbHelper = DatabaseHelper.getInstance(context);
//Clean user information if we are connected to the Internet
if(APIRequestHelper.isAPIavailable(context))
clean(); clean();
} }

View File

@ -63,7 +63,7 @@ public class SearchUserActivity extends AppCompatActivity
setContentView(R.layout.activity_search_user); setContentView(R.layout.activity_search_user);
//Create a get user helper object //Create a get user helper object
getUsersHelper = new GetUsersHelper(this, DatabaseHelper.getInstance(this)); getUsersHelper = new GetUsersHelper(this);
//Get view //Get view
searchField = findViewById(R.id.activity_search_user_field); searchField = findViewById(R.id.activity_search_user_field);

View File

@ -186,7 +186,7 @@ public abstract class AbstractPostsListFragment extends AbstractFragment
mCommentsHelper = new CommentsHelper(getActivity()); mCommentsHelper = new CommentsHelper(getActivity());
//Create user helper //Create user helper
mUserHelper = new GetUsersHelper(getActivity(), DatabaseHelper.getInstance(getActivity())); mUserHelper = new GetUsersHelper(getActivity());
//Create likes helper //Create likes helper
mLikesHelper = new LikesHelper(getActivity()); mLikesHelper = new LikesHelper(getActivity());

View File

@ -222,7 +222,7 @@ public class ConversationFragment extends Fragment
conversation_id = getArguments().getInt(ARG_CONVERSATION_ID); conversation_id = getArguments().getInt(ARG_CONVERSATION_ID);
//Get user helper //Get user helper
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper); getUsersHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
if(conversation_id < 1){ if(conversation_id < 1){
throw new RuntimeException(TAG + " requires a valid conversation ID when created !"); throw new RuntimeException(TAG + " requires a valid conversation ID when created !");

View File

@ -112,7 +112,7 @@ public class ConversationsListFragment extends AbstractFragment implements Adapt
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity()); DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Instantiate the user information helper //Instantiate the user information helper
userHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()), dbHelper); userHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
//Create the conversation list helper //Create the conversation list helper
conversationsListHelper = new ConversationsListHelper(getActivity(), dbHelper); conversationsListHelper = new ConversationsListHelper(getActivity(), dbHelper);

View File

@ -127,7 +127,7 @@ public class FriendsListFragment extends Fragment implements OnFriendListActionL
mFriendsHelper = new FriendsListHelper(mDbHelper, mContext); mFriendsHelper = new FriendsListHelper(mDbHelper, mContext);
//Create get user helper //Create get user helper
mUsersHelper = new GetUsersHelper(mContext, mDbHelper); mUsersHelper = new GetUsersHelper(mContext);
//Cast activity to mConvOpener //Cast activity to mConvOpener
try { try {

View File

@ -36,6 +36,7 @@ import org.communiquons.android.comunic.client.ui.listeners.openConversationList
import org.communiquons.android.comunic.client.ui.views.AppBarLayout; import org.communiquons.android.comunic.client.ui.views.AppBarLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
import static org.communiquons.android.comunic.client.ui.Constants.IntentRequestCode.CONVERSATION_UPDATE_FIND_USER_ID_INTENT; import static org.communiquons.android.comunic.client.ui.Constants.IntentRequestCode.CONVERSATION_UPDATE_FIND_USER_ID_INTENT;
@ -171,7 +172,7 @@ public class UpdateConversationFragment extends Fragment {
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity()); DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Get User helper //Get User helper
usersHelper = new GetUsersHelper(getActivity(), dbHelper); usersHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
//Get conversation list helper //Get conversation list helper
convListHelper = new ConversationsListHelper(getActivity(), dbHelper); convListHelper = new ConversationsListHelper(getActivity(), dbHelper);

View File

@ -91,7 +91,7 @@ public class UserPageFragment extends Fragment {
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity()); DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Create getUserHelper instance //Create getUserHelper instance
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper); getUsersHelper = new GetUsersHelper(getActivity());
//Get the open user page listener //Get the open user page listener
mOpenUsersPageListener = (onOpenUsersPageListener) getActivity(); mOpenUsersPageListener = (onOpenUsersPageListener) getActivity();