Skip to content

Comments

Add share button#61

Merged
uhooi merged 14 commits intodevelopfrom
feature/add_share
Oct 4, 2020
Merged

Add share button#61
uhooi merged 14 commits intodevelopfrom
feature/add_share

Conversation

@uhooi
Copy link
Owner

@uhooi uhooi commented Sep 29, 2020

Overview

モンスター詳細画面のアクションバーに共有ボタンを追加した。
Twitterなどのアプリにモンスターの画像とテキストを共有できる。

Issue

Screenshots

Before After
monsterDetail-light monsterDetail-light

スクリーンショット 2020-10-04 12 42 40

Implementation details

iOSと異なり、画像を共有するには一時フォルダに保存する必要があるため、以下の手順を踏んでいる。

  1. Coilを使い、モンスターの画像をURLから Drawable 型で取得する
  2. DrawableBitmap 型に変換する
  3. Bitmap をPNGファイルに変換し、外部ストレージのキャッシュフォルダへ保存する
  4. PNGファイルのURIを取得し、それをストリームにセットして共有する

References

@uhooi uhooi self-assigned this Sep 29, 2020
Copy link
Contributor

@rmakiyama rmakiyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uhooi
Copy link
Owner Author

uhooi commented Sep 30, 2020

別途ツイートで見たもので ShareCompat の使い方はいかが参考になりそうなのでコメントを残しておきます!
https://github.com/google/iosched/blob/b428d2be4bb96bd423e47cb709c906ce5d02150f/mobile/src/main/java/com/google/samples/apps/iosched/ui/sessiondetail/SessionDetailFragment.kt#L129-L133

ありがとうございます!
こちらのコードのおかげでシェアシート(正式名称がわからない)を表示することができました。
51cc5cb

ただ特定のフラグメントのみに共有ボタンを表示できていないので、もう少し調べてみます。
おそらくリスナー的な仕組みを使うのだと予想しています。

@uhooi
Copy link
Owner Author

uhooi commented Sep 30, 2020

ただ特定のフラグメントのみに共有ボタンを表示できていないので、もう少し調べてみます。
おそらくリスナー的な仕組みを使うのだと予想しています。

できました!
アクティビティでなくフラグメントに onCreateOptionsMenu() メソッドを実装すればいいだけでした笑
73f454c

@uhooi uhooi merged commit b0ef1fb into develop Oct 4, 2020
@uhooi uhooi deleted the feature/add_share branch October 4, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add share button

2 participants