From 53e60228fea63c01e0b7d5b20107d039a220089e Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 12 Nov 2017 14:00:36 +0100 Subject: [PATCH] Current user infos displayed --- .../android/comunic/client/MainActivity.java | 6 +++ .../client/fragments/FriendsListFragment.java | 3 ++ .../client/fragments/UserInfosFragment.java | 48 +++++++++++++++++- .../res/drawable/default_account_image.png | Bin 0 -> 968 bytes .../main/res/layout/fragment_userinfos.xml | 32 ++++++++++-- 5 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/default_account_image.png 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 0000000000000000000000000000000000000000..46d81c9027ac8537d0cea9a8312e466dd37c9d5d GIT binary patch literal 968 zcmV;(12_DMP) z_WM1eDEfN=P)cE%CR(i)YPA{&A^-Y4j$`b0JFM4htX3<8Vfc3dpp>HD??c!1|2h5N zs8CfEs;Z*f?P9y#VzF4{4ua&_4Yu2D3(RevddV zcEq^f@A&}`MGfc1J^7=X=Y!{0$@wOSSS8N9r_@CP6aLu|L(+@0U; zc6>$v04x@Z+@s*(;ep?FI1EGhzMq@(%jJ^k?lT7f06`Go_4Spx^Y8EP%y&N*001zX z&G7d2#?<+{ySwsSibhd{`}=zYL6A8oESF2%-rnYR+RU|!d3=1tX0w6kc}F)dpP!%1 zBdJgTk|d$q?ZUFGRGphBiWrSXsMqUwdV0dg$45B;2!epCt1H;Ho%w=Pk|a2e1KYOo z{QL~x_nGGbrU07FCdT72D5Xq|6h#q^YpeV{oOWrZ1@t7z` z44~8Llwt%%2s!GFQX&9?AiyvTltqSNKoA6W09viqNhZLl8=Oid@q>*-0E&3~!&*sg zP6VLYY?cl{Qk#DSpsFgf#|TAAk|e0AnjJuqZ+}=TiS0iEs8*|`1(3w{9|5p>jC2Ym qvHeE?JT^YZG)S2NlraGwWBWe>FYK+XBM!m<0000 - - + android:orientation="horizontal" + android:layout_centerVertical="true" + android:layout_centerHorizontal="true"> - \ No newline at end of file + + + + + + + \ No newline at end of file