Fix issue #825
This commit is contained in:
parent
d8fe5f11af
commit
5bf074b8db
|
@ -98,6 +98,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
@ -215,6 +216,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
||||||
private RelativeLayout loader;
|
private RelativeLayout loader;
|
||||||
private String contentType;
|
private String contentType;
|
||||||
private int max_media_count;
|
private int max_media_count;
|
||||||
|
public static HashMap<String, Uri> filesMap;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -243,7 +245,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
||||||
}else {
|
}else {
|
||||||
style = R.style.Dialog;
|
style = R.style.Dialog;
|
||||||
}
|
}
|
||||||
|
filesMap = new HashMap<>();
|
||||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
||||||
max_media_count = 9999;
|
max_media_count = 9999;
|
||||||
}else{
|
}else{
|
||||||
|
@ -934,6 +936,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
||||||
toot_picture.setEnabled(false);
|
toot_picture.setEnabled(false);
|
||||||
toot_it.setEnabled(false);
|
toot_it.setEnabled(false);
|
||||||
String filename = Helper.getFileName(this.activityWeakReference.get(), uriFile);
|
String filename = Helper.getFileName(this.activityWeakReference.get(), uriFile);
|
||||||
|
filesMap.put(filename, uriFile);
|
||||||
new HttpsConnection(this.activityWeakReference.get()).upload(bs, filename, accountReply != null ? accountReply.getToken() : null, (TootActivity) this.activityWeakReference.get());
|
new HttpsConnection(this.activityWeakReference.get()).upload(bs, filename, accountReply != null ? accountReply.getToken() : null, (TootActivity) this.activityWeakReference.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1602,7 +1605,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRetrieveAttachment(final Attachment attachment, Error error) {
|
public void onRetrieveAttachment(final Attachment attachment, String fileName, Error error) {
|
||||||
if( error != null || attachment == null){
|
if( error != null || attachment == null){
|
||||||
if( error != null)
|
if( error != null)
|
||||||
Toasty.error(getApplicationContext(), error.getError(), Toast.LENGTH_LONG).show();
|
Toasty.error(getApplicationContext(), error.getError(), Toast.LENGTH_LONG).show();
|
||||||
|
@ -1629,18 +1632,39 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
||||||
String url = attachment.getPreview_url();
|
String url = attachment.getPreview_url();
|
||||||
if (url == null || url.trim().equals(""))
|
if (url == null || url.trim().equals(""))
|
||||||
url = attachment.getUrl();
|
url = attachment.getUrl();
|
||||||
|
|
||||||
|
|
||||||
final ImageView imageView = new ImageView(getApplicationContext());
|
final ImageView imageView = new ImageView(getApplicationContext());
|
||||||
imageView.setId(Integer.parseInt(attachment.getId()));
|
imageView.setId(Integer.parseInt(attachment.getId()));
|
||||||
|
|
||||||
Glide.with(imageView.getContext())
|
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
|
||||||
.asBitmap()
|
if( fileName != null && filesMap.containsKey(fileName)){
|
||||||
.load(url)
|
Uri uri = filesMap.get(fileName);
|
||||||
.into(new SimpleTarget<Bitmap>() {
|
Glide.with(imageView.getContext())
|
||||||
@Override
|
.asBitmap()
|
||||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
.load(uri)
|
||||||
imageView.setImageBitmap(resource);
|
.into(new SimpleTarget<Bitmap>() {
|
||||||
}
|
@Override
|
||||||
});
|
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||||
|
imageView.setImageBitmap(resource);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
Glide.with(imageView.getContext())
|
||||||
|
.asBitmap()
|
||||||
|
.load(url)
|
||||||
|
.into(new SimpleTarget<Bitmap>() {
|
||||||
|
@Override
|
||||||
|
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||||
|
imageView.setImageBitmap(resource);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
||||||
imParams.setMargins(20, 5, 20, 5);
|
imParams.setMargins(20, 5, 20, 5);
|
||||||
imParams.height = (int) Helper.convertDpToPixel(100, getApplicationContext());
|
imParams.height = (int) Helper.convertDpToPixel(100, getApplicationContext());
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class UpdateDescriptionAttachmentAsyncTask extends AsyncTask<Void, Void,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
listener.onRetrieveAttachment(attachment, api.getError());
|
listener.onRetrieveAttachment(attachment, null, api.getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ public class HttpsConnection {
|
||||||
|
|
||||||
((TootActivity) context).runOnUiThread(new Runnable() {
|
((TootActivity) context).runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onRetrieveAttachment(attachment, null);
|
listener.onRetrieveAttachment(attachment, fileName,null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1276,7 +1276,7 @@ public class HttpsConnection {
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) { }
|
||||||
((TootActivity) context).runOnUiThread(new Runnable() {
|
((TootActivity) context).runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onRetrieveAttachment(null, error);
|
listener.onRetrieveAttachment(null, fileName, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1420,7 +1420,7 @@ public class HttpsConnection {
|
||||||
|
|
||||||
((TootActivity)context).runOnUiThread(new Runnable() {
|
((TootActivity)context).runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onRetrieveAttachment(attachment, null);
|
listener.onRetrieveAttachment(attachment, fileName,null);
|
||||||
}});
|
}});
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
((TootActivity)context).runOnUiThread(new Runnable() {
|
((TootActivity)context).runOnUiThread(new Runnable() {
|
||||||
|
@ -1435,7 +1435,7 @@ public class HttpsConnection {
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) { }
|
||||||
((TootActivity)context).runOnUiThread(new Runnable() {
|
((TootActivity)context).runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
listener.onRetrieveAttachment(null, error);
|
listener.onRetrieveAttachment(null, fileName,error);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||||
* Interface when an attachment has been retrieved
|
* Interface when an attachment has been retrieved
|
||||||
*/
|
*/
|
||||||
public interface OnRetrieveAttachmentInterface {
|
public interface OnRetrieveAttachmentInterface {
|
||||||
void onRetrieveAttachment(Attachment attachment, Error error);
|
void onRetrieveAttachment(Attachment attachment, String fileName, Error error);
|
||||||
void onUpdateProgress(int progress);
|
void onUpdateProgress(int progress);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue