Improve media import from wysiwyg

This commit is contained in:
tom79 2019-07-21 19:00:22 +02:00
parent fad9f3708c
commit 6703b5f061
2 changed files with 18 additions and 11 deletions

View File

@ -1238,7 +1238,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
}
}else if (requestCode == wysiwyg.PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK && data != null && data.getData() != null) {
String filename = Helper.getFileName(TootActivity.this, data.getData());
upload(TootActivity.this, data.getData(), filename);
upload(TootActivity.this, data.getData(), "fedilabins_"+filename);
}
}
@ -1337,7 +1337,16 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
imageView.setImageBitmap(resource);
if( displayWYSIWYG()) {
url_for_media = finalUrl;
wysiwyg.insertImage(resource);
Iterator it = filesMap.entrySet().iterator();
String fileName = null;
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
fileName = (String) pair.getKey();
it.remove();
}
if( fileName != null && fileName.toString().contains("fedilabins_")) {
wysiwyg.insertImage(resource);
}
}
}
});
@ -2813,8 +2822,14 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
String suffix = "";
if(suffixPosition > 0) suffix = filename.substring(suffixPosition);
try {
File file;
tempInput = getContentResolver().openInputStream(inUri);
File file = File.createTempFile("randomTemp1", suffix, getCacheDir());
if( fname.startsWith("fedilabins_")){
file = File.createTempFile("fedilabins_randomTemp1", suffix, getCacheDir());
}else{
file = File.createTempFile("randomTemp1", suffix, getCacheDir());
}
filesMap.put(file.getAbsolutePath(), inUri);
tempOut = new FileOutputStream(file.getAbsoluteFile());
byte[] buff = new byte[1024];

View File

@ -37,9 +37,7 @@ import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.style.QuoteSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
@ -637,8 +635,6 @@ public class Status implements Parcelable{
if( valArray.length > 1 ){
String contentOriginal = valArray[0];
String url = valArray[1];
Log.v(Helper.TAG,"contentOriginal: " + contentOriginal);
Log.v(Helper.TAG,"url: " + url);
Glide.with(context)
.asBitmap()
.load(url)
@ -646,14 +642,10 @@ public class Status implements Parcelable{
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
final String targetedEmoji = contentOriginal;
Log.v(Helper.TAG,"contentSpan.toString(): " + spannableStringContent.toString());
if (spannableStringContent != null && spannableStringContent.toString().contains(targetedEmoji)) {
//emojis can be used several times so we have to loop
Log.v(Helper.TAG,"ok: " + spannableStringContent.toString());
for (int startPosition = -1; (startPosition = spannableStringContent.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
final int endPosition = startPosition + targetedEmoji.length();
Log.v(Helper.TAG,"startPosition: " + startPosition);
Log.v(Helper.TAG,"endPosition: " + endPosition);
if( endPosition <= spannableStringContent.toString().length() && endPosition >= startPosition) {
spannableStringContent.setSpan(
new ImageSpan(context,