From c63f9904a5015113f110d7bece0bf44da3a52f5b Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 13 Dec 2017 19:06:36 +0100 Subject: [PATCH] Fixed fragments issue --- .idea/misc.xml | 2 +- .../fragments/ConversationsListFragment.java | 4 ++-- .../client/fragments/FriendsListFragment.java | 12 ++++++++---- .../client/fragments/UserInfosFragment.java | 19 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 503aca7..33952c6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -55,7 +55,7 @@ - + diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java index 13fb500..5b09e91 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java @@ -80,7 +80,7 @@ public class ConversationsListFragment extends Fragment { userHelper = new GetUsersHelper(getActivity(), dbHelper); //Create the conversation list helper - conversationsListHelper = new ConversationsListHelper(getActivity()); + conversationsListHelper = new ConversationsListHelper(getActivity(), dbHelper); //Get the conversation target list view conversationsListView = view.findViewById(R.id.fragment_conversationslist_list); @@ -91,7 +91,7 @@ public class ConversationsListFragment extends Fragment { protected ArrayList doInBackground(Void... params) { //Get the list of conversations - ArrayList list = conversationsListHelper.download(); + ArrayList list = conversationsListHelper.get(); process_conversations_list(list); return list; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java index e2efce1..9cf0147 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java @@ -80,6 +80,14 @@ public class FriendsListFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_friendslist, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + rootView = view; //Save application context mContext = getActivity().getApplicationContext(); @@ -93,10 +101,6 @@ public class FriendsListFragment extends Fragment { //Retain the fragment //setRetainInstance(true); - //Inflate the layout for this fragment - rootView = inflater.inflate(R.layout.fragment_friendslist, container, false); - return rootView; - } @Override diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserInfosFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserInfosFragment.java index 0232f36..168a68b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserInfosFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserInfosFragment.java @@ -10,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.data.Account.AccountUtils; @@ -43,7 +44,12 @@ public class UserInfosFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - View result = inflater.inflate(R.layout.fragment_userinfos, container, false); + return inflater.inflate(R.layout.fragment_userinfos, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); //Get context mContext = getActivity().getApplicationContext(); @@ -53,8 +59,8 @@ public class UserInfosFragment extends Fragment { dbHelper = new DatabaseHelper(mContext); //Get required views - final ImageView imageView = (ImageView) result.findViewById(R.id.fragments_userinfos_account_image); - final TextView userNameView = (TextView) result.findViewById(R.id.fragments_userinfos_user_name); + final ImageView imageView = (ImageView) view.findViewById(R.id.fragments_userinfos_account_image); + final TextView userNameView = (TextView) view.findViewById(R.id.fragments_userinfos_user_name); //Retrieve user informations in order to display them int user_id = new AccountUtils(mContext).get_current_user_id(); @@ -62,6 +68,12 @@ public class UserInfosFragment extends Fragment { @Override public void callback(UserInfo info) { + //Check for errors + if(info == null){ + Toast.makeText(mContext, R.string.err_get_user_info, Toast.LENGTH_SHORT).show(); + return; + } + //Set the name of the user userNameView.setText(info.getFullName()); @@ -70,6 +82,5 @@ public class UserInfosFragment extends Fragment { } }); - return result; } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2ca6a4a..47822cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,4 +50,5 @@ m s date_hours + Couldn\'t get user information !