Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Make "share" button more meaningful: share an article title.
Browse files Browse the repository at this point in the history
  • Loading branch information
gshadows committed Jul 15, 2018
1 parent 6574cff commit 6215ca4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class ArticleDetailActivity extends AppCompatActivity
private ViewPager mPager;
private MyPagerAdapter mPagerAdapter;
private ImageView mPhotoView;

private String mCurrentPhotoUrl;
private int mCurrentPage;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -79,9 +82,10 @@ public void onPageSelected(int position) {
findViewById(R.id.share_fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ((mCursor == null) || !mCursor.moveToPosition(mCurrentPage)) return;
startActivity(Intent.createChooser(ShareCompat.IntentBuilder.from(ArticleDetailActivity.this)
.setType("text/plain")
.setText("Some sample text")
.setText(getString(R.string.share_prefix) + mCursor.getString(ArticleLoader.Query.TITLE))
.getIntent(), getString(R.string.action_share)));
}
});
Expand Down Expand Up @@ -127,8 +131,6 @@ public void onLoaderReset(Loader<Cursor> cursorLoader) {
mPagerAdapter.notifyDataSetChanged();
}

private String mCurrentPhotoUrl;

public void onUpdatePhoto (@NonNull String url, @NonNull Bitmap bitmap) {
if (!url.equals(mCurrentPhotoUrl)) return;
if (bitmap == null) return;
Expand All @@ -147,6 +149,7 @@ public MyPagerAdapter(FragmentManager fm) {
public void setPrimaryItem (ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
if (mCursor == null) return;
mCurrentPage = position;
mCursor.moveToPosition(position);
mCurrentPhotoUrl = mCursor.getString(ArticleLoader.Query.PHOTO_URL);
if (object != null) {
Expand Down
1 change: 1 addition & 0 deletions XYZReader/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<string name="action_share">Share</string>

<string name="photo_desc">Article title photo</string>
<string name="share_prefix">Now reading a great article!\n</string>

</resources>

0 comments on commit 6215ca4

Please sign in to comment.