dandelion/app/src/main/java/com/github/dfa/diaspora_android/service/AvatarImageLoader.java

59 lines
1.8 KiB
Java
Raw Normal View History

2016-07-29 14:00:28 +02:00
/*
This file is part of the dandelion*.
2016-07-29 14:00:28 +02:00
dandelion* is free software: you can redistribute it and/or modify
2016-07-29 14:00:28 +02:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dandelion* is distributed in the hope that it will be useful,
2016-07-29 14:00:28 +02:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the dandelion*.
2016-07-29 14:00:28 +02:00
If not, see <http://www.gnu.org/licenses/>.
*/
2016-10-26 16:23:14 +02:00
package com.github.dfa.diaspora_android.service;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
2016-03-29 19:38:50 +02:00
import java.io.File;
public class AvatarImageLoader {
private File avatarFile;
public AvatarImageLoader(Context context) {
avatarFile = new File(context.getFilesDir(), "avatar0.png");
}
public boolean clearAvatarImage() {
2016-07-04 11:19:09 +02:00
return (!isAvatarDownloaded() || avatarFile.delete());
}
public boolean loadToImageView(ImageView imageView) {
if (avatarFile.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(avatarFile.getAbsolutePath());
imageView.setImageBitmap(bitmap);
return true;
}
return false;
}
public boolean isAvatarDownloaded() {
return avatarFile.exists();
}
public void startImageDownload(ImageView imageView, String avatarUrl) {
if (!avatarUrl.equals("")) {
new ImageDownloadTask(imageView, avatarFile.getAbsolutePath()).execute(avatarUrl);
}
}
}