cleanup horrible code in displayImageCaption
This commit is contained in:
parent
69e6844711
commit
729209f1f5
@ -223,12 +223,7 @@ public class ArticleFragment extends Fragment {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
try {
|
||||
URL url = new URL(m_article.link.trim());
|
||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||
|
||||
m_activity.openUri(Uri.parse(uri));
|
||||
|
||||
m_activity.openUri(Uri.parse(m_article.link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
m_activity.toast(R.string.error_other_error);
|
||||
@ -262,11 +257,7 @@ public class ArticleFragment extends Fragment {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
URL url = new URL(m_article.link.trim());
|
||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||
|
||||
m_activity.openUri(Uri.parse(uri));
|
||||
m_activity.openUri(Uri.parse(m_article.link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
m_activity.toast(R.string.error_other_error);
|
||||
@ -274,7 +265,6 @@ public class ArticleFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
registerForContextMenu(title);
|
||||
}
|
||||
|
||||
ImageView share = (ImageView)view.findViewById(R.id.share);
|
||||
@ -301,12 +291,10 @@ public class ArticleFragment extends Fragment {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
URL url = new URL((m_article.comments_link != null && m_article.comments_link.length() > 0) ?
|
||||
m_article.comments_link : m_article.link);
|
||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||
String url = (m_article.comments_link != null && m_article.comments_link.length() > 0) ?
|
||||
m_article.comments_link : m_article.link;
|
||||
|
||||
m_activity.openUri(Uri.parse(uri));
|
||||
m_activity.openUri(Uri.parse(url));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
m_activity.toast(R.string.error_other_error);
|
||||
|
@ -355,24 +355,21 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
|
||||
Elements es = doc.getElementsByAttributeValue("src", url);
|
||||
if (es.size() > 0) {
|
||||
if (es.get(0).hasAttr("title")) {
|
||||
Dialog dia = new Dialog(this);
|
||||
if (es.get(0).hasAttr("alt")) {
|
||||
dia.setTitle(es.get(0).attr("alt"));
|
||||
} else {
|
||||
dia.setTitle(es.get(0).attr("title"));
|
||||
}
|
||||
TextView titleText = new TextView(this);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||
titleText.setPaddingRelative(24, 24, 24, 24);
|
||||
} else {
|
||||
titleText.setPadding(24, 24, 24, 24);
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setMessage(es.get(0).attr("title"))
|
||||
.setPositiveButton(R.string.dialog_close, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
||||
titleText.setTextSize(16);
|
||||
titleText.setText(es.get(0).attr("title"));
|
||||
dia.setContentView(titleText);
|
||||
dia.show();
|
||||
} else {
|
||||
toast(R.string.no_caption_to_display);
|
||||
}
|
||||
|
@ -117,39 +117,8 @@ public class OfflineActivity extends CommonActivity {
|
||||
content = article.getString(article.getColumnIndex("content"));
|
||||
article.close();
|
||||
}
|
||||
|
||||
// Android doesn't give us an easy way to access title tags;
|
||||
// we'll use Jsoup on the body text to grab the title text
|
||||
// from the first image tag with this url. This will show
|
||||
// the wrong text if an image is used multiple times.
|
||||
Document doc = Jsoup.parse(content);
|
||||
Elements es = doc.getElementsByAttributeValue("src", getLastContentImageHitTestUrl());
|
||||
if (es.size() > 0){
|
||||
if (es.get(0).hasAttr("title")){
|
||||
Dialog dia = new Dialog(this);
|
||||
if (es.get(0).hasAttr("alt")){
|
||||
dia.setTitle(es.get(0).attr("alt"));
|
||||
} else {
|
||||
dia.setTitle(es.get(0).attr("title"));
|
||||
}
|
||||
TextView titleText = new TextView(this);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||
titleText.setPaddingRelative(24, 24, 24, 24);
|
||||
} else {
|
||||
titleText.setPadding(24, 24, 24, 24);
|
||||
}
|
||||
|
||||
titleText.setTextSize(16);
|
||||
titleText.setText(es.get(0).attr("title"));
|
||||
dia.setContentView(titleText);
|
||||
dia.show();
|
||||
} else {
|
||||
toast(R.string.no_caption_to_display);
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_caption_to_display);
|
||||
}
|
||||
|
||||
displayImageCaption(getLastContentImageHitTestUrl(), content);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
|
@ -203,19 +203,14 @@ public class OfflineArticleFragment extends Fragment {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
URL url = new URL(link.trim());
|
||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||
|
||||
m_activity.openUri(Uri.parse(uri));
|
||||
m_activity.openUri(Uri.parse(link));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
m_activity.toast(R.string.error_other_error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
registerForContextMenu(title);
|
||||
|
||||
}
|
||||
|
||||
ImageView share = (ImageView)view.findViewById(R.id.share);
|
||||
|
Loading…
Reference in New Issue
Block a user