unify sharing code

This commit is contained in:
Andrew Dolgov 2015-12-01 23:10:18 +03:00
parent d4f355fc79
commit f6ee9be9a4
6 changed files with 29 additions and 64 deletions

View File

@ -401,12 +401,7 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
return true;
case R.id.article_img_share:
if (url != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(intent, url));
shareText(url);
}
return true;
// TODO: this needs access to article text, I'm afraid

View File

@ -243,6 +243,26 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
}
}
protected Intent getShareIntent(String text, String subject) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
if (subject != null) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
}
return shareIntent;
}
protected void shareText(String text) {
startActivity(getShareIntent(text, null));
}
protected void shareText(String text, String subject) {
startActivity(getShareIntent(text, subject));
}
private void openUriWithCustomTab(Uri uri) {
if (m_customTabClient != null) {
TypedValue tvBackground = new TypedValue();
@ -255,9 +275,7 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
builder.setToolbarColor(tvBackground.data);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, uri.toString());
Intent shareIntent = getShareIntent(uri.toString(), null);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
CommonActivity.PENDING_INTENT_CHROME_SHARE, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -546,12 +546,7 @@ public class OnlineActivity extends CommonActivity {
return true;
case R.id.article_img_share:
if (getLastContentImageHitTestUrl() != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_TEXT, getLastContentImageHitTestUrl());
startActivity(Intent.createChooser(intent, getLastContentImageHitTestUrl()));
shareText(getLastContentImageHitTestUrl());
}
return true;
case R.id.article_img_view_caption:
@ -1328,35 +1323,12 @@ public class OnlineActivity extends CommonActivity {
return tmp.replaceAll(",$", "");
}
public void shareText(String text) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, text));
}
public void shareArticle(Article article) {
if (article != null) {
Intent intent = getShareIntent(article);
startActivity(Intent.createChooser(intent,
getString(R.string.share_article)));
shareText(article.link, article.title);
}
}
protected Intent getShareIntent(Article article) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, article.link);
return intent;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (m_prefs.getBoolean("use_volume_keys", false)) {

View File

@ -238,12 +238,7 @@ public class VideoPlayerActivity extends CommonActivity {
return true;
case R.id.article_vid_share:
if (m_streamUri != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, m_streamUri);
startActivity(Intent.createChooser(intent, m_streamUri));
shareText(m_streamUri);
}
return true;
default:

View File

@ -112,12 +112,7 @@ public class YoutubePlayerActivity extends CommonActivity implements YouTubePlay
return true;
case R.id.article_vid_share:
if (m_streamUri != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, m_streamUri);
startActivity(Intent.createChooser(intent, m_streamUri));
shareText(m_streamUri);
}
return true;
default:

View File

@ -97,12 +97,7 @@ public class OfflineActivity extends CommonActivity {
return true;
case R.id.article_img_share:
if (getLastContentImageHitTestUrl() != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, getLastContentImageHitTestUrl());
startActivity(Intent.createChooser(intent, getLastContentImageHitTestUrl()));
shareText(getLastContentImageHitTestUrl());
}
return true;
case R.id.article_img_view_caption:
@ -665,13 +660,8 @@ public class OfflineActivity extends CommonActivity {
if (article != null) {
String title = article.getString(article.getColumnIndex("title"));
String link = article.getString(article.getColumnIndex("link"));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, link);
return intent;
return getShareIntent(link, title);
} else {
return null;
}