From 45b6478b20b6f5029d51b40142e868e331eb61cd Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 24 Sep 2017 15:05:00 +0200 Subject: [PATCH] Makes the profile picture icon in toolbar clickable to open menu --- .../activities/MainActivity.java | 14 ++++-- .../gouv/etalab/mastodon/helper/Helper.java | 47 ++----------------- app/src/main/res/layout/activity_main.xml | 6 +++ .../activities/MainActivity.java | 15 +++--- 4 files changed, 27 insertions(+), 55 deletions(-) diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 6bcb643db..2219c8bb7 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -40,6 +40,7 @@ import android.support.v7.widget.SearchView; import android.support.v7.widget.SwitchCompat; import android.util.Patterns; import android.view.ContextMenu; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.View; @@ -107,7 +108,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID; import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; -import static fr.gouv.etalab.mastodon.helper.Helper.changeHamburgerIcon; import static fr.gouv.etalab.mastodon.helper.Helper.changeUser; import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts; import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems; @@ -353,7 +353,6 @@ public class MainActivity extends AppCompatActivity toolbarTitle.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fragmentManager = getSupportFragmentManager(); - if( navigationView.getMenu().findItem(R.id.nav_favorites) != null && navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){ DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES"); if (faveFrag != null && faveFrag.isVisible()) { @@ -502,10 +501,15 @@ public class MainActivity extends AppCompatActivity registerForContextMenu(drawer); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawer.addDrawerListener(toggle); toggle.setDrawerIndicatorEnabled(false); - changeHamburgerIcon(MainActivity.this, account.getAvatar()); - toggle.syncState(); + ImageView iconbar = (ImageView) toolbar.findViewById(R.id.iconbar); + iconbar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + drawer.openDrawer(Gravity.START); + } + }); + Helper.loadPictureIcon(MainActivity.this, account.getAvatar(),iconbar); headerLayout = navigationView.getHeaderView(0); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 1eb7ed566..1331898c5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -980,7 +980,7 @@ public class Helper { * @param activity Activity The current activity * @param url String the url of the profile picture */ - public static void changeHamburgerIcon(final Activity activity, String url){ + public static void loadPictureIcon(final Activity activity, String url, final ImageView imageView){ ImageLoader imageLoader; DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) .cacheOnDisk(true).resetViewBeforeLoading(true).build(); @@ -989,14 +989,13 @@ public class Helper { url = "https://" + Helper.getLiveInstance(activity) + url; } imageLoader.loadImage(url, options, new SimpleImageLoadingListener(){ + @SuppressWarnings("ConstantConditions") @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); Resources res = activity.getResources(); - Bitmap loadedImageResized = Bitmap.createScaledBitmap(loadedImage, (int)convertDpToPixel(40, activity), (int)convertDpToPixel(40, activity), true); - BitmapDrawable icon = new BitmapDrawable(res, getRoundedCornerBitmap(loadedImageResized, 90)); - if( ((MainActivity)activity).getSupportActionBar() != null) - ((MainActivity)activity).getSupportActionBar().setIcon(icon); + BitmapDrawable icon = new BitmapDrawable(res, getRoundedCornerBitmap(loadedImage, 150)); + imageView.setImageDrawable(icon); } @Override public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){ @@ -1004,44 +1003,6 @@ public class Helper { }}); } - /** - * Load the profile picture in the current action bar - * @param activity Activity The current activity - * @param url String the url of the profile picture - */ - public static void loadPPInActionBar(final Activity activity, String url){ - ImageLoader imageLoader; - DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) - .cacheOnDisk(true).resetViewBeforeLoading(true).build(); - imageLoader = ImageLoader.getInstance(); - if( url.startsWith("/") ){ - url = "https://" + Helper.getLiveInstance(activity) + url; - } - imageLoader.loadImage(url, options, new SimpleImageLoadingListener(){ - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - super.onLoadingComplete(imageUri, view, loadedImage); - - Drawable ppDrawable; - Toolbar toolBar = (Toolbar) activity.findViewById(R.id.toolbar); - if( toolBar != null){ - ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(25, activity), (int) convertDpToPixel(25, activity), true)); - toolBar.findViewById(R.id.pp_actionBar).setBackgroundDrawable(ppDrawable); - }else{ - ActionBar supportActionBar = ((TootActivity) activity).getSupportActionBar(); - if( supportActionBar != null){ - ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(20, activity), (int) convertDpToPixel(20, activity), true)); - supportActionBar.setIcon(ppDrawable); - } - } - - - } - @Override - public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){ - - }}); - } /** * Update the header with the new selected account diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f987228ea..b3a3bfcd6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -31,6 +31,7 @@ tools:context="mastodon.etalab.gouv.fr.mastodon.fr.etalab.gouv.fr.mastodon.activities.MainActivity"> +