mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Clean HTML from RSS feeds with Jsoup and show Link Warning
This commit is contained in:
73
briar-android/res/layout/fragment_link_dialog.xml
Normal file
73
briar-android/res/layout/fragment_link_dialog.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/margin_large">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/link_warning_title"
|
||||
android:textColor="@color/briar_primary"
|
||||
android:textSize="@dimen/text_size_large"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:text="@string/link_warning_intro"
|
||||
android:textColor="@color/briar_primary"
|
||||
android:textSize="@dimen/text_size_medium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/urlView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:textIsSelectable="true"
|
||||
android:typeface="monospace"
|
||||
tools:text="http://very.bad.site.com"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:text="@string/link_warning_text"
|
||||
android:textColor="@color/briar_primary"
|
||||
android:textSize="@dimen/text_size_medium"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
style="@style/BriarButtonFlat.Positive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/cancel"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/openButton"
|
||||
style="@style/BriarButtonFlat.Negative"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/link_warning_open_link"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -308,6 +308,12 @@
|
||||
<string name="feedback_settings_title">Feedback</string>
|
||||
<string name="send_feedback">Send feedback</string>
|
||||
|
||||
<!-- Link Warning -->
|
||||
<string name="link_warning_title">Link Warning</string>
|
||||
<string name="link_warning_intro">You are about to open the following link with an external app.</string>
|
||||
<string name="link_warning_text">This can be used to identify you. Think about whether you trust the person that sent you this link and consider opening it with Orfox.</string>
|
||||
<string name="link_warning_open_link">Open Link</string>
|
||||
|
||||
<!-- Multiple Identities -->
|
||||
<string name="anonymous">Anonymous</string>
|
||||
<string name="new_identity_title">New Identity</string>
|
||||
|
||||
@@ -30,6 +30,8 @@ import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
import static org.briarproject.android.blogs.BasePostPagerFragment.POST_ID;
|
||||
import static org.briarproject.android.util.AndroidUtils.TEASER_LENGTH;
|
||||
import static org.briarproject.android.util.AndroidUtils.getTeaser;
|
||||
import static org.briarproject.android.util.AndroidUtils.getSpanned;
|
||||
import static org.briarproject.android.util.AndroidUtils.makeLinksClickable;
|
||||
import static org.briarproject.api.blogs.MessageType.POST;
|
||||
|
||||
@UiThread
|
||||
@@ -108,15 +110,17 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
}
|
||||
|
||||
// post body
|
||||
CharSequence bodyText = item.getBody();
|
||||
if (listener == null) {
|
||||
body.setText(getSpanned(item.getBody()));
|
||||
makeLinksClickable(body);
|
||||
body.setTextIsSelectable(true);
|
||||
} else {
|
||||
body.setTextIsSelectable(false);
|
||||
if (item.getBody().length() > TEASER_LENGTH)
|
||||
bodyText = getTeaser(ctx, item.getBody());
|
||||
body.setText(getTeaser(ctx, item.getBody()));
|
||||
else
|
||||
body.setText(item.getBody());
|
||||
}
|
||||
body.setText(bodyText);
|
||||
|
||||
// reblog button
|
||||
reblogButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@@ -6,14 +6,24 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Html;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.widget.LinkDialogFragment;
|
||||
import org.briarproject.util.IoUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
@@ -142,4 +152,31 @@ public class AndroidUtils {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static Spanned getSpanned(String s) {
|
||||
return Html.fromHtml(s);
|
||||
}
|
||||
|
||||
public static void makeLinksClickable(TextView v) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
|
||||
URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
|
||||
for (URLSpan span : spans) {
|
||||
int start = ssb.getSpanStart(span);
|
||||
int end = ssb.getSpanEnd(span);
|
||||
final String url = span.getURL();
|
||||
ssb.removeSpan(span);
|
||||
ClickableSpan cSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View v2) {
|
||||
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||
FragmentManager fm = ((AppCompatActivity) v2.getContext())
|
||||
.getSupportFragmentManager();
|
||||
f.show(fm, f.getUniqueTag());
|
||||
}
|
||||
};
|
||||
ssb.setSpan(cSpan, start, end, 0);
|
||||
}
|
||||
v.setText(ssb);
|
||||
v.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.briarproject.android.widget;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
|
||||
|
||||
public class LinkDialogFragment extends DialogFragment {
|
||||
|
||||
private static final String TAG = LinkDialogFragment.class.getName();
|
||||
|
||||
private String url;
|
||||
|
||||
public static LinkDialogFragment newInstance(String url) {
|
||||
LinkDialogFragment f = new LinkDialogFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("url", url);
|
||||
f.setArguments(args);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
url = getArguments().getString("url");
|
||||
|
||||
setStyle(STYLE_NO_TITLE, R.style.BriarDialogTheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_link_dialog, container,
|
||||
false);
|
||||
|
||||
TextView urlView = (TextView) v.findViewById(R.id.urlView);
|
||||
urlView.setText(url);
|
||||
|
||||
Button openButton = (Button) v.findViewById(R.id.openButton);
|
||||
openButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
startActivity(i);
|
||||
}
|
||||
});
|
||||
|
||||
Button cancelButton = (Button) v.findViewById(R.id.cancelButton);
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getDialog().cancel();
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user