|
1 | 1 | package fr.free.nrw.commons.theme;
|
2 | 2 |
|
| 3 | +import android.accounts.Account; |
| 4 | +import android.accounts.AccountManager; |
3 | 5 | import android.content.ActivityNotFoundException;
|
4 | 6 | import android.content.Intent;
|
5 | 7 | import android.support.annotation.NonNull;
|
|
9 | 11 | import android.support.v7.app.AlertDialog;
|
10 | 12 | import android.support.v7.widget.Toolbar;
|
11 | 13 | import android.view.MenuItem;
|
| 14 | +import android.view.View; |
12 | 15 | import android.view.ViewGroup;
|
| 16 | +import android.widget.TextView; |
13 | 17 | import android.widget.Toast;
|
14 | 18 |
|
15 | 19 | import butterknife.BindView;
|
|
18 | 22 | import fr.free.nrw.commons.CommonsApplication;
|
19 | 23 | import fr.free.nrw.commons.R;
|
20 | 24 | import fr.free.nrw.commons.WelcomeActivity;
|
| 25 | +import fr.free.nrw.commons.auth.AccountUtil; |
21 | 26 | import fr.free.nrw.commons.auth.LoginActivity;
|
22 | 27 | import fr.free.nrw.commons.contributions.ContributionsActivity;
|
23 | 28 | import fr.free.nrw.commons.nearby.NearbyActivity;
|
@@ -47,6 +52,22 @@ public void initDrawer() {
|
47 | 52 | toggle.setDrawerIndicatorEnabled(true);
|
48 | 53 | toggle.syncState();
|
49 | 54 | setDrawerPaneWidth();
|
| 55 | + setUserName(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Set the username in navigationHeader. |
| 60 | + */ |
| 61 | + private void setUserName() { |
| 62 | + |
| 63 | + View navHeaderView = navigationView.getHeaderView(0); |
| 64 | + TextView username = (TextView) navHeaderView.findViewById(R.id.username); |
| 65 | + |
| 66 | + AccountManager accountManager = AccountManager.get(this); |
| 67 | + Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType()); |
| 68 | + if (allAccounts.length != 0) { |
| 69 | + username.setText(allAccounts[0].name); |
| 70 | + } |
50 | 71 | }
|
51 | 72 |
|
52 | 73 | public void initBackButton() {
|
|
0 commit comments