Update settings icon

This commit is contained in:
Mario Danic 2018-11-29 14:00:02 +01:00
parent 844b0b4942
commit 312570e51c
3 changed files with 49 additions and 8 deletions

View file

@ -23,6 +23,8 @@ package com.nextcloud.talk.controllers;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.InputType; import android.text.InputType;
@ -42,6 +44,17 @@ import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler; import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler; import com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.kennyc.bottomsheet.BottomSheet; import com.kennyc.bottomsheet.BottomSheet;
@ -63,6 +76,7 @@ import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.KeyboardUtils; import com.nextcloud.talk.utils.KeyboardUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.glide.GlideApp;
import org.apache.commons.lang3.builder.CompareToBuilder; import org.apache.commons.lang3.builder.CompareToBuilder;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -176,20 +190,43 @@ public class ConversationsListController extends BaseController implements Searc
prepareViews(); prepareViews();
} }
private void loadUserAvatar(MenuItem menuItem) {
int avatarSize = menuItem.getIcon().getIntrinsicHeight();
GlideUrl glideUrl = new GlideUrl(ApiUtils.getUrlForAvatarWithName(currentUser.getBaseUrl(),
currentUser.getUserId(), R.dimen.avatar_size), new LazyHeaders.Builder()
.setHeader("Accept", "image/*")
.setHeader("User-Agent", ApiUtils.getUserAgent())
.build());
menuItem.getActionView().getima
GlideApp.with(getActivity())
.asBitmap()
.centerInside()
.override(avatarSize, avatarSize)
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.load(glideUrl)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
menuItem.setIcon(new BitmapDrawable(resource));
}
});
}
@Override @Override
protected void onAttach(@NonNull View view) { protected void onAttach(@NonNull View view) {
super.onAttach(view); super.onAttach(view);
eventBus.register(this); eventBus.register(this);
currentUser = userUtils.getCurrentUser(); UserEntity tempUser;
if (currentUser != (tempUser = userUtils.getCurrentUser())) {
if (currentUser != null) { currentUser = tempUser;
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
} }
if (currentUser != null) { if (currentUser != null) {
credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
shouldUseLastMessageLayout = currentUser.hasSpreedCapabilityWithName("last-room-activity"); shouldUseLastMessageLayout = currentUser.hasSpreedCapabilityWithName("last-room-activity");
fetchData(false); fetchData(false);
} }
} }
@ -252,6 +289,9 @@ public class ConversationsListController extends BaseController implements Searc
searchItem.expandActionView(); searchItem.expandActionView();
searchView.setQuery(adapter.getFilter(String.class), false); searchView.setQuery(adapter.getFilter(String.class), false);
} }
MenuItem menuItem = menu.findItem(R.id.action_settings);
loadUserAvatar(menuItem);
} }
private void fetchData(boolean fromBottomSheet) { private void fetchData(boolean fromBottomSheet) {

View file

@ -15,8 +15,10 @@
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
app:titleMarginStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="24dp" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout <com.bluelinelabs.conductor.ChangeHandlerFrameLayout

View file

@ -7,5 +7,4 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimary</item> <item name="colorAccent">@color/colorPrimary</item>
</style> </style>
</resources> </resources>