image loading via glide
add fallback icons
|
@ -1,35 +1,47 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* Copyright (C) 2017 Tobias Kaminsky
|
||||
* Copyright (C) 2017 Nextcloud.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Nextcloud Android client application
|
||||
* <p>
|
||||
* Copyright (C) 2017 Tobias Kaminsky
|
||||
* Copyright (C) 2017 Nextcloud.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.GenericRequestBuilder;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.model.StreamEncoder;
|
||||
import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.lib.common.ExternalLink;
|
||||
import com.owncloud.android.lib.common.ExternalLinkType;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.svg.SvgDecoder;
|
||||
import com.owncloud.android.utils.svg.SvgDrawableTranscoder;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
@ -169,4 +181,45 @@ public class ExternalLinksProvider {
|
|||
}
|
||||
return externalLink;
|
||||
}
|
||||
|
||||
private void downloadPNGIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder) {
|
||||
Glide
|
||||
.with(context)
|
||||
.load(iconUrl)
|
||||
.centerCrop()
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.crossFade()
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
private void downloadSVGIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder) {
|
||||
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context)
|
||||
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
|
||||
.from(Uri.class)
|
||||
.as(SVG.class)
|
||||
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
|
||||
.sourceEncoder(new StreamEncoder())
|
||||
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
|
||||
.decoder(new SvgDecoder())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.animate(android.R.anim.fade_in);
|
||||
|
||||
|
||||
Uri uri = Uri.parse(iconUrl);
|
||||
requestBuilder
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.load(uri)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
public void downloadIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder){
|
||||
if (iconUrl.endsWith(".svg")){
|
||||
downloadSVGIcon(context, iconUrl, imageView, placeholder);
|
||||
} else {
|
||||
downloadPNGIcon(context, iconUrl, imageView, placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.accounts.AccountManagerFuture;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -43,6 +44,8 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
|
@ -760,7 +763,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
|||
if (quotas.size() > 0) {
|
||||
final ExternalLink firstQuota = quotas.get(0);
|
||||
mQuotaTextView.setText(firstQuota.name);
|
||||
mQuotaTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.arrow_down, 0, 0, 0);
|
||||
mQuotaTextView.setClickable(true);
|
||||
mQuotaTextView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -773,6 +775,25 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
|||
startActivity(externalWebViewIntent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SimpleTarget target = new SimpleTarget<PictureDrawable>() {
|
||||
@Override
|
||||
public void onResourceReady(PictureDrawable resource, GlideAnimation glideAnimation) {
|
||||
mQuotaTextView.setCompoundDrawablesWithIntrinsicBounds(resource.getCurrent(), null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
|
||||
mQuotaTextView.setCompoundDrawablesWithIntrinsicBounds(errorDrawable, null, null, null);
|
||||
}
|
||||
};
|
||||
|
||||
externalLinksProvider.downloadIcon(this, firstQuota.iconUrl, target, R.drawable.ic_link_grey);
|
||||
|
||||
} else {
|
||||
mQuotaTextView.setText(String.format(
|
||||
getString(R.string.drawer_quota),
|
||||
|
@ -871,10 +892,26 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
|||
public void updateExternalLinksInDrawer() {
|
||||
if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
|
||||
mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links);
|
||||
for (ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
|
||||
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
||||
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
||||
.setIcon(R.drawable.ic_activity_light_grey);
|
||||
for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
|
||||
SimpleTarget target = new SimpleTarget<PictureDrawable>() {
|
||||
@Override
|
||||
public void onResourceReady(PictureDrawable resource, GlideAnimation glideAnimation) {
|
||||
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
||||
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
||||
.setIcon(resource.getCurrent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||
super.onLoadFailed(e, errorDrawable);
|
||||
|
||||
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
||||
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
||||
.setIcon(errorDrawable);
|
||||
}
|
||||
};
|
||||
|
||||
externalLinksProvider.downloadIcon(this, link.iconUrl, target, R.drawable.ic_link_grey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/main/res/drawable-hdpi/ic_link_black.png
Normal file
After Width: | Height: | Size: 321 B |
BIN
src/main/res/drawable-hdpi/ic_link_grey.png
Normal file
After Width: | Height: | Size: 782 B |
BIN
src/main/res/drawable-mdpi/ic_link_black.png
Normal file
After Width: | Height: | Size: 196 B |
BIN
src/main/res/drawable-mdpi/ic_link_grey.png
Normal file
After Width: | Height: | Size: 470 B |
BIN
src/main/res/drawable-xhdpi/ic_link_black.png
Normal file
After Width: | Height: | Size: 356 B |
BIN
src/main/res/drawable-xhdpi/ic_link_grey.png
Normal file
After Width: | Height: | Size: 876 B |
BIN
src/main/res/drawable-xxhdpi/ic_link_black.png
Normal file
After Width: | Height: | Size: 515 B |
BIN
src/main/res/drawable-xxhdpi/ic_link_grey.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/main/res/drawable-xxxhdpi/ic_link_black.png
Normal file
After Width: | Height: | Size: 667 B |
BIN
src/main/res/drawable-xxxhdpi/ic_link_grey.png
Normal file
After Width: | Height: | Size: 1.6 KiB |