Removes support for profile pictures which are not loaded as it is due to mastodon.social server
This commit is contained in:
parent
587c8ef749
commit
83e64c2dda
|
@ -642,21 +642,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
|||
|
||||
}
|
||||
|
||||
imageLoader.displayImage(account.getAvatar(), account_pp, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
new HttpsConnection(ShowAccountActivity.this).download(account.getAvatar(), account_pp, options);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(account.getAvatar(), account_pp, options);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -272,104 +272,6 @@ public class HttpsConnection {
|
|||
}
|
||||
|
||||
|
||||
public void download(final String downloadUrl, final ImageView imageView, final DisplayImageOptions options) {
|
||||
|
||||
final ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
|
||||
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
|
||||
.imageDownloader(new PatchBaseImageDownloader(context))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
if( !imageLoader.isInited())
|
||||
imageLoader.init(configImg);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String cache = sharedpreferences.getString(Helper.SET_PICTURE_URL + Helper.md5(downloadUrl), null);
|
||||
|
||||
if( cache != null){
|
||||
String[] val = cache.split("\\|");
|
||||
if( val.length == 2){
|
||||
Date date = Helper.stringToDate(context, val[0]);
|
||||
final String uri = val[1];
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(Calendar.DATE, -1);
|
||||
Date dateBefore = cal.getTime();
|
||||
if( date.after(dateBefore)){
|
||||
imageLoader.displayImage(uri, imageView, options);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(downloadUrl);
|
||||
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
httpsURLConnection.setRequestProperty("User-Agent", Helper.USER_AGENT);
|
||||
// always check HTTP response code first
|
||||
String fileName = "";
|
||||
String disposition = httpsURLConnection.getHeaderField("Content-Disposition");
|
||||
|
||||
if (disposition != null) {
|
||||
// extracts file name from header field
|
||||
int index = disposition.indexOf("filename=");
|
||||
if (index > 0) {
|
||||
fileName = disposition.substring(index + 10,
|
||||
disposition.length() - 1);
|
||||
}
|
||||
} else {
|
||||
// extracts file name from URL
|
||||
fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1,
|
||||
downloadUrl.length());
|
||||
}
|
||||
// opens input stream from the HTTP connection
|
||||
InputStream inputStream;
|
||||
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
inputStream = httpsURLConnection.getInputStream();
|
||||
}else{
|
||||
inputStream = httpsURLConnection.getErrorStream();
|
||||
}
|
||||
File saveDir = context.getCacheDir();
|
||||
final String saveFilePath = saveDir + File.separator + fileName;
|
||||
|
||||
// opens an output stream to save into file
|
||||
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
|
||||
|
||||
int bytesRead;
|
||||
byte[] buffer = new byte[CHUNK_SIZE];
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
if(context instanceof AppCompatActivity)
|
||||
((AppCompatActivity)context).runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
imageLoader.displayImage("file://"+saveFilePath, imageView, options);
|
||||
}});
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.SET_PICTURE_URL + Helper.md5(downloadUrl), Helper.dateToString(context, new Date() )+ "|" +"file://"+saveFilePath);
|
||||
editor.apply();
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
httpsURLConnection.disconnect();
|
||||
} catch (Exception e) {
|
||||
Error error = new Error();
|
||||
error.setError(context.getString(R.string.toast_error));
|
||||
if(httpsURLConnection != null)
|
||||
httpsURLConnection.disconnect();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void upload(final InputStream inputStream, final OnRetrieveAttachmentInterface listener) {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
|
|
@ -50,9 +50,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -72,7 +70,6 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.HttpsConnection;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface;
|
||||
|
@ -684,21 +681,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
|
||||
//Profile picture
|
||||
imageLoader.displayImage(notification.getAccount().getAvatar(), holder.notification_account_profile, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
new HttpsConnection(context).download(notification.getAccount().getAvatar(), holder.notification_account_profile, options);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(notification.getAccount().getAvatar(), holder.notification_account_profile, options);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -613,55 +613,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
|
||||
if( status.getReblog() != null) {
|
||||
imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
new HttpsConnection(context).download(ppurl, holder.status_account_profile_boost, options);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
new HttpsConnection(context).download(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options);
|
||||
imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options);
|
||||
holder.status_account_profile_boost.setVisibility(View.VISIBLE);
|
||||
holder.status_account_profile_boost_by.setVisibility(View.VISIBLE);
|
||||
holder.status_account_profile.setVisibility(View.GONE);
|
||||
}else{
|
||||
imageLoader.displayImage(ppurl, holder.status_account_profile, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
new HttpsConnection(context).download(ppurl, holder.status_account_profile, options);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
}
|
||||
});
|
||||
imageLoader.displayImage(ppurl, holder.status_account_profile, options);
|
||||
holder.status_account_profile_boost.setVisibility(View.GONE);
|
||||
holder.status_account_profile_boost_by.setVisibility(View.GONE);
|
||||
holder.status_account_profile.setVisibility(View.VISIBLE);
|
||||
|
|
Loading…
Reference in New Issue