mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Simplied GetUserHelper constructors
This commit is contained in:
parent
039f6d994c
commit
8a309dd508
@ -23,17 +23,12 @@ import java.util.ArrayList;
|
||||
* Created by pierre on 12/10/17.
|
||||
*/
|
||||
|
||||
public class GetUsersHelper {
|
||||
public class GetUsersHelper extends BaseHelper {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
*/
|
||||
private final String TAG = "GetUsersHelper";
|
||||
|
||||
/**
|
||||
* The context of the application
|
||||
*/
|
||||
private Context mContext;
|
||||
private final String TAG = GetUsersHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* User information database helper
|
||||
@ -46,30 +41,11 @@ public class GetUsersHelper {
|
||||
* @param context The context of the application
|
||||
*/
|
||||
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
|
||||
@ -127,7 +103,7 @@ public class GetUsersHelper {
|
||||
public AdvancedUserInfo get_advanced_infos(int userID){
|
||||
|
||||
//Perform an API request
|
||||
APIRequest params = new APIRequest(mContext,
|
||||
APIRequest params = new APIRequest(getContext(),
|
||||
"user/getAdvancedUserInfos");
|
||||
params.setTryContinueOnError(true);
|
||||
params.addInt("userID", userID);
|
||||
@ -263,7 +239,7 @@ public class GetUsersHelper {
|
||||
private ArrayList<Integer> search_users_online(String query, int limit){
|
||||
|
||||
//Make an API request
|
||||
APIRequest params = new APIRequest(mContext, "search/user");
|
||||
APIRequest params = new APIRequest(getContext(), "search/user");
|
||||
params.addString("query", query);
|
||||
params.addString("searchLimit", ""+limit);
|
||||
|
||||
@ -299,7 +275,7 @@ public class GetUsersHelper {
|
||||
|
||||
//Perform a request on the API server
|
||||
//Setup the request
|
||||
APIRequest requestParameters = new APIRequest(mContext,
|
||||
APIRequest requestParameters = new APIRequest(getContext(),
|
||||
"user/getInfosMultiple");
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.communiquons.android.comunic.client.data.helpers;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
@ -35,11 +36,14 @@ class UsersInfoDbHelper {
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param dbHelper Database helper object
|
||||
* @param context Application context
|
||||
*/
|
||||
UsersInfoDbHelper(DatabaseHelper dbHelper){
|
||||
this.dbHelper = dbHelper;
|
||||
clean();
|
||||
UsersInfoDbHelper(Context context){
|
||||
this.dbHelper = DatabaseHelper.getInstance(context);
|
||||
|
||||
//Clean user information if we are connected to the Internet
|
||||
if(APIRequestHelper.isAPIavailable(context))
|
||||
clean();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public class SearchUserActivity extends AppCompatActivity
|
||||
setContentView(R.layout.activity_search_user);
|
||||
|
||||
//Create a get user helper object
|
||||
getUsersHelper = new GetUsersHelper(this, DatabaseHelper.getInstance(this));
|
||||
getUsersHelper = new GetUsersHelper(this);
|
||||
|
||||
//Get view
|
||||
searchField = findViewById(R.id.activity_search_user_field);
|
||||
|
@ -186,7 +186,7 @@ public abstract class AbstractPostsListFragment extends AbstractFragment
|
||||
mCommentsHelper = new CommentsHelper(getActivity());
|
||||
|
||||
//Create user helper
|
||||
mUserHelper = new GetUsersHelper(getActivity(), DatabaseHelper.getInstance(getActivity()));
|
||||
mUserHelper = new GetUsersHelper(getActivity());
|
||||
|
||||
//Create likes helper
|
||||
mLikesHelper = new LikesHelper(getActivity());
|
||||
|
@ -222,7 +222,7 @@ public class ConversationFragment extends Fragment
|
||||
conversation_id = getArguments().getInt(ARG_CONVERSATION_ID);
|
||||
|
||||
//Get user helper
|
||||
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper);
|
||||
getUsersHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
|
||||
|
||||
if(conversation_id < 1){
|
||||
throw new RuntimeException(TAG + " requires a valid conversation ID when created !");
|
||||
|
@ -112,7 +112,7 @@ public class ConversationsListFragment extends AbstractFragment implements Adapt
|
||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
|
||||
|
||||
//Instantiate the user information helper
|
||||
userHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()), dbHelper);
|
||||
userHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
|
||||
|
||||
//Create the conversation list helper
|
||||
conversationsListHelper = new ConversationsListHelper(getActivity(), dbHelper);
|
||||
|
@ -127,7 +127,7 @@ public class FriendsListFragment extends Fragment implements OnFriendListActionL
|
||||
mFriendsHelper = new FriendsListHelper(mDbHelper, mContext);
|
||||
|
||||
//Create get user helper
|
||||
mUsersHelper = new GetUsersHelper(mContext, mDbHelper);
|
||||
mUsersHelper = new GetUsersHelper(mContext);
|
||||
|
||||
//Cast activity to mConvOpener
|
||||
try {
|
||||
|
@ -36,6 +36,7 @@ import org.communiquons.android.comunic.client.ui.listeners.openConversationList
|
||||
import org.communiquons.android.comunic.client.ui.views.AppBarLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
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());
|
||||
|
||||
//Get User helper
|
||||
usersHelper = new GetUsersHelper(getActivity(), dbHelper);
|
||||
usersHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
|
||||
|
||||
//Get conversation list helper
|
||||
convListHelper = new ConversationsListHelper(getActivity(), dbHelper);
|
||||
|
@ -91,7 +91,7 @@ public class UserPageFragment extends Fragment {
|
||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
|
||||
|
||||
//Create getUserHelper instance
|
||||
getUsersHelper = new GetUsersHelper(getActivity(), dbHelper);
|
||||
getUsersHelper = new GetUsersHelper(getActivity());
|
||||
|
||||
//Get the open user page listener
|
||||
mOpenUsersPageListener = (onOpenUsersPageListener) getActivity();
|
||||
|
Loading…
Reference in New Issue
Block a user