diff --git a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java index c20cc57..7364bb1 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java @@ -53,6 +53,12 @@ public class MainActivity extends AppCompatActivity { //Initialize account objects account = new Account(this); + //Check if user is signed in or not + if(!account.signed_in()){ + //Open the login activity + startActivity(new Intent(this, LoginActivity.class)); + } + //If it is the first time the application is launched, started the user friends tab if(savedInstanceState == null){ openFriendsFragment(); 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 5492993..beb5304 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 @@ -23,6 +23,9 @@ public class FriendsListFragment extends Fragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { + //Retain the fragment + setRetainInstance(true); + //Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_friendslist, container, false); 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 3932e79..63850e8 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 @@ -2,13 +2,21 @@ package org.communiquons.android.comunic.client.fragments; import android.app.Fragment; +import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.Account.AccountUtils; +import org.communiquons.android.comunic.client.data.DatabaseHelper; +import org.communiquons.android.comunic.client.data.ImageLoadTask; +import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersInfos; +import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo; /** * User informations fragment @@ -21,9 +29,47 @@ import org.communiquons.android.comunic.client.R; public class UserInfosFragment extends Fragment { + /** + * Application context + */ + Context mContext; + + /** + * Database helper + */ + DatabaseHelper dbHelper; + + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_userinfos, container, false); + View result = inflater.inflate(R.layout.fragment_userinfos, container, false); + + //Get context + mContext = getActivity().getApplicationContext(); + + //Open DBHelper if required + if(dbHelper == null) + 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); + + //Retrieve user informations in order to display them + int user_id = new AccountUtils(mContext).get_current_user_id(); + new GetUsersInfos(mContext, dbHelper).get(user_id, new GetUsersInfos.getUserInfosCallback() { + @Override + public void callback(UserInfo info) { + + //Set the name of the user + userNameView.setText(info.getFullName()); + + //Get and show the user account image + new ImageLoadTask(mContext, info.getAcountImageURL(), imageView).execute(); + } + }); + + return result; } } diff --git a/app/src/main/res/drawable/default_account_image.png b/app/src/main/res/drawable/default_account_image.png new file mode 100644 index 0000000..46d81c9 Binary files /dev/null and b/app/src/main/res/drawable/default_account_image.png differ diff --git a/app/src/main/res/layout/fragment_userinfos.xml b/app/src/main/res/layout/fragment_userinfos.xml index f0d1576..dab18c5 100644 --- a/app/src/main/res/layout/fragment_userinfos.xml +++ b/app/src/main/res/layout/fragment_userinfos.xml @@ -1,11 +1,33 @@ - - + android:orientation="horizontal" + android:layout_centerVertical="true" + android:layout_centerHorizontal="true"> - \ No newline at end of file + + + + + + + \ No newline at end of file