Stop adding link info when composing toot (#418)
This commit is contained in:
parent
ccc2efcca1
commit
df4dfa7766
|
@ -32,11 +32,6 @@ android {
|
|||
lintOptions {
|
||||
disable 'MissingTranslation'
|
||||
}
|
||||
packagingOptions { //remove metadata files of jsoup library from final build
|
||||
exclude 'META-INF/CHANGES'
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/README.md'
|
||||
}
|
||||
}
|
||||
|
||||
ext.supportLibraryVersion = '26.1.0'
|
||||
|
@ -62,7 +57,6 @@ dependencies {
|
|||
compile "com.github.chrisbanes:PhotoView:2.1.3"
|
||||
compile "com.mikepenz:google-material-typeface:3.0.1.0.original@aar"
|
||||
compile "com.theartofdev.edmodo:android-image-cropper:2.5.1"
|
||||
compile "org.jsoup:jsoup:1.10.3"
|
||||
|
||||
//room
|
||||
compile "android.arch.persistence.room:runtime:1.0.0-rc1"
|
||||
|
|
|
@ -58,8 +58,3 @@
|
|||
public static *** v(...);
|
||||
public static *** i(...);
|
||||
}
|
||||
|
||||
# for jsoup
|
||||
-keep public class org.jsoup.** {
|
||||
public *;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ import com.keylesspalace.tusky.util.IOUtils;
|
|||
import com.keylesspalace.tusky.util.ListUtils;
|
||||
import com.keylesspalace.tusky.util.MediaUtils;
|
||||
import com.keylesspalace.tusky.util.MentionTokenizer;
|
||||
import com.keylesspalace.tusky.util.ParserUtils;
|
||||
import com.keylesspalace.tusky.util.SpanUtils;
|
||||
import com.keylesspalace.tusky.util.StringUtils;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
|
@ -122,7 +121,7 @@ import retrofit2.Call;
|
|||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ComposeActivity extends BaseActivity implements ComposeOptionsFragment.Listener, ParserUtils.ParserListener {
|
||||
public class ComposeActivity extends BaseActivity implements ComposeOptionsFragment.Listener {
|
||||
private static final String TAG = "ComposeActivity"; // logging tag
|
||||
private static final int STATUS_CHARACTER_LIMIT = 500;
|
||||
private static final int STATUS_MEDIA_SIZE_LIMIT = 8388608; // 8MiB
|
||||
|
@ -340,8 +339,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
updateHideMediaToggleColor();
|
||||
updateVisibleCharactersLeft();
|
||||
|
||||
final ParserUtils parser = new ParserUtils(this);
|
||||
|
||||
// Setup the main text field.
|
||||
setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" }
|
||||
final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
|
||||
|
@ -362,13 +359,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
}
|
||||
});
|
||||
|
||||
textEditor.addOnPasteListener(new EditTextTyped.OnPasteListener() {
|
||||
@Override
|
||||
public void onPaste() {
|
||||
parser.getPastedURLText(ComposeActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
textEditor.setAdapter(new MentionAutoCompleteAdapter(this, R.layout.item_autocomplete));
|
||||
textEditor.setTokenizer(new MentionTokenizer());
|
||||
|
||||
|
@ -463,9 +453,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
int left = Math.min(start, end);
|
||||
int right = Math.max(start, end);
|
||||
textEditor.getText().replace(left, right, text, 0, text.length());
|
||||
|
||||
parser.putInClipboardManager(this, text);
|
||||
textEditor.onPaste();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1502,49 +1489,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveHeaderInfo(ParserUtils.HeaderInfo headerInfo) {
|
||||
if (!TextUtils.isEmpty(headerInfo.title)) {
|
||||
Editable text = textEditor.getText();
|
||||
int index = text.toString().indexOf(headerInfo.baseUrl);
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
text.insert(index, headerInfo.title + StringUtils.carriageReturn);
|
||||
}
|
||||
if (!TextUtils.isEmpty(headerInfo.image)) {
|
||||
Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
|
||||
builder.listener(new Picasso.Listener() {
|
||||
@Override
|
||||
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
target = MediaUtils.picassoImageTarget(ComposeActivity.this, new MediaUtils.MediaListener() {
|
||||
@Override
|
||||
public void onCallback(final Uri headerInfo) {
|
||||
if (headerInfo != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long mediaSize = MediaUtils.getMediaSize(getContentResolver(),
|
||||
headerInfo);
|
||||
pickMedia(headerInfo, mediaSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Picasso.with(this).load(headerInfo.image).into(target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onErrorHeaderInfo() {
|
||||
displayTransientError(R.string.error_generic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a synchronous search request for accounts fulfilling the given partial mention text.
|
||||
*/
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
package com.keylesspalace.tusky.util;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.helper.HttpConnection;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.keylesspalace.tusky.util.StringUtils.QUOTE;
|
||||
|
||||
/**
|
||||
* Inspect and get the information from a URL.
|
||||
*/
|
||||
public class ParserUtils {
|
||||
private static final String TAG = "ParserUtils";
|
||||
private ParserListener parserListener;
|
||||
|
||||
public ParserUtils(ParserListener parserListener) {
|
||||
this.parserListener = parserListener;
|
||||
}
|
||||
|
||||
// ComposeActivity : EditText inside the onTextChanged
|
||||
public void getPastedURLText(Context context) {
|
||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
String pasteData;
|
||||
if (clipboard.hasPrimaryClip()) {
|
||||
// get what is in the clipboard
|
||||
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
|
||||
pasteData = item.getText().toString();
|
||||
|
||||
// If we share with an app, it's not only an url
|
||||
List<String> strings = StringUtils.extractUrl(pasteData);
|
||||
if (strings.size() > 0) {
|
||||
String url = strings.get(0); // we assume that the first url is the good one
|
||||
if (URLUtil.isValidUrl(url)) {
|
||||
new ThreadHeaderInfo().execute(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void putInClipboardManager(Context context, String string) {
|
||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("", string);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
|
||||
/** parse the HTML page */
|
||||
private HeaderInfo parsePageHeaderInfo(String urlStr) throws Exception {
|
||||
Connection con = Jsoup.connect(urlStr);
|
||||
HeaderInfo headerInfo = new HeaderInfo();
|
||||
con.userAgent(HttpConnection.DEFAULT_UA);
|
||||
Document doc = con.get();
|
||||
|
||||
// get info
|
||||
String text;
|
||||
Elements metaOgTitle = doc.select("meta[property=og:title]");
|
||||
if (metaOgTitle != null) {
|
||||
text = metaOgTitle.attr("content");
|
||||
} else {
|
||||
text = doc.title();
|
||||
}
|
||||
|
||||
String imageUrl = null;
|
||||
Elements metaOgImage = doc.select("meta[property=og:image]");
|
||||
if (metaOgImage != null) {
|
||||
imageUrl = metaOgImage.attr("content");
|
||||
}
|
||||
|
||||
// set info
|
||||
headerInfo.baseUrl = urlStr;
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
headerInfo.title = QUOTE + text + QUOTE;
|
||||
}
|
||||
if (!TextUtils.isEmpty(imageUrl)) {
|
||||
headerInfo.image = (imageUrl);
|
||||
}
|
||||
return headerInfo;
|
||||
}
|
||||
|
||||
public interface ParserListener {
|
||||
void onReceiveHeaderInfo(HeaderInfo headerInfo);
|
||||
|
||||
void onErrorHeaderInfo();
|
||||
}
|
||||
|
||||
public class HeaderInfo {
|
||||
public String baseUrl;
|
||||
public String title;
|
||||
public String image;
|
||||
}
|
||||
|
||||
private class ThreadHeaderInfo extends AsyncTask<String, Void, HeaderInfo> {
|
||||
protected HeaderInfo doInBackground(String... urls) {
|
||||
try {
|
||||
String url = urls[0];
|
||||
return parsePageHeaderInfo(url);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "ThreadHeaderInfo#parsePageHeaderInfo() failed." + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(HeaderInfo headerInfo) {
|
||||
if (headerInfo != null) {
|
||||
Log.i(TAG, "ThreadHeaderInfo#parsePageHeaderInfo() success." + headerInfo.title + " " + headerInfo.image);
|
||||
parserListener.onReceiveHeaderInfo(headerInfo);
|
||||
} else {
|
||||
parserListener.onErrorHeaderInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||
|
@ -14,6 +15,7 @@ allprojects {
|
|||
jcenter()
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url 'https://maven.google.com' }
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue