Fix caching

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-10-26 18:56:03 +02:00
parent 55d78401ad
commit 6852a4d103
4 changed files with 22 additions and 8 deletions

View file

@ -25,7 +25,9 @@ import android.text.format.DateUtils;
import android.view.View;
import android.widget.TextView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.helpers.api.ApiHelper;
import com.nextcloud.talk.api.models.json.rooms.Room;
@ -111,16 +113,21 @@ public class RoomItem extends AbstractFlexibleItem<RoomItem.RoomItemViewHolder>
holder.avatarImageView.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(room.getName())) {
String glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
room.getName())).toString();
GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
room.getName()), new LazyHeaders.Builder()
.setHeader("Accept", "*/*")
.build());
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(glideUrl)
.placeholder(holder.avatarImageViewInvisible.getDrawable())
.circleCrop()
.centerInside()
.into(holder.avatarImageView);
} else {
holder.avatarImageView.setDrawable(holder.avatarImageViewInvisible.getDrawable());
}

View file

@ -23,7 +23,9 @@ package com.nextcloud.talk.adapters.items;
import android.view.View;
import android.widget.TextView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.helpers.api.ApiHelper;
import com.nextcloud.talk.api.models.User;
@ -97,13 +99,17 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
holder.avatarImageView.setTextAndColorSeed(String.valueOf(user.getName().
toUpperCase().charAt(0)), ColorUtils.colorSeed);
String glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
user.getUserId())).toString();
GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
user.getUserId()), new LazyHeaders.Builder()
.setHeader("Accept", "*/*")
.setHeader("Cache-Control", "max-age=0")
.build());
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.placeholder(holder.avatarImageViewInvisible.getDrawable())
.load(glideUrl)
.circleCrop()
.centerInside()

View file

@ -255,7 +255,9 @@ public class CallsListController extends BaseController implements SearchView.On
}
, () -> {
dispose(roomsQueryDisposable);
swipeRefreshLayout.setRefreshing(false);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
});
} else {
cacheQueryDisposable = cacheUtils.getViewCache(userEntity.getId(), TAG)

View file

@ -52,8 +52,7 @@ public class CachingGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
registry.replace(GlideUrl.class, InputStream.class,
new OkHttpUrlLoader.Factory(okHttpClient));
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
}
@Override