2016-07-29 14:00:28 +02:00
|
|
|
/*
|
2017-02-24 18:47:14 +01:00
|
|
|
This file is part of the dandelion*.
|
2016-07-29 14:00:28 +02:00
|
|
|
|
2017-02-24 18:47:14 +01: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.
|
|
|
|
|
2017-02-24 18:47:14 +01:00
|
|
|
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
|
2017-02-24 18:47:14 +01:00
|
|
|
along with the dandelion*.
|
2016-07-29 14:00:28 +02:00
|
|
|
|
|
|
|
If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-10-14 01:26:56 +02:00
|
|
|
|
2016-10-26 16:23:14 +02:00
|
|
|
package com.github.dfa.diaspora_android.service;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
|
|
|
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;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
|
|
|
public class AvatarImageLoader {
|
|
|
|
private File avatarFile;
|
|
|
|
|
2016-03-26 01:14:17 +01:00
|
|
|
public AvatarImageLoader(Context context) {
|
2016-06-04 03:48:57 +02:00
|
|
|
avatarFile = new File(context.getFilesDir(), "avatar0.png");
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
public boolean clearAvatarImage() {
|
2016-07-04 11:19:09 +02:00
|
|
|
return (!isAvatarDownloaded() || avatarFile.delete());
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2016-03-26 01:14:17 +01:00
|
|
|
if (!avatarUrl.equals("")) {
|
2016-03-25 00:12:00 +01:00
|
|
|
new ImageDownloadTask(imageView, avatarFile.getAbsolutePath()).execute(avatarUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|