Simplified ConversationsListHelper constructor

This commit is contained in:
Pierre HUBERT 2019-03-02 10:19:54 +01:00
parent 0eed4d1f6e
commit 882a949169
6 changed files with 10 additions and 35 deletions

View File

@ -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;
import android.support.annotation.NonNull;
@ -51,10 +52,10 @@ class ConversationsListDbHelper {
/**
* Create the conversation database helper
*
* @param databaseHelper Object pointing on database helper
* @param context Application context
*/
ConversationsListDbHelper(@NonNull DatabaseHelper databaseHelper){
this.databaseHelper = databaseHelper;
ConversationsListDbHelper(@NonNull Context context){
this.databaseHelper = DatabaseHelper.getInstance(context);
}

View File

@ -38,31 +38,14 @@ public class ConversationsListHelper extends BaseHelper {
*/
private ConversationsListDbHelper convDBHelper;
/**
* Database helper
*/
private DatabaseHelper dbHelper;
/**
* The constructor of the class
*
* @param context The context of execution of the application
* @param dbHelper Database helper
*/
public ConversationsListHelper(Context context, DatabaseHelper dbHelper){
super(context);
convDBHelper = new ConversationsListDbHelper(dbHelper);
this.dbHelper = dbHelper;
}
/**
* The constructor of the class
*
* @param context The context of execution of the application
*/
public ConversationsListHelper(Context context){
this(context, DatabaseHelper.getInstance(context));
super(context);
convDBHelper = new ConversationsListDbHelper(context);
}
/**

View File

@ -175,7 +175,7 @@ public class MainActivity extends BaseActivity implements
dbHelper = DatabaseHelper.getInstance(this);
//Initialize conversation list helper
conversationsListHelper = new ConversationsListHelper(this, dbHelper);
conversationsListHelper = new ConversationsListHelper(this);
//Use navigation bar
getSupportActionBar().hide();

View File

@ -208,14 +208,11 @@ public class ConversationFragment extends Fragment
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Database helper
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Set conversation message helper
convMessHelper = new ConversationMessagesHelper(getActivity());
//Set conversation list helper
convListHelper = new ConversationsListHelper(getActivity(), dbHelper);
convListHelper = new ConversationsListHelper(getActivity());
//Get the conversation ID
assert getArguments() != null;

View File

@ -108,14 +108,11 @@ public class ConversationsListFragment extends AbstractFragment implements Adapt
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Database helper
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Instantiate the user information helper
userHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
//Create the conversation list helper
conversationsListHelper = new ConversationsListHelper(getActivity(), dbHelper);
conversationsListHelper = new ConversationsListHelper(getActivity());
//Get the conversation target list view
conversationsListView = view.findViewById(R.id.fragment_conversationslist_list);

View File

@ -168,14 +168,11 @@ public class UpdateConversationFragment extends Fragment {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get database helper instance
DatabaseHelper dbHelper = DatabaseHelper.getInstance(getActivity());
//Get User helper
usersHelper = new GetUsersHelper(Objects.requireNonNull(getActivity()));
//Get conversation list helper
convListHelper = new ConversationsListHelper(getActivity(), dbHelper);
convListHelper = new ConversationsListHelper(getActivity());
//Get conversation opener
try {