From 882a9491699d19acd6c2fb5d5ae91e39e97d1920 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 2 Mar 2019 10:19:54 +0100 Subject: [PATCH] Simplified ConversationsListHelper constructor --- .../helpers/ConversationsListDbHelper.java | 7 ++++--- .../data/helpers/ConversationsListHelper.java | 21 ++----------------- .../client/ui/activities/MainActivity.java | 2 +- .../ui/fragments/ConversationFragment.java | 5 +---- .../fragments/ConversationsListFragment.java | 5 +---- .../fragments/UpdateConversationFragment.java | 5 +---- 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListDbHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListDbHelper.java index 0e4e848..9ba3bac 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListDbHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListDbHelper.java @@ -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); } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListHelper.java index 3fa607a..4b2e28e 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/ConversationsListHelper.java @@ -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); } /** diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index 64623c6..dd6d581 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -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(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index 9935272..c7b44ab 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -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; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java index 59198b7..6af418b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java @@ -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); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java index bd7ace8..e7cd468 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java @@ -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 {