Apply user information in drawer.

This commit is contained in:
Pierre HUBERT 2018-08-01 07:06:05 +02:00
parent 11e4cba9de
commit f0b9058894
4 changed files with 56 additions and 11 deletions

View File

@ -56,7 +56,7 @@ public class GetUsersHelper {
* @param udbHelper User database helper * @param udbHelper User database helper
*/ */
public GetUsersHelper(@NonNull Context context, @NonNull UsersInfosDbHelper udbHelper){ public GetUsersHelper(@NonNull Context context, @NonNull UsersInfosDbHelper udbHelper){
mContext = context; mContext = context.getApplicationContext();
this.udbHelper = udbHelper; this.udbHelper = udbHelper;
} }
@ -304,11 +304,11 @@ public class GetUsersHelper {
//Convert the IDs into a string //Convert the IDs into a string
String id_string = ""; StringBuilder id_string = new StringBuilder();
for(int id : IDs) { for(int id : IDs) {
id_string += id + ","; id_string.append(id).append(",");
} }
requestParameters.addString("usersID", id_string); requestParameters.addString("usersID", id_string.toString());
try { try {

View File

@ -18,6 +18,7 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.SubMenu; import android.view.SubMenu;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.communiquons.android.comunic.client.BuildConfig; import org.communiquons.android.comunic.client.BuildConfig;
@ -28,6 +29,8 @@ import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.helpers.ConversationsListHelper; import org.communiquons.android.comunic.client.data.helpers.ConversationsListHelper;
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper; import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
import org.communiquons.android.comunic.client.data.helpers.DebugHelper; import org.communiquons.android.comunic.client.data.helpers.DebugHelper;
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopRunnable; import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopRunnable;
import org.communiquons.android.comunic.client.data.services.NotificationsService; import org.communiquons.android.comunic.client.data.services.NotificationsService;
import org.communiquons.android.comunic.client.data.utils.AccountUtils; import org.communiquons.android.comunic.client.data.utils.AccountUtils;
@ -46,6 +49,7 @@ import org.communiquons.android.comunic.client.ui.listeners.onPostOpenListener;
import org.communiquons.android.comunic.client.ui.listeners.openConversationListener; import org.communiquons.android.comunic.client.ui.listeners.openConversationListener;
import org.communiquons.android.comunic.client.ui.listeners.updateConversationListener; import org.communiquons.android.comunic.client.ui.listeners.updateConversationListener;
import org.communiquons.android.comunic.client.ui.utils.UiUtils; import org.communiquons.android.comunic.client.ui.utils.UiUtils;
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
/** /**
@ -72,11 +76,6 @@ public class MainActivity extends AppCompatActivity implements
*/ */
private AccountHelper accountHelper; private AccountHelper accountHelper;
/**
* Account utils object
*/
private AccountUtils aUtils;
/** /**
* Friends list refresh thread * Friends list refresh thread
*/ */
@ -251,6 +250,44 @@ public class MainActivity extends AppCompatActivity implements
NavigationView navigationView = findViewById(R.id.nav_view); NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
//Get information about the user
new Thread(new Runnable() {
@Override
public void run() {
final UserInfo info = new GetUsersHelper(getApplicationContext()).getSingle(
new AccountUtils(getApplicationContext()).get_current_user_id(), false);
//Apply user information
if(mDrawer != null){
mDrawer.post(new Runnable() {
@Override
public void run() {
applyUserInfoInDrawer(info);
}
});
}
}
}).start();
}
/**
* Apply current user information in the drawer
*
* @param info Information about the user to apply
*/
private void applyUserInfoInDrawer(@Nullable UserInfo info){
//Check for errors
if(info == null){
Toast.makeText(MainActivity.this, R.string.err_get_user_info,
Toast.LENGTH_SHORT).show();
return;
}
//Apply user information
((TextView)findViewById(R.id.current_user_name)).setText(info.getDisplayFullName());
((WebUserAccountImage)findViewById(R.id.current_user_account_image)).setUser(info);
} }
@Override @Override

View File

@ -54,6 +54,13 @@ public class AdvancedUserInfoFragment extends Fragment {
this.mAdvancedUserInfo = advancedUserInfo; this.mAdvancedUserInfo = advancedUserInfo;
} }
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View File

@ -12,8 +12,8 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"> android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView <org.communiquons.android.comunic.client.ui.views.WebUserAccountImage
android:id="@+id/imageView" android:id="@+id/current_user_account_image"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc" android:contentDescription="@string/nav_header_desc"
@ -21,6 +21,7 @@
android:src="@drawable/default_account_image" /> android:src="@drawable/default_account_image" />
<TextView <TextView
android:id="@+id/current_user_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing" android:paddingTop="@dimen/nav_header_vertical_spacing"